Update bug 529119 tests to not rely on error page titles.
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 19 Nov 2009 20:42:00 -0500
changeset 35153 720ed723568b785fba9b3ef431d4257172b26f39
parent 35152 b8c270d946974646b22c531685aa279282b74d6a
child 35154 cf145e14e35bddc6b54a08ca61279a4f91de9393
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
bugs529119
milestone1.9.3a1pre
Update bug 529119 tests to not rely on error page titles.
docshell/test/test_bug529119-1.html
docshell/test/test_bug529119-2.html
--- a/docshell/test/test_bug529119-1.html
+++ b/docshell/test/test_bug529119-1.html
@@ -12,35 +12,34 @@ SimpleTest.waitForExplicitFinish();
 
 var workingURL = "http://localhost:8888/tests/docshell/test/bug529119-window.html";
 var faultyURL = "http://some-non-existent-domain-27489274c892748217cn2384.com/";
 
 var w = null;
 var phase = 0;
 var gotWrongPageOnTryAgainClick = false;
 
-function pollForPage(expected_title, f, w)
+function pollForPage(f, w)
 {
   // Start with polling after a delay, we might mistakenly take the current page
   // as an expected one.
   window.setTimeout(function() {
-    var iterationsLeft = 20;
+    var iterationsLeft = 200;
     var int = window.setInterval(function() {
       iterationsLeft--;
-      
-      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+
+      var haveErrorPage = false;
       try {
         var title = w.document.title;
       }
       catch (ex) {
-        alert(ex);
-        return;
+        haveErrorPage = true;
       }
   
-      if (iterationsLeft == 0 || title.match(expected_title)) {
+      if (iterationsLeft == 0 || haveErrorPage) {
         window.clearInterval(int);
         f(iterationsLeft > 0);
       }
     }, 100);
   }, 1000);
 }
 
 function windowLoaded()
@@ -51,25 +50,25 @@ function windowLoaded()
     case 0:
       /* 2. We have succeededfully loaded a page, now go to a faulty URL */
       window.setTimeout(function() {
         w.location.href = faultyURL;
       }, 0);
     
       phase = 1;
 
-      pollForPage("Problem loading page", function(succeeded) {
+      pollForPage(function(succeeded) {
         ok(succeeded, "Waiting for error page succeeded");
         
         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
         /* 3. now, while we are on the error page, try to reload it, actually 
            click the "Try Again" button */
         w.location.reload();
 
-        pollForPage("Problem loading page", function(succeeded) {
+        pollForPage(function(succeeded) {
           ok(succeeded, "Waiting for error page succeeded");
           
           netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
           /* 4-finish, check we are still on the error page */
           is(w.location.href, faultyURL, "Is on an error page");
           isnot(w.location.href, workingURL, "Is not on the previous page");
           is(gotWrongPageOnTryAgainClick, false, 
             "Must not get www.example.com page on reload of an error page");
--- a/docshell/test/test_bug529119-2.html
+++ b/docshell/test/test_bug529119-2.html
@@ -11,35 +11,34 @@
 SimpleTest.waitForExplicitFinish();
 
 var workingURL = "http://localhost:8888/tests/docshell/test/bug529119-window.html";
 var faultyURL = "http://some-non-existent-domain-27489274c892748217cn2384.com/";
 
 var w = null;
 var phase = 0;
 
-function pollForPage(expected_title, f, w)
+function pollForPage(expectErrorPage, f, w)
 {
   // Start with polling after a delay, we might mistakenly take the current page
   // as an expected one.
   window.setTimeout(function() {
-    var iterationsLeft = 20;
+    var iterationsLeft = 200;
     var int = window.setInterval(function() {
       iterationsLeft--;
       
-      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+      var haveErrorPage = false;
       try {
         var title = w.document.title;
       }
       catch (ex) {
-        alert(ex);
-        return;
+        haveErrorPage = true;
       }
   
-      if (iterationsLeft == 0 || title.match(expected_title)) {
+      if (iterationsLeft == 0 || expectErrorPage == haveErrorPage) {
         window.clearInterval(int);
         f(iterationsLeft > 0);
       }
     }, 100);
   }, 1000);
 }
 
 function windowLoaded()
@@ -47,29 +46,29 @@ function windowLoaded()
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 
   /* 2. We have successfully loaded a page, now go to a faulty URL */
   // XXX The test fails when we change the location synchronously 
   window.setTimeout(function() {
     w.location.href = faultyURL;
   }, 0);
 
-  pollForPage("Problem loading page", function(succeeded) {
+  pollForPage(true, function(succeeded) {
     ok(succeeded, "Waiting for error page succeeded");
     
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     /* 3. now, while we are on the error page, navigate back */
     try {
       w.back();
     }
     catch(ex) {
       ok(false, "w.back() threw " + ex);
     }
 
-    pollForPage("Test bug 529119, sub-window", function(succeeded) {
+    pollForPage(false, function(succeeded) {
       ok(succeeded, "Waiting for original page succeeded");
       
       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       /* 4-finish, check we are back at the original page */
       isnot(w.location.href, faultyURL, "Is on an error page");
       is(w.location.href, workingURL, "Is not on the previous page");
       w.close();
       SimpleTest.finish();