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

Unified Diff: chrome/test/chromedriver/chrome/mobile_emulation_override_manager_unittest.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_unittest.cc
diff --git a/chrome/test/chromedriver/chrome/geolocation_override_manager_unittest.cc b/chrome/test/chromedriver/chrome/mobile_emulation_override_manager_unittest.cc
similarity index 54%
copy from chrome/test/chromedriver/chrome/geolocation_override_manager_unittest.cc
copy to chrome/test/chromedriver/chrome/mobile_emulation_override_manager_unittest.cc
index b5e668d27680dee897cfd07d2a261159460768a7..bcb3b17ffd00ffd383f440fdbfcc741cb6412f74 100644
--- a/chrome/test/chromedriver/chrome/geolocation_override_manager_unittest.cc
+++ b/chrome/test/chromedriver/chrome/mobile_emulation_override_manager_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// 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.
@@ -7,8 +7,8 @@
#include "base/compiler_specific.h"
#include "base/values.h"
-#include "chrome/test/chromedriver/chrome/geolocation_override_manager.h"
-#include "chrome/test/chromedriver/chrome/geoposition.h"
+#include "chrome/test/chromedriver/chrome/device_metrics.h"
+#include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/stub_devtools_client.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -53,69 +53,60 @@ class RecorderDevToolsClient : public StubDevToolsClient {
std::vector<Command> commands_;
};
-void AssertGeolocationCommand(const Command& command,
- const Geoposition& geoposition) {
- ASSERT_EQ("Page.setGeolocationOverride", command.method);
- double latitude, longitude, accuracy;
- ASSERT_TRUE(command.params.GetDouble("latitude", &latitude));
- ASSERT_TRUE(command.params.GetDouble("longitude", &longitude));
- ASSERT_TRUE(command.params.GetDouble("accuracy", &accuracy));
- ASSERT_EQ(geoposition.latitude, latitude);
- ASSERT_EQ(geoposition.longitude, longitude);
- ASSERT_EQ(geoposition.accuracy, accuracy);
+void AssertDeviceMetricsCommand(const Command& command,
+ const DeviceMetrics& device_metrics) {
+ ASSERT_EQ("Page.setDeviceMetricsOverride", command.method);
+ int width, height;
+ double device_scale_factor, font_scale_factor;
+ bool emulate_viewport, fit_window, text_autosizing;
+ ASSERT_TRUE(command.params.GetInteger("width", &width));
+ ASSERT_TRUE(command.params.GetInteger("height", &height));
+ ASSERT_TRUE(command.params.GetDouble("deviceScaleFactor",
+ &device_scale_factor));
+ ASSERT_TRUE(command.params.GetBoolean("emulateViewport", &emulate_viewport));
+ ASSERT_TRUE(command.params.GetBoolean("fitWindow", &fit_window));
+ ASSERT_TRUE(command.params.GetBoolean("textAutosizing", &text_autosizing));
+ ASSERT_TRUE(command.params.GetDouble("fontScaleFactor", &font_scale_factor));
+ ASSERT_EQ(device_metrics.width, width);
+ ASSERT_EQ(device_metrics.height, height);
+ ASSERT_EQ(device_metrics.device_scale_factor, device_scale_factor);
+ ASSERT_EQ(device_metrics.emulate_viewport, emulate_viewport);
+ ASSERT_EQ(device_metrics.fit_window, fit_window);
+ ASSERT_EQ(device_metrics.text_autosizing, text_autosizing);
+ ASSERT_EQ(device_metrics.font_scale_factor, font_scale_factor);
}
} // namespace
-TEST(GeolocationOverrideManager, OverrideSendsCommand) {
+TEST(MobileEmulationOverrideManager, SendsCommandOnConnect) {
RecorderDevToolsClient client;
- GeolocationOverrideManager manager(&client);
- Geoposition geoposition = {1, 2, 3};
- manager.OverrideGeolocation(geoposition);
- ASSERT_EQ(1u, client.commands_.size());
- ASSERT_NO_FATAL_FAILURE(
- AssertGeolocationCommand(client.commands_[0], geoposition));
-
- geoposition.latitude = 5;
- manager.OverrideGeolocation(geoposition);
- ASSERT_EQ(2u, client.commands_.size());
- ASSERT_NO_FATAL_FAILURE(
- AssertGeolocationCommand(client.commands_[1], geoposition));
-}
-
-TEST(GeolocationOverrideManager, SendsCommandOnConnect) {
- RecorderDevToolsClient client;
- GeolocationOverrideManager manager(&client);
+ DeviceMetrics device_metrics(1, 2, 3.0);
+ MobileEmulationOverrideManager manager(&client, &device_metrics);
ASSERT_EQ(0u, client.commands_.size());
ASSERT_EQ(kOk, manager.OnConnected(&client).code());
- Geoposition geoposition = {1, 2, 3};
- manager.OverrideGeolocation(geoposition);
ASSERT_EQ(1u, client.commands_.size());
ASSERT_EQ(kOk, manager.OnConnected(&client).code());
ASSERT_EQ(2u, client.commands_.size());
ASSERT_NO_FATAL_FAILURE(
- AssertGeolocationCommand(client.commands_[1], geoposition));
+ AssertDeviceMetricsCommand(client.commands_[1], device_metrics));
}
-TEST(GeolocationOverrideManager, SendsCommandOnNavigation) {
+TEST(MobileEmulationOverrideManager, SendsCommandOnNavigation) {
RecorderDevToolsClient client;
- GeolocationOverrideManager manager(&client);
+ DeviceMetrics device_metrics(1, 2, 3.0);
+ MobileEmulationOverrideManager manager(&client, &device_metrics);
base::DictionaryValue main_frame_params;
ASSERT_EQ(kOk,
manager.OnEvent(&client, "Page.frameNavigated", main_frame_params)
.code());
- ASSERT_EQ(0u, client.commands_.size());
-
- Geoposition geoposition = {1, 2, 3};
- manager.OverrideGeolocation(geoposition);
ASSERT_EQ(1u, client.commands_.size());
ASSERT_EQ(kOk,
manager.OnEvent(&client, "Page.frameNavigated", main_frame_params)
.code());
ASSERT_EQ(2u, client.commands_.size());
ASSERT_NO_FATAL_FAILURE(
- AssertGeolocationCommand(client.commands_[1], geoposition));
+ AssertDeviceMetricsCommand(client.commands_[1], device_metrics));
base::DictionaryValue sub_frame_params;
sub_frame_params.SetString("frame.parentId", "id");

Powered by Google App Engine
This is Rietveld 408576698