window-parent.html (1464B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>window.parent</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, parent) 10 }, '`window.parent` for top-level browsing context'); 11 12 async_test(t => { 13 var iframe = document.createElement('iframe'); 14 iframe.onload = t.step_func_done(function () { 15 var iWindow = iframe.contentWindow; 16 assert_equals(iWindow.parent, window); 17 }); 18 document.body.appendChild(iframe); 19 }, '`window.parent` on single nested browsing context'); 20 21 async_test(t => { 22 var iframe = document.createElement('iframe'); 23 var iframe2; 24 25 var testFunc = t.step_func_done(function () { 26 var frameWindow = iframe.contentWindow; 27 var frame2Window = iframe2.contentWindow; 28 assert_equals(frameWindow.parent, window); 29 assert_equals(frame2Window.parent, frameWindow); 30 assert_not_equals(frame2Window.parent, window); 31 }); 32 33 var nestFrame = function () { 34 iframe2 = iframe.contentDocument.createElement('iframe'); 35 // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1229707 36 iframe2.src = '/common/blank.html'; 37 iframe2.addEventListener('load', testFunc); 38 iframe.contentDocument.body.appendChild(iframe2); 39 }; 40 41 iframe.addEventListener('load', nestFrame); 42 document.body.appendChild(iframe); 43 }, '`window.parent` for multiple nested browsing contexts'); 44 </script>