4 // When both timeouts finish, the counter will be 2.
5 window
.completionCounter
= 0;
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(
18 document
.getElementById("closureResult").innerText
= (window
== parent
? "PASS" : "FAIL");
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++;"
27 window
.setInterval(checkResult
, 10);
29 function checkResult() {
30 if (completionCounter
< 2)
32 if (window
.testRunner
)
33 testRunner
.notifyDone();
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>