window-top.html (1768B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>window.top</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <div id="log"></div> 7 <script> 8 test(function() { 9 assert_equals(window, top) 10 }, "Top level browsing context"); 11 12 function step_func(test) { 13 return function (top_pointer) { 14 test.step(function() {assert_equals(top_pointer, window);}) 15 test.done(); 16 } 17 } 18 19 var t1 = async_test("One nested iframe"); 20 t1.step(function() { 21 var iframe = document.createElement("iframe"); 22 //iframe.src = "data:text/html," 23 24 iframe.onload = t1.step_func( 25 function() { 26 var doc = iframe.contentDocument; 27 iframe.contentWindow.test_func = step_func(t1); 28 29 var script = doc.createElement("script") 30 script.textContent = "test_func(top);" 31 doc.body.appendChild(script); 32 }); 33 document.body.appendChild(iframe); 34 }); 35 36 var t2 = async_test("Two nested iframes"); 37 t2.step(function() { 38 var iframe = document.createElement("iframe"); 39 //iframe.src = "data:text/html," 40 41 iframe.onload = t2.step_func( 42 function() { 43 var doc = iframe.contentDocument; 44 iframe2 = document.createElement("iframe"); 45 //iframe2.src = "data:text/html," 46 // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1229707 47 iframe2.src = '/common/blank.html'; 48 49 iframe2.onload = t2.step_func( 50 function() { 51 var doc2 = iframe2.contentDocument; 52 53 iframe2.contentWindow.test_func = step_func(t2); 54 55 var script = doc2.createElement("script") 56 script.textContent = "test_func(top);" 57 doc2.body.appendChild(script); 58 }); 59 doc.body.appendChild(iframe2); 60 }); 61 62 document.body.appendChild(iframe); 63 }); 64 65 </script>