test_mq_prefers_contrast_dynamic.html (2605B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1691793 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1691793</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1691793">Mozilla Bug 1691793</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 17 </div> 18 <pre id="test"> 19 </pre> 20 <script> 21 "use strict"; 22 23 SimpleTest.registerCleanupFunction(async () => { 24 await SpecialPowers.flushPrefEnv(); 25 }); 26 27 // Returns a Promise which will be resolved when the "change" event is received 28 // for the given media query string. 29 function promiseForChange(mediaQuery) { 30 return new Promise(resolve => { 31 window.matchMedia(mediaQuery).addEventListener("change", event => { 32 resolve(event.matches); 33 }, { once: true }); 34 }); 35 } 36 37 add_task(async () => { 38 const initiallyMatches = 39 window.matchMedia("(prefers-contrast: more)").matches; 40 const changePromise = initiallyMatches ? 41 promiseForChange("(prefers-contrast: more)") : null; 42 await SpecialPowers.pushPrefEnv({ set: [["ui.useAccessibilityTheme", 0]]}); 43 44 if (changePromise) { 45 await changePromise; 46 } 47 48 ok(!window.matchMedia("(prefers-contrast: more)").matches, 49 "Does not match prefers-contrast: more) when the system unsets " + 50 "UseAccessibilityTheme"); 51 ok(!window.matchMedia("(prefers-contrast)").matches, 52 "Does not match (prefers-contrast) when the system unsets " + 53 "UseAccessibilityTheme"); 54 ok(window.matchMedia("(prefers-contrast: no-preference)").matches, 55 "Matches (prefers-contrast: no-preference) when the system unsets " + 56 "UseAccessibilityTheme"); 57 }); 58 59 add_task(async () => { 60 const more = promiseForChange("(prefers-contrast: more)"); 61 const booleanContext = promiseForChange("(prefers-contrast)"); 62 const noPreference = promiseForChange("(prefers-contrast: no-preference)"); 63 64 await SpecialPowers.pushPrefEnv({ set: [["ui.useAccessibilityTheme", 1]]}); 65 66 const [ moreResult, booleanContextResult, noPreferenceResult ] = 67 await Promise.all([ more, booleanContext, noPreference ]); 68 69 ok(moreResult, 70 "Matches (prefers-contrast: more) when the system sets " + 71 "UseAccessibilityTheme"); 72 ok(booleanContextResult, 73 "Matches (prefers-contrast) when the system sets UseAccessibilityTheme"); 74 ok(!noPreferenceResult, 75 "Does not match (prefers-contrast: no-preference) when the " + 76 "system sets UseAccessibilityTheme"); 77 }); 78 79 </script> 80 </body> 81 </html>