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

Side by Side Diff: chrome/test/chromedriver/chrome/mobile_emulation_override_manager.cc

Issue 288193004: [Chromedriver] Add Device Metrics override support to ChromeDriver via Capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/values.h"
6 #include "chrome/test/chromedriver/chrome/device_metrics.h"
7 #include "chrome/test/chromedriver/chrome/devtools_client.h"
8 #include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h"
9 #include "chrome/test/chromedriver/chrome/status.h"
10
11 MobileEmulationOverrideManager::MobileEmulationOverrideManager(
12 DevToolsClient* client,
13 const DeviceMetrics* device_metrics)
14 : client_(client), overridden_device_metrics_(device_metrics) {
15 if (overridden_device_metrics_)
16 client_->AddListener(this);
17 }
18
19 MobileEmulationOverrideManager::~MobileEmulationOverrideManager() {
20 }
21
22 Status MobileEmulationOverrideManager::OnConnected(DevToolsClient* client) {
23 return ApplyOverrideIfNeeded();
24 }
25
26 Status MobileEmulationOverrideManager::OnEvent(
27 DevToolsClient* client,
28 const std::string& method,
29 const base::DictionaryValue& params) {
30 if (method == "Page.frameNavigated") {
31 const base::Value* unused_value;
32 if (!params.Get("frame.parentId", &unused_value))
33 return ApplyOverrideIfNeeded();
34 }
35 return Status(kOk);
36 }
37
38 Status MobileEmulationOverrideManager::ApplyOverrideIfNeeded() {
39 if (overridden_device_metrics_ == NULL)
40 return Status(kOk);
41
42 base::DictionaryValue params;
43 params.SetInteger("width", overridden_device_metrics_->width);
44 params.SetInteger("height", overridden_device_metrics_->height);
45 params.SetDouble("deviceScaleFactor",
46 overridden_device_metrics_->device_scale_factor);
47 params.SetBoolean("emulateViewport",
pfeldman 2014/05/20 18:57:29 Note that you are using undocumented API that is a
dgozman 2014/05/20 19:01:40 Yes, I want to do this to emphasize it's not only
srawlins 2014/05/20 19:36:15 @pfeldman, @dgozman: SGTM. We can update chromedri
48 overridden_device_metrics_->emulate_viewport);
49 params.SetBoolean("fitWindow", overridden_device_metrics_->fit_window);
50 params.SetBoolean("textAutosizing",
51 overridden_device_metrics_->text_autosizing);
52 params.SetDouble("fontScaleFactor",
53 overridden_device_metrics_->font_scale_factor);
54 return client_->SendCommand("Page.setDeviceMetricsOverride", params);
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698