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;
16 testCount
= window
.testCount
|| defaultTestCount
;
18 function finish(pass
, msg
, event
) {
20 testPassed(msg
|| "");
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
)
30 if (event
.type
=== "load") {
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
);
37 testFailed("Failed to access contents of stylesheet: " + event
.target
.href
);
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
);
52 if (++eventCount
>= testCount
)
56 function pass(event
) { finish(true, "", event
); }
57 function fail(event
) { finish(false, "", event
); }