content/base/test/test_meta_viewport3.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <meta charset="utf-8">
michael@0 5 <title>meta viewport test</title>
michael@0 6 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 8 <meta name="viewport" content="width=320">
michael@0 9 <script src="viewport_helpers.js"></script>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <p>width=320</p>
michael@0 13 <script type="application/javascript;version=1.7">
michael@0 14 "use strict";
michael@0 15
michael@0 16 SimpleTest.waitForExplicitFinish();
michael@0 17
michael@0 18 let tests = [];
michael@0 19
michael@0 20 tests.push(function test1() {
michael@0 21 SpecialPowers.pushPrefEnv(scaleRatio(1.0),
michael@0 22 function() {
michael@0 23 let info = getViewportInfo(800, 80);
michael@0 24 is(info.defaultZoom, 2.5, "initial zoom fits the displayWidth");
michael@0 25 is(info.width, 320, "width is set explicitly");
michael@0 26 is(info.height, 40, "height is at the absolute minimum");
michael@0 27 is(info.autoSize, false, "width=device-width enables autoSize");
michael@0 28 is(info.allowZoom, true, "zooming is enabled by default");
michael@0 29
michael@0 30 info = getViewportInfo(480, 800);
michael@0 31 is(info.defaultZoom, 1.5, "initial zoom fits the new displayWidth");
michael@0 32 is(info.width, 320, "explicit width is unchanged");
michael@0 33 is(info.height, 533, "height changes proportional to displayHeight");
michael@0 34
michael@0 35 nextTest();
michael@0 36 });
michael@0 37 });
michael@0 38
michael@0 39 tests.push(function test2() {
michael@0 40 SpecialPowers.pushPrefEnv(scaleRatio(1.5),
michael@0 41 function() {
michael@0 42 // With an explicit width in CSS px, the scaleRatio has no effect.
michael@0 43 let info = getViewportInfo(800, 80);
michael@0 44 is(info.defaultZoom, 2.5, "initial zoom still fits the displayWidth");
michael@0 45 is(info.width, 320, "width is still set explicitly");
michael@0 46 is(info.height, 40, "height is still minimum height");
michael@0 47
michael@0 48 nextTest();
michael@0 49 });
michael@0 50 });
michael@0 51
michael@0 52 function getViewportInfo(aDisplayWidth, aDisplayHeight) {
michael@0 53 let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {},
michael@0 54 width = {}, height = {}, autoSize = {};
michael@0 55
michael@0 56 let cwu = SpecialPowers.getDOMWindowUtils(window);
michael@0 57 cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom,
michael@0 58 minZoom, maxZoom, width, height, autoSize);
michael@0 59 return {
michael@0 60 defaultZoom: defaultZoom.value,
michael@0 61 minZoom: minZoom.value,
michael@0 62 maxZoom: maxZoom.value,
michael@0 63 width: width.value,
michael@0 64 height: height.value,
michael@0 65 autoSize: autoSize.value,
michael@0 66 allowZoom: allowZoom.value
michael@0 67 };
michael@0 68 }
michael@0 69
michael@0 70 function nextTest() {
michael@0 71 if (tests.length)
michael@0 72 (tests.shift())();
michael@0 73 else
michael@0 74 SimpleTest.finish();
michael@0 75 }
michael@0 76 addEventListener("load", nextTest);
michael@0 77 </script>
michael@0 78 </body>
michael@0 79 </html>

mercurial