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

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

Issue 1093993003: Allow embedded_test_server to serve from multiple directories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix iOS Created 5 years, 8 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
« no previous file with comments | « net/test/embedded_test_server/embedded_test_server.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 fetcher->SetRequestContext(request_context_getter_.get()); 166 fetcher->SetRequestContext(request_context_getter_.get());
167 fetcher->Start(); 167 fetcher->Start();
168 WaitForResponses(1); 168 WaitForResponses(1);
169 169
170 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status()); 170 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status());
171 EXPECT_EQ(HTTP_OK, fetcher->GetResponseCode()); 171 EXPECT_EQ(HTTP_OK, fetcher->GetResponseCode());
172 EXPECT_EQ("<p>Hello World!</p>", GetContentFromFetcher(*fetcher)); 172 EXPECT_EQ("<p>Hello World!</p>", GetContentFromFetcher(*fetcher));
173 EXPECT_EQ("", GetContentTypeFromFetcher(*fetcher)); 173 EXPECT_EQ("", GetContentTypeFromFetcher(*fetcher));
174 } 174 }
175 175
176 TEST_F(EmbeddedTestServerTest, ServeFilesFromDirectories) {
177 base::FilePath src_dir;
178 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
179 std::vector<base::FilePath> src_dirs;
180 src_dirs.push_back(src_dir.AppendASCII("net").AppendASCII("data"));
181 src_dirs.push_back(src_dir.AppendASCII("net").AppendASCII("data")
182 .AppendASCII("embedded_test_server"));
183 server_->ServeFilesFromDirectories(src_dirs);
184
185 // There is also a file named "test.html" in directory
186 // "embedded_test_server", but the one in net/data should match.
187 scoped_ptr<URLFetcher> fetcher(URLFetcher::Create(
188 server_->GetURL("/test.html"), URLFetcher::GET, this));
189 fetcher->SetRequestContext(request_context_getter_.get());
190
191 scoped_ptr<URLFetcher> fetcher2(URLFetcher::Create(
192 server_->GetURL("/test2.html"), URLFetcher::GET, this));
193 fetcher2->SetRequestContext(request_context_getter_.get());
194
195 scoped_ptr<URLFetcher> fetcher3(URLFetcher::Create(
196 server_->GetURL("/test3.html"), URLFetcher::GET, this));
197 fetcher3->SetRequestContext(request_context_getter_.get());
198
199 fetcher->Start();
200 fetcher2->Start();
201 fetcher3->Start();
202 WaitForResponses(3);
203
204 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status());
205 EXPECT_EQ(HTTP_OK, fetcher->GetResponseCode());
206 EXPECT_EQ("<p>Hello World!</p>", GetContentFromFetcher(*fetcher));
207 EXPECT_EQ("", GetContentTypeFromFetcher(*fetcher));
208
209 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher2->GetStatus().status());
210 EXPECT_EQ(HTTP_OK, fetcher2->GetResponseCode());
211 EXPECT_EQ("<p>Second file</p>", GetContentFromFetcher(*fetcher2));
212 EXPECT_EQ("", GetContentTypeFromFetcher(*fetcher2));
213
214 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher3->GetStatus().status());
215 EXPECT_EQ(HTTP_NOT_FOUND, fetcher3->GetResponseCode());
216 }
217
176 TEST_F(EmbeddedTestServerTest, DefaultNotFoundResponse) { 218 TEST_F(EmbeddedTestServerTest, DefaultNotFoundResponse) {
177 scoped_ptr<URLFetcher> fetcher( 219 scoped_ptr<URLFetcher> fetcher(
178 URLFetcher::Create(server_->GetURL("/non-existent"), 220 URLFetcher::Create(server_->GetURL("/non-existent"),
179 URLFetcher::GET, 221 URLFetcher::GET,
180 this)); 222 this));
181 fetcher->SetRequestContext(request_context_getter_.get()); 223 fetcher->SetRequestContext(request_context_getter_.get());
182 224
183 fetcher->Start(); 225 fetcher->Start();
184 WaitForResponses(1); 226 WaitForResponses(1);
185 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status()); 227 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 ASSERT_TRUE(base::PlatformThread::Create(0, &delegate, &thread_handle)); 369 ASSERT_TRUE(base::PlatformThread::Create(0, &delegate, &thread_handle));
328 base::PlatformThread::Join(thread_handle); 370 base::PlatformThread::Join(thread_handle);
329 } 371 }
330 372
331 INSTANTIATE_TEST_CASE_P(EmbeddedTestServerThreadingTestInstantiation, 373 INSTANTIATE_TEST_CASE_P(EmbeddedTestServerThreadingTestInstantiation,
332 EmbeddedTestServerThreadingTest, 374 EmbeddedTestServerThreadingTest,
333 testing::Combine(testing::Bool(), testing::Bool())); 375 testing::Combine(testing::Bool(), testing::Bool()));
334 376
335 } // namespace test_server 377 } // namespace test_server
336 } // namespace net 378 } // namespace net
OLDNEW
« no previous file with comments | « net/test/embedded_test_server/embedded_test_server.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698