OLD | NEW |
| 1 <html> |
| 2 <head> |
| 3 <script> |
1 function setMetaViewport(override) | 4 function setMetaViewport(override) |
2 { | 5 { |
3 var VIEWPORTS = { | 6 var VIEWPORTS = { |
4 "w=320": "width=320", | 7 "w=320": "width=320", |
5 "w=dw": "width=device-width", | 8 "w=dw": "width=device-width", |
6 "w=980": "width=980", | 9 "w=980": "width=980", |
7 "none": "no viewport (desktop site)" | 10 "none": "no viewport (desktop site)" |
8 }; | 11 }; |
9 | 12 |
10 var viewport = VIEWPORTS["none"]; | 13 var viewport = VIEWPORTS["none"]; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 testMQDimension("height", document.documentElement.clientHeight); | 101 testMQDimension("height", document.documentElement.clientHeight); |
99 } | 102 } |
100 testJS("document.documentElement.clientHeight"); | 103 testJS("document.documentElement.clientHeight"); |
101 testJS("document.documentElement.offsetHeight"); | 104 testJS("document.documentElement.offsetHeight"); |
102 testJS("document.documentElement.scrollHeight"); | 105 testJS("document.documentElement.scrollHeight"); |
103 if (full) | 106 if (full) |
104 testJS("document.body.clientHeight"); | 107 testJS("document.body.clientHeight"); |
105 testJS("document.body.offsetHeight"); | 108 testJS("document.body.offsetHeight"); |
106 testJS("document.body.scrollHeight"); | 109 testJS("document.body.scrollHeight"); |
107 | 110 |
108 var measured = document.querySelectorAll(".device-emulation-measure"); | |
109 for (var i = 0; i < measured.length; ++i) | |
110 writeResult("measured " + measured[i].getAttribute("type") + ": " + meas
ured[i].offsetWidth + "x" + measured[i].offsetHeight); | |
111 | |
112 return results.join("\n"); | 111 return results.join("\n"); |
113 } | 112 } |
114 | 113 |
115 function testJS(expr, unit) | 114 function testJS(expr, unit) |
116 { | 115 { |
117 if (unit === undefined) | 116 if (unit === undefined) |
118 unit = "px"; | 117 unit = "px"; |
119 | 118 |
120 var ans = eval(expr); | 119 var ans = eval(expr); |
121 if (typeof ans == "number") | 120 if (typeof ans == "number") |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (matchMedia("screen and (min-" + feature + ":" + mid + unit + ")").matche
s) | 178 if (matchMedia("screen and (min-" + feature + ":" + mid + unit + ")").matche
s) |
180 return mqBinarySearch(feature, mid, maxValue, unit); // feature is >= mi
d | 179 return mqBinarySearch(feature, mid, maxValue, unit); // feature is >= mi
d |
181 else | 180 else |
182 return mqBinarySearch(feature, minValue, mid - 1, unit); // feature is <
mid | 181 return mqBinarySearch(feature, minValue, mid - 1, unit); // feature is <
mid |
183 } | 182 } |
184 | 183 |
185 function writeResult(key, val) | 184 function writeResult(key, val) |
186 { | 185 { |
187 results.push(key + (val ? " = " + val : "")); | 186 results.push(key + (val ? " = " + val : "")); |
188 } | 187 } |
| 188 </script> |
189 | 189 |
190 var initialize_DeviceEmulationTest = function() { | 190 <script> |
| 191 // This test is based on http://jsbin.com/urowoh/latest. |
| 192 setMetaViewport(); |
| 193 </script> |
191 | 194 |
192 InspectorTest.getPageMetrics = function(full, callback) | 195 <style> |
193 { | 196 html { |
194 InspectorTest.evaluateInPage("dumpMetrics(" + full + ")", callback); | 197 overflow-x: hidden; |
195 } | 198 } |
196 | 199 |
197 InspectorTest.applyEmulationAndReload = function(enabled, width, height, deviceS
caleFactor, viewport, insets, noReload, callback) | 200 body { |
198 { | 201 margin: 0; |
199 if (enabled) { | 202 min-height: 1000px; |
200 var params = {}; | 203 overflow-x: hidden; |
201 params.width = width; | 204 } |
202 params.height = height; | 205 body.small { |
203 params.deviceScaleFactor = deviceScaleFactor; | 206 min-height: 100px; |
204 params.mobile = true; | 207 } |
205 params.fitWindow = false; | 208 </style> |
206 params.scale = 1; | 209 </head> |
207 params.screenWidth = width; | |
208 params.screenHeight = height; | |
209 params.positionX = 0; | |
210 params.positionY = 0; | |
211 if (insets) { | |
212 params.screenWidth += insets.left + insets.right; | |
213 params.positionX = insets.left; | |
214 params.screenHeight += insets.top + insets.bottom; | |
215 params.positionY = insets.top; | |
216 } | |
217 InspectorTest.sendCommand("Emulation.setDeviceMetricsOverride", params,
emulateCallback); | |
218 } else { | |
219 InspectorTest.sendCommand("Emulation.clearDeviceMetricsOverride", {}, em
ulateCallback); | |
220 } | |
221 | 210 |
222 function emulateCallback(result) | 211 <body> |
223 { | 212 </body> |
224 if (result.error) | 213 </html> |
225 InspectorTest._deviceEmulationResults.push("Error: " + result.error)
; | |
226 if (noReload) | |
227 callback(); | |
228 else | |
229 InspectorTest.navigate(InspectorTest._deviceEmulationPageUrl + "?" +
viewport, callback); | |
230 } | |
231 }; | |
232 | |
233 InspectorTest.emulateAndGetMetrics = function(width, height, deviceScaleFactor,
viewport, insets, noReload, callback) | |
234 { | |
235 InspectorTest._deviceEmulationResults.push("Emulating device: " + width + "x
" + height + "x" + deviceScaleFactor + " viewport='" + viewport + "'"); | |
236 var full = !!width && !!height && !!deviceScaleFactor; | |
237 InspectorTest.applyEmulationAndReload(true, width, height, deviceScaleFactor
, viewport, insets, noReload, InspectorTest.getPageMetrics.bind(InspectorTest, f
ull, printMetrics)); | |
238 | |
239 function printMetrics(metrics) | |
240 { | |
241 InspectorTest._deviceEmulationResults.push(metrics + "\n"); | |
242 callback(); | |
243 } | |
244 }; | |
245 | |
246 InspectorTest.testDeviceEmulation = function(pageUrl, width, height, deviceScale
Factor, viewport, insets, noReload) | |
247 { | |
248 InspectorTest._deviceEmulationPageUrl = pageUrl; | |
249 InspectorTest._deviceEmulationResults = []; | |
250 InspectorTest.emulateAndGetMetrics(width, height, deviceScaleFactor, viewpor
t, insets, noReload, callback); | |
251 | |
252 function callback() | |
253 { | |
254 InspectorTest.log(InspectorTest._deviceEmulationResults.join("\n")); | |
255 InspectorTest.completeTest(); | |
256 } | |
257 }; | |
258 | |
259 }; | |
OLD | NEW |