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

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: 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
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>
+
+<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');
+ 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>

Powered by Google App Engine
This is Rietveld 408576698