Bug 425001 - Tests for bugs 400731 and 431826 rely on timers and are therefore fragile. TEST ONLY FIX. r=gavin a=beltzner
authorJohnathan Nightingale <johnath@mozilla.com>
Tue, 14 Apr 2009 10:16:48 -0400
changeset 25473 9964b0a18b289a5a2c421becf7c0902b4ccb9b4b
parent 25472 9a49d7ecebe2ebb39a42e0df2623befbb1fc55de
child 25474 fa309179bf4faf6dc40ec1e12162455def38911e
push id1457
push userjnightingale@mozilla.com
push dateTue, 19 May 2009 15:41:01 +0000
reviewersgavin, beltzner
bugs425001, 400731, 431826
milestone1.9.1b5pre
Bug 425001 - Tests for bugs 400731 and 431826 rely on timers and are therefore fragile. TEST ONLY FIX. r=gavin a=beltzner Replace with DOMContentLoaded listeners, since onload doesn't work for error pages.
browser/components/certerror/test/browser_bug431826.js
browser/components/safebrowsing/content/test/browser_bug400731.js
--- a/browser/components/certerror/test/browser_bug431826.js
+++ b/browser/components/certerror/test/browser_bug431826.js
@@ -3,42 +3,42 @@ var newBrowser
 function test() {
   waitForExplicitFinish();
   
   var newTab = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
   newBrowser = gBrowser.getBrowserForTab(newTab);
   
   // Navigate to a site with a broken cert
+  window.addEventListener("DOMContentLoaded", testBrokenCert, true);
   newBrowser.contentWindow.location = 'https://nocert.example.com/';
-  // XXX - This timer and the next should be replaced with an event
-  // handler when bug 425001 is fixed.
-  window.setTimeout(testBrokenCert, 2000);
 }
 
 function testBrokenCert() {
+  window.removeEventListener("DOMContentLoaded", testBrokenCert, true);
   
   // Confirm that we are displaying the contributed error page, not the default
   ok(/^about:certerror/.test(gBrowser.contentWindow.document.documentURI), "Broken page should go to about:certerror, not about:neterror");
   
   // Confirm that the expert section is collapsed
   var expertDiv = gBrowser.contentWindow.document.getElementById("expertContent");
   ok(expertDiv, "Expert content div should exist");
   ok(expertDiv.hasAttribute("collapsed"), "Expert content should be collapsed by default");
   
   // Tweak the expert mode pref
   Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch)
                                           .setBoolPref("browser.xul.error_pages.expert_bad_cert", true);
   
+  window.addEventListener("DOMContentLoaded", testExpertPref, true);
   newBrowser.reload();
-  window.setTimeout(testExpertPref, 2000);
 }
 
 function testExpertPref() {
   
+  window.removeEventListener("DOMContentLoaded", testExpertPref, true);
   var expertDiv = gBrowser.contentWindow.document.getElementById("expertContent");
   var technicalDiv = gBrowser.contentWindow.document.getElementById("technicalContent");
   ok(!expertDiv.hasAttribute("collapsed"), "Expert content should not be collapsed with the expert mode pref set");
   ok(!technicalDiv.hasAttribute("collapsed"), "Technical content should not be collapsed with the expert mode pref set");
   
   // Clean up
   gBrowser.removeCurrentTab();
   finish();
--- a/browser/components/safebrowsing/content/test/browser_bug400731.js
+++ b/browser/components/safebrowsing/content/test/browser_bug400731.js
@@ -5,34 +5,38 @@ function test() {
   waitForExplicitFinish();
   
   var newTab = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
   newBrowser = gBrowser.getBrowserForTab(newTab);
   
   // Navigate to malware site.  Can't use an onload listener here since
   // error pages don't fire onload
+  window.addEventListener("DOMContentLoaded", testMalware, true);
   newBrowser.contentWindow.location = 'http://www.mozilla.com/firefox/its-an-attack.html';
-  window.setTimeout(testMalware, 2000);
 }
 
 function testMalware() {
+  window.removeEventListener("DOMContentLoaded", testMalware, true);
+
   // Confirm that "Ignore this warning" is visible - bug 422410
   var el = newBrowser.contentDocument.getElementById("ignoreWarningButton");
   ok(el, "Ignore warning button should be present for malware");
   
   var style = newBrowser.contentWindow.getComputedStyle(el, null);
   is(style.display, "-moz-box", "Ignore Warning button should be display:-moz-box for malware");
   
   // Now launch the phishing test
+  window.addEventListener("DOMContentLoaded", testPhishing, true);
   newBrowser.contentWindow.location = 'http://www.mozilla.com/firefox/its-a-trap.html';
-  window.setTimeout(testPhishing, 2000);
 }
 
 function testPhishing() {
+  window.removeEventListener("DOMContentLoaded", testPhishing, true);
+  
   var el = newBrowser.contentDocument.getElementById("ignoreWarningButton");
   ok(el, "Ignore warning button should be present for phishing");
   
   var style = newBrowser.contentWindow.getComputedStyle(el, null);
   is(style.display, "-moz-box", "Ignore Warning button should be display:-moz-box for phishing");
   
   gBrowser.removeCurrentTab();
   finish();