test_srcdoc.html (3626B)
1 <!doctype html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=802895 5 --> 6 <head> 7 <title>Tests for srcdoc iframes introduced in bug 802895</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=802895">Mozilla Bug 802895</a> 13 14 <iframe id="pframe" src="file_srcdoc.html"></iframe> 15 16 <pre id="test"> 17 <script> 18 19 SimpleTest.waitForExplicitFinish(); 20 SimpleTest.requestFlakyTimeout("untriaged"); 21 var pframe = $("pframe"); 22 23 var loadState = 0; 24 pframe.contentWindow.addEventListener("load", function () { 25 26 var pframeDoc = pframe.contentDocument; 27 28 var iframe = pframeDoc.getElementById("iframe"); 29 var innerDoc = iframe.contentDocument; 30 var iframe1 = pframeDoc.getElementById("iframe1"); 31 var innerDoc1 = iframe1.contentDocument; 32 33 var finish = false; 34 var finish1 = false; 35 var finish3 = false; 36 37 38 39 is(iframe.srcdoc, "Hello World", "Bad srcdoc attribute contents") 40 41 is(innerDoc.domain, document.domain, "Wrong domain"); 42 is(innerDoc.referrer, pframeDoc.referrer, "Wrong referrer"); 43 is(innerDoc.body.innerHTML, "Hello World", "Wrong body"); 44 is(innerDoc.compatMode, "CSS1Compat", "Not standards compliant"); 45 46 is(innerDoc1.domain, document.domain, "Wrong domain with src attribute"); 47 is(innerDoc1.referrer, pframeDoc.referrer, "Wrong referrer with src attribute"); 48 is(innerDoc1.body.innerHTML, "Goodbye World", "Wrong body with src attribute") 49 is(innerDoc1.compatMode, "CSS1Compat", "Not standards compliant with src attribute"); 50 51 var iframe2 = pframeDoc.getElementById("iframe2"); 52 var innerDoc2 = iframe2.contentDocument; 53 try { 54 innerDoc2.domain; 55 foundError = false; 56 } 57 catch (error) { 58 foundError = true; 59 } 60 ok(foundError, "srcdoc iframe not sandboxed"); 61 62 //Test changed srcdoc attribute 63 iframe.onload = function () { 64 65 iframe = pframeDoc.getElementById("iframe"); 66 innerDoc = iframe.contentDocument; 67 68 is(iframe.srcdoc, "Hello again", "Bad srcdoc attribute contents with srcdoc attribute changed"); 69 is(innerDoc.domain, document.domain, "Wrong domain with srcdoc attribute changed"); 70 is(innerDoc.referrer, pframeDoc.referrer, "Wrong referrer with srcdoc attribute changed"); 71 is(innerDoc.body.innerHTML, "Hello again", "Wrong body with srcdoc attribute changed"); 72 is(innerDoc.compatMode, "CSS1Compat", "Not standards compliant with srcdoc attribute changed"); 73 74 finish = true; 75 if (finish && finish1 && finish3) { 76 SimpleTest.finish(); 77 } 78 }; 79 80 iframe.srcdoc = "Hello again"; 81 82 var iframe3 = pframeDoc.getElementById("iframe3"); 83 84 // Test srcdoc attribute removal 85 iframe3.onload = function () { 86 var innerDoc3 = iframe3.contentDocument; 87 is(innerDoc3.body.innerText, "Gone", "Bad srcdoc attribute removal"); 88 finish3 = true; 89 if (finish && finish1 && finish3) { 90 SimpleTest.finish(); 91 } 92 } 93 94 iframe3.removeAttribute("srcdoc"); 95 96 97 var iframe1load = false; 98 iframe1.onload = function () { 99 iframe1load = true; 100 } 101 102 iframe1.src = "data:text/plain;charset=US-ASCII,Goodbyeeee"; 103 104 // Need to test that changing the src doesn't change the iframe. 105 setTimeout(function () { 106 ok(!iframe1load, "Changing src attribute shouldn't cause a load when srcdoc is set"); 107 finish1 = true; 108 if (finish && finish1 && finish3) { 109 SimpleTest.finish(); 110 } 111 }, 2000); 112 113 }); 114 115 </script> 116 </pre> 117 </body> 118 </html>