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

Side by Side Diff: chrome/test/chromedriver/chrome/devtools_client_impl_unittest.cc

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 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) 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 <list> 5 #include <list>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 SyncWebSocket::StatusCode ReceiveNextMessage( 63 SyncWebSocket::StatusCode ReceiveNextMessage(
64 std::string* message, 64 std::string* message,
65 const base::TimeDelta& timeout) override { 65 const base::TimeDelta& timeout) override {
66 if (timeout <= base::TimeDelta()) 66 if (timeout <= base::TimeDelta())
67 return SyncWebSocket::kTimeout; 67 return SyncWebSocket::kTimeout;
68 base::DictionaryValue response; 68 base::DictionaryValue response;
69 response.SetInteger("id", id_); 69 response.SetInteger("id", id_);
70 base::DictionaryValue result; 70 base::DictionaryValue result;
71 result.SetInteger("param", 1); 71 result.SetInteger("param", 1);
72 response.Set("result", result.DeepCopy()); 72 response.Set("result", result.DeepCopy());
73 base::JSONWriter::Write(&response, message); 73 base::JSONWriter::Write(response, message);
74 --queued_messages_; 74 --queued_messages_;
75 return SyncWebSocket::kOk; 75 return SyncWebSocket::kOk;
76 } 76 }
77 77
78 bool HasNextMessage() override { return queued_messages_ > 0; } 78 bool HasNextMessage() override { return queued_messages_ > 0; }
79 79
80 protected: 80 protected:
81 bool connected_; 81 bool connected_;
82 int id_; 82 int id_;
83 int queued_messages_; 83 int queued_messages_;
(...skipping 29 matching lines...) Expand all
113 base::Bind(&CreateMockSyncWebSocket<MockSyncWebSocket>); 113 base::Bind(&CreateMockSyncWebSocket<MockSyncWebSocket>);
114 DevToolsClientImpl client(factory, "http://url", "id", 114 DevToolsClientImpl client(factory, "http://url", "id",
115 base::Bind(&CloserFunc)); 115 base::Bind(&CloserFunc));
116 ASSERT_EQ(kOk, client.ConnectIfNecessary().code()); 116 ASSERT_EQ(kOk, client.ConnectIfNecessary().code());
117 base::DictionaryValue params; 117 base::DictionaryValue params;
118 params.SetInteger("param", 1); 118 params.SetInteger("param", 1);
119 scoped_ptr<base::DictionaryValue> result; 119 scoped_ptr<base::DictionaryValue> result;
120 Status status = client.SendCommandAndGetResult("method", params, &result); 120 Status status = client.SendCommandAndGetResult("method", params, &result);
121 ASSERT_EQ(kOk, status.code()); 121 ASSERT_EQ(kOk, status.code());
122 std::string json; 122 std::string json;
123 base::JSONWriter::Write(result.get(), &json); 123 base::JSONWriter::Write(*result, &json);
124 ASSERT_STREQ("{\"param\":1}", json.c_str()); 124 ASSERT_STREQ("{\"param\":1}", json.c_str());
125 } 125 }
126 126
127 namespace { 127 namespace {
128 128
129 class MockSyncWebSocket2 : public SyncWebSocket { 129 class MockSyncWebSocket2 : public SyncWebSocket {
130 public: 130 public:
131 MockSyncWebSocket2() {} 131 MockSyncWebSocket2() {}
132 ~MockSyncWebSocket2() override {} 132 ~MockSyncWebSocket2() override {}
133 133
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 return false; 718 return false;
719 int id; 719 int id;
720 EXPECT_TRUE(dict->GetInteger("id", &id)); 720 EXPECT_TRUE(dict->GetInteger("id", &id));
721 std::string method; 721 std::string method;
722 EXPECT_TRUE(dict->GetString("method", &method)); 722 EXPECT_TRUE(dict->GetString("method", &method));
723 723
724 base::DictionaryValue response; 724 base::DictionaryValue response;
725 response.SetInteger("id", id); 725 response.SetInteger("id", id);
726 response.Set("result", new base::DictionaryValue()); 726 response.Set("result", new base::DictionaryValue());
727 std::string json_response; 727 std::string json_response;
728 base::JSONWriter::Write(&response, &json_response); 728 base::JSONWriter::Write(response, &json_response);
729 queued_response_.push_back(json_response); 729 queued_response_.push_back(json_response);
730 730
731 // Push one event. 731 // Push one event.
732 base::DictionaryValue event; 732 base::DictionaryValue event;
733 event.SetString("method", "updateEvent"); 733 event.SetString("method", "updateEvent");
734 event.Set("params", new base::DictionaryValue()); 734 event.Set("params", new base::DictionaryValue());
735 std::string json_event; 735 std::string json_event;
736 base::JSONWriter::Write(&event, &json_event); 736 base::JSONWriter::Write(event, &json_event);
737 queued_response_.push_back(json_event); 737 queued_response_.push_back(json_event);
738 738
739 return true; 739 return true;
740 } 740 }
741 741
742 SyncWebSocket::StatusCode ReceiveNextMessage( 742 SyncWebSocket::StatusCode ReceiveNextMessage(
743 std::string* message, 743 std::string* message,
744 const base::TimeDelta& timeout) override { 744 const base::TimeDelta& timeout) override {
745 if (queued_response_.empty()) 745 if (queued_response_.empty())
746 return SyncWebSocket::kDisconnected; 746 return SyncWebSocket::kDisconnected;
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 client.AddListener(&listener1); 1094 client.AddListener(&listener1);
1095 client.AddListener(&listener2); 1095 client.AddListener(&listener2);
1096 msgs.push_back("{\"id\": 1, \"result\": {}}"); 1096 msgs.push_back("{\"id\": 1, \"result\": {}}");
1097 msgs.push_back("{\"method\": \"event\", \"params\": {}}"); 1097 msgs.push_back("{\"method\": \"event\", \"params\": {}}");
1098 base::DictionaryValue params; 1098 base::DictionaryValue params;
1099 ASSERT_EQ(kOk, client.SendCommand("cmd", params).code()); 1099 ASSERT_EQ(kOk, client.SendCommand("cmd", params).code());
1100 ASSERT_EQ(2u, listener2.msgs_.size()); 1100 ASSERT_EQ(2u, listener2.msgs_.size());
1101 ASSERT_EQ("cmd", listener2.msgs_.front()); 1101 ASSERT_EQ("cmd", listener2.msgs_.front());
1102 ASSERT_EQ("event", listener2.msgs_.back()); 1102 ASSERT_EQ("event", listener2.msgs_.back());
1103 } 1103 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/chrome/devtools_client_impl.cc ('k') | chrome/test/chromedriver/chrome/dom_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698