Bug 416622 - "docshell navigation tests intermittently failing with NS_ERROR_XPC_BAD_OP_ON_WN_PROTO" (Tolerate partially-constructed windows) [p=hk9565@gmail.com (Adam Barth) r=bzbarsky]
authorreed@reedloden.com
Mon, 11 Feb 2008 20:35:19 -0800
changeset 11570 cba2ba655d2f07fd1f238f1fa45989875eeaee19
parent 11569 31a1454f62e259d2d97708cc2fdd0275e8d4d503
child 11571 d6000b85cbb93965c6d82b9acb75368de78674c9
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs416622
milestone1.9b4pre
Bug 416622 - "docshell navigation tests intermittently failing with NS_ERROR_XPC_BAD_OP_ON_WN_PROTO" (Tolerate partially-constructed windows) [p=hk9565@gmail.com (Adam Barth) r=bzbarsky]
docshell/test/navigation/NavigationUtils.js
docshell/test/navigation/test_bug13871.html
docshell/test/navigation/test_bug278916.html
docshell/test/navigation/test_bug279495.html
docshell/test/navigation/test_child.html
docshell/test/navigation/test_grandchild.html
docshell/test/navigation/test_not-opener.html
docshell/test/navigation/test_opener.html
docshell/test/navigation/test_sibling-matching-parent.html
docshell/test/navigation/test_sibling-off-domain.html
--- a/docshell/test/navigation/NavigationUtils.js
+++ b/docshell/test/navigation/NavigationUtils.js
@@ -204,16 +204,21 @@ function xpcWaitForFinishedFrames(callba
         frameFinished();
       }
     }
     for (var i = 0; i < win.frames.length; i++)
       searchForFinishedFrames(win.frames[i]);
   }
 
   function poll() {
-    // This only gives us UniversalXPConnect for the current stack frame
-    // We're using setInterval, so the main page's privileges are still normal
-    xpcEnumerateContentWindows(searchForFinishedFrames);
+    try {
+      // This only gives us UniversalXPConnect for the current stack frame
+      // We're using setInterval, so the main page's privileges are still normal
+      xpcEnumerateContentWindows(searchForFinishedFrames);
+    } catch(ex) {
+      // We might be accessing windows before they are fully constructed,
+      // which can throw.  We'll find those frames on our next poll().
+    }
   }
 
   var frameWaitInterval = setInterval(poll, 500);
 }
 
--- a/docshell/test/navigation/test_bug13871.html
+++ b/docshell/test/navigation/test_bug13871.html
@@ -10,32 +10,32 @@
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 window.onload = function () {
   navigateByLocation(window0.frames[0]);
   navigateByOpen("window1_child0");
   navigateByForm("window2_child0");
   navigateByHyperlink("window3_child0");
-}
 
