Bug 1413735 - Rewrite test_bug580069.html to avoid a potential race condition, r=qdot
authorNika Layzell <nika@thelayzells.com>
Sat, 09 Mar 2019 02:27:35 +0000
changeset 521374 54607c048929
parent 521373 af2e51990c3d
child 521375 51fc0fd585a7
push id10866
push usernerli@mozilla.com
push dateTue, 12 Mar 2019 18:59:09 +0000
treeherdermozilla-beta@445c24a51727 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1413735, 580069
milestone67.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 1413735 - Rewrite test_bug580069.html to avoid a potential race condition, r=qdot Differential Revision: https://phabricator.services.mozilla.com/D22581
docshell/test/mochitest/test_bug580069.html
--- a/docshell/test/mochitest/test_bug580069.html
+++ b/docshell/test/mochitest/test_bug580069.html
@@ -2,60 +2,59 @@
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=580069
 -->
 <head>
   <title>Test for Bug 580069</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=580069">Mozilla Bug 580069</a>
 
-<iframe id='iframe' src='file_bug580069_1.html'></iframe>
-
 <script type="application/javascript">
 
-SimpleTest.waitForExplicitFinish();
-
-var iframe = document.getElementById('iframe');
-var iframeCw = iframe.contentWindow;
+add_task(async function() {
+  let iframe = document.createElement("iframe");
+  iframe.setAttribute("src", "file_bug580069_1.html");
 
-// Called when file_bug580069_1.html loads.
-function page1Load() {
-  // This should cause us to load file 2.
-  dump('page1Load\n');
-  iframeCw.document.getElementById('form').submit();
-}
+  // Insert the initial <iframe> document, and wait for page1Load to be called
+  // after it loads.
+  document.body.appendChild(iframe);
+  await new Promise(resolve => {
+    window.page1Load = resolve;
+  });
+  let iframeCw = iframe.contentWindow;
 
-// Called when file_bug580069_2.html loads.
-var page2Loads = 0;
-function page2Load(method) {
+  info("iframe's location is: " + iframeCw.location + "\n");
 
-  dump("iframe's location is: " + iframeCw.location + ", method is " + method + "\n");
+  // Submit the forum and wait for the initial page load using a POST load.
+  iframeCw.document.getElementById("form").submit();
+  let method1 = await new Promise(resolve => {
+    window.page2Load = resolve;
+  });
 
-  if (page2Loads == 0) {
-    is(method, "POST", "Method for first load should be POST.");
-    iframeCw.history.replaceState('', '', '?replaced');
+  info("iframe's location is: " + iframeCw.location + ", method is " + method1 + "\n");
+  is(method1, "POST", "Method for first load should be POST.");
+
+  // Push a new state, and refresh the page. This refresh shouldn't pop up the
+  // "are you sure you want to refresh a page with POST data?" dialog. If it
+  // does, this test will hang and fail, and we'll see 'Refreshing iframe...' at
+  // the end of the test log.
+  iframeCw.history.replaceState('', '', '?replaced');
 
-    // This refresh shouldn't pop up the "are you sure you want to refresh a page
-    // with POST data?" dialog.  If it does, this test will hang and fail, and
-    // we'll see 'Refreshing iframe...' at the end of the test log.
-    dump('Refreshing iframe...\n');
-    iframeCw.location.reload();
-  }
-  else if (page2Loads == 1) {
-    is(method, "GET", "Method for second load should be GET.");
-    is(iframeCw.location.search, "?replaced", "Wrong search on iframe after refresh.");
-    SimpleTest.finish();
-  }
-  else {
-    ok(false, "page2Load should only be called twice.");
-  }
+  info('Refreshing iframe...\n');
+  iframeCw.location.reload();
+  let method2 = await new Promise(resolve => {
+    window.page2Load = resolve;
+  });
 
-  page2Loads++;
-}
+  info("iframe's location is: " + iframeCw.location + ", method is " + method2 + "\n");
+  is(method2, "GET", "Method for second load should be GET.");
+  is(iframeCw.location.search, "?replaced", "Wrong search on iframe after refresh.");
+});
 </script>
 
 </body>
 </html>