display_mode.html (4548B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1104916 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Display Mode</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://global/skin"/> 11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 12 <script type="application/javascript"> 13 var imports = [ "SimpleTest", "is", "isnot", "ok" ]; 14 for (var n of imports) { 15 window[n] = window.opener.wrappedJSObject[n]; 16 } 17 18 /** Test for Display Mode */ 19 20 function waitOneEvent(element, name) { 21 return new Promise(function(resolve, reject) { 22 element.addEventListener(name, function() { 23 resolve(); 24 }, {once: true}); 25 }); 26 } 27 28 function promiseNextTick() { 29 return new Promise(resolve => setTimeout(resolve, 0)); 30 } 31 32 async function test_task() { 33 var iframe = document.getElementById("subdoc"); 34 var subdoc = iframe.contentDocument; 35 var style = subdoc.getElementById("style"); 36 var bodyComputedStyled = subdoc.defaultView.getComputedStyle(subdoc.body); 37 var win = Services.wm.getMostRecentWindow("navigator:browser"); 38 39 function queryApplies(q) { 40 style.setAttribute("media", q); 41 return bodyComputedStyled.getPropertyValue("text-decoration-line") == 42 "underline"; 43 } 44 45 function shouldApply(q) { 46 ok(queryApplies(q), q + " should apply"); 47 } 48 49 function shouldNotApply(q) { 50 ok(!queryApplies(q), q + " should not apply"); 51 } 52 53 function setDisplayMode(mode) { 54 window.browsingContext.top.displayMode = mode; 55 } 56 57 shouldApply("all and (display-mode: browser)"); 58 shouldNotApply("all and (display-mode: fullscreen)"); 59 shouldNotApply("all and (display-mode: standalone)"); 60 shouldNotApply("all and (display-mode: minimal-ui)"); 61 62 // Test entering the OS's fullscreen mode. 63 var fullScreenEntered = waitOneEvent(win, "sizemodechange"); 64 synthesizeKey("KEY_F11"); 65 await fullScreenEntered; 66 // Wait for the next tick to apply media feature changes. See bug 1430380. 67 await promiseNextTick(); 68 shouldApply("all and (display-mode: fullscreen)"); 69 shouldNotApply("all and (display-mode: browser)"); 70 var fullScreenExited = waitOneEvent(win, "sizemodechange"); 71 synthesizeKey("KEY_F11"); 72 await fullScreenExited; 73 // Wait for the next tick to apply media feature changes. See bug 1430380. 74 await promiseNextTick(); 75 shouldNotApply("all and (display-mode: fullscreen)"); 76 shouldApply("all and (display-mode: browser)"); 77 78 // Test entering fullscreen through document requestFullScreen. 79 fullScreenEntered = waitOneEvent(document, "mozfullscreenchange"); 80 document.body.mozRequestFullScreen(); 81 await fullScreenEntered 82 ok(document.mozFullScreenElement, "window entered fullscreen"); 83 shouldApply("all and (display-mode: fullscreen)"); 84 shouldNotApply("all and (display-mode: browser)"); 85 fullScreenExited = waitOneEvent(document, "mozfullscreenchange"); 86 document.mozCancelFullScreen(); 87 await fullScreenExited; 88 ok(!document.mozFullScreenElement, "window exited fullscreen"); 89 shouldNotApply("all and (display-mode: fullscreen)"); 90 shouldApply("all and (display-mode: browser)"); 91 92 // Test entering display mode mode through docshell 93 setDisplayMode("standalone"); 94 shouldApply("all and (display-mode: standalone)"); 95 shouldNotApply("all and (display-mode: fullscreen)"); 96 shouldNotApply("all and (display-mode: browser)"); 97 shouldNotApply("all and (display-mode: minimal-ui)"); 98 99 // Test that changes in the display mode are reflected 100 setDisplayMode("minimal-ui"); 101 shouldApply("all and (display-mode: minimal-ui)"); 102 shouldNotApply("all and (display-mode: standalone)"); 103 104 // Set the display mode back. 105 setDisplayMode("browser"); 106 107 window.close(); 108 window.SimpleTest.finish(); 109 } 110 </script> 111 </head> 112 <body onload="test_task()"> 113 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1104916">Mozilla Bug 1104916</a> 114 <iframe id="subdoc" src="http://mochi.test:8888/tests/layout/style/test/chrome/media_queries_iframe.html" allowfullscreen></iframe> 115 <p id="display"></p> 116 <div id="content" style="display: none"> 117 118 </div> 119 <pre id="test"> 120 </pre> 121 </body> 122 </html>