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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/test/chromedriver/chrome/geolocation_override_manager.h" 10 #include "chrome/test/chromedriver/chrome/device_metrics.h"
11 #include "chrome/test/chromedriver/chrome/geoposition.h" 11 #include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h"
12 #include "chrome/test/chromedriver/chrome/status.h" 12 #include "chrome/test/chromedriver/chrome/status.h"
13 #include "chrome/test/chromedriver/chrome/stub_devtools_client.h" 13 #include "chrome/test/chromedriver/chrome/stub_devtools_client.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace { 16 namespace {
17 17
18 struct Command { 18 struct Command {
19 Command() {} 19 Command() {}
20 Command(const std::string& method, const base::DictionaryValue& params) 20 Command(const std::string& method, const base::DictionaryValue& params)
21 : method(method) { 21 : method(method) {
(...skipping 24 matching lines...) Expand all
46 const std::string& method, 46 const std::string& method,
47 const base::DictionaryValue& params, 47 const base::DictionaryValue& params,
48 scoped_ptr<base::DictionaryValue>* result) OVERRIDE { 48 scoped_ptr<base::DictionaryValue>* result) OVERRIDE {
49 commands_.push_back(Command(method, params)); 49 commands_.push_back(Command(method, params));
50 return Status(kOk); 50 return Status(kOk);
51 } 51 }
52 52
53 std::vector<Command> commands_; 53 std::vector<Command> commands_;
54 }; 54 };
55 55
56 void AssertGeolocationCommand(const Command& command, 56 void AssertDeviceMetricsCommand(const Command& command,
57 const Geoposition& geoposition) { 57 const DeviceMetrics& device_metrics) {
58 ASSERT_EQ("Page.setGeolocationOverride", command.method); 58 ASSERT_EQ("Page.setDeviceMetricsOverride", command.method);
59 double latitude, longitude, accuracy; 59 int width, height;
60 ASSERT_TRUE(command.params.GetDouble("latitude", &latitude)); 60 double device_scale_factor, font_scale_factor;
61 ASSERT_TRUE(command.params.GetDouble("longitude", &longitude)); 61 bool emulate_viewport, fit_window, text_autosizing;
62 ASSERT_TRUE(command.params.GetDouble("accuracy", &accuracy)); 62 ASSERT_TRUE(command.params.GetInteger("width", &width));
63 ASSERT_EQ(geoposition.latitude, latitude); 63 ASSERT_TRUE(command.params.GetInteger("height", &height));
64 ASSERT_EQ(geoposition.longitude, longitude); 64 ASSERT_TRUE(command.params.GetDouble("deviceScaleFactor",
65 ASSERT_EQ(geoposition.accuracy, accuracy); 65 &device_scale_factor));
66 ASSERT_TRUE(command.params.GetBoolean("emulateViewport", &emulate_viewport));
67 ASSERT_TRUE(command.params.GetBoolean("fitWindow", &fit_window));
68 ASSERT_TRUE(command.params.GetBoolean("textAutosizing", &text_autosizing));
69 ASSERT_TRUE(command.params.GetDouble("fontScaleFactor", &font_scale_factor));
70 ASSERT_EQ(device_metrics.width, width);
71 ASSERT_EQ(device_metrics.height, height);
72 ASSERT_EQ(device_metrics.device_scale_factor, device_scale_factor);
73 ASSERT_EQ(device_metrics.emulate_viewport, emulate_viewport);
74 ASSERT_EQ(device_metrics.fit_window, fit_window);
75 ASSERT_EQ(device_metrics.text_autosizing, text_autosizing);
76 ASSERT_EQ(device_metrics.font_scale_factor, font_scale_factor);
66 } 77 }
67 78
68 } // namespace 79 } // namespace
69 80
70 TEST(GeolocationOverrideManager, OverrideSendsCommand) { 81 TEST(MobileEmulationOverrideManager, SendsCommandOnConnect) {
71 RecorderDevToolsClient client; 82 RecorderDevToolsClient client;
72 GeolocationOverrideManager manager(&client); 83 DeviceMetrics device_metrics(1, 2, 3.0);
73 Geoposition geoposition = {1, 2, 3}; 84 MobileEmulationOverrideManager manager(&client, &device_metrics);
74 manager.OverrideGeolocation(geoposition);
75 ASSERT_EQ(1u, client.commands_.size());
76 ASSERT_NO_FATAL_FAILURE(
77 AssertGeolocationCommand(client.commands_[0], geoposition));
78
79 geoposition.latitude = 5;
80 manager.OverrideGeolocation(geoposition);
81 ASSERT_EQ(2u, client.commands_.size());
82 ASSERT_NO_FATAL_FAILURE(
83 AssertGeolocationCommand(client.commands_[1], geoposition));
84 }
85
86 TEST(GeolocationOverrideManager, SendsCommandOnConnect) {
87 RecorderDevToolsClient client;
88 GeolocationOverrideManager manager(&client);
89 ASSERT_EQ(0u, client.commands_.size()); 85 ASSERT_EQ(0u, client.commands_.size());
90 ASSERT_EQ(kOk, manager.OnConnected(&client).code()); 86 ASSERT_EQ(kOk, manager.OnConnected(&client).code());
91 87
92 Geoposition geoposition = {1, 2, 3};
93 manager.OverrideGeolocation(geoposition);
94 ASSERT_EQ(1u, client.commands_.size()); 88 ASSERT_EQ(1u, client.commands_.size());
95 ASSERT_EQ(kOk, manager.OnConnected(&client).code()); 89 ASSERT_EQ(kOk, manager.OnConnected(&client).code());
96 ASSERT_EQ(2u, client.commands_.size()); 90 ASSERT_EQ(2u, client.commands_.size());
97 ASSERT_NO_FATAL_FAILURE( 91 ASSERT_NO_FATAL_FAILURE(
98 AssertGeolocationCommand(client.commands_[1], geoposition)); 92 AssertDeviceMetricsCommand(client.commands_[1], device_metrics));
99 } 93 }
100 94
101 TEST(GeolocationOverrideManager, SendsCommandOnNavigation) { 95 TEST(MobileEmulationOverrideManager, SendsCommandOnNavigation) {
102 RecorderDevToolsClient client; 96 RecorderDevToolsClient client;
103 GeolocationOverrideManager manager(&client); 97 DeviceMetrics device_metrics(1, 2, 3.0);
98 MobileEmulationOverrideManager manager(&client, &device_metrics);
104 base::DictionaryValue main_frame_params; 99 base::DictionaryValue main_frame_params;
105 ASSERT_EQ(kOk, 100 ASSERT_EQ(kOk,
106 manager.OnEvent(&client, "Page.frameNavigated", main_frame_params) 101 manager.OnEvent(&client, "Page.frameNavigated", main_frame_params)
107 .code()); 102 .code());
108 ASSERT_EQ(0u, client.commands_.size());
109
110 Geoposition geoposition = {1, 2, 3};
111 manager.OverrideGeolocation(geoposition);
112 ASSERT_EQ(1u, client.commands_.size()); 103 ASSERT_EQ(1u, client.commands_.size());
113 ASSERT_EQ(kOk, 104 ASSERT_EQ(kOk,
114 manager.OnEvent(&client, "Page.frameNavigated", main_frame_params) 105 manager.OnEvent(&client, "Page.frameNavigated", main_frame_params)
115 .code()); 106 .code());
116 ASSERT_EQ(2u, client.commands_.size()); 107 ASSERT_EQ(2u, client.commands_.size());
117 ASSERT_NO_FATAL_FAILURE( 108 ASSERT_NO_FATAL_FAILURE(
118 AssertGeolocationCommand(client.commands_[1], geoposition)); 109 AssertDeviceMetricsCommand(client.commands_[1], device_metrics));
119 110
120 base::DictionaryValue sub_frame_params; 111 base::DictionaryValue sub_frame_params;
121 sub_frame_params.SetString("frame.parentId", "id"); 112 sub_frame_params.SetString("frame.parentId", "id");
122 ASSERT_EQ( 113 ASSERT_EQ(
123 kOk, 114 kOk,
124 manager.OnEvent(&client, "Page.frameNavigated", sub_frame_params).code()); 115 manager.OnEvent(&client, "Page.frameNavigated", sub_frame_params).code());
125 ASSERT_EQ(2u, client.commands_.size()); 116 ASSERT_EQ(2u, client.commands_.size());
126 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698