Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: LayoutTests/http/tests/security/document-origin.html

Issue 758913002: Implement the 'document.origin' accessor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Moar assertions. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/security/document-origin-domain.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5832cea63b7387beb226809024728565feca1532
--- /dev/null
+++ b/LayoutTests/http/tests/security/document-origin.html
@@ -0,0 +1,156 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>document.origin</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+ <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("srcdoc IFrame.");
+ t.step(function () {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('srcdoc', '<p>Yay!</p>');
+ 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("data: IFrame.");
+ t.step(function () {
+ var iframe = document.createElement('iframe');
+ iframe.src = "data:text/html,<script>" +
+ " window.addEventListener('message', function (e) {" +
+ " event.source.postMessage({" +
+ " 'origin': document.origin," +
+ " 'id': e.data.id" +
+ " }, e.origin);" +
+ " });" +
+ "</sc" + "ript>";
+
+ iframe.addEventListener('load', function () {
+ iframe.contentWindow.postMessage({ 'id': 'data-iframe' }, '*');
+ });
+ window.addEventListener('message', function (e) {
+ if (e.data.id != 'data-iframe')
+ return;
+
+ assert_equals(e.data.origin, 'null');
+ 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');
+ 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>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/http/tests/security/document-origin-domain.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698