Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / device-emulation / device-emulation-partial.html
blobd58f571ffa005ab211e1e11637de6a70aede6a88
1 <html>
2 <head>
4 <script src="../../http/tests/inspector/inspector-test.js"></script>
6 <style>
7 body {
8 margin: 0;
9 min-height: 1000px;
11 </style>
13 <script>
14 function dumpMetrics()
16 return JSON.stringify({
17 width: window.innerWidth,
18 height: window.innerHeight,
19 screenWidth: window.screen.width,
20 screenHeight: window.screen.height,
21 screenX: window.screenX,
22 screenY: window.screenY,
23 deviceScaleFactor: window.devicePixelRatio
24 });
27 function test()
29 function getPageMetrics(callback)
31 InspectorTest.evaluateInPage("dumpMetrics()", parse);
33 function parse(json)
35 callback(JSON.parse(json.value));
39 var initialMetrics;
41 function testPartialOverride(name, value, next)
43 var params = {width: 0, height: 0, deviceScaleFactor: 0, mobile: false, fitWindow: false};
44 if (name === null) {
45 InspectorTest.PageAgent.clearDeviceMetricsOverride(getPageMetrics.bind(null, check));
46 } else {
47 if (name)
48 params[name] = value;
49 InspectorTest.PageAgent.invoke_setDeviceMetricsOverride(params, getPageMetrics.bind(null, check));
52 function check(metrics)
54 var fail = false;
55 for (var key in initialMetrics) {
56 var expected = key === name ? value : initialMetrics[key];
57 if (metrics[key] !== expected) {
58 InspectorTest.addResult("[FAIL]: " + metrics[key] + " instead of " + expected + " for " + key);
59 fail = true;
62 if (!fail)
63 InspectorTest.addResult(name ? ("[PASS]: " + name + "=" + value) : "[PASS]");
64 next();
68 InspectorTest.runTestSuite([
69 function collectMetrics(next)
71 function collect(metrics)
73 initialMetrics = metrics;
74 next();
76 getPageMetrics(collect);
79 function noOverrides(next)
81 testPartialOverride("", 0, next);
84 function width(next)
86 testPartialOverride("width", 300, next);
89 function height(next)
91 testPartialOverride("height", 400, next);
94 function deviceScaleFactor1(next)
96 testPartialOverride("deviceScaleFactor", 1, next);
99 function deviceScaleFactor2(next)
101 testPartialOverride("deviceScaleFactor", 2, next);
104 function clear(next)
106 testPartialOverride(null, null, next);
109 function anotherWidth(next)
111 testPartialOverride("width", 400, next);
114 function anotherHeight(next)
116 testPartialOverride("height", 300, next);
119 function deviceScaleFactor3(next)
121 testPartialOverride("deviceScaleFactor", 3, next);
124 function clear(next)
126 testPartialOverride(null, null, next);
130 </script>
132 </head>
133 <body onload="runTest()">
135 Tests that overriding only a single parameter does not affect others.
136 </p>
137 </body>
138 </html>