OLD | NEW |
1 // Tiny test rig for all security/link-crossorigin-*.html tests, | 1 // Tiny test rig for all security/link-crossorigin-*.html tests, |
2 // which exercise <link> + CORS variations. | 2 // which exercise <link> + CORS variations. |
3 | 3 |
4 self.jsTestIsAsync = true; | 4 window.jsTestIsAsync = true; |
5 | 5 |
6 if (window.testRunner) { | 6 if (window.testRunner) { |
7 testRunner.dumpAsText(); | 7 testRunner.dumpAsText(); |
8 testRunner.waitUntilDone(); | 8 testRunner.waitUntilDone(); |
9 } | 9 } |
10 | 10 |
11 // The common case is to have four sub-tests. To override | 11 // The common case is to have four sub-tests. To override |
12 // for a test, assign window.test_count. | 12 // for a test, assign window.testCount. |
13 var default_test_count = 4; | 13 var defaultTestCount = 4; |
14 | 14 |
15 var event_count = 0; | 15 var eventCount = 0; |
16 test_count = window.test_count || default_test_count; | 16 testCount = window.testCount || defaultTestCount; |
17 | 17 |
18 function finish(pass, msg) { | 18 function finish(pass, msg, event) { |
19 if (pass) | 19 if (pass) |
20 testPassed(msg || ""); | 20 testPassed(msg || ""); |
21 else | 21 else |
22 testFailed(msg || ""); | 22 testFailed(msg || ""); |
23 if (++event_count >= test_count) | 23 |
| 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) |
| 33 ; |
| 34 if (document.styleSheets[i].cssRules[0].cssText.indexOf("gre
en") == -1) |
| 35 testFailed("Failed to find occurrence of 'green' in styl
esheet: " + event.target.href); |
| 36 } catch (e) { |
| 37 testFailed("Failed to access contents of stylesheet: " + eve
nt.target.href); |
| 38 } |
| 39 } else { |
| 40 try { |
| 41 // Will throw as .cssRules should return 0. |
| 42 if (document.styleSheets[i].cssRules[0].cssRules[0]) |
| 43 ; |
| 44 testFailed("Should not be able to access contents of stylesh
eet: " + event.target.href); |
| 45 } catch (e) { |
| 46 ; |
| 47 } |
| 48 } |
| 49 break; |
| 50 } |
| 51 } |
| 52 if (++eventCount >= testCount) |
24 finishJSTest(); | 53 finishJSTest(); |
25 } | 54 } |
26 | 55 |
27 function pass() { finish(true); } | 56 function pass(event) { finish(true, "", event); } |
28 function fail() { finish(false); } | 57 function fail(event) { finish(false, "", event); } |
OLD | NEW |