Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Window / timeout-callback-scope.html
blobc33aba8afe9b8d6f401ebc413abba08aa8d22221
1 <html>
2 <script>
4 // When both timeouts finish, the counter will be 2.
5 window.completionCounter = 0;
6 function test()
8 if (window.testRunner) {
9 testRunner.dumpAsText();
10 testRunner.waitUntilDone();
12 // Get the iframe's window.
13 var iframeWindow = window.frames["testIframe"];
14 // setTimeout with a callback specified as a JS closure.
15 // This one should run in the context of the main page.
16 iframeWindow.setTimeout(
17 function() {
18 document.getElementById("closureResult").innerText = (window == parent ? "PASS" : "FAIL");
19 completionCounter++;
20 }, 1);
21 // setTimeout with a JS string containing similar code.
22 // This one should run 'inside' iframe.
23 iframeWindow.setTimeout(
24 "parent.document.getElementById('stringResult').innerText = (window != parent ? 'PASS' : 'FAIL');" +
25 "parent.completionCounter++;"
26 , 1);
27 window.setInterval(checkResult, 10);
29 function checkResult() {
30 if (completionCounter < 2)
31 return;
32 if (window.testRunner)
33 testRunner.notifyDone();
35 </script>
36 <body onload="test()">
37 <p>Test verifies that a timeout callback is run in the proper execution context. 2 timeouts are set on a child iframe's window. 'Closure' callback should execute in the main page, 'string' callback should execute in the iframe. Test passes if you see 2 lines 'PASS' below.</p>
38 <div id=closureResult>FAIL</div>
39 <div id=stringResult>FAIL</div>
40 <iframe style="display:none" src="about:blank" name=testIframe></iframe>
41 </body>
42 </html>