| 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 |
<!-- This is the real test stylesheet and has correct CORS attributes and http headers --> |
| 11 |
<link rel="stylesheet" href="http://localhost:8081/test/browser.expect.css" crossorigin="anonymous"> |
| 12 |
</head> |
| 13 |
<body> |
| 14 |
<the-fixture id="fixture">Fixture</the-fixture> |
| 15 |
|
| 16 |
<script type="module"> |
| 17 |
function rafP(callback) { |
| 18 |
return new Promise((resolve) => { |
| 19 |
requestAnimationFrame(() => { |
| 20 |
requestAnimationFrame(() => { |
| 21 |
callback(); |
| 22 |
resolve(); |
| 23 |
}); |
| 24 |
}); |
| 25 |
}); |
| 26 |
} |
| 27 |
|
| 28 |
self.runTest = async function runTest() { |
| 29 |
return await testPreferenceSwitch(); |
| 30 |
} |
| 31 |
|
| 32 |
async function testPreferenceSwitch() { |
| 33 |
const purple = 'rgb(128, 0, 128)'; |
| 34 |
const pink = 'rgb(255, 192, 203)'; |
| 35 |
|
| 36 |
function testColor(test_name, color) { |
| 37 |
var actual = getComputedStyle(fixture).color; |
| 38 |
if (actual !== color) { |
| 39 |
throw new Error((window.location.hash ?? '#no-preference') + ' - ' + test_name + ': ' + fixture.id + '.color; expected ' + color + ' but got ' + actual); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
if (window.location.hash === '#light') { |
| 44 |
await rafP(() => { |
| 45 |
testColor('before', pink); |
| 46 |
}); |
| 47 |
} else if (window.location.hash === '#dark') { |
| 48 |
await rafP(() => { |
| 49 |
testColor('before', purple); |
| 50 |
}); |
| 51 |
} else { |
| 52 |
await rafP(() => { |
| 53 |
testColor('before', pink); |
| 54 |
}); |
| 55 |
} |
| 56 |
|
| 57 |
return true; |
| 58 |
} |
| 59 |
</script> |
| 60 |
</body> |
| 61 |
</html> |