 Chromium Code Reviews
 Chromium Code Reviews Issue 251933005:
  [ChromeDriver] Support mobile emulation on desktop Chrome.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 251933005:
  [ChromeDriver] Support mobile emulation on desktop Chrome.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..a4ad7a7adc703f970d9acfaf695ca3d6f21c80da 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 = DeviceMetrics(1, 2, 3.0); | 
| 
samuong
2014/05/16 23:00:35
Change this to:
DeviceMetrics device_metrics(1, 2
 
sam.rawlins
2014/05/16 23:35:51
Done.
 | 
| + 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 = DeviceMetrics(1, 2, 3.0); | 
| 
samuong
2014/05/16 23:00:35
Change this to:
DeviceMetrics device_metrics(1, 2
 
sam.rawlins
2014/05/16 23:35:51
Done.
 | 
| + 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"); |