| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title></title> |
| 6 |
<link rel="help" href="https://drafts.csswg.org/selectors/#relational"> |
| 7 |
<!-- Included only to trigger CORS errors --> |
| 8 |
<!-- This stylesheet is not accessible in JS and must not cause cascading failures --> |
| 9 |
<link rel="stylesheet" href="http://localhost:8081/test/basic.expect.css"> |
| 10 |
|
| 11 |
<script src="http://localhost:8082/dist/browser-global.js"></script> |
| 12 |
<script>cssHasPseudo(document, { observedAttributes: ['attrname', 'a_test_attr', 'c_test_attr'], debug: false, hover: true, forcePolyfill: window.location.hash === '#force-polyfill' });</script> |
| 13 |
|
| 14 |
<!-- This is the real test stylesheet and has correct CORS attributes and http headers --> |
| 15 |
<link id="the-stylesheet" rel="stylesheet" href="http://localhost:8081/test/browser-stylesheet-loading.expect.css" crossorigin="anonymous"> |
| 16 |
</head> |
| 17 |
<body> |
| 18 |
<p id="hello-world">Hello World</p> |
| 19 |
|
| 20 |
<script type="module"> |
| 21 |
function rafP(callback) { |
| 22 |
return new Promise((resolve) => { |
| 23 |
requestAnimationFrame(() => { |
| 24 |
requestAnimationFrame(() => { |
| 25 |
callback(); |
| 26 |
resolve(); |
| 27 |
}); |
| 28 |
}); |
| 29 |
}); |
| 30 |
} |
| 31 |
|
| 32 |
self.runTest = async function runTest() { |
| 33 |
const testLoadingAfterJSResult = await testLoadingAfterJS(); |
| 34 |
|
| 35 |
return testLoadingAfterJSResult; |
| 36 |
} |
| 37 |
|
| 38 |
async function testLoadingAfterJS() { |
| 39 |
function testColor(test_name, color) { |
| 40 |
var actual = getComputedStyle(document.getElementById('hello-world')).color; |
| 41 |
if (actual !== color) { |
| 42 |
throw new Error(test_name + ': div#hello-world.color; expected ' + color + ' but got ' + actual); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
const green = 'rgb(0, 128, 0)'; |
| 47 |
const black = 'rgb(0, 0, 0)'; |
| 48 |
|
| 49 |
await rafP(() => { |
| 50 |
testColor(`Text is green when loading a stylesheet after initializing the polyfill`, green); |
| 51 |
}); |
| 52 |
|
| 53 |
document.getElementById('the-stylesheet').remove(); |
| 54 |
|
| 55 |
await rafP(() => { |
| 56 |
testColor(`Text is green when loading a stylesheet after initializing the polyfill`, black); |
| 57 |
}); |
| 58 |
|
| 59 |
var head = document.head; |
| 60 |
var link = document.createElement("link"); |
| 61 |
|
| 62 |
link.type = "text/css"; |
| 63 |
link.rel = "stylesheet"; |
| 64 |
link.href = "http://localhost:8081/test/browser-stylesheet-loading.expect.css?delay"; |
| 65 |
link.crossOrigin = "anonymous"; |
| 66 |
|
| 67 |
const loadWaiter = new Promise((resolve) => { |
| 68 |
link.addEventListener('load', resolve); |
| 69 |
}); |
| 70 |
|
| 71 |
head.appendChild(link); |
| 72 |
|
| 73 |
await loadWaiter; |
| 74 |
|
| 75 |
await rafP(() => { |
| 76 |
testColor(`Text is green when loading a stylesheet after initializing the polyfill`, green); |
| 77 |
}); |
| 78 |
|
| 79 |
return true; |
| 80 |
} |
| 81 |
</script> |
| 82 |
</body> |
| 83 |
</html> |