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

Unified Diff: LayoutTests/http/tests/security/resources/link-crossorigin-common.js

Issue 1011103002: Allow cross-origin cssRules access to CORS-fetched stylesheet. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: compile fix.. Created 5 years, 9 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/resources/link-crossorigin-common.js
diff --git a/LayoutTests/http/tests/security/resources/link-crossorigin-common.js b/LayoutTests/http/tests/security/resources/link-crossorigin-common.js
index a7f1bdfc2e8b5b750cb054ce9cbed28af0feb441..a50b3a57bec4aadec0a8b8183026dbd0d09928b6 100644
--- a/LayoutTests/http/tests/security/resources/link-crossorigin-common.js
+++ b/LayoutTests/http/tests/security/resources/link-crossorigin-common.js
@@ -1,7 +1,7 @@
// Tiny test rig for all security/link-crossorigin-*.html tests,
// which exercise <link> + CORS variations.
-self.jsTestIsAsync = true;
+window.jsTestIsAsync = true;
if (window.testRunner) {
testRunner.dumpAsText();
@@ -9,20 +9,49 @@ if (window.testRunner) {
}
// The common case is to have four sub-tests. To override
-// for a test, assign window.test_count.
-var default_test_count = 4;
+// for a test, assign window.testCount.
+var defaultTestCount = 4;
-var event_count = 0;
-test_count = window.test_count || default_test_count;
+var eventCount = 0;
+testCount = window.testCount || defaultTestCount;
-function finish(pass, msg) {
+function finish(pass, msg, event) {
if (pass)
testPassed(msg || "");
- else
+ else
testFailed(msg || "");
- if (++event_count >= test_count)
+
+ // Verify that the stylesheet is (in)accessible.
+ // (only report failures so as to avoid subtest ordering instability.)
+ if (event !== undefined && event.target && event.target.rel === "stylesheet") {
+ for (var i = 0; i < document.styleSheets.length; ++i) {
+ if (document.styleSheets[i].href !== event.target.href)
+ continue;
+ if (event.type === "load") {
+ try {
+ if (document.styleSheets[i].cssRules[0].cssText.length >= 0)
+ ;
+ if (document.styleSheets[i].cssRules[0].cssText.indexOf("green") == -1)
+ testFailed("Failed to find occurrence of 'green' in stylesheet: " + event.target.href);
+ } catch (e) {
+ testFailed("Failed to access contents of stylesheet: " + event.target.href);
+ }
+ } else {
+ try {
+ // Will throw as .cssRules should return 0.
+ if (document.styleSheets[i].cssRules[0].cssRules[0])
+ ;
+ testFailed("Should not be able to access contents of stylesheet: " + event.target.href);
+ } catch (e) {
+ ;
+ }
+ }
+ break;
+ }
+ }
+ if (++eventCount >= testCount)
finishJSTest();
}
-function pass() { finish(true); }
-function fail() { finish(false); }
+function pass(event) { finish(true, "", event); }
+function fail(event) { finish(false, "", event); }

Powered by Google App Engine
This is Rietveld 408576698