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

Side by Side Diff: chrome/test/chromedriver/server/http_handler_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) 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> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 request.method = "post"; 67 request.method = "post";
68 request.path = "/base/session"; 68 request.path = "/base/session";
69 net::HttpServerResponseInfo response; 69 net::HttpServerResponseInfo response;
70 handler.Handle(request, base::Bind(&OnResponse, &response)); 70 handler.Handle(request, base::Bind(&OnResponse, &response));
71 ASSERT_EQ(net::HTTP_OK, response.status_code()); 71 ASSERT_EQ(net::HTTP_OK, response.status_code());
72 base::DictionaryValue body; 72 base::DictionaryValue body;
73 body.SetInteger("status", kOk); 73 body.SetInteger("status", kOk);
74 body.SetInteger("value", 1); 74 body.SetInteger("value", 1);
75 body.SetString("sessionId", "session_id"); 75 body.SetString("sessionId", "session_id");
76 std::string json; 76 std::string json;
77 base::JSONWriter::Write(&body, &json); 77 base::JSONWriter::Write(body, &json);
78 ASSERT_EQ(json, response.body()); 78 ASSERT_EQ(json, response.body());
79 } 79 }
80 80
81 TEST(HttpHandlerTest, HandleInvalidPost) { 81 TEST(HttpHandlerTest, HandleInvalidPost) {
82 HttpHandler handler("/"); 82 HttpHandler handler("/");
83 handler.command_map_->push_back( 83 handler.command_map_->push_back(
84 CommandMapping(kPost, "path", base::Bind(&DummyCommand, Status(kOk)))); 84 CommandMapping(kPost, "path", base::Bind(&DummyCommand, Status(kOk))));
85 net::HttpServerRequestInfo request; 85 net::HttpServerRequestInfo request;
86 request.method = "post"; 86 request.method = "post";
87 request.path = "/path"; 87 request.path = "/path";
(...skipping 24 matching lines...) Expand all
112 request.method = "post"; 112 request.method = "post";
113 request.path = "/path"; 113 request.path = "/path";
114 net::HttpServerResponseInfo response; 114 net::HttpServerResponseInfo response;
115 handler.Handle(request, base::Bind(&OnResponse, &response)); 115 handler.Handle(request, base::Bind(&OnResponse, &response));
116 ASSERT_EQ(net::HTTP_OK, response.status_code()); 116 ASSERT_EQ(net::HTTP_OK, response.status_code());
117 base::DictionaryValue body; 117 base::DictionaryValue body;
118 body.SetInteger("status", kOk); 118 body.SetInteger("status", kOk);
119 body.SetInteger("value", 1); 119 body.SetInteger("value", 1);
120 body.SetString("sessionId", "session_id"); 120 body.SetString("sessionId", "session_id");
121 std::string json; 121 std::string json;
122 base::JSONWriter::Write(&body, &json); 122 base::JSONWriter::Write(body, &json);
123 ASSERT_EQ(json, response.body()); 123 ASSERT_EQ(json, response.body());
124 } 124 }
125 125
126 TEST(MatchesCommandTest, DiffMethod) { 126 TEST(MatchesCommandTest, DiffMethod) {
127 CommandMapping command(kPost, "path", base::Bind(&DummyCommand, Status(kOk))); 127 CommandMapping command(kPost, "path", base::Bind(&DummyCommand, Status(kOk)));
128 std::string session_id; 128 std::string session_id;
129 base::DictionaryValue params; 129 base::DictionaryValue params;
130 ASSERT_FALSE(internal::MatchesCommand( 130 ASSERT_FALSE(internal::MatchesCommand(
131 "get", "path", command, &session_id, &params)); 131 "get", "path", command, &session_id, &params));
132 ASSERT_TRUE(session_id.empty()); 132 ASSERT_TRUE(session_id.empty());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ASSERT_TRUE(internal::MatchesCommand( 165 ASSERT_TRUE(internal::MatchesCommand(
166 "post", "path/1/space/2/3", command, &session_id, &params)); 166 "post", "path/1/space/2/3", command, &session_id, &params));
167 ASSERT_EQ("1", session_id); 167 ASSERT_EQ("1", session_id);
168 ASSERT_EQ(2u, params.size()); 168 ASSERT_EQ(2u, params.size());
169 std::string param; 169 std::string param;
170 ASSERT_TRUE(params.GetString("a", &param)); 170 ASSERT_TRUE(params.GetString("a", &param));
171 ASSERT_EQ("2", param); 171 ASSERT_EQ("2", param);
172 ASSERT_TRUE(params.GetString("b", &param)); 172 ASSERT_TRUE(params.GetString("b", &param));
173 ASSERT_EQ("3", param); 173 ASSERT_EQ("3", param);
174 } 174 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/server/http_handler.cc ('k') | chromeos/dbus/shill_client_unittest_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698