Created
August 24, 2016 07:29
-
-
Save allstarschh/9b033bd15ab97bf329dcdd0cab5207ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 60c5fc0aaf43feabc850aa507ad98bc53822c622 | |
Author: Yoshi Huang <allstars.chh@mozilla.com> | |
Date: Wed Aug 24 15:26:34 2016 +0800 | |
postMessage test | |
diff --git a/browser/components/originattributes/test/browser.ini b/browser/components/originattributes/test/browser.ini | |
index c2784a2..f723b8bb 100644 | |
--- a/browser/components/originattributes/test/browser.ini | |
+++ b/browser/components/originattributes/test/browser.ini | |
@@ -4,10 +4,11 @@ support-files = | |
test.js | |
test.js^headers^ | |
test.html | |
test_firstParty.html | |
test_firstParty_cookie.html | |
test_firstParty_html_redirect.html | |
test_firstParty_http_redirect.html | |
test_firstParty_http_redirect.html^headers^ | |
+ test_firstParty_postMessage.html | |
[browser_firstPartyIsolation.js] | |
diff --git a/browser/components/originattributes/test/browser_firstPartyIsolation.js b/browser/components/originattributes/test/browser_firstPartyIsolation.js | |
index ed207e3..63e6185 100644 | |
--- a/browser/components/originattributes/test/browser_firstPartyIsolation.js | |
+++ b/browser/components/originattributes/test/browser_firstPartyIsolation.js | |
@@ -75,8 +75,25 @@ add_task(function* redirect_test() { | |
"The page should have been redirected to http://example.com"); | |
Assert.equal(content.document.nodePrincipal.originAttributes.firstPartyDomain, | |
attrs.firstPartyDomain, "The document should have firstPartyDomain"); | |
}); | |
gBrowser.removeTab(tab); | |
gBrowser.removeTab(tab2); | |
}); | |
+ | |
+add_task(function* postMessage_test() { | |
+ let tab = gBrowser.addTab(BASE_URL + "test_firstParty_postMessage.html"); | |
+ yield BrowserTestUtils.browserLoaded(tab.linkedBrowser, true, function (url) { | |
+ return url == BASE_URL + "test_firstParty_postMessage.html"; | |
+ }); | |
+ | |
+ yield ContentTask.spawn(tab.linkedBrowser, { firstPartyDomain: BASE_DOMAIN }, function* (attrs) { | |
+ info("document principal: " + content.document.nodePrincipal.origin); | |
+ let value = content.document.getElementById("message").textContent; | |
+ info("value="+value); | |
+ Assert.equal(value, "OK"); | |
+ }); | |
+ | |
+ gBrowser.removeTab(tab); | |
+}); | |
+ | |
diff --git a/browser/components/originattributes/test/test.html b/browser/components/originattributes/test/test.html | |
index 3eb8293..e72e953 100644 | |
--- a/browser/components/originattributes/test/test.html | |
+++ b/browser/components/originattributes/test/test.html | |
@@ -1,12 +1,21 @@ | |
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Test for Bug 1260931</title> | |
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> | |
<script src="test.js"></script> | |
+ <script> | |
+ window.onmessage = function (evt) { | |
+ window.parent.postMessage("OK", "http://mochi.test:8888"); | |
+ }; | |
+ setTimeout((function() { | |
+ window.parent.postMessage("KO", "http://mochi.test:8888"); | |
+ })(), 1000); | |
+ | |
+ </script> | |
</head> | |
<body> | |
Hello World. | |
</body> | |
</html> | |
diff --git a/browser/components/originattributes/test/test_firstParty_postMessage.html b/browser/components/originattributes/test/test_firstParty_postMessage.html | |
new file mode 100644 | |
index 0000000..47eb06b | |
--- /dev/null | |
+++ b/browser/components/originattributes/test/test_firstParty_postMessage.html | |
@@ -0,0 +1,24 @@ | |
+<!DOCTYPE HTML> | |
+<html> | |
+<head> | |
+ <meta charset="utf-8"/> | |
+ <title>Test for Bug 1260931</title> | |
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> | |
+</head> | |
+<script> | |
+function onload() { | |
+ let iframe1 = document.getElementById("iframe1"); | |
+ iframe1.contentWindow.postMessage("HI", "http://mochi.test:8888"); | |
+} | |
+ | |
+window.onmessage = function (evt) { | |
+ document.getElementById("message").textContent = evt.data; | |
+} | |
+</script> | |
+<body onload="onload()"> | |
+ <div> | |
+ <iframe id="iframe1" src="test.html"></iframe> | |
+ <span id="message"></span> | |
+ </div> | |
+</body> | |
+</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment