|
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="width=device-width, initial-scale=1"> |
|
9 <script src="viewport_helpers.js"></script> |
|
10 </head> |
|
11 <body> |
|
12 <p>width=device-width, initial-scale=1</p> |
|
13 <script type="application/javascript;version=1.7"> |
|
14 "use strict"; |
|
15 |
|
16 SimpleTest.waitForExplicitFinish(); |
|
17 |
|
18 let tests = []; |
|
19 |
|
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 100%"); |
|
25 is(info.width, 800, "width is the same as the displayWidth"); |
|
26 is(info.height, 480, "height is the same as the displayHeight"); |
|
27 is(info.autoSize, true, "width=device-width enables autoSize"); |
|
28 is(info.allowZoom, true, "zooming is enabled by default"); |
|
29 |
|
30 info = getViewportInfo(900, 600); |
|
31 is(info.width, 900, "changing the displayWidth changes the width"); |
|
32 is(info.height, 600, "changing the displayHeight changes the height"); |
|
33 |
|
34 nextTest(); |
|
35 }); |
|
36 }); |
|
37 |
|
38 tests.push(function test2() { |
|
39 SpecialPowers.pushPrefEnv(scaleRatio(1.5), |
|
40 function() { |
|
41 let info = getViewportInfo(900, 600); |
|
42 is(info.defaultZoom, 1.5, "initial zoom is 150%"); |
|
43 is(info.width, 600, "width equals displayWidth/1.5"); |
|
44 is(info.height, 400, "height equals displayHeight/1.5"); |
|
45 |
|
46 nextTest(); |
|
47 }); |
|
48 }); |
|
49 |
|
50 function getViewportInfo(aDisplayWidth, aDisplayHeight) { |
|
51 let defaultZoom = {}, allowZoom = {}, minZoom = {}, maxZoom = {}, |
|
52 width = {}, height = {}, autoSize = {}; |
|
53 |
|
54 let cwu = SpecialPowers.getDOMWindowUtils(window); |
|
55 cwu.getViewportInfo(aDisplayWidth, aDisplayHeight, defaultZoom, allowZoom, |
|
56 minZoom, maxZoom, width, height, autoSize); |
|
57 return { |
|
58 defaultZoom: defaultZoom.value, |
|
59 minZoom: minZoom.value, |
|
60 maxZoom: maxZoom.value, |
|
61 width: width.value, |
|
62 height: height.value, |
|
63 autoSize: autoSize.value, |
|
64 allowZoom: allowZoom.value |
|
65 }; |
|
66 } |
|
67 |
|
68 function nextTest() { |
|
69 if (tests.length) |
|
70 (tests.shift())(); |
|
71 else |
|
72 SimpleTest.finish(); |
|
73 } |
|
74 addEventListener("load", nextTest); |
|
75 </script> |
|
76 </body> |
|
77 </html> |