Bug 1129091 - Wait for the iframes to load before running test functions that use them. r?jgraham draft
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 15 May 2018 07:57:15 -0400
changeset 795269 d5dbb2d3a5a1d9eff4eea8f181ed4ea7f21c6f3c
parent 795256 cf3ee14023483cbbb57129479537c713e22c1980
push id109907
push userkgupta@mozilla.com
push dateTue, 15 May 2018 11:57:38 +0000
reviewersjgraham
bugs1129091
milestone62.0a1
Bug 1129091 - Wait for the iframes to load before running test functions that use them. r?jgraham MozReview-Commit-ID: Di6pxnrZxcZ
testing/web-platform/tests/old-tests/submission/Microsoft/history/history_000.htm
--- a/testing/web-platform/tests/old-tests/submission/Microsoft/history/history_000.htm
+++ b/testing/web-platform/tests/old-tests/submission/Microsoft/history/history_000.htm
@@ -317,13 +317,30 @@
             }
         }
         function queue(func) {
             //50 allows adequate time for .back and .forward navigations to queue first
             setTimeout(func, 50);
         }
 
         add_result_callback(testFinished);
-        //start the first test manually
-        queue(testCollection[testIndex]);
+
+        function startTestsWhenIframesLoaded() {
+          if (testframe1.contentWindow.document.readyState != 'complete' ||
+              testframe2.contentWindow.document.readyState != 'complete') {
+            return;
+          }
+          testframe1.removeEventListener('load', startTestsWhenIframesLoaded, false);
+          testframe2.removeEventListener('load', startTestsWhenIframesLoaded, false);
+
+          //start the first test
+          queue(testCollection[testIndex]);
+        }
+
+        // add listeners to trigger the tests once the iframes are loaded,
+        // but also try to start it right away in case the load events have
+        // already fired and we missed them.
+        testframe1.addEventListener('load', startTestsWhenIframesLoaded, false);
+        testframe2.addEventListener('load', startTestsWhenIframesLoaded, false);
+        startTestsWhenIframesLoaded();
      </script>
 </body>
 </html>