write-active-document.html (1347B)
1 <!doctype html> 2 <title>document.write only writes to active documents</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <body><div id="log"></div></body> 6 <script> 7 async_test(function(t) { 8 var child = document.createElement("iframe"); 9 child.src = "empty.html?1"; 10 child.onload = t.step_func(function() { 11 var child1 = child.contentDocument; 12 var link = child1.createElement("a"); 13 link.href = "data:text/html,Clicked."; 14 link.innerText = "Link."; 15 child1.body.appendChild(link); 16 var grandchild = child1.createElement("iframe"); 17 grandchild.src = "empty.html?2"; 18 grandchild.onload = t.step_func(function() { 19 var grandchild1 = grandchild.contentDocument; 20 child.onload = t.step_func(function() { 21 // This is a write to an inactive document 22 child1.write('WRITE HAPPENED'); 23 assert_equals(child1.body.lastChild.tagName, "IFRAME"); 24 // This is a write to an active but not fully active document 25 grandchild1.write('WRITE HAPPENED'); 26 assert_equals(grandchild1.body.innerHTML, "WRITE HAPPENED"); 27 t.done(); 28 }); 29 link.click(); 30 }); 31 child1.body.appendChild(grandchild); 32 }); 33 document.body.appendChild(child); 34 }); 35 </script>