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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/chrome/mobile_emulation_override_manager.cc
diff --git a/chrome/test/chromedriver/chrome/mobile_emulation_override_manager.cc b/chrome/test/chromedriver/chrome/mobile_emulation_override_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aa6caf3a1ccc05060173e1557af7730cb6c14f73
--- /dev/null
+++ b/chrome/test/chromedriver/chrome/mobile_emulation_override_manager.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/values.h"
+#include "chrome/test/chromedriver/chrome/device_metrics.h"
+#include "chrome/test/chromedriver/chrome/devtools_client.h"
+#include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h"
+#include "chrome/test/chromedriver/chrome/status.h"
+
+MobileEmulationOverrideManager::MobileEmulationOverrideManager(
+ DevToolsClient* client,
+ const DeviceMetrics* device_metrics)
+ : client_(client), overridden_device_metrics_(device_metrics) {
+ if (overridden_device_metrics_)
+ client_->AddListener(this);
+}
+
+MobileEmulationOverrideManager::~MobileEmulationOverrideManager() {
+}
+
+Status MobileEmulationOverrideManager::OnConnected(DevToolsClient* client) {
+ return ApplyOverrideIfNeeded();
+}
+
+Status MobileEmulationOverrideManager::OnEvent(
+ DevToolsClient* client,
+ const std::string& method,
+ const base::DictionaryValue& params) {
+ if (method == "Page.frameNavigated") {
+ const base::Value* unused_value;
+ if (!params.Get("frame.parentId", &unused_value))
+ return ApplyOverrideIfNeeded();
+ }
+ return Status(kOk);
+}
+
+Status MobileEmulationOverrideManager::ApplyOverrideIfNeeded() {
+ if (overridden_device_metrics_ == NULL)
+ return Status(kOk);
+
+ base::DictionaryValue params;
+ params.SetInteger("width", overridden_device_metrics_->width);
+ params.SetInteger("height", overridden_device_metrics_->height);
+ params.SetDouble("deviceScaleFactor",
+ overridden_device_metrics_->device_scale_factor);
+ 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
+ overridden_device_metrics_->emulate_viewport);
+ params.SetBoolean("fitWindow", overridden_device_metrics_->fit_window);
+ params.SetBoolean("textAutosizing",
+ overridden_device_metrics_->text_autosizing);
+ params.SetDouble("fontScaleFactor",
+ overridden_device_metrics_->font_scale_factor);
+ return client_->SendCommand("Page.setDeviceMetricsOverride", params);
+}

Powered by Google App Engine
This is Rietveld 408576698