Bug 947755 - Try to avoid use of setTimeout when there is an event to use. r=khuey, a=test-only
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sat, 13 Feb 2016 03:40:01 +0200
changeset 317233 4d79b3bbd36e8afa5e8c2f0eaeda3780925577d7
parent 317232 b7770ba5c62061663dde53289ebeb2d8037369f7
child 317234 186aeb040821c87a9c7b4f75b41e0d36a3dbaec3
push id5703
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:18:41 +0000
treeherdermozilla-beta@31e373ad5b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey, test-only
bugs947755
milestone46.0a2
Bug 947755 - Try to avoid use of setTimeout when there is an event to use. r=khuey, a=test-only
docshell/test/navigation/file_document_write_1.html
docshell/test/navigation/test_sessionhistory.html
--- a/docshell/test/navigation/file_document_write_1.html
+++ b/docshell/test/navigation/file_document_write_1.html
@@ -1,22 +1,30 @@
 <html>
   <head>
     <script>
       function run() {
         document.open();
         document.write("<h5 id='dynamic'>document.written content</h5>");
         document.close();
         window.history.go(-1);
-        opener.setTimeout("isTestDynamic()", 2500);
       }
 
       function start() {
         if (++opener.testCount == 1) {
           setTimeout(run, 0);
         }
       }
+
+      window.addEventListener("pageshow",
+        function() {
+          ++opener.file_document_write_1_loadCount;
+          if (opener.file_document_write_1_loadCount == 2) {
+            opener.setTimeout("isTestDynamic()", 0);
+          }
+          opener.ok(opener.file_document_write_1_loadCount <= 2);
+        });
     </script>
   </head>
   <body onload="start();">
     <h5>static content</h5>
   </body>
 </html>
--- a/docshell/test/navigation/test_sessionhistory.html
+++ b/docshell/test/navigation/test_sessionhistory.html
@@ -44,16 +44,17 @@ function nextTest_() {
     testWindow = window.open(testFiles.shift(), "", "width=300,height=300");
     testWindow.onunload = function () { } //XXX
   } else {
     SimpleTest.finish();
   }
 }
 
 // Needed by file_document_write_1.html
+window.file_document_write_1_loadCount = 0;
 function isTestDynamic() {
   var dyn = testWindow.document.getElementById("dynamic");
   is(dyn, null, "Should have gone back to the static page!");
   nextTest();
   testWindow.close();
 }
 
 function nextTest() {