DOMParser-parseFromString-url-moretests.html (2338B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>DOMParser: Document's url</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <div id=log></div> 7 <script> 8 async_test(function() { 9 var iframe = document.createElement("iframe"); 10 iframe.onload = this.step_func(function() { 11 var child = iframe.contentWindow; 12 var supportedTypes = [ 13 "text/html", 14 "text/xml", 15 "application/xml", 16 "application/xhtml+xml", 17 "image/svg+xml", 18 ]; 19 20 supportedTypes.forEach(function(type) { 21 test(function() { 22 var dp = new DOMParser(); 23 var doc = dp.parseFromString("<html></html>", type); 24 assert_equals(doc.URL, document.URL); 25 }, "Parent window (" + type + ")"); 26 27 test(function() { 28 var dp = new child.DOMParser(); 29 var doc = dp.parseFromString("<html></html>", type); 30 assert_equals(doc.URL, child.document.URL); 31 }, "Child window (" + type + ")"); 32 33 test(function() { 34 var dp = new DOMParser(); 35 var doc = child.DOMParser.prototype.parseFromString.call(dp, "<html></html>", type); 36 assert_equals(doc.URL, document.URL); 37 }, "Parent window with child method (" + type + ")"); 38 39 test(function() { 40 var dp = new child.DOMParser(); 41 var doc = DOMParser.prototype.parseFromString.call(dp, "<html></html>", type); 42 assert_equals(doc.URL, child.document.URL); 43 }, "Child window with parent method (" + type + ")"); 44 }); 45 46 var dpBeforeNavigation = new child.DOMParser(), urlBeforeNavigation = child.document.URL; 47 iframe.onload = this.step_func_done(function() { 48 supportedTypes.forEach(function(type) { 49 test(function() { 50 var doc = dpBeforeNavigation.parseFromString("<html></html>", type); 51 assert_equals(doc.URL, urlBeforeNavigation); 52 }, "Child window crossing navigation (" + type + ")"); 53 54 test(function() { 55 var dp = new child.DOMParser(); 56 var doc = dp.parseFromString("<html></html>", type); 57 assert_equals(doc.URL, child.document.URL); 58 }, "Child window after navigation (" + type + ")"); 59 }); 60 }); 61 iframe.src = "/common/blank.html?2"; 62 }); 63 iframe.src = "/common/blank.html?1"; 64 document.body.appendChild(iframe); 65 }); 66 </script>