| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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> | |
| 6 #include <vector> | |
| 7 | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/values.h" | 5 #include "base/values.h" |
| 10 #include "chrome/test/chromedriver/chrome/device_metrics.h" | 6 #include "chrome/test/chromedriver/chrome/device_metrics.h" |
| 11 #include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h" | 7 #include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h" |
| 8 #include "chrome/test/chromedriver/chrome/recorder_devtools_client.h" |
| 12 #include "chrome/test/chromedriver/chrome/status.h" | 9 #include "chrome/test/chromedriver/chrome/status.h" |
| 13 #include "chrome/test/chromedriver/chrome/stub_devtools_client.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 11 |
| 16 namespace { | 12 namespace { |
| 17 | 13 |
| 18 struct Command { | |
| 19 Command() {} | |
| 20 Command(const std::string& method, const base::DictionaryValue& params) | |
| 21 : method(method) { | |
| 22 this->params.MergeDictionary(¶ms); | |
| 23 } | |
| 24 Command(const Command& command) { | |
| 25 *this = command; | |
| 26 } | |
| 27 Command& operator=(const Command& command) { | |
| 28 method = command.method; | |
| 29 params.Clear(); | |
| 30 params.MergeDictionary(&command.params); | |
| 31 return *this; | |
| 32 } | |
| 33 ~Command() {} | |
| 34 | |
| 35 std::string method; | |
| 36 base::DictionaryValue params; | |
| 37 }; | |
| 38 | |
| 39 class RecorderDevToolsClient : public StubDevToolsClient { | |
| 40 public: | |
| 41 RecorderDevToolsClient() {} | |
| 42 ~RecorderDevToolsClient() override {} | |
| 43 | |
| 44 // Overridden from StubDevToolsClient: | |
| 45 Status SendCommandAndGetResult( | |
| 46 const std::string& method, | |
| 47 const base::DictionaryValue& params, | |
| 48 scoped_ptr<base::DictionaryValue>* result) override { | |
| 49 commands_.push_back(Command(method, params)); | |
| 50 return Status(kOk); | |
| 51 } | |
| 52 | |
| 53 std::vector<Command> commands_; | |
| 54 }; | |
| 55 | |
| 56 void AssertDeviceMetricsCommand(const Command& command, | 14 void AssertDeviceMetricsCommand(const Command& command, |
| 57 const DeviceMetrics& device_metrics) { | 15 const DeviceMetrics& device_metrics) { |
| 58 ASSERT_EQ("Page.setDeviceMetricsOverride", command.method); | 16 ASSERT_EQ("Page.setDeviceMetricsOverride", command.method); |
| 59 int width, height; | 17 int width, height; |
| 60 double device_scale_factor, font_scale_factor; | 18 double device_scale_factor, font_scale_factor; |
| 61 bool mobile, fit_window, text_autosizing; | 19 bool mobile, fit_window, text_autosizing; |
| 62 ASSERT_TRUE(command.params.GetInteger("width", &width)); | 20 ASSERT_TRUE(command.params.GetInteger("width", &width)); |
| 63 ASSERT_TRUE(command.params.GetInteger("height", &height)); | 21 ASSERT_TRUE(command.params.GetInteger("height", &height)); |
| 64 ASSERT_TRUE(command.params.GetDouble("deviceScaleFactor", | 22 ASSERT_TRUE(command.params.GetDouble("deviceScaleFactor", |
| 65 &device_scale_factor)); | 23 &device_scale_factor)); |
| 66 ASSERT_TRUE(command.params.GetBoolean("mobile", &mobile)); | 24 ASSERT_TRUE(command.params.GetBoolean("mobile", &mobile)); |
| 67 ASSERT_TRUE(command.params.GetBoolean("fitWindow", &fit_window)); | 25 ASSERT_TRUE(command.params.GetBoolean("fitWindow", &fit_window)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ASSERT_NO_FATAL_FAILURE( | 66 ASSERT_NO_FATAL_FAILURE( |
| 109 AssertDeviceMetricsCommand(client.commands_[2], device_metrics)); | 67 AssertDeviceMetricsCommand(client.commands_[2], device_metrics)); |
| 110 | 68 |
| 111 base::DictionaryValue sub_frame_params; | 69 base::DictionaryValue sub_frame_params; |
| 112 sub_frame_params.SetString("frame.parentId", "id"); | 70 sub_frame_params.SetString("frame.parentId", "id"); |
| 113 ASSERT_EQ( | 71 ASSERT_EQ( |
| 114 kOk, | 72 kOk, |
| 115 manager.OnEvent(&client, "Page.frameNavigated", sub_frame_params).code()); | 73 manager.OnEvent(&client, "Page.frameNavigated", sub_frame_params).code()); |
| 116 ASSERT_EQ(4u, client.commands_.size()); | 74 ASSERT_EQ(4u, client.commands_.size()); |
| 117 } | 75 } |
| OLD | NEW |