content/base/test/test_meta_viewport4.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial