4 <script src=
"../../http/tests/inspector/inspector-test.js"></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
29 function getPageMetrics(callback
)
31 InspectorTest
.evaluateInPage("dumpMetrics()", parse
);
35 callback(JSON
.parse(json
.value
));
41 function testPartialOverride(name
, value
, next
)
43 var params
= {width
: 0, height
: 0, deviceScaleFactor
: 0, mobile
: false, fitWindow
: false};
45 InspectorTest
.PageAgent
.clearDeviceMetricsOverride(getPageMetrics
.bind(null, check
));
49 InspectorTest
.PageAgent
.invoke_setDeviceMetricsOverride(params
, getPageMetrics
.bind(null, check
));
52 function check(metrics
)
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
);
63 InspectorTest
.addResult(name
? ("[PASS]: " + name
+ "=" + value
) : "[PASS]");
68 InspectorTest
.runTestSuite([
69 function collectMetrics(next
)
71 function collect(metrics
)
73 initialMetrics
= metrics
;
76 getPageMetrics(collect
);
79 function noOverrides(next
)
81 testPartialOverride("", 0, next
);
86 testPartialOverride("width", 300, next
);
91 testPartialOverride("height", 400, next
);
94 function deviceScaleFactor1(next
)
96 testPartialOverride("deviceScaleFactor", 1, next
);
99 function deviceScaleFactor2(next
)
101 testPartialOverride("deviceScaleFactor", 2, 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
);
126 testPartialOverride(null, null, next
);
133 <body onload=
"runTest()">
135 Tests that overriding only a single parameter does not affect others.