-xpcWaitForFinishedFrames(function() {
-  isInaccessible(window0.frames[0], "Should not be able to navigate off-domain frame by setting location.");
-  isInaccessible(window1.frames[0], "Should not be able to navigate off-domain frame by calling window.open.");
-  isInaccessible(window2.frames[0], "Should not be able to navigate off-domain frame by submitting form.");
-  isInaccessible(window3.frames[0], "Should not be able to navigate off-domain frame by targeted hyperlink.");
+  xpcWaitForFinishedFrames(function() {
+    isInaccessible(window0.frames[0], "Should not be able to navigate off-domain frame by setting location.");
+    isInaccessible(window1.frames[0], "Should not be able to navigate off-domain frame by calling window.open.");
+    isInaccessible(window2.frames[0], "Should not be able to navigate off-domain frame by submitting form.");
+    isInaccessible(window3.frames[0], "Should not be able to navigate off-domain frame by targeted hyperlink.");
 
-  window0.close();
-  window1.close();
-  window2.close();
-  window3.close();
+    window0.close();
+    window1.close();
+    window2.close();
+    window3.close();
 
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 4);
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 4);
+}
 
 var window0 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/parent.html", "window0", "width=10,height=10");
 var window1 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/parent.html", "window1", "width=10,height=10");
 var window2 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/parent.html", "window2", "width=10,height=10");
 var window3 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/parent.html", "window3", "width=10,height=10");
 </script>
 </head>
 <body>
--- a/docshell/test/navigation/test_bug278916.html
+++ b/docshell/test/navigation/test_bug278916.html
@@ -4,31 +4,29 @@
     <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
     <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     <script type="text/javascript" src="NavigationUtils.js"></script>
 <script>
 window.onload = function () {
   document.getElementById("link0").href = target_url;
-
   sendMouseEvent({type:"click"}, "link0");
-}
-
-xpcWaitForFinishedFrames(function() {
-  var array_of_frames = xpcGetFramesByName("window0");
-  is(array_of_frames.length, 1, "Should only open one window using a fancy hyperlink.");
+  
+  xpcWaitForFinishedFrames(function() {
+    var array_of_frames = xpcGetFramesByName("window0");
+    is(array_of_frames.length, 1, "Should only open one window using a fancy hyperlink.");
 
-  for (var i=0; i < array_of_frames.length; ++i)
-    array_of_frames[i].close();
+    for (var i=0; i < array_of_frames.length; ++i)
+      array_of_frames[i].close();
 
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 1);
-
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 1);
+}
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=278916">Mozilla Bug 278916</a>
 <div id="links">
 <a id="link0" target="window0" onclick="window.open('', 'window0', 'width=10,height=10');">This is a fancy hyperlink</a>
 </div>
 <pre id="test">
--- a/docshell/test/navigation/test_bug279495.html
+++ b/docshell/test/navigation/test_bug279495.html
@@ -8,35 +8,35 @@
     <script type="text/javascript" src="NavigationUtils.js"></script>
 <script>
 window.onload = function () {
   document.getElementById("link0").href = target_url;
   document.getElementById("link1").href = target_url;
 
   sendMouseEvent({type:"click"}, "link0");
   sendMouseEvent({type:"click"}, "link1");
+
+  xpcWaitForFinishedFrames(function() {
+    countAndClose("window0", 1);
+    countAndClose("window1", 1);
+
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 2);
 }
 
 function countAndClose(name, expected_count) {
   var array_of_frames = xpcGetFramesByName(name);
   is(array_of_frames.length, expected_count,
      "Should only open " + expected_count +
      " window(s) with name " + name + " using a fancy hyperlink.");
 
   for (var i=0; i < array_of_frames.length; ++i)
     array_of_frames[i].close();
 }
-
-xpcWaitForFinishedFrames(function() {
-  countAndClose("window0", 1);
-  countAndClose("window1", 1);
-
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 2);
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=279495">Mozilla Bug 279495</a>
 <div id="links">
 <a id="link0" target="window0" onclick="window.open('blank.html', 'window0', 'width=10,height=10');">This is a fancy hyperlink</a>
 <a id="link1" target="window1" onclick="window.open('http://test1.example.org:80/tests/docshell/test/navigation/blank.html', 'window1', 'width=10,height=10');">This is a fancy hyperlink</a>
 </div>
--- a/docshell/test/navigation/test_child.html
+++ b/docshell/test/navigation/test_child.html
@@ -10,27 +10,27 @@
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 window.onload = function() {
   navigateByLocation(frames[0]);
   navigateByOpen("child1");
   navigateByForm("child2");
   navigateByHyperlink("child3");
-}
 
-xpcWaitForFinishedFrames(function() {
-  isNavigated(frames[0], "Should be able to navigate off-domain child by setting location.");
-  isNavigated(frames[1], "Should be able to navigate off-domain child by calling window.open.");
-  isNavigated(frames[2], "Should be able to navigate off-domain child by submitting form.");
-  isNavigated(frames[3], "Should be able to navigate off-domain child by targeted hyperlink.");
+  xpcWaitForFinishedFrames(function() {
+    isNavigated(frames[0], "Should be able to navigate off-domain child by setting location.");
+    isNavigated(frames[1], "Should be able to navigate off-domain child by calling window.open.");
+    isNavigated(frames[2], "Should be able to navigate off-domain child by submitting form.");
+    isNavigated(frames[3], "Should be able to navigate off-domain child by targeted hyperlink.");
 
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 4);
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 4);
+}
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 <iframe name="child0" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
 <iframe name="child1" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
 <iframe name="child2" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
--- a/docshell/test/navigation/test_grandchild.html
+++ b/docshell/test/navigation/test_grandchild.html
@@ -10,27 +10,27 @@
       iframe { width: 90%; height: 200px; }
     </style>
 <script>
 window.onload = function () {
   navigateByLocation(frames[0].frames[0]);
   navigateByOpen("child1_child0");
   navigateByForm("child2_child0");
   navigateByHyperlink("child3_child0");
-}
 
-xpcWaitForFinishedFrames(function() {
-  isNavigated(frames[0].frames[0], "Should be able to navigate off-domain grandchild by setting location.");
-  isNavigated(frames[1].frames[0], "Should be able to navigate off-domain grandchild by calling window.open.");
-  isNavigated(frames[2].frames[0], "Should be able to navigate off-domain grandchild by submitting form.");
-  isNavigated(frames[3].frames[0], "Should be able to navigate off-domain grandchild by targeted hyperlink.");
+  xpcWaitForFinishedFrames(function() {
+    isNavigated(frames[0].frames[0], "Should be able to navigate off-domain grandchild by setting location.");
+    isNavigated(frames[1].frames[0], "Should be able to navigate off-domain grandchild by calling window.open.");
+    isNavigated(frames[2].frames[0], "Should be able to navigate off-domain grandchild by submitting form.");
+    isNavigated(frames[3].frames[0], "Should be able to navigate off-domain grandchild by targeted hyperlink.");
 
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 4);
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 4);
+}
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 <iframe name="child0" src="http://test1.example.org:80/tests/docshell/test/navigation/parent.html"></iframe>
 <iframe name="child1" src="http://test1.example.org:80/tests/docshell/test/navigation/parent.html"></iframe>
 <iframe name="child2" src="http://test1.example.org:80/tests/docshell/test/navigation/parent.html"></iframe>
--- a/docshell/test/navigation/test_not-opener.html
+++ b/docshell/test/navigation/test_not-opener.html
@@ -10,31 +10,31 @@
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 window.onload = function () {
   //navigateByLocation(window0);  // Don't have a handle to the window.
   navigateByOpen("window1");
   navigateByForm("window2");
   navigateByHyperlink("window3");
-}
 
-xpcWaitForFinishedFrames(function() {
-  is(xpcGetFramesByName("window1").length, 2, "Should not be able to navigate popup's popup by calling window.open.");
-  is(xpcGetFramesByName("window2").length, 2, "Should not be able to navigate popup's popup by submitting form.");
-  is(xpcGetFramesByName("window3").length, 2, "Should not be able to navigate popup's popup by targeted hyperlink.");
+  xpcWaitForFinishedFrames(function() {
+    is(xpcGetFramesByName("window1").length, 2, "Should not be able to navigate popup's popup by calling window.open.");
+    is(xpcGetFramesByName("window2").length, 2, "Should not be able to navigate popup's popup by submitting form.");
+    is(xpcGetFramesByName("window3").length, 2, "Should not be able to navigate popup's popup by targeted hyperlink.");
 
-  //opener0.close();
-  opener1.close();
-  opener2.close();
-  opener3.close();
+    //opener0.close();
+    opener1.close();
+    opener2.close();
+    opener3.close();
 
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 3);
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 3);
+}
 
 //opener0 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/open.html#window0", "_blank", "width=10,height=10");
 opener1 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/open.html#window1", "_blank", "width=10,height=10");
 opener2 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/open.html#window2", "_blank", "width=10,height=10");
 opener3 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/open.html#window3", "_blank", "width=10,height=10");
 </script>
 </head>
 <body>
--- a/docshell/test/navigation/test_opener.html
+++ b/docshell/test/navigation/test_opener.html
@@ -10,32 +10,32 @@
       iframe { width: 90%; height: 50px; }
     </style>
 <script>
 window.onload = function () {
   navigateByLocation(window0);
   navigateByOpen("window1");
   navigateByForm("window2");
   navigateByHyperlink("window3");
-}
 
-xpcWaitForFinishedFrames(function() {
-  isNavigated(window0, "Should be able to navigate popup by setting location.");
-  isNavigated(window1, "Should be able to navigate popup by calling window.open.");
-  isNavigated(window2, "Should be able to navigate popup by submitting form.");
-  isNavigated(window3, "Should be able to navigate popup by targeted hyperlink.");
+  xpcWaitForFinishedFrames(function() {
+    isNavigated(window0, "Should be able to navigate popup by setting location.");
+    isNavigated(window1, "Should be able to navigate popup by calling window.open.");
+    isNavigated(window2, "Should be able to navigate popup by submitting form.");
+    isNavigated(window3, "Should be able to navigate popup by targeted hyperlink.");
 
-  window0.close();
-  window1.close();
-  window2.close();
-  window3.close();
+    window0.close();
+    window1.close();
+    window2.close();
+    window3.close();
 
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 4);
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 4);
+}
 
 var window0 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/blank.html", "window0", "width=10,height=10");
 var window1 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/blank.html", "window1", "width=10,height=10");
 var window2 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/blank.html", "window2", "width=10,height=10");
 var window3 = window.open("http://test1.example.org:80/tests/docshell/test/navigation/blank.html", "window3", "width=10,height=10");
 </script>
 </head>
 <body>
--- a/docshell/test/navigation/test_sibling-matching-parent.html
+++ b/docshell/test/navigation/test_sibling-matching-parent.html
@@ -11,27 +11,27 @@
     </style>
 <script>
 window.onload = function () {
   document.getElementById('active').innerHTML =
       '<iframe src="navigate.html#parent.frames[0],location"></iframe>' +
       '<iframe src="navigate.html#child1,open"></iframe>' +
       '<iframe src="navigate.html#child2,form"></iframe>' +
       '<iframe src="navigate.html#child3,hyperlink"></iframe>';
-}
 
-xpcWaitForFinishedFrames(function() {
-  isNavigated(frames[0], "Should be able to navigate sibling with on-domain parent by setting location.");
-  isNavigated(frames[1], "Should be able to navigate sibling with on-domain parent by calling window.open.");
-  isNavigated(frames[2], "Should be able to navigate sibling with on-domain parent by submitting form.");
-  isNavigated(frames[3], "Should be able to navigate sibling with on-domain parent by targeted hyperlink.");
+  xpcWaitForFinishedFrames(function() {
+    isNavigated(frames[0], "Should be able to navigate sibling with on-domain parent by setting location.");
+    isNavigated(frames[1], "Should be able to navigate sibling with on-domain parent by calling window.open.");
+    isNavigated(frames[2], "Should be able to navigate sibling with on-domain parent by submitting form.");
+    isNavigated(frames[3], "Should be able to navigate sibling with on-domain parent by targeted hyperlink.");
 
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 4);
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 4);
+}
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 <iframe name="child0" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
 <iframe name="child1" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
 <iframe name="child2" src="http://test1.example.org:80/tests/docshell/test/navigation/blank.html"></iframe>
--- a/docshell/test/navigation/test_sibling-off-domain.html
+++ b/docshell/test/navigation/test_sibling-off-domain.html
@@ -11,27 +11,27 @@
     </style>
 <script>
 window.onload = function () {
   document.getElementById('active').innerHTML =
       '<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#parent.frames[0],location"></iframe>' +
       '<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#child1,open"></iframe>' +
       '<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#child2,form"></iframe>' +
       '<iframe src="http://test1.example.org:80/tests/docshell/test/navigation/navigate.html#child3,hyperlink"></iframe>';
-}
 
-xpcWaitForFinishedFrames(function() {
-  isBlank(frames[0], "Should not be able to navigate off-domain sibling by setting location.");
-  isBlank(frames[1], "Should not be able to navigate off-domain sibling by calling window.open.");
-  isBlank(frames[2], "Should not be able to navigate off-domain sibling by submitting form.");
-  isBlank(frames[3], "Should not be able to navigate off-domain sibling by targeted hyperlink.");
+  xpcWaitForFinishedFrames(function() {
+    isBlank(frames[0], "Should not be able to navigate off-domain sibling by setting location.");
+    isBlank(frames[1], "Should not be able to navigate off-domain sibling by calling window.open.");
+    isBlank(frames[2], "Should not be able to navigate off-domain sibling by submitting form.");
+    isBlank(frames[3], "Should not be able to navigate off-domain sibling by targeted hyperlink.");
 
-  xpcCleanupWindows();
-  SimpleTest.finish();
-}, 4);
+    xpcCleanupWindows();
+    SimpleTest.finish();
+  }, 4);
+}
 </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408052">Mozilla Bug 408052</a>
 <div id="frames">
 <iframe name="child0" src="blank.html"></iframe>
 <iframe name="child1" src="blank.html"></iframe>
 <iframe name="child2" src="blank.html"></iframe>