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

Side by Side Diff: net/test/embedded_test_server/embedded_test_server_unittest.cc

Issue 15505003: GTTF: Convert most tests in content to use EmbeddedTestServer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 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 | Annotate | Revision Log
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 "net/test/embedded_test_server/embedded_test_server.h" 5 #include "net/test/embedded_test_server/embedded_test_server.h"
6 6
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "net/http/http_response_headers.h" 9 #include "net/http/http_response_headers.h"
10 #include "net/test/embedded_test_server/http_request.h" 10 #include "net/test/embedded_test_server/http_request.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // Waits until the specified number of responses are received. 75 // Waits until the specified number of responses are received.
76 void WaitForResponses(int num_responses) { 76 void WaitForResponses(int num_responses) {
77 num_responses_received_ = 0; 77 num_responses_received_ = 0;
78 num_responses_expected_ = num_responses; 78 num_responses_expected_ = num_responses;
79 // Will be terminated in OnURLFetchComplete(). 79 // Will be terminated in OnURLFetchComplete().
80 MessageLoop::current()->Run(); 80 MessageLoop::current()->Run();
81 } 81 }
82 82
83 // Handles |request| sent to |path| and returns the response per |content|, 83 // Handles |request| sent to |path| and returns the response per |content|,
84 // |content type|, and |code|. Saves the request URL for verification. 84 // |content type|, and |code|. Saves the request URL for verification.
85 scoped_ptr<HttpResponse> HandleRequest(const std::string& path, 85 scoped_ptr<HttpResponseInterface> HandleRequest(
86 const std::string& content, 86 const std::string& path,
87 const std::string& content_type, 87 const std::string& content,
88 ResponseCode code, 88 const std::string& content_type,
89 const HttpRequest& request) { 89 ResponseCode code,
90 const HttpRequest& request) {
90 request_relative_url_ = request.relative_url; 91 request_relative_url_ = request.relative_url;
91 92
92 GURL absolute_url = server_->GetURL(request.relative_url); 93 GURL absolute_url = server_->GetURL(request.relative_url);
93 if (absolute_url.path() == path) { 94 if (absolute_url.path() == path) {
94 scoped_ptr<HttpResponse> http_response(new HttpResponse); 95 scoped_ptr<HttpResponse> http_response(new HttpResponse);
95 http_response->set_code(code); 96 http_response->set_code(code);
96 http_response->set_content(content); 97 http_response->set_content(content);
97 http_response->set_content_type(content_type); 98 http_response->set_content_type(content_type);
98 return http_response.Pass(); 99 return http_response.PassAs<HttpResponseInterface>();
99 } 100 }
100 101
101 return scoped_ptr<HttpResponse>(); 102 return scoped_ptr<HttpResponseInterface>();
102 } 103 }
103 104
104 protected: 105 protected:
105 int num_responses_received_; 106 int num_responses_received_;
106 int num_responses_expected_; 107 int num_responses_expected_;
107 std::string request_relative_url_; 108 std::string request_relative_url_;
108 base::Thread io_thread_; 109 base::Thread io_thread_;
109 scoped_refptr<TestURLRequestContextGetter> request_context_getter_; 110 scoped_refptr<TestURLRequestContextGetter> request_context_getter_;
110 scoped_ptr<EmbeddedTestServer> server_; 111 scoped_ptr<EmbeddedTestServer> server_;
111 }; 112 };
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 EXPECT_EQ("text/html", GetContentTypeFromFetcher(*fetcher2)); 236 EXPECT_EQ("text/html", GetContentTypeFromFetcher(*fetcher2));
236 237
237 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher3->GetStatus().status()); 238 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher3->GetStatus().status());
238 EXPECT_EQ(NOT_FOUND, fetcher3->GetResponseCode()); 239 EXPECT_EQ(NOT_FOUND, fetcher3->GetResponseCode());
239 EXPECT_EQ("No chocolates", GetContentFromFetcher(*fetcher3)); 240 EXPECT_EQ("No chocolates", GetContentFromFetcher(*fetcher3));
240 EXPECT_EQ("text/plain", GetContentTypeFromFetcher(*fetcher3)); 241 EXPECT_EQ("text/plain", GetContentTypeFromFetcher(*fetcher3));
241 } 242 }
242 243
243 } // namespace test_server 244 } // namespace test_server
244 } // namespace net 245 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698