Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / security / resources / link-crossorigin-common.js
bloba50b3a57bec4aadec0a8b8183026dbd0d09928b6
1 // Tiny test rig for all security/link-crossorigin-*.html tests,
2 // which exercise <link> + CORS variations.
4 window.jsTestIsAsync = true;
6 if (window.testRunner) {
7 testRunner.dumpAsText();
8 testRunner.waitUntilDone();
11 // The common case is to have four sub-tests. To override
12 // for a test, assign window.testCount.
13 var defaultTestCount = 4;
15 var eventCount = 0;
16 testCount = window.testCount || defaultTestCount;
18 function finish(pass, msg, event) {
19 if (pass)
20 testPassed(msg || "");
21 else
22 testFailed(msg || "");
24 // Verify that the stylesheet is (in)accessible.
25 // (only report failures so as to avoid subtest ordering instability.)
26 if (event !== undefined && event.target && event.target.rel === "stylesheet") {
27 for (var i = 0; i < document.styleSheets.length; ++i) {
28 if (document.styleSheets[i].href !== event.target.href)
29 continue;
30 if (event.type === "load") {
31 try {
32 if (document.styleSheets[i].cssRules[0].cssText.length >= 0)
34 if (document.styleSheets[i].cssRules[0].cssText.indexOf("green") == -1)
35 testFailed("Failed to find occurrence of 'green' in stylesheet: " + event.target.href);
36 } catch (e) {
37 testFailed("Failed to access contents of stylesheet: " + event.target.href);
39 } else {
40 try {
41 // Will throw as .cssRules should return 0.
42 if (document.styleSheets[i].cssRules[0].cssRules[0])
44 testFailed("Should not be able to access contents of stylesheet: " + event.target.href);
45 } catch (e) {
49 break;
52 if (++eventCount >= testCount)
53 finishJSTest();
56 function pass(event) { finish(true, "", event); }
57 function fail(event) { finish(false, "", event); }