Bug 800854 - Make browser_bug400731.js more robust by registering the DOMContentLoaded handler at the right time; r=gcp
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 12 Oct 2012 12:07:25 -0400
changeset 110244 dd2ae94d1e01ad18e38546bc2b0d1b415c91528c
parent 110243 78f0949318a5214b732aae686a645c8bc6656f02
child 110245 c7e467ada390a9bcbbfa23fc260d4b4f21d06efa
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersgcp
bugs800854, 400731
milestone19.0a1
Bug 800854 - Make browser_bug400731.js more robust by registering the DOMContentLoaded handler at the right time; r=gcp
browser/components/safebrowsing/content/test/browser_bug400731.js
--- a/browser/components/safebrowsing/content/test/browser_bug400731.js
+++ b/browser/components/safebrowsing/content/test/browser_bug400731.js
@@ -1,18 +1,27 @@
 /* Check for the intended visibility of the "Ignore this warning" text*/
 
 function test() {
   waitForExplicitFinish();
   
   gBrowser.selectedTab = gBrowser.addTab();
   
   // Navigate to malware site.  Can't use an onload listener here since
-  // error pages don't fire onload
-  window.addEventListener("DOMContentLoaded", testMalware, true);
+  // error pages don't fire onload.  Also can't register the DOMContentLoaded
+  // handler here because registering it too soon would mean that we might
+  // get it for about:blank, and not about:blocked.
+  gBrowser.addTabsProgressListener({
+    onLocationChange: function(aTab, aWebProgress, aRequest, aLocation, aFlags) {
+      if (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_ERROR_PAGE) {
+        gBrowser.removeTabsProgressListener(this);
+        window.addEventListener("DOMContentLoaded", testMalware, true);
+      }
+    }
+  });
   content.location = "http://www.mozilla.org/firefox/its-an-attack.html";
 }
 
 function testMalware() {
   window.removeEventListener("DOMContentLoaded", testMalware, true);
 
   // Confirm that "Ignore this warning" is visible - bug 422410
   var el = content.document.getElementById("ignoreWarningButton");