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

Unified Diff: LayoutTests/http/tests/security/contentSecurityPolicy/resources/child-src-test.js

Issue 131103010: CSP 1.1: Introduce the 'child-src' directive. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Tests. Created 6 years, 11 months 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/contentSecurityPolicy/resources/child-src-test.js
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/resources/child-src-test.js b/LayoutTests/http/tests/security/contentSecurityPolicy/resources/child-src-test.js
new file mode 100644
index 0000000000000000000000000000000000000000..58deac27f0516b7a50deb6271a626d7350dcacb7
--- /dev/null
+++ b/LayoutTests/http/tests/security/contentSecurityPolicy/resources/child-src-test.js
@@ -0,0 +1,45 @@
+var EXPECT_BLOCK = true;
+var EXPECT_LOAD = false;
+
+window.jsTestIsAsync = true;
+window.wasPostTestScriptParsed = true;
+
+var iframe;
+function injectFrame(url, shouldBlock) {
+ window.onload = function () {
+ iframe = document.createElement('iframe');
+ iframe.onload = iframeLoaded(shouldBlock);
+ iframe.src = url;
+ document.body.appendChild(iframe);
+ };
+}
+
+function iframeLoaded(expectBlock) {
+ return function(ev) {
+ var failed = true;
+ try {
+ console.log("IFrame load event fired: the IFrame's location is '" + ev.target.contentWindow.location.href + "'.");
+ if (expectBlock) {
+ testFailed("The IFrame should have been blocked (or cross-origin). It wasn't.");
+ failed = true;
+ } else {
+ testPassed("The IFrame should not have been blocked. It wasn't.");
+ failed = false;
+ }
+ } catch (ex) {
+ debug("IFrame load event fired: the IFrame is cross-origin (or was blocked).");
+ if (expectBlock) {
+ testPassed("The IFrame should have been blocked (or cross-origin). It was.");
+ failed = false;
+ } else {
+ testFailed("The IFrame should not have been blocked. It was.");
+ failed = true;
+ }
+ }
+ finishJSTest();
+ };
+}
+
+function injectFrameRedirectingTo(url, shouldBlock) {
+ injectFrame("/security/contentSecurityPolicy/resources/redir.php?url=" + url, shouldBlock);
+}

Powered by Google App Engine
This is Rietveld 408576698