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