Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>document.origin</title> | |
| 5 <script src="/resources/testharness.js"></script> | |
| 6 <script src="/resources/testharnessreport.js"></script> | |
| 7 </head> | |
| 8 <body> | |
| 9 <script> | |
| 10 test(function() { | |
| 11 assert_equals(document.origin, 'http://127.0.0.1:8000'); | |
| 12 }, 'Top-level document.'); | |
| 13 | |
| 14 test(function() { | |
| 15 var doc = document.implementation.createHTMLDocument(); | |
| 16 assert_equals(doc.origin, 'http://127.0.0.1:8000'); | |
| 17 }, 'createHTMLDocument()'); | |
| 18 | |
| 19 | |
| 20 (function() { | |
|
philipj_slow
2014/11/28 09:07:31
You can get rid of the function blocks with async_
Mike West
2014/11/28 09:10:55
Oh, cool.
I'll clean these up in a subsequent CL,
| |
| 21 var t = async_test("about:blank IFrame."); | |
| 22 t.step(function () { | |
| 23 var iframe = document.createElement('iframe'); | |
| 24 iframe.addEventListener('load', function () { | |
| 25 assert_equals(iframe.contentDocument.origin, 'http://127.0.0.1:8 000'); | |
| 26 t.done(); | |
| 27 }); | |
| 28 document.body.appendChild(iframe); | |
| 29 }); | |
| 30 })(); | |
| 31 | |
| 32 (function() { | |
| 33 var t = async_test("srcdoc IFrame."); | |
| 34 t.step(function () { | |
| 35 var iframe = document.createElement('iframe'); | |
| 36 iframe.setAttribute('srcdoc', '<p>Yay!</p>'); | |
| 37 iframe.addEventListener('load', function () { | |
| 38 assert_equals(iframe.contentDocument.origin, 'http://127.0.0.1:8 000'); | |
| 39 t.done(); | |
| 40 }); | |
| 41 document.body.appendChild(iframe); | |
| 42 }); | |
| 43 })(); | |
| 44 | |
| 45 (function() { | |
| 46 var t = async_test("Same-origin IFrame."); | |
| 47 t.step(function () { | |
| 48 var iframe = document.createElement('iframe'); | |
| 49 iframe.src = "/security/resources/postmessage-document-origin.html"; | |
| 50 iframe.addEventListener('load', function () { | |
| 51 iframe.contentWindow.postMessage({ 'id': 'same-origin-iframe' }, '*'); | |
| 52 }); | |
| 53 window.addEventListener('message', function (e) { | |
| 54 if (e.data.id != 'same-origin-iframe') | |
| 55 return; | |
| 56 | |
| 57 assert_equals(e.data.origin, 'http://127.0.0.1:8000'); | |
| 58 assert_equals(e.data.origin, e.origin); | |
| 59 t.done(); | |
| 60 }); | |
| 61 document.body.appendChild(iframe); | |
| 62 }); | |
| 63 })(); | |
| 64 | |
| 65 (function() { | |
| 66 var t = async_test("Cross-origin IFrame."); | |
| 67 t.step(function () { | |
| 68 var iframe = document.createElement('iframe'); | |
| 69 iframe.src = "http://localhost:8080/security/resources/postmessage-d ocument-origin.html"; | |
| 70 iframe.addEventListener('load', function () { | |
| 71 iframe.contentWindow.postMessage({ 'id': 'cross-origin-iframe' } , '*'); | |
| 72 }); | |
| 73 window.addEventListener('message', function (e) { | |
| 74 if (e.data.id != 'cross-origin-iframe') | |
| 75 return; | |
| 76 | |
| 77 assert_equals(e.data.origin, 'http://localhost:8080'); | |
| 78 assert_equals(e.data.origin, e.origin); | |
| 79 t.done(); | |
| 80 }); | |
| 81 document.body.appendChild(iframe); | |
| 82 }); | |
| 83 })(); | |
| 84 | |
| 85 (function() { | |
| 86 var t = async_test("data: IFrame."); | |
| 87 t.step(function () { | |
| 88 var iframe = document.createElement('iframe'); | |
| 89 iframe.src = "data:text/html,<script>" + | |
| 90 " window.addEventListener('message', function (e) {" + | |
| 91 " event.source.postMessage({" + | |
| 92 " 'origin': document.origin," + | |
| 93 " 'id': e.data.id" + | |
| 94 " }, e.origin);" + | |
| 95 " });" + | |
| 96 "</sc" + "ript>"; | |
| 97 | |
| 98 iframe.addEventListener('load', function () { | |
| 99 iframe.contentWindow.postMessage({ 'id': 'data-iframe' }, '*'); | |
| 100 }); | |
| 101 window.addEventListener('message', function (e) { | |
| 102 if (e.data.id != 'data-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 | |
| 113 (function() { | |
| 114 var t = async_test("Sandboxed same-origin IFrame."); | |
| 115 t.step(function () { | |
| 116 var iframe = document.createElement('iframe'); | |
| 117 iframe.setAttribute('sandbox', 'allow-scripts'); | |
| 118 iframe.src = "/security/resources/postmessage-document-origin.html"; | |
| 119 iframe.addEventListener('load', function () { | |
| 120 iframe.contentWindow.postMessage({ 'id': 'sandboxed-same-origin- iframe' }, '*'); | |
| 121 }); | |
| 122 window.addEventListener('message', function (e) { | |
| 123 if (e.data.id != 'sandboxed-same-origin-iframe') | |
| 124 return; | |
| 125 | |
| 126 assert_equals(e.data.origin, 'null'); | |
| 127 assert_equals(e.data.origin, e.origin); | |
| 128 t.done(); | |
| 129 }); | |
| 130 document.body.appendChild(iframe); | |
| 131 }); | |
| 132 })(); | |
| 133 | |
| 134 (function() { | |
| 135 var t = async_test("Sandboxed cross-origin IFrame."); | |
| 136 t.step(function () { | |
| 137 var iframe = document.createElement('iframe'); | |
| 138 iframe.setAttribute('sandbox', 'allow-scripts'); | |
| 139 iframe.src = "http://localhost:8080/security/resources/postmessage-d ocument-origin.html"; | |
| 140 iframe.addEventListener('load', function () { | |
| 141 iframe.contentWindow.postMessage({ 'id': 'sandboxed-cross-origin -iframe' }, '*'); | |
| 142 }); | |
| 143 window.addEventListener('message', function (e) { | |
| 144 if (e.data.id != 'sandboxed-cross-origin-iframe') | |
| 145 return; | |
| 146 | |
| 147 assert_equals(e.data.origin, 'null'); | |
| 148 assert_equals(e.data.origin, e.origin); | |
| 149 t.done(); | |
| 150 }); | |
| 151 document.body.appendChild(iframe); | |
| 152 }); | |
| 153 })(); | |
| 154 </script> | |
| 155 </body> | |
| 156 </html> | |
| OLD | NEW |