Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: third_party/WebKit/LayoutTests/inspector-protocol/emulation/device-emulation-test.js

Issue 1638953002: [DevTools] Migrate device-emulation tests from OverridesSupport to inspector-protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 function setMetaViewport(override) 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.indexOf(key) !== -1) {
13 viewport = VIEWPORTS[key]; 13 viewport = VIEWPORTS[key];
14 window.__viewport = key;
14 break; 15 break;
15 } 16 }
16 } 17 }
17 if (override) 18 if (override) {
18 viewport = VIEWPORTS[override]; 19 viewport = VIEWPORTS[override];
20 window.__viewport = override;
21 }
19 if (viewport != VIEWPORTS["none"]) 22 if (viewport != VIEWPORTS["none"])
20 document.write('<meta name="viewport" content="'+viewport+'">'); 23 document.write('<meta name="viewport" content="'+viewport+'">');
21 } 24 }
22 25
23 // matchMedia() polyfill from https://github.com/paulirish/matchMedia.js 26 // matchMedia() polyfill from https://github.com/paulirish/matchMedia.js
24 // Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MI T/BSD license 27 // Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MI T/BSD license
25 window.matchMedia = window.matchMedia || (function(doc, undefined){ 28 window.matchMedia = window.matchMedia || (function(doc, undefined){
26 var bool, 29 var bool,
27 docElem = doc.documentElement, 30 docElem = doc.documentElement,
28 refNode = docElem.firstElementChild || docElem.firstChild, 31 refNode = docElem.firstElementChild || docElem.firstChild,
(...skipping 19 matching lines...) Expand all
48 51
49 var results; 52 var results;
50 53
51 function dumpMetrics(full) 54 function dumpMetrics(full)
52 { 55 {
53 results = []; 56 results = [];
54 writeResult("Device:", ""); 57 writeResult("Device:", "");
55 testJS("window.screenX"); 58 testJS("window.screenX");
56 testJS("window.screenY"); 59 testJS("window.screenY");
57 60
58 writeResult("Viewport:", location.search); 61 writeResult("Viewport:", "?" + window.__viewport);
59 62
60 testMQOrientation(); 63 testMQOrientation();
61 testJS("window.orientation", ""); 64 testJS("window.orientation", "");
62 65
63 if (full) { 66 if (full) {
64 testMQDimension("resolution", null, "dpi"); 67 testMQDimension("resolution", null, "dpi");
65 testMQDevicePixelRatio(window.devicePixelRatio); 68 testMQDevicePixelRatio(window.devicePixelRatio);
66 testJS("window.devicePixelRatio", ""); 69 testJS("window.devicePixelRatio", "");
67 } 70 }
68 71
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return mqBinarySearch(feature, minValue, mid - 1, unit); // feature is < mid 178 return mqBinarySearch(feature, minValue, mid - 1, unit); // feature is < mid
176 } 179 }
177 180
178 function writeResult(key, val) 181 function writeResult(key, val)
179 { 182 {
180 results.push(key + (val ? " = " + val : "")); 183 results.push(key + (val ? " = " + val : ""));
181 } 184 }
182 185
183 var initialize_DeviceEmulationTest = function() { 186 var initialize_DeviceEmulationTest = function() {
184 187
185 InspectorTest.preloadPanel("network");
186
187 InspectorTest.getPageMetrics = function(full, callback) 188 InspectorTest.getPageMetrics = function(full, callback)
188 { 189 {
189 InspectorTest.evaluateInPage("dumpMetrics(" + full + ")", callback); 190 InspectorTest.evaluateInPage("dumpMetrics(" + full + ")", callback);
190 } 191 }
191 192
192 InspectorTest.applyEmulationAndReload = function(enabled, width, height, deviceS caleFactor, viewport, insets, noReload, callback) 193 InspectorTest.applyEmulationAndReload = function(enabled, width, height, deviceS caleFactor, viewport, insets, noReload, callback)
193 { 194 {
194 function PageResizer() 195 if (enabled) {
195 { 196 var params = {};
197 params.width = width;
198 params.height = height;
199 params.deviceScaleFactor = deviceScaleFactor;
200 params.mobile = true;
201 params.fitWindow = false;
202 params.scale = 1;
203 params.screenWidth = width;
204 params.screenHeight = height;
205 params.positionX = 0;
206 params.positionY = 0;
207 if (insets) {
208 params.screenWidth += insets.left + insets.right;
209 params.positionX = insets.left;
210 params.screenHeight += insets.top + insets.bottom;
211 params.positionY = insets.top;
212 }
213 InspectorTest.sendCommand("Emulation.setDeviceMetricsOverride", params, emulateCallback);
214 } else {
215 InspectorTest.sendCommand("Emulation.clearDeviceMetricsOverride", {}, em ulateCallback);
196 } 216 }
197 217
198 PageResizer.prototype = 218 function emulateCallback(result)
199 { 219 {
200 update: function(dipWidth, dipHeight, scale) { }, 220 if (result.error)
201 __proto__: WebInspector.Object.prototype 221 InspectorTest._deviceEmulationResults.push("Error: " + result.error) ;
202 }
203
204 InspectorTest.addSniffer(WebInspector.overridesSupport, "_deviceMetricsOverr ideAppliedForTest", emulateCallback);
205 if (insets)
206 WebInspector.overridesSupport.setPageResizer(new PageResizer(), new Size (10, 10), insets);
207 else
208 WebInspector.overridesSupport.setPageResizer(null, new Size(0, 0), new I nsets(0, 0));
209
210 if (enabled) {
211 var device = {title: "", width: width, height: height, deviceScaleFactor : deviceScaleFactor, userAgent: "", touch: false, mobile: true};
212 WebInspector.overridesSupport.emulateDevice(device);
213 } else {
214 WebInspector.overridesSupport.reset();
215 }
216 WebInspector.overridesSupport.settings._emulationEnabled.set(enabled);
217
218 function emulateCallback()
219 {
220 var warning = WebInspector.overridesSupport.warningMessage();
221 if (warning)
222 InspectorTest._deviceEmulationResults.push("Emulation warning: " + w arning);
223 if (noReload) 222 if (noReload)
224 callback(); 223 callback();
225 else 224 else
226 InspectorTest.navigate(InspectorTest._deviceEmulationPageUrl + "?" + viewport, callback); 225 InspectorTest.navigate(InspectorTest._deviceEmulationPageUrl + "?" + viewport, callback);
227 } 226 }
228 }; 227 };
229 228
230 InspectorTest.emulateAndGetMetrics = function(width, height, deviceScaleFactor, viewport, insets, noReload, callback) 229 InspectorTest.emulateAndGetMetrics = function(width, height, deviceScaleFactor, viewport, insets, noReload, callback)
231 { 230 {
232 InspectorTest._deviceEmulationResults.push("Emulating device: " + width + "x " + height + "x" + deviceScaleFactor + " viewport='" + viewport + "'"); 231 InspectorTest._deviceEmulationResults.push("Emulating device: " + width + "x " + height + "x" + deviceScaleFactor + " viewport='" + viewport + "'");
233 var full = !!width && !!height && !!deviceScaleFactor; 232 var full = !!width && !!height && !!deviceScaleFactor;
234 InspectorTest.applyEmulationAndReload(true, width, height, deviceScaleFactor , viewport, insets, noReload, InspectorTest.getPageMetrics.bind(InspectorTest, f ull, printMetrics)); 233 InspectorTest.applyEmulationAndReload(true, width, height, deviceScaleFactor , viewport, insets, noReload, InspectorTest.getPageMetrics.bind(InspectorTest, f ull, printMetrics));
235 234
236 function printMetrics(metrics) 235 function printMetrics(metrics)
237 { 236 {
238 InspectorTest._deviceEmulationResults.push(metrics.value + "\n"); 237 InspectorTest._deviceEmulationResults.push(metrics + "\n");
239 callback(); 238 callback();
240 } 239 }
241 }; 240 };
242 241
243 InspectorTest.testDeviceEmulation = function(pageUrl, width, height, deviceScale Factor, viewport, insets, noReload) 242 InspectorTest.testDeviceEmulation = function(pageUrl, width, height, deviceScale Factor, viewport, insets, noReload)
244 { 243 {
245 InspectorTest._deviceEmulationPageUrl = pageUrl; 244 InspectorTest._deviceEmulationPageUrl = pageUrl;
246 InspectorTest._deviceEmulationResults = []; 245 InspectorTest._deviceEmulationResults = [];
247 InspectorTest.emulateAndGetMetrics(width, height, deviceScaleFactor, viewpor t, insets, noReload, callback); 246 InspectorTest.emulateAndGetMetrics(width, height, deviceScaleFactor, viewpor t, insets, noReload, callback);
248 247
249 function callback() 248 function callback()
250 { 249 {
251 InspectorTest.addResult(InspectorTest._deviceEmulationResults.join("\n") ); 250 InspectorTest.log(InspectorTest._deviceEmulationResults.join("\n"));
252 InspectorTest.completeTest(); 251 InspectorTest.completeTest();
253 } 252 }
254 }; 253 };
255 254
256 }; 255 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698