Chromium Code Reviews| Index: LayoutTests/http/tests/security/document-origin.html |
| diff --git a/LayoutTests/http/tests/security/document-origin.html b/LayoutTests/http/tests/security/document-origin.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..48e4545ff5d75ccf4dddb701a716e016e68d048e |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/security/document-origin.html |
| @@ -0,0 +1,112 @@ |
| +<!DOCTYPE html> |
| +<title>document.origin</title> |
| +<script src="/resources/testharness.js"></script> |
| +<script src="/resources/testharnessreport.js"></script> |
| + |
| +<iframe id="srcdoc" srcdoc="<p>yay</p>"></iframe> |
|
jochen (gone - plz use gerrit)
2014/11/25 15:53:49
where do you check the origin in the srcdoc?
Mike West
2014/11/25 15:56:34
I thought I did, but I apparently didn't.
Fixing!
|
| + |
| +<script> |
| +test(function() { |
| + assert_equals(document.origin, 'http://127.0.0.1:8000'); |
| +}, 'Top-level document.'); |
| + |
| +test(function() { |
| + var doc = document.implementation.createHTMLDocument(); |
| + assert_equals(doc.origin, 'http://127.0.0.1:8000'); |
| +}, 'createHTMLDocument()'); |
| + |
| + |
| +(function() { |
| + var t = async_test("about:blank IFrame."); |
| + t.step(function () { |
| + var iframe = document.createElement('iframe'); |
| + iframe.addEventListener('load', function () { |
| + assert_equals(iframe.contentDocument.origin, 'http://127.0.0.1:8000'); |
| + t.done(); |
| + }); |
| + document.body.appendChild(iframe); |
| + }); |
| +})(); |
| + |
| +(function() { |
| + var t = async_test("Same-origin IFrame."); |
| + t.step(function () { |
| + var iframe = document.createElement('iframe'); |
| + iframe.src = "/security/resources/postmessage-document-origin.html"; |
| + iframe.addEventListener('load', function () { |
| + iframe.contentWindow.postMessage({ 'id': 'same-origin-iframe' }, '*'); |
| + }); |
| + window.addEventListener('message', function (e) { |
| + if (e.data.id != 'same-origin-iframe') |
| + return; |
| + |
| + assert_equals(e.data.origin, 'http://127.0.0.1:8000'); |
| + assert_equals(e.data.origin, e.origin); |
| + t.done(); |
| + }); |
| + document.body.appendChild(iframe); |
| + }); |
| +})(); |
| + |
| +(function() { |
| + var t = async_test("Cross-origin IFrame."); |
| + t.step(function () { |
| + var iframe = document.createElement('iframe'); |
| + iframe.src = "http://localhost:8080/security/resources/postmessage-document-origin.html"; |
| + iframe.addEventListener('load', function () { |
| + iframe.contentWindow.postMessage({ 'id': 'cross-origin-iframe' }, '*'); |
| + }); |
| + window.addEventListener('message', function (e) { |
| + if (e.data.id != 'cross-origin-iframe') |
| + return; |
| + |
| + assert_equals(e.data.origin, 'http://localhost:8080'); |
| + assert_equals(e.data.origin, e.origin); |
| + t.done(); |
| + }); |
| + document.body.appendChild(iframe); |
| + }); |
| +})(); |
| + |
| +(function() { |
| + var t = async_test("Sandboxed same-origin IFrame."); |
| + t.step(function () { |
| + var iframe = document.createElement('iframe'); |
| + iframe.setAttribute('sandbox', 'allow-scripts'); |
| + iframe.src = "/security/resources/postmessage-document-origin.html"; |
| + iframe.addEventListener('load', function () { |
| + iframe.contentWindow.postMessage({ 'id': 'sandboxed-same-origin-iframe' }, '*'); |
| + }); |
| + window.addEventListener('message', function (e) { |
| + if (e.data.id != 'sandboxed-same-origin-iframe') |
| + return; |
| + |
| + assert_equals(e.data.origin, 'null'); |
|
Mike West
2014/11/25 15:56:34
This test and the one below test that sandboxed if
|
| + assert_equals(e.data.origin, e.origin); |
| + t.done(); |
| + }); |
| + document.body.appendChild(iframe); |
| + }); |
| +})(); |
| + |
| +(function() { |
| + var t = async_test("Sandboxed cross-origin IFrame."); |
| + t.step(function () { |
| + var iframe = document.createElement('iframe'); |
| + iframe.setAttribute('sandbox', 'allow-scripts'); |
| + iframe.src = "http://localhost:8080/security/resources/postmessage-document-origin.html"; |
| + iframe.addEventListener('load', function () { |
| + iframe.contentWindow.postMessage({ 'id': 'sandboxed-cross-origin-iframe' }, '*'); |
| + }); |
| + window.addEventListener('message', function (e) { |
| + if (e.data.id != 'sandboxed-cross-origin-iframe') |
| + return; |
| + |
| + assert_equals(e.data.origin, 'null'); |
| + assert_equals(e.data.origin, e.origin); |
| + t.done(); |
| + }); |
| + document.body.appendChild(iframe); |
| + }); |
| +})(); |
| +</script> |