From 1a96884ab3dae526e2a539361992c76791b12412 Mon Sep 17 00:00:00 2001 From: "Olli.Pettay%helsinki.fi" Date: Thu, 21 Feb 2008 12:47:27 +0000 Subject: [PATCH] bug 380454, r=benjamin, sr=sicking --- .../content/test/browser_autodiscovery.js | 160 ++++++++++-------- .../html/content/src/nsHTMLLinkElement.cpp | 8 +- xpcom/glue/nsThreadUtils.cpp | 2 +- xpcom/threads/nsThreadManager.cpp | 4 + xpcom/threads/nsThreadManager.h | 3 +- 5 files changed, 104 insertions(+), 73 deletions(-) diff --git a/browser/base/content/test/browser_autodiscovery.js b/browser/base/content/test/browser_autodiscovery.js index ed4628f449e..445d90a5803 100644 --- a/browser/base/content/test/browser_autodiscovery.js +++ b/browser/base/content/test/browser_autodiscovery.js @@ -13,22 +13,36 @@ function test() { setTimeout(iconDiscovery, 1000); } -function iconDiscovery() { - var tests = [ - { text: "rel icon discovered" }, - { rel: "abcdefg icon qwerty", text: "rel may contain additional rels separated by spaces" }, - { rel: "ICON", text: "rel is case insensitive" }, - { rel: "shortcut-icon", pass: false, text: "rel shortcut-icon not discovered" }, - { href: "moz.png", text: "relative href works" }, - { href: "notthere.png", text: "404'd icon is removed properly" }, - { href: "data:image/x-icon,%00", type: "image/x-icon", text: "data: URIs work" }, - { type: "image/png; charset=utf-8", text: "type may have optional parameters (RFC2046)" } - ]; +var iconDiscoveryTests = [ + { text: "rel icon discovered" }, + { rel: "abcdefg icon qwerty", text: "rel may contain additional rels separated by spaces" }, + { rel: "ICON", text: "rel is case insensitive" }, + { rel: "shortcut-icon", pass: false, text: "rel shortcut-icon not discovered" }, + { href: "moz.png", text: "relative href works" }, + { href: "notthere.png", text: "404'd icon is removed properly" }, + { href: "data:image/x-icon,%00", type: "image/x-icon", text: "data: URIs work" }, + { type: "image/png; charset=utf-8", text: "type may have optional parameters (RFC2046)" } +]; - for (let i = 0; i < tests.length; i++) { +function runIconDiscoveryTest() { + var test = iconDiscoveryTests[0]; + var head = gTestPage.document.getElementById("linkparent"); + var hasSrc = gProxyFavIcon.hasAttribute("src"); + if (test.pass) + ok(hasSrc, test.text); + else + ok(!hasSrc, test.text); + + head.removeChild(head.getElementsByTagName('link')[0]); + iconDiscoveryTests.shift(); + setTimeout(iconDiscovery, 0) // Run the next test. +} + +function iconDiscovery() { + if (iconDiscoveryTests.length) { gProxyFavIcon.removeAttribute("src"); - var test = tests[i]; + var test = iconDiscoveryTests[0]; var head = gTestPage.document.getElementById("linkparent"); var link = gTestPage.document.createElement("link"); @@ -43,45 +57,68 @@ function iconDiscovery() { link.type = type; head.appendChild(link); - var hasSrc = gProxyFavIcon.hasAttribute("src"); - if (test.pass) - ok(hasSrc, test.text); - else - ok(!hasSrc, test.text); - - head.removeChild(link); + setTimeout(runIconDiscoveryTest, 0); + } else { + searchDiscovery(); } - searchDiscovery(); +} + +var searchDiscoveryTests = [ + { text: "rel search discovered" }, + { rel: "SEARCH", text: "rel is case insensitive" }, + { rel: "-search-", pass: false, text: "rel -search- not discovered" }, + { rel: "foo bar baz search quux", text: "rel may contain additional rels separated by spaces" }, + { href: "https://not.mozilla.com", text: "HTTPS ok" }, + { href: "ftp://not.mozilla.com", text: "FTP ok" }, + { href: "data:text/foo,foo", pass: false, text: "data URI not permitted" }, + { href: "javascript:alert(0)", pass: false, text: "JS URI not permitted" }, + { type: "APPLICATION/OPENSEARCHDESCRIPTION+XML", text: "type is case insensitve" }, + { type: " application/opensearchdescription+xml ", text: "type may contain extra whitespace" }, + { type: "application/opensearchdescription+xml; charset=utf-8", text: "type may have optional parameters (RFC2046)" }, + { type: "aapplication/opensearchdescription+xml", pass: false, text: "type should not be loosely matched" }, + { rel: "search search search", count: 1, text: "only one engine should be added" } +]; + +function runSearchDiscoveryTest() { + var browser = gBrowser.getBrowserForDocument(gTestPage.document); + var test = searchDiscoveryTests[0]; + var title = test.title || searchDiscoveryTests.length; + if (browser.engines) { + var hasEngine = (test.count) ? (browser.engines[0].title == title && + browser.engines.length == test.count) : + (browser.engines[0].title == title); + ok(hasEngine, test.text); + browser.engines = null; + } + else + ok(!test.pass, test.text); + + searchDiscoveryTests.shift(); + setTimeout(searchDiscovery, 0) // Run the next test. +} + +function runMultipleEnginesTestAndFinalize() { + var browser = gBrowser.getBrowserForDocument(gTestPage.document); + ok(browser.engines, "has engines"); + is(browser.engines.length, 1, "only one engine"); + is(browser.engines[0].uri, "http://first.mozilla.com/search.xml", "first engine wins"); + + gTestPage.close(); + finish(); } function searchDiscovery() { - var tests = [ - { text: "rel search discovered" }, - { rel: "SEARCH", text: "rel is case insensitive" }, - { rel: "-search-", pass: false, text: "rel -search- not discovered" }, - { rel: "foo bar baz search quux", text: "rel may contain additional rels separated by spaces" }, - { href: "https://not.mozilla.com", text: "HTTPS ok" }, - { href: "ftp://not.mozilla.com", text: "FTP ok" }, - { href: "data:text/foo,foo", pass: false, text: "data URI not permitted" }, - { href: "javascript:alert(0)", pass: false, text: "JS URI not permitted" }, - { type: "APPLICATION/OPENSEARCHDESCRIPTION+XML", text: "type is case insensitve" }, - { type: " application/opensearchdescription+xml ", text: "type may contain extra whitespace" }, - { type: "application/opensearchdescription+xml; charset=utf-8", text: "type may have optional parameters (RFC2046)" }, - { type: "aapplication/opensearchdescription+xml", pass: false, text: "type should not be loosely matched" }, - { rel: "search search search", count: 1, text: "only one engine should be added" } - ]; - var head = gTestPage.document.getElementById("linkparent"); var browser = gBrowser.getBrowserForDocument(gTestPage.document); - for (let i = 0; i < tests.length; i++) { - var test = tests[i]; + if (searchDiscoveryTests.length) { + var test = searchDiscoveryTests[0]; var link = gTestPage.document.createElement("link"); var rel = test.rel || "search"; var href = test.href || "http://so.not.here.mozilla.com/search.xml"; var type = test.type || "application/opensearchdescription+xml"; - var title = test.title || i; + var title = test.title || searchDiscoveryTests.length; if (test.pass == undefined) test.pass = true; @@ -91,33 +128,20 @@ function searchDiscovery() { link.title = title; head.appendChild(link); - if (browser.engines) { - var hasEngine = (test.count) ? (browser.engines[0].title == title && - browser.engines.length == test.count) : - (browser.engines[0].title == title); - ok(hasEngine, test.text); - browser.engines = null; - } - else - ok(!test.pass, test.text); + setTimeout(runSearchDiscoveryTest, 0); + } else { + // Test multiple engines with the same title + var link = gTestPage.document.createElement("link"); + link.rel = "search"; + link.href = "http://first.mozilla.com/search.xml"; + link.type = "application/opensearchdescription+xml"; + link.title = "Test Engine"; + var link2 = link.cloneNode(false); + link2.href = "http://second.mozilla.com/search.xml"; + + head.appendChild(link); + head.appendChild(link2); + + setTimeout(runMultipleEnginesTestAndFinalize, 0); } - - // Test multiple engines with the same title - var link = gTestPage.document.createElement("link"); - link.rel = "search"; - link.href = "http://first.mozilla.com/search.xml"; - link.type = "application/opensearchdescription+xml"; - link.title = "Test Engine"; - var link2 = link.cloneNode(false); - link2.href = "http://second.mozilla.com/search.xml"; - - head.appendChild(link); - head.appendChild(link2); - - ok(browser.engines, "has engines"); - is(browser.engines.length, 1, "only one engine"); - is(browser.engines[0].uri, "http://first.mozilla.com/search.xml", "first engine wins"); - - gTestPage.close(); - finish(); } diff --git a/content/html/content/src/nsHTMLLinkElement.cpp b/content/html/content/src/nsHTMLLinkElement.cpp index 9d8af089e54..52299f3b9c7 100644 --- a/content/html/content/src/nsHTMLLinkElement.cpp +++ b/content/html/content/src/nsHTMLLinkElement.cpp @@ -58,6 +58,7 @@ #include "nsParserUtils.h" #include "nsContentUtils.h" #include "nsPIDOMWindow.h" +#include "nsPLDOMEvent.h" class nsHTMLLinkElement : public nsGenericHTMLElement, public nsIDOMHTMLLinkElement, @@ -273,9 +274,10 @@ nsHTMLLinkElement::CreateAndDispatchEvent(nsIDocument* aDoc, strings, eIgnoreCase) != ATTR_VALUE_NO_MATCH) return; - nsContentUtils::DispatchTrustedEvent(aDoc, - static_cast(this), - aEventName, PR_TRUE, PR_TRUE); + nsRefPtr event = new nsPLDOMEvent(this, aEventName); + if (event) { + event->PostDOMEvent(); + } } nsresult diff --git a/xpcom/glue/nsThreadUtils.cpp b/xpcom/glue/nsThreadUtils.cpp index 0ae127194d7..1bc0a60f6b7 100644 --- a/xpcom/glue/nsThreadUtils.cpp +++ b/xpcom/glue/nsThreadUtils.cpp @@ -136,7 +136,7 @@ NS_DispatchToCurrentThread(nsIRunnable *event) { #ifdef MOZILLA_INTERNAL_API nsIThread *thread = NS_GetCurrentThread(); - NS_ENSURE_STATE(thread); + if (!thread) { return NS_ERROR_UNEXPECTED; } #else nsCOMPtr thread; nsresult rv = NS_GetCurrentThread(getter_AddRefs(thread)); diff --git a/xpcom/threads/nsThreadManager.cpp b/xpcom/threads/nsThreadManager.cpp index 8bb78154e78..d06171ea488 100644 --- a/xpcom/threads/nsThreadManager.cpp +++ b/xpcom/threads/nsThreadManager.cpp @@ -200,6 +200,10 @@ nsThreadManager::GetCurrentThread() if (data) return static_cast(data); + if (!mInitialized) { + return nsnull; + } + // OK, that's fine. We'll dynamically create one :-) nsRefPtr thread = new nsThread(); if (!thread || NS_FAILED(thread->InitCurrentThread())) diff --git a/xpcom/threads/nsThreadManager.h b/xpcom/threads/nsThreadManager.h index b18f5853dff..e561f81a2ab 100644 --- a/xpcom/threads/nsThreadManager.h +++ b/xpcom/threads/nsThreadManager.h @@ -69,7 +69,8 @@ public: // method must be called when the given thread is the current thread. void UnregisterCurrentThread(nsThread *thread); - // Returns the current thread. Returns null if OOM. + // Returns the current thread. Returns null if OOM or if ThreadManager isn't + // initialized. nsThread *GetCurrentThread(); // This needs to be public in order to support static instantiation of this