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/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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 WaitForResponses(1); | 139 WaitForResponses(1); |
140 | 140 |
141 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status()); | 141 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status()); |
142 EXPECT_EQ(SUCCESS, fetcher->GetResponseCode()); | 142 EXPECT_EQ(SUCCESS, fetcher->GetResponseCode()); |
143 EXPECT_EQ("<b>Worked!</b>", GetContentFromFetcher(*fetcher)); | 143 EXPECT_EQ("<b>Worked!</b>", GetContentFromFetcher(*fetcher)); |
144 EXPECT_EQ("text/html", GetContentTypeFromFetcher(*fetcher)); | 144 EXPECT_EQ("text/html", GetContentTypeFromFetcher(*fetcher)); |
145 | 145 |
146 EXPECT_EQ("/test?q=foo", request_relative_url_); | 146 EXPECT_EQ("/test?q=foo", request_relative_url_); |
147 } | 147 } |
148 | 148 |
| 149 TEST_F(EmbeddedTestServerTest, ServeFilesFromDirectory) { |
| 150 base::FilePath src_dir; |
| 151 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); |
| 152 server_->ServeFilesFromDirectory( |
| 153 src_dir.AppendASCII("net").AppendASCII("data")); |
| 154 |
| 155 scoped_ptr<URLFetcher> fetcher( |
| 156 URLFetcher::Create(server_->GetURL("/test.html"), |
| 157 URLFetcher::GET, |
| 158 this)); |
| 159 fetcher->SetRequestContext(request_context_getter_.get()); |
| 160 fetcher->Start(); |
| 161 WaitForResponses(1); |
| 162 |
| 163 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status()); |
| 164 EXPECT_EQ(SUCCESS, fetcher->GetResponseCode()); |
| 165 EXPECT_EQ("<p>Hello World!</p>", GetContentFromFetcher(*fetcher)); |
| 166 EXPECT_EQ("", GetContentTypeFromFetcher(*fetcher)); |
| 167 } |
| 168 |
149 TEST_F(EmbeddedTestServerTest, DefaultNotFoundResponse) { | 169 TEST_F(EmbeddedTestServerTest, DefaultNotFoundResponse) { |
150 scoped_ptr<URLFetcher> fetcher( | 170 scoped_ptr<URLFetcher> fetcher( |
151 URLFetcher::Create(server_->GetURL("/non-existent"), | 171 URLFetcher::Create(server_->GetURL("/non-existent"), |
152 URLFetcher::GET, | 172 URLFetcher::GET, |
153 this)); | 173 this)); |
154 fetcher->SetRequestContext(request_context_getter_.get()); | 174 fetcher->SetRequestContext(request_context_getter_.get()); |
155 | 175 |
156 fetcher->Start(); | 176 fetcher->Start(); |
157 WaitForResponses(1); | 177 WaitForResponses(1); |
158 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status()); | 178 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher->GetStatus().status()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 EXPECT_EQ("text/html", GetContentTypeFromFetcher(*fetcher2)); | 235 EXPECT_EQ("text/html", GetContentTypeFromFetcher(*fetcher2)); |
216 | 236 |
217 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher3->GetStatus().status()); | 237 EXPECT_EQ(URLRequestStatus::SUCCESS, fetcher3->GetStatus().status()); |
218 EXPECT_EQ(NOT_FOUND, fetcher3->GetResponseCode()); | 238 EXPECT_EQ(NOT_FOUND, fetcher3->GetResponseCode()); |
219 EXPECT_EQ("No chocolates", GetContentFromFetcher(*fetcher3)); | 239 EXPECT_EQ("No chocolates", GetContentFromFetcher(*fetcher3)); |
220 EXPECT_EQ("text/plain", GetContentTypeFromFetcher(*fetcher3)); | 240 EXPECT_EQ("text/plain", GetContentTypeFromFetcher(*fetcher3)); |
221 } | 241 } |
222 | 242 |
223 } // namespace test_server | 243 } // namespace test_server |
224 } // namespace net | 244 } // namespace net |
OLD | NEW |