Index: LayoutTests/http/tests/security/isolatedWorld/resources/bypass-main-world-csp-for-inline-style.js |
diff --git a/LayoutTests/http/tests/security/isolatedWorld/resources/bypass-main-world-csp-for-inline-style.js b/LayoutTests/http/tests/security/isolatedWorld/resources/bypass-main-world-csp-for-inline-style.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ce26eb0bd6417089ff0be8f03561d894b7ade4f4 |
--- /dev/null |
+++ b/LayoutTests/http/tests/security/isolatedWorld/resources/bypass-main-world-csp-for-inline-style.js |
@@ -0,0 +1,61 @@ |
+if (window.testRunner) { |
+ testRunner.dumpAsText(); |
+ testRunner.waitUntilDone(); |
+} |
+ |
+tests = 4; |
+window.addEventListener("message", function(message) { |
+ tests -= 1; |
+ test(); |
+}, false); |
+ |
+function test() { |
+ function injectInlineStyle(shouldSucceed, tests) { |
+ var id = 'div' + tests; |
+ var div = document.createElement('div'); |
+ div.id = id; |
+ document.body.appendChild(div); |
+ var style = document.createElement('style'); |
+ style.innerText = '#' + id + ' { color: red; }'; |
+ document.body.appendChild(style); |
+ var success = window.getComputedStyle(document.getElementById(id)).color === "rgb(255, 0, 0)"; |
+ if (shouldSucceed) { |
+ if (success) |
+ console.log("PASS: Style assignment in test " + tests + " was blocked by CSP."); |
+ else |
+ console.log("FAIL: Style assignment in test " + tests + " was not blocked by CSP."); |
+ } else { |
+ if (success) |
+ console.log("FAIL: Style assignment in test " + tests + " was blocked by CSP."); |
+ else |
+ console.log("PASS: Style assignment in test " + tests + " was not blocked by CSP."); |
+ } |
+ window.postMessage("next", "*"); |
+ } |
+ |
+ switch (tests) { |
+ case 4: |
+ console.log("Injecting in main world: this should fail."); |
+ injectInlineStyle(false, tests); |
+ break; |
+ case 3: |
+ console.log("Injecting into isolated world without bypass: this should fail."); |
+ testRunner.evaluateScriptInIsolatedWorld(1, String(eval("injectInlineStyle")) + "\ninjectInlineStyle(false," + tests + ");"); |
+ break; |
+ case 2: |
+ console.log("Starting to bypass main world's CSP: this should pass!"); |
+ testRunner.setIsolatedWorldContentSecurityPolicy(1, 'style-src \'unsafe-inline\' *'); |
+ testRunner.evaluateScriptInIsolatedWorld(1, String(eval("injectInlineStyle")) + "\ninjectInlineStyle(true," + tests + ");"); |
+ break; |
+ case 1: |
+ console.log("Injecting into main world again: this should fail."); |
+ injectInlineStyle(false, tests); |
+ break; |
+ case 0: |
+ testRunner.setIsolatedWorldContentSecurityPolicy(1, ''); |
+ testRunner.notifyDone(); |
+ break; |
+ } |
+} |
+ |
+document.addEventListener('DOMContentLoaded', test); |