srcdoc_process_attributes.html (2696B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Whenever `srcdoc` attribute is set, changed, or removed, the UA must process the <iframe> attributes</title> 4 <link rel="help" href="https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:process-the-iframe-attributes-2"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <body> 8 <script> 9 function createIFrameWithBlobSrc() { 10 var iframe = document.createElement("iframe"); 11 iframe.src = URL.createObjectURL(new Blob(["src"], {type: "text/html"})); 12 return iframe; 13 } 14 15 async_test(function(t) { 16 var iframe = createIFrameWithBlobSrc(); 17 var isAdded = false; 18 iframe.onload = t.step_func(function() { 19 assert_equals(iframe.contentDocument.location.protocol, "blob:"); 20 assert_equals(iframe.contentDocument.body.textContent, "src"); 21 22 iframe.onload = t.step_func_done(function() { 23 assert_true(isAdded); 24 assert_equals(iframe.contentDocument.location.href, "about:srcdoc"); 25 assert_equals(iframe.contentDocument.body.textContent, "srcdoc"); 26 }); 27 28 iframe.setAttribute("srcdoc", "srcdoc"); 29 isAdded = true; 30 }); 31 32 document.body.appendChild(iframe); 33 }, "Adding `srcdoc` attribute triggers attributes processing"); 34 35 async_test(function(t) { 36 var iframe = createIFrameWithBlobSrc(); 37 var isChanged = false; 38 iframe.srcdoc = "old"; 39 iframe.onload = t.step_func(function() { 40 assert_equals(iframe.contentDocument.location.href, "about:srcdoc"); 41 assert_equals(iframe.contentDocument.body.textContent, "old"); 42 43 iframe.onload = t.step_func_done(function() { 44 assert_true(isChanged); 45 assert_equals(iframe.contentDocument.location.href, "about:srcdoc"); 46 assert_equals(iframe.contentDocument.body.textContent, "new"); 47 }); 48 49 iframe.srcdoc = "new"; 50 isChanged = true; 51 }); 52 53 document.body.appendChild(iframe); 54 }, "Setting `srcdoc` (via property) triggers attributes processing"); 55 56 async_test(function(t) { 57 var iframe = createIFrameWithBlobSrc(); 58 var isRemoved = false; 59 iframe.srcdoc = "srcdoc"; 60 iframe.onload = t.step_func(function() { 61 assert_equals(iframe.contentDocument.location.href, "about:srcdoc"); 62 assert_equals(iframe.contentDocument.body.textContent, "srcdoc"); 63 64 iframe.onload = t.step_func_done(function() { 65 assert_true(isRemoved); 66 assert_equals(iframe.contentDocument.location.protocol, "blob:"); 67 assert_equals(iframe.contentDocument.body.textContent, "src"); 68 }); 69 70 iframe.removeAttribute("srcdoc"); 71 isRemoved = true; 72 }); 73 74 document.body.appendChild(iframe); 75 }, "Removing `srcdoc` attribute triggers attributes processing"); 76 </script>