Debian Codegraph @

plugins/css-prefers-color-scheme/test/_browser.html

raw
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 <script src="http://localhost:8082/dist/browser-global.js"></script>
13 <script>self._prefersColorScheme = prefersColorSchemeInit()</script>
14 </head>
15 <body>
16 <the-fixture id="fixture">Fixture</the-fixture>
17
18 <script type="module">
19 function rafP(callback) {
20 return new Promise((resolve) => {
21 requestAnimationFrame(() => {
22 requestAnimationFrame(() => {
23 callback();
24 resolve();
25 });
26 });
27 });
28 }
29
30 self.runTest = async function runTest() {
31 return await testPreferenceSwitch();
32 }
33
34 async function testPreferenceSwitch() {
35 const purple = 'rgb(128, 0, 128)';
36 const pink = 'rgb(255, 192, 203)';
37
38 function testColor(test_name, color) {
39 var actual = getComputedStyle(fixture).color;
40 if (actual !== color) {
41 throw new Error((window.location.hash ?? '#no-preference') + ' - ' + test_name + ': ' + fixture.id + '.color; expected ' + color + ' but got ' + actual);
42 }
43 }
44
45 if (window.location.hash === '#light') {
46 await rafP(() => {
47 testColor('before', pink);
48 });
49
50 self._prefersColorScheme.scheme = 'dark';
51
52 await rafP(() => {
53 testColor('dark', purple);
54 });
55
56 self._prefersColorScheme.scheme = 'light';
57
58 await rafP(() => {
59 testColor('light', pink);
60 });
61
62 self._prefersColorScheme.scheme = '';
63
64 await rafP(() => {
65 testColor('empty', pink);
66 });
67
68 } else if (window.location.hash === '#dark') {
69 await rafP(() => {
70 testColor('before', purple);
71 });
72
73 self._prefersColorScheme.scheme = 'dark';
74
75 await rafP(() => {
76 testColor('dark', purple);
77 });
78
79 self._prefersColorScheme.scheme = 'light';
80
81 await rafP(() => {
82 testColor('light', pink);
83 });
84
85 self._prefersColorScheme.scheme = '';
86
87 await rafP(() => {
88 testColor('empty', purple);
89 });
90
91 } else {
92 await rafP(() => {
93 testColor('before', pink);
94 });
95
96 self._prefersColorScheme.scheme = 'dark';
97
98 await rafP(() => {
99 testColor('dark', purple);
100 });
101
102 self._prefersColorScheme.scheme = 'light';
103
104 await rafP(() => {
105 testColor('light', pink);
106 });
107
108 self._prefersColorScheme.scheme = '';
109
110 await rafP(() => {
111 testColor('empty', pink);
112 });
113 }
114
115 return true;
116 }
117 </script>
118 </body>
119 </html>