Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=473400
5 -->
6 <head>
7 <title>Test for Bug 473400</title>
8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
10 </head>
11 <body onload="run()">
12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=473400">Mozilla Bug 473400</a>
13 <iframe id="subdoc" src="about:blank"></iframe>
14 <div id="content" style="display: none">
16 </div>
17 <pre id="test">
18 <script class="testbody" type="application/javascript; version=1.7">
20 /** Test for Bug 473400 **/
22 SimpleTest.waitForExplicitFinish();
24 function run() {
25 var subdoc = document.getElementById("subdoc").contentDocument;
26 var subwin = document.getElementById("subdoc").contentWindow;
27 var style = subdoc.createElement("style");
28 style.setAttribute("type", "text/css");
29 subdoc.getElementsByTagName("head")[0].appendChild(style);
30 var sheet = style.sheet;
31 var iframe_style = document.getElementById("subdoc").style;
33 // Create a style rule and an element now based on the given media
34 // query "q", and return the computed style that should be passed to
35 // query_applies to see if that query currently applies.
36 var n = 0;
37 function make_query(q) {
38 var i = ++n;
39 sheet.insertRule("@media " + q + " { #e" + i + " { text-decoration: underline; } }", sheet.cssRules.length);
40 var e = subdoc.createElement("div");
41 e.id = "e" + i;
42 subdoc.body.appendChild(e);
43 var cs = subdoc.defaultView.getComputedStyle(e, "");
44 cs._originalQueryText = q;
45 return cs;
46 }
47 function query_applies(cs) {
48 return cs.getPropertyValue("text-decoration") == "underline";
49 }
51 function should_apply(cs) {
52 ok(query_applies(cs), cs._originalQueryText + " should apply");
53 }
55 function should_not_apply(cs) {
56 ok(!query_applies(cs), cs._originalQueryText + " should not apply");
57 }
59 var content_div = document.getElementById("content");
60 content_div.style.font = "initial";
61 var em_size =
62 getComputedStyle(content_div, "").fontSize.match(/^(\d+)px$/)[1];
64 let width_val = 317; // pick two not-too-round numbers
65 let height_val = 228;
66 iframe_style.width = width_val + "px";
67 iframe_style.height = height_val + "px";
68 var wh_queries = [
69 make_query("all and (min-width: " +
70 (Math.ceil(width_val/em_size) + 1) + "em)"),
71 make_query("all and (min-width: " +
72 (Math.floor(width_val/em_size) - 1) + "em)"),
73 make_query("all and (max-width: " +
74 (Math.ceil(width_val/em_size) + 1) + "em)"),
75 make_query("all and (max-width: " +
76 (Math.floor(width_val/em_size) - 1) + "em)"),
77 make_query("all and (min-width: " +
78 (Math.ceil(width_val/(em_size*2)) + 1) + "em)"),
79 make_query("all and (min-width: " +
80 (Math.floor(width_val/(em_size*2)) - 1) + "em)"),
81 make_query("all and (max-width: " +
82 (Math.ceil(width_val/(em_size*2)) + 1) + "em)"),
83 make_query("all and (max-width: " +
84 (Math.floor(width_val/(em_size*2)) - 1) + "em)")
85 ];
87 is(wh_queries[0].fontSize, em_size + "px", "text zoom is 1.0");
88 should_not_apply(wh_queries[0]);
89 should_apply(wh_queries[1]);
90 should_apply(wh_queries[2]);
91 should_not_apply(wh_queries[3]);
92 SpecialPowers.setTextZoom(subwin, 2.0);
93 isnot(wh_queries[0].fontSize, em_size + "px", "text zoom is not 1.0");
94 should_not_apply(wh_queries[4]);
95 should_apply(wh_queries[5]);
96 should_apply(wh_queries[6]);
97 should_not_apply(wh_queries[7]);
98 SpecialPowers.setTextZoom(subwin, 1.0);
99 is(wh_queries[0].fontSize, em_size + "px", "text zoom is 1.0");
100 is(subwin.innerHeight, 228, "full zoom is 1.0");
101 should_not_apply(wh_queries[0]);
102 should_apply(wh_queries[1]);
103 should_apply(wh_queries[2]);
104 should_not_apply(wh_queries[3]);
105 SpecialPowers.setFullZoom(subwin, 2.0);
106 isnot(subwin.innerHeight, 228, "full zoom is not 1.0");
107 should_not_apply(wh_queries[4]);
108 should_apply(wh_queries[5]);
109 should_apply(wh_queries[6]);
110 should_not_apply(wh_queries[7]);
111 SpecialPowers.setFullZoom(subwin, 1.0);
112 is(subwin.innerHeight, 228, "full zoom is 1.0");
114 SimpleTest.finish();
115 }
117 </script>
118 </pre>
119 </body>
120 </html>