| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <wininet.h> | 6 #include <wininet.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/stringprintf.h" |
| 11 #include "base/win/scoped_handle.h" | 12 #include "base/win/scoped_handle.h" |
| 12 #include "chrome_frame/test/test_server.h" | 13 #include "chrome_frame/test/test_server.h" |
| 13 #include "net/base/host_resolver_proc.h" | 14 #include "net/base/host_resolver_proc.h" |
| 14 #include "net/cookies/cookie_monster.h" | 15 #include "net/cookies/cookie_monster.h" |
| 15 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
| 16 #include "net/http/http_auth_handler_factory.h" | 17 #include "net/http/http_auth_handler_factory.h" |
| 17 #include "net/http/http_cache.h" | 18 #include "net/http/http_cache.h" |
| 18 #include "net/http/http_network_session.h" | 19 #include "net/http/http_network_session.h" |
| 19 #include "net/proxy/proxy_service.h" | 20 #include "net/proxy/proxy_service.h" |
| 20 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 public: | 65 public: |
| 65 TestURLRequest(const GURL& url, | 66 TestURLRequest(const GURL& url, |
| 66 Delegate* delegate, | 67 Delegate* delegate, |
| 67 TestURLRequestContext* context) | 68 TestURLRequestContext* context) |
| 68 : net::URLRequest(url, delegate, context) { | 69 : net::URLRequest(url, delegate, context) { |
| 69 } | 70 } |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 class UrlTaskChain { | 73 class UrlTaskChain { |
| 73 public: | 74 public: |
| 74 UrlTaskChain(const char* url, UrlTaskChain* next) | 75 UrlTaskChain(const std::string& url, UrlTaskChain* next) |
| 75 : url_(url), next_(next) { | 76 : url_(url), next_(next) { |
| 76 } | 77 } |
| 77 | 78 |
| 78 void Run() { | 79 void Run() { |
| 79 EXPECT_EQ(0, delegate_.response_started_count()); | 80 EXPECT_EQ(0, delegate_.response_started_count()); |
| 80 | 81 |
| 81 MessageLoopForIO loop; | 82 MessageLoopForIO loop; |
| 82 | 83 |
| 83 TestURLRequestContext context; | 84 TestURLRequestContext context; |
| 84 TestURLRequest r(GURL(url_), &delegate_, &context); | 85 TestURLRequest r(GURL(url_), &delegate_, &context); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 131 } |
| 131 | 132 |
| 132 } // end namespace | 133 } // end namespace |
| 133 | 134 |
| 134 TEST_F(TestServerTest, TestServer) { | 135 TEST_F(TestServerTest, TestServer) { |
| 135 // The web server needs a loop to exist on this thread during construction | 136 // The web server needs a loop to exist on this thread during construction |
| 136 // the loop must be created before we construct the server. | 137 // the loop must be created before we construct the server. |
| 137 MessageLoopForUI loop; | 138 MessageLoopForUI loop; |
| 138 | 139 |
| 139 test_server::SimpleWebServer server(1337); | 140 test_server::SimpleWebServer server(1337); |
| 141 test_server::SimpleWebServer redirected_server(server.host(), 1338); |
| 140 test_server::SimpleResponse person("/person", "Guthrie Govan!"); | 142 test_server::SimpleResponse person("/person", "Guthrie Govan!"); |
| 141 server.AddResponse(&person); | 143 server.AddResponse(&person); |
| 142 test_server::FileResponse file("/file", source_path().Append( | 144 test_server::FileResponse file("/file", source_path().Append( |
| 143 FILE_PATH_LITERAL("CFInstance.js"))); | 145 FILE_PATH_LITERAL("CFInstance.js"))); |
| 144 server.AddResponse(&file); | 146 server.AddResponse(&file); |
| 145 test_server::RedirectResponse redir("/redir", "http://localhost:1338/dest"); | 147 test_server::RedirectResponse redir( |
| 148 "/redir", |
| 149 base::StringPrintf("http://%hs:1338/dest", |
| 150 redirected_server.host().c_str())); |
| 146 server.AddResponse(&redir); | 151 server.AddResponse(&redir); |
| 147 | 152 |
| 148 test_server::SimpleWebServer redirected_server(1338); | |
| 149 test_server::SimpleResponse dest("/dest", "Destination"); | 153 test_server::SimpleResponse dest("/dest", "Destination"); |
| 150 redirected_server.AddResponse(&dest); | 154 redirected_server.AddResponse(&dest); |
| 151 | 155 |
| 152 // We should never hit this, but it's our way to break out of the test if | 156 // We should never hit this, but it's our way to break out of the test if |
| 153 // things start hanging. | 157 // things start hanging. |
| 154 QuitMessageHit quit_msg(&loop); | 158 QuitMessageHit quit_msg(&loop); |
| 155 loop.PostDelayedTask(FROM_HERE, base::Bind(QuitMessageLoop, &quit_msg), | 159 loop.PostDelayedTask(FROM_HERE, base::Bind(QuitMessageLoop, &quit_msg), |
| 156 base::TimeDelta::FromSeconds(10)); | 160 base::TimeDelta::FromSeconds(10)); |
| 157 | 161 |
| 158 UrlTaskChain quit_task("http://localhost:1337/quit", NULL); | 162 UrlTaskChain quit_task( |
| 159 UrlTaskChain fnf_task("http://localhost:1337/404", &quit_task); | 163 base::StringPrintf("http://%hs:1337/quit", server.host().c_str()), NULL); |
| 160 UrlTaskChain person_task("http://localhost:1337/person", &fnf_task); | 164 UrlTaskChain fnf_task( |
| 161 UrlTaskChain file_task("http://localhost:1337/file", &person_task); | 165 base::StringPrintf("http://%hs:1337/404", server.host().c_str()), |
| 162 UrlTaskChain redir_task("http://localhost:1337/redir", &file_task); | 166 &quit_task); |
| 167 UrlTaskChain person_task( |
| 168 base::StringPrintf("http://%hs:1337/person", server.host().c_str()), |
| 169 &fnf_task); |
| 170 UrlTaskChain file_task( |
| 171 base::StringPrintf("http://%hs:1337/file", server.host().c_str()), |
| 172 &person_task); |
| 173 UrlTaskChain redir_task( |
| 174 base::StringPrintf("http://%hs:1337/redir", server.host().c_str()), |
| 175 &file_task); |
| 163 | 176 |
| 164 DWORD tid = 0; | 177 DWORD tid = 0; |
| 165 base::win::ScopedHandle worker(::CreateThread( | 178 base::win::ScopedHandle worker(::CreateThread( |
| 166 NULL, 0, FetchUrl, &redir_task, 0, &tid)); | 179 NULL, 0, FetchUrl, &redir_task, 0, &tid)); |
| 167 loop.MessageLoop::Run(); | 180 loop.MessageLoop::Run(); |
| 168 | 181 |
| 169 EXPECT_FALSE(quit_msg.hit_); | 182 EXPECT_FALSE(quit_msg.hit_); |
| 170 if (!quit_msg.hit_) { | 183 if (!quit_msg.hit_) { |
| 171 EXPECT_EQ(::WaitForSingleObject(worker, 10 * 1000), WAIT_OBJECT_0); | 184 EXPECT_EQ(::WaitForSingleObject(worker, 10 * 1000), WAIT_OBJECT_0); |
| 172 | 185 |
| 173 EXPECT_EQ(person.accessed(), 1); | 186 EXPECT_EQ(person.accessed(), 1); |
| 174 EXPECT_EQ(file.accessed(), 1); | 187 EXPECT_EQ(file.accessed(), 1); |
| 175 EXPECT_EQ(redir.accessed(), 1); | 188 EXPECT_EQ(redir.accessed(), 1); |
| 176 | 189 |
| 177 EXPECT_TRUE(person_task.response().find("Guthrie") != std::string::npos); | 190 EXPECT_TRUE(person_task.response().find("Guthrie") != std::string::npos); |
| 178 EXPECT_TRUE(file_task.response().find("function") != std::string::npos); | 191 EXPECT_TRUE(file_task.response().find("function") != std::string::npos); |
| 179 EXPECT_TRUE(redir_task.response().find("Destination") != std::string::npos); | 192 EXPECT_TRUE(redir_task.response().find("Destination") != std::string::npos); |
| 180 } else { | 193 } else { |
| 181 ::TerminateThread(worker, ~0); | 194 ::TerminateThread(worker, ~0); |
| 182 } | 195 } |
| 183 } | 196 } |
| OLD | NEW |