Bug 1440537 - Fix a cross-origin navigation test to navigate reliably. r=bzbarsky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 25 Apr 2019 22:36:39 +0200
changeset 530464 5b63c5b38dcc382a4fa0afdbbf67b147057c4fac
parent 530463 a07956b430eb080767e43e1ecea50821be0de1a2
child 530465 b65d6e86de493a8e94b8c348bf0ab5329d998ed2
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1440537, 1218456
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1440537 - Fix a cross-origin navigation test to navigate reliably. r=bzbarsky This subtest (of test_iframe_sandbox_navigation.html) starts intermittently failing with my first patch of this bug. It relied on the pres-context being created when sendMouseEvent is called in order to navigate away (we only navigate away by clicking a link if there's a link handler). sendMouseEvent calls getBoundingClientRect() which used to do this. It no longer does though. I could make sendMouseEvent do that automatically using SpecialPowers or such, or from the DOMWindowUtils code, but I think I'd prefer not to do that. This is the only test that wasn't trivially fixable, and this awkwardness can be removed when bug 1218456 is fixed. Differential Revision: https://phabricator.services.mozilla.com/D28910
dom/html/test/file_iframe_sandbox_d_if11.html
--- a/dom/html/test/file_iframe_sandbox_d_if11.html
+++ b/dom/html/test/file_iframe_sandbox_d_if11.html
@@ -2,24 +2,39 @@
 <html>
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 341604</title>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script src="/tests/SimpleTest/EventUtils.js"></script>
 </head>
 <script type="application/javascript">
+
+function navigateAway() {
+  // Anchor clicks are only handled if we have a pres-context, and we may not
+  // have one yet by the time this runs, and getBoundingClientRect() won't
+  // construct it after bug 1440537.
+  //
+  // So we may need to wait a few frames to make this reliable.
+  //
+  // FIXME(emilio, bug 1218456): This dance shouldn't be needed.
+  let anchor = document.getElementById("anchor");
+  if (anchor.getBoundingClientRect().width > 0)
+    anchor.click();
+  else
+    requestAnimationFrame(navigateAway);
+}
+
 function doTest() {
-  // this should fail the first time, but work the second
   try {
+    // this should fail the first time, but work the second
     window.parent.ok_wrapper(true, "a document that was loaded, navigated to another document, had 'allow-same-origin' added and then was" +
       " navigated back should be same-origin with its parent");
-  } 
-  catch (e) {
-    sendMouseEvent({type:'click'}, 'anchor');
+  } catch (e) {
+    navigateAway();
   }
 }
 
 </script>
 <body onload='doTest()'>
   I am sandboxed with 'allow-scripts'
   <a href='file_iframe_sandbox_d_if12.html' id='anchor'>CLICK ME</a>
 </body>