OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>document.origin</title> |
| 3 <script src="/resources/testharness.js"></script> |
| 4 <script src="/resources/testharnessreport.js"></script> |
| 5 |
| 6 <iframe id="srcdoc" srcdoc="<p>yay</p>"></iframe> |
| 7 |
| 8 <script> |
| 9 test(function() { |
| 10 assert_equals(document.origin, 'http://127.0.0.1:8000'); |
| 11 }, 'Top-level document.'); |
| 12 |
| 13 test(function() { |
| 14 var doc = document.implementation.createHTMLDocument(); |
| 15 assert_equals(doc.origin, 'http://127.0.0.1:8000'); |
| 16 }, 'createHTMLDocument()'); |
| 17 |
| 18 |
| 19 (function() { |
| 20 var t = async_test("about:blank IFrame."); |
| 21 t.step(function () { |
| 22 var iframe = document.createElement('iframe'); |
| 23 iframe.addEventListener('load', function () { |
| 24 assert_equals(iframe.contentDocument.origin, 'http://127.0.0.1:8000'
); |
| 25 t.done(); |
| 26 }); |
| 27 document.body.appendChild(iframe); |
| 28 }); |
| 29 })(); |
| 30 |
| 31 (function() { |
| 32 var t = async_test("Same-origin IFrame."); |
| 33 t.step(function () { |
| 34 var iframe = document.createElement('iframe'); |
| 35 iframe.src = "/security/resources/postmessage-document-origin.html"; |
| 36 iframe.addEventListener('load', function () { |
| 37 iframe.contentWindow.postMessage({ 'id': 'same-origin-iframe' }, '*'
); |
| 38 }); |
| 39 window.addEventListener('message', function (e) { |
| 40 if (e.data.id != 'same-origin-iframe') |
| 41 return; |
| 42 |
| 43 assert_equals(e.data.origin, 'http://127.0.0.1:8000'); |
| 44 assert_equals(e.data.origin, e.origin); |
| 45 t.done(); |
| 46 }); |
| 47 document.body.appendChild(iframe); |
| 48 }); |
| 49 })(); |
| 50 |
| 51 (function() { |
| 52 var t = async_test("Cross-origin IFrame."); |
| 53 t.step(function () { |
| 54 var iframe = document.createElement('iframe'); |
| 55 iframe.src = "http://localhost:8080/security/resources/postmessage-docum
ent-origin.html"; |
| 56 iframe.addEventListener('load', function () { |
| 57 iframe.contentWindow.postMessage({ 'id': 'cross-origin-iframe' }, '*
'); |
| 58 }); |
| 59 window.addEventListener('message', function (e) { |
| 60 if (e.data.id != 'cross-origin-iframe') |
| 61 return; |
| 62 |
| 63 assert_equals(e.data.origin, 'http://localhost:8080'); |
| 64 assert_equals(e.data.origin, e.origin); |
| 65 t.done(); |
| 66 }); |
| 67 document.body.appendChild(iframe); |
| 68 }); |
| 69 })(); |
| 70 |
| 71 (function() { |
| 72 var t = async_test("Sandboxed same-origin IFrame."); |
| 73 t.step(function () { |
| 74 var iframe = document.createElement('iframe'); |
| 75 iframe.setAttribute('sandbox', 'allow-scripts'); |
| 76 iframe.src = "/security/resources/postmessage-document-origin.html"; |
| 77 iframe.addEventListener('load', function () { |
| 78 iframe.contentWindow.postMessage({ 'id': 'sandboxed-same-origin-ifra
me' }, '*'); |
| 79 }); |
| 80 window.addEventListener('message', function (e) { |
| 81 if (e.data.id != 'sandboxed-same-origin-iframe') |
| 82 return; |
| 83 |
| 84 assert_equals(e.data.origin, 'null'); |
| 85 assert_equals(e.data.origin, e.origin); |
| 86 t.done(); |
| 87 }); |
| 88 document.body.appendChild(iframe); |
| 89 }); |
| 90 })(); |
| 91 |
| 92 (function() { |
| 93 var t = async_test("Sandboxed cross-origin IFrame."); |
| 94 t.step(function () { |
| 95 var iframe = document.createElement('iframe'); |
| 96 iframe.setAttribute('sandbox', 'allow-scripts'); |
| 97 iframe.src = "http://localhost:8080/security/resources/postmessage-docum
ent-origin.html"; |
| 98 iframe.addEventListener('load', function () { |
| 99 iframe.contentWindow.postMessage({ 'id': 'sandboxed-cross-origin-ifr
ame' }, '*'); |
| 100 }); |
| 101 window.addEventListener('message', function (e) { |
| 102 if (e.data.id != 'sandboxed-cross-origin-iframe') |
| 103 return; |
| 104 |
| 105 assert_equals(e.data.origin, 'null'); |
| 106 assert_equals(e.data.origin, e.origin); |
| 107 t.done(); |
| 108 }); |
| 109 document.body.appendChild(iframe); |
| 110 }); |
| 111 })(); |
| 112 </script> |
OLD | NEW |