Bug 425001 - Tests for bugs 400731 and 431826 rely on timers and are therefore fragile. TEST ONLY FIX.
authorJohnathan Nightingale <johnath@mozilla.com>
Tue, 21 Apr 2009 16:17:14 -0400
changeset 27585 7c4109d886248d1fdbb89389d0df8f2867453395
parent 27584 da575593579c861e0f6d30b2dbb3486f15bc7045
child 27586 08215d4a20fa931e6adeea6e2eb6534f72173509
push id6629
push userjnightingale@mozilla.com
push dateTue, 21 Apr 2009 20:19:33 +0000
treeherdermozilla-central@7c4109d88624 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs425001, 400731, 431826
milestone1.9.2a1pre
Bug 425001 - Tests for bugs 400731 and 431826 rely on timers and are therefore fragile. TEST ONLY FIX. 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();