OLD | NEW |
1 function setMetaViewport() | 1 function setMetaViewport(override) |
2 { | 2 { |
3 var VIEWPORTS = { | 3 var VIEWPORTS = { |
4 "w=320": "width=320", | 4 "w=320": "width=320", |
5 "w=dw": "width=device-width", | 5 "w=dw": "width=device-width", |
6 "w=980": "width=980", | 6 "w=980": "width=980", |
7 "none": "no viewport (desktop site)" | 7 "none": "no viewport (desktop site)" |
8 }; | 8 }; |
9 | 9 |
10 var viewport = VIEWPORTS["none"]; | 10 var viewport = VIEWPORTS["none"]; |
11 for (var key in VIEWPORTS) { | 11 for (var key in VIEWPORTS) { |
12 if (location.search == "?" + key) { | 12 if (location.search == "?" + key) { |
13 viewport = VIEWPORTS[key]; | 13 viewport = VIEWPORTS[key]; |
14 break; | 14 break; |
15 } | 15 } |
16 } | 16 } |
| 17 if (override) |
| 18 viewport = VIEWPORTS[override]; |
17 if (viewport != VIEWPORTS["none"]) | 19 if (viewport != VIEWPORTS["none"]) |
18 document.write('<meta name="viewport" content="'+viewport+'">'); | 20 document.write('<meta name="viewport" content="'+viewport+'">'); |
19 } | 21 } |
20 | 22 |
21 // matchMedia() polyfill from https://github.com/paulirish/matchMedia.js | 23 // matchMedia() polyfill from https://github.com/paulirish/matchMedia.js |
22 // Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MI
T/BSD license | 24 // Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MI
T/BSD license |
23 window.matchMedia = window.matchMedia || (function(doc, undefined){ | 25 window.matchMedia = window.matchMedia || (function(doc, undefined){ |
24 var bool, | 26 var bool, |
25 docElem = doc.documentElement, | 27 docElem = doc.documentElement, |
26 refNode = docElem.firstElementChild || docElem.firstChild, | 28 refNode = docElem.firstElementChild || docElem.firstChild, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 182 |
181 var initialize_DeviceEmulationTest = function() { | 183 var initialize_DeviceEmulationTest = function() { |
182 | 184 |
183 InspectorTest.preloadPanel("network"); | 185 InspectorTest.preloadPanel("network"); |
184 | 186 |
185 InspectorTest.getPageMetrics = function(full, callback) | 187 InspectorTest.getPageMetrics = function(full, callback) |
186 { | 188 { |
187 InspectorTest.evaluateInPage("dumpMetrics(" + full + ")", callback); | 189 InspectorTest.evaluateInPage("dumpMetrics(" + full + ")", callback); |
188 } | 190 } |
189 | 191 |
190 InspectorTest.applyEmulationAndReload = function(enabled, width, height, deviceS
caleFactor, viewport, insets, callback) | 192 InspectorTest.applyEmulationAndReload = function(enabled, width, height, deviceS
caleFactor, viewport, insets, noReload, callback) |
191 { | 193 { |
192 function PageResizer() | 194 function PageResizer() |
193 { | 195 { |
194 } | 196 } |
195 | 197 |
196 PageResizer.prototype = | 198 PageResizer.prototype = |
197 { | 199 { |
198 update: function(dipWidth, dipHeight, scale) { }, | 200 update: function(dipWidth, dipHeight, scale) { }, |
199 __proto__: WebInspector.Object.prototype | 201 __proto__: WebInspector.Object.prototype |
200 } | 202 } |
(...skipping 10 matching lines...) Expand all Loading... |
211 } else { | 213 } else { |
212 WebInspector.overridesSupport.reset(); | 214 WebInspector.overridesSupport.reset(); |
213 } | 215 } |
214 WebInspector.overridesSupport.settings._emulationEnabled.set(enabled); | 216 WebInspector.overridesSupport.settings._emulationEnabled.set(enabled); |
215 | 217 |
216 function emulateCallback() | 218 function emulateCallback() |
217 { | 219 { |
218 var warning = WebInspector.overridesSupport.warningMessage(); | 220 var warning = WebInspector.overridesSupport.warningMessage(); |
219 if (warning) | 221 if (warning) |
220 InspectorTest._deviceEmulationResults.push("Emulation warning: " + w
arning); | 222 InspectorTest._deviceEmulationResults.push("Emulation warning: " + w
arning); |
221 InspectorTest.navigate(InspectorTest._deviceEmulationPageUrl + "?" + vie
wport, callback); | 223 if (noReload) |
| 224 callback(); |
| 225 else |
| 226 InspectorTest.navigate(InspectorTest._deviceEmulationPageUrl + "?" +
viewport, callback); |
222 } | 227 } |
223 }; | 228 }; |
224 | 229 |
225 InspectorTest.emulateAndGetMetrics = function(width, height, deviceScaleFactor,
viewport, insets, callback) | 230 InspectorTest.emulateAndGetMetrics = function(width, height, deviceScaleFactor,
viewport, insets, noReload, callback) |
226 { | 231 { |
227 InspectorTest._deviceEmulationResults.push("Emulating device: " + width + "x
" + height + "x" + deviceScaleFactor + " viewport='" + viewport + "'"); | 232 InspectorTest._deviceEmulationResults.push("Emulating device: " + width + "x
" + height + "x" + deviceScaleFactor + " viewport='" + viewport + "'"); |
228 var full = !!width && !!height && !!deviceScaleFactor; | 233 var full = !!width && !!height && !!deviceScaleFactor; |
229 InspectorTest.applyEmulationAndReload(true, width, height, deviceScaleFactor
, viewport, insets, InspectorTest.getPageMetrics.bind(InspectorTest, full, print
Metrics)); | 234 InspectorTest.applyEmulationAndReload(true, width, height, deviceScaleFactor
, viewport, insets, noReload, InspectorTest.getPageMetrics.bind(InspectorTest, f
ull, printMetrics)); |
230 | 235 |
231 function printMetrics(metrics) | 236 function printMetrics(metrics) |
232 { | 237 { |
233 InspectorTest._deviceEmulationResults.push(metrics.value + "\n"); | 238 InspectorTest._deviceEmulationResults.push(metrics.value + "\n"); |
234 callback(); | 239 callback(); |
235 } | 240 } |
236 }; | 241 }; |
237 | 242 |
238 InspectorTest.testDeviceEmulation = function(pageUrl, width, height, deviceScale
Factor, viewport, insets) | 243 InspectorTest.testDeviceEmulation = function(pageUrl, width, height, deviceScale
Factor, viewport, insets, noReload) |
239 { | 244 { |
240 InspectorTest._deviceEmulationPageUrl = pageUrl; | 245 InspectorTest._deviceEmulationPageUrl = pageUrl; |
241 InspectorTest._deviceEmulationResults = []; | 246 InspectorTest._deviceEmulationResults = []; |
242 InspectorTest.emulateAndGetMetrics(width, height, deviceScaleFactor, viewpor
t, insets, callback); | 247 InspectorTest.emulateAndGetMetrics(width, height, deviceScaleFactor, viewpor
t, insets, noReload, callback); |
243 | 248 |
244 function callback() | 249 function callback() |
245 { | 250 { |
246 InspectorTest.addResult(InspectorTest._deviceEmulationResults.join("\n")
); | 251 InspectorTest.addResult(InspectorTest._deviceEmulationResults.join("\n")
); |
247 InspectorTest.completeTest(); | 252 InspectorTest.completeTest(); |
248 } | 253 } |
249 }; | 254 }; |
250 | 255 |
251 }; | 256 }; |
OLD | NEW |