| 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 "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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |