| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/chromedriver/chrome/devtools_client_impl.h" | 5 #include "chrome/test/chromedriver/chrome/devtools_client_impl.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 SyncWebSocket::StatusCode ReceiveNextMessage( | 66 SyncWebSocket::StatusCode ReceiveNextMessage( |
| 67 std::string* message, | 67 std::string* message, |
| 68 const Timeout& timeout) override { | 68 const Timeout& timeout) override { |
| 69 if (timeout.IsExpired()) | 69 if (timeout.IsExpired()) |
| 70 return SyncWebSocket::kTimeout; | 70 return SyncWebSocket::kTimeout; |
| 71 base::DictionaryValue response; | 71 base::DictionaryValue response; |
| 72 response.SetInteger("id", id_); | 72 response.SetInteger("id", id_); |
| 73 base::DictionaryValue result; | 73 base::DictionaryValue result; |
| 74 result.SetInteger("param", 1); | 74 result.SetInteger("param", 1); |
| 75 response.Set("result", result.DeepCopy()); | 75 response.Set("result", base::MakeUnique<base::Value>(result)); |
| 76 base::JSONWriter::Write(response, message); | 76 base::JSONWriter::Write(response, message); |
| 77 --queued_messages_; | 77 --queued_messages_; |
| 78 return SyncWebSocket::kOk; | 78 return SyncWebSocket::kOk; |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool HasNextMessage() override { return queued_messages_ > 0; } | 81 bool HasNextMessage() override { return queued_messages_ > 0; } |
| 82 | 82 |
| 83 protected: | 83 protected: |
| 84 bool connected_; | 84 bool connected_; |
| 85 int id_; | 85 int id_; |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 EXPECT_TRUE(value->GetAsDictionary(&dict)); | 719 EXPECT_TRUE(value->GetAsDictionary(&dict)); |
| 720 if (!dict) | 720 if (!dict) |
| 721 return false; | 721 return false; |
| 722 int id; | 722 int id; |
| 723 EXPECT_TRUE(dict->GetInteger("id", &id)); | 723 EXPECT_TRUE(dict->GetInteger("id", &id)); |
| 724 std::string method; | 724 std::string method; |
| 725 EXPECT_TRUE(dict->GetString("method", &method)); | 725 EXPECT_TRUE(dict->GetString("method", &method)); |
| 726 | 726 |
| 727 base::DictionaryValue response; | 727 base::DictionaryValue response; |
| 728 response.SetInteger("id", id); | 728 response.SetInteger("id", id); |
| 729 response.Set("result", new base::DictionaryValue()); | 729 response.Set("result", base::MakeUnique<base::DictionaryValue>()); |
| 730 std::string json_response; | 730 std::string json_response; |
| 731 base::JSONWriter::Write(response, &json_response); | 731 base::JSONWriter::Write(response, &json_response); |
| 732 queued_response_.push_back(json_response); | 732 queued_response_.push_back(json_response); |
| 733 | 733 |
| 734 // Push one event. | 734 // Push one event. |
| 735 base::DictionaryValue event; | 735 base::DictionaryValue event; |
| 736 event.SetString("method", "updateEvent"); | 736 event.SetString("method", "updateEvent"); |
| 737 event.Set("params", new base::DictionaryValue()); | 737 event.Set("params", base::MakeUnique<base::DictionaryValue>()); |
| 738 std::string json_event; | 738 std::string json_event; |
| 739 base::JSONWriter::Write(event, &json_event); | 739 base::JSONWriter::Write(event, &json_event); |
| 740 queued_response_.push_back(json_event); | 740 queued_response_.push_back(json_event); |
| 741 | 741 |
| 742 return true; | 742 return true; |
| 743 } | 743 } |
| 744 | 744 |
| 745 SyncWebSocket::StatusCode ReceiveNextMessage( | 745 SyncWebSocket::StatusCode ReceiveNextMessage( |
| 746 std::string* message, | 746 std::string* message, |
| 747 const Timeout& timeout) override { | 747 const Timeout& timeout) override { |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 const Timeout& timeout) override { | 1141 const Timeout& timeout) override { |
| 1142 EXPECT_LE(sent_responses_, 1); | 1142 EXPECT_LE(sent_responses_, 1); |
| 1143 EXPECT_EQ(sent_messages_, 2); | 1143 EXPECT_EQ(sent_messages_, 2); |
| 1144 base::DictionaryValue response; | 1144 base::DictionaryValue response; |
| 1145 if (sent_responses_ == 0) | 1145 if (sent_responses_ == 0) |
| 1146 response.SetInteger("id", 1); | 1146 response.SetInteger("id", 1); |
| 1147 else | 1147 else |
| 1148 response.SetInteger("id", 2); | 1148 response.SetInteger("id", 2); |
| 1149 base::DictionaryValue result; | 1149 base::DictionaryValue result; |
| 1150 result.SetInteger("param", 1); | 1150 result.SetInteger("param", 1); |
| 1151 response.Set("result", result.DeepCopy()); | 1151 response.Set("result", base::MakeUnique<base::Value>(result)); |
| 1152 base::JSONWriter::Write(response, message); | 1152 base::JSONWriter::Write(response, message); |
| 1153 sent_responses_++; | 1153 sent_responses_++; |
| 1154 return SyncWebSocket::kOk; | 1154 return SyncWebSocket::kOk; |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 bool HasNextMessage() override { return sent_messages_ > sent_responses_; } | 1157 bool HasNextMessage() override { return sent_messages_ > sent_responses_; } |
| 1158 | 1158 |
| 1159 private: | 1159 private: |
| 1160 int id_; | 1160 int id_; |
| 1161 int sent_messages_; | 1161 int sent_messages_; |
| 1162 int sent_responses_; | 1162 int sent_responses_; |
| 1163 }; | 1163 }; |
| 1164 | 1164 |
| 1165 } // namespace | 1165 } // namespace |
| 1166 | 1166 |
| 1167 TEST_F(DevToolsClientImplTest, SendCommandAndIgnoreResponse) { | 1167 TEST_F(DevToolsClientImplTest, SendCommandAndIgnoreResponse) { |
| 1168 SyncWebSocketFactory factory = | 1168 SyncWebSocketFactory factory = |
| 1169 base::Bind(&CreateMockSyncWebSocket<MockSyncWebSocket7>); | 1169 base::Bind(&CreateMockSyncWebSocket<MockSyncWebSocket7>); |
| 1170 DevToolsClientImpl client(factory, "http://url", "id", | 1170 DevToolsClientImpl client(factory, "http://url", "id", |
| 1171 base::Bind(&CloserFunc)); | 1171 base::Bind(&CloserFunc)); |
| 1172 ASSERT_EQ(kOk, client.ConnectIfNecessary().code()); | 1172 ASSERT_EQ(kOk, client.ConnectIfNecessary().code()); |
| 1173 base::DictionaryValue params; | 1173 base::DictionaryValue params; |
| 1174 params.SetInteger("param", 1); | 1174 params.SetInteger("param", 1); |
| 1175 ASSERT_EQ(kOk, client.SendCommandAndIgnoreResponse("method", params).code()); | 1175 ASSERT_EQ(kOk, client.SendCommandAndIgnoreResponse("method", params).code()); |
| 1176 ASSERT_EQ(kOk, client.SendCommand("method", params).code()); | 1176 ASSERT_EQ(kOk, client.SendCommand("method", params).code()); |
| 1177 } | 1177 } |
| OLD | NEW |