OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/geolocation_override_manager.h" | 6 #include "chrome/test/chromedriver/chrome/geolocation_override_manager.h" |
11 #include "chrome/test/chromedriver/chrome/geoposition.h" | 7 #include "chrome/test/chromedriver/chrome/geoposition.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 AssertGeolocationCommand(const Command& command, | 14 void AssertGeolocationCommand(const Command& command, |
57 const Geoposition& geoposition) { | 15 const Geoposition& geoposition) { |
58 ASSERT_EQ("Page.setGeolocationOverride", command.method); | 16 ASSERT_EQ("Page.setGeolocationOverride", command.method); |
59 double latitude, longitude, accuracy; | 17 double latitude, longitude, accuracy; |
60 ASSERT_TRUE(command.params.GetDouble("latitude", &latitude)); | 18 ASSERT_TRUE(command.params.GetDouble("latitude", &latitude)); |
61 ASSERT_TRUE(command.params.GetDouble("longitude", &longitude)); | 19 ASSERT_TRUE(command.params.GetDouble("longitude", &longitude)); |
62 ASSERT_TRUE(command.params.GetDouble("accuracy", &accuracy)); | 20 ASSERT_TRUE(command.params.GetDouble("accuracy", &accuracy)); |
63 ASSERT_EQ(geoposition.latitude, latitude); | 21 ASSERT_EQ(geoposition.latitude, latitude); |
64 ASSERT_EQ(geoposition.longitude, longitude); | 22 ASSERT_EQ(geoposition.longitude, longitude); |
65 ASSERT_EQ(geoposition.accuracy, accuracy); | 23 ASSERT_EQ(geoposition.accuracy, accuracy); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 ASSERT_NO_FATAL_FAILURE( | 75 ASSERT_NO_FATAL_FAILURE( |
118 AssertGeolocationCommand(client.commands_[1], geoposition)); | 76 AssertGeolocationCommand(client.commands_[1], geoposition)); |
119 | 77 |
120 base::DictionaryValue sub_frame_params; | 78 base::DictionaryValue sub_frame_params; |
121 sub_frame_params.SetString("frame.parentId", "id"); | 79 sub_frame_params.SetString("frame.parentId", "id"); |
122 ASSERT_EQ( | 80 ASSERT_EQ( |
123 kOk, | 81 kOk, |
124 manager.OnEvent(&client, "Page.frameNavigated", sub_frame_params).code()); | 82 manager.OnEvent(&client, "Page.frameNavigated", sub_frame_params).code()); |
125 ASSERT_EQ(2u, client.commands_.size()); | 83 ASSERT_EQ(2u, client.commands_.size()); |
126 } | 84 } |
OLD | NEW |