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" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // The web server needs a loop to exist on this thread during construction | 133 // The web server needs a loop to exist on this thread during construction |
134 // the loop must be created before we construct the server. | 134 // the loop must be created before we construct the server. |
135 MessageLoopForUI loop; | 135 MessageLoopForUI loop; |
136 | 136 |
137 test_server::SimpleWebServer server(1337); | 137 test_server::SimpleWebServer server(1337); |
138 test_server::SimpleResponse person("/person", "Guthrie Govan!"); | 138 test_server::SimpleResponse person("/person", "Guthrie Govan!"); |
139 server.AddResponse(&person); | 139 server.AddResponse(&person); |
140 test_server::FileResponse file("/file", source_path().Append( | 140 test_server::FileResponse file("/file", source_path().Append( |
141 FILE_PATH_LITERAL("CFInstance.js"))); | 141 FILE_PATH_LITERAL("CFInstance.js"))); |
142 server.AddResponse(&file); | 142 server.AddResponse(&file); |
143 test_server::RedirectResponse redir("/goog", "http://www.google.com/"); | 143 test_server::RedirectResponse redir("/redir", "http://localhost:1338/dest"); |
144 server.AddResponse(&redir); | 144 server.AddResponse(&redir); |
145 | 145 |
| 146 test_server::SimpleWebServer redirected_server(1338); |
| 147 test_server::SimpleResponse dest("/dest", "Destination"); |
| 148 redirected_server.AddResponse(&dest); |
| 149 |
146 // We should never hit this, but it's our way to break out of the test if | 150 // We should never hit this, but it's our way to break out of the test if |
147 // things start hanging. | 151 // things start hanging. |
148 QuitMessageHit quit_msg(&loop); | 152 QuitMessageHit quit_msg(&loop); |
149 loop.PostDelayedTask(FROM_HERE, base::Bind(QuitMessageLoop, &quit_msg), | 153 loop.PostDelayedTask(FROM_HERE, base::Bind(QuitMessageLoop, &quit_msg), |
150 base::TimeDelta::FromSeconds(10)); | 154 base::TimeDelta::FromSeconds(10)); |
151 | 155 |
152 UrlTaskChain quit_task("http://localhost:1337/quit", NULL); | 156 UrlTaskChain quit_task("http://localhost:1337/quit", NULL); |
153 UrlTaskChain fnf_task("http://localhost:1337/404", &quit_task); | 157 UrlTaskChain fnf_task("http://localhost:1337/404", &quit_task); |
154 UrlTaskChain person_task("http://localhost:1337/person", &fnf_task); | 158 UrlTaskChain person_task("http://localhost:1337/person", &fnf_task); |
155 UrlTaskChain file_task("http://localhost:1337/file", &person_task); | 159 UrlTaskChain file_task("http://localhost:1337/file", &person_task); |
156 UrlTaskChain goog_task("http://localhost:1337/goog", &file_task); | 160 UrlTaskChain redir_task("http://localhost:1337/redir", &file_task); |
157 | 161 |
158 DWORD tid = 0; | 162 DWORD tid = 0; |
159 base::win::ScopedHandle worker(::CreateThread( | 163 base::win::ScopedHandle worker(::CreateThread( |
160 NULL, 0, FetchUrl, &goog_task, 0, &tid)); | 164 NULL, 0, FetchUrl, &redir_task, 0, &tid)); |
161 loop.MessageLoop::Run(); | 165 loop.MessageLoop::Run(); |
162 | 166 |
163 EXPECT_FALSE(quit_msg.hit_); | 167 EXPECT_FALSE(quit_msg.hit_); |
164 if (!quit_msg.hit_) { | 168 if (!quit_msg.hit_) { |
165 EXPECT_EQ(::WaitForSingleObject(worker, 10 * 1000), WAIT_OBJECT_0); | 169 EXPECT_EQ(::WaitForSingleObject(worker, 10 * 1000), WAIT_OBJECT_0); |
166 | 170 |
167 EXPECT_EQ(person.accessed(), 1); | 171 EXPECT_EQ(person.accessed(), 1); |
168 EXPECT_EQ(file.accessed(), 1); | 172 EXPECT_EQ(file.accessed(), 1); |
169 EXPECT_EQ(redir.accessed(), 1); | 173 EXPECT_EQ(redir.accessed(), 1); |
170 | 174 |
171 EXPECT_TRUE(person_task.response().find("Guthrie") != std::string::npos); | 175 EXPECT_TRUE(person_task.response().find("Guthrie") != std::string::npos); |
172 EXPECT_TRUE(file_task.response().find("function") != std::string::npos); | 176 EXPECT_TRUE(file_task.response().find("function") != std::string::npos); |
173 EXPECT_TRUE(goog_task.response().find("<title>") != std::string::npos); | 177 EXPECT_TRUE(redir_task.response().find("Destination") != std::string::npos); |
174 } else { | 178 } else { |
175 ::TerminateThread(worker, ~0); | 179 ::TerminateThread(worker, ~0); |
176 } | 180 } |
177 } | 181 } |
OLD | NEW |