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

Side by Side Diff: webkit/glue/resource_fetcher_unittest.cc

Issue 16490: Add FTP unit test in preparation for portable FTP implementation.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/mimetype_unittest.cc ('k') | webkit/glue/unittest_test_server.h » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "config.h" 5 #include "config.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 8
9 MSVC_PUSH_WARNING_LEVEL(0); 9 MSVC_PUSH_WARNING_LEVEL(0);
10 #include "ResourceResponse.h" 10 #include "ResourceResponse.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 bool completed_; 146 bool completed_;
147 int time_elapsed_ms_; 147 int time_elapsed_ms_;
148 ResourceResponse response_; 148 ResourceResponse response_;
149 std::string data_; 149 std::string data_;
150 }; 150 };
151 151
152 FetcherDelegate* FetcherDelegate::instance_ = NULL; 152 FetcherDelegate* FetcherDelegate::instance_ = NULL;
153 153
154 // Test a fetch from the test server. 154 // Test a fetch from the test server.
155 TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { 155 TEST_F(ResourceFetcherTests, ResourceFetcherDownload) {
156 UnittestTestServer server; 156 scoped_refptr<UnittestTestServer> server =
157 UnittestTestServer::CreateServer();
158 ASSERT_TRUE(NULL != server.get());
157 159
158 WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); 160 WebFrame* web_frame = test_shell_->webView()->GetMainFrame();
159 // Not safe, but this is a unittest, so whatever. 161 // Not safe, but this is a unittest, so whatever.
160 WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame); 162 WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame);
161 WebCore::Frame* frame = web_frame_impl->frame(); 163 WebCore::Frame* frame = web_frame_impl->frame();
162 164
163 GURL url = server.TestServerPage("files/test_shell/index.html"); 165 GURL url = server->TestServerPage("files/test_shell/index.html");
164 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 166 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate);
165 scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( 167 scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher(
166 url, frame, delegate.get())); 168 url, frame, delegate.get()));
167 169
168 delegate->WaitForResponse(); 170 delegate->WaitForResponse();
169 171
170 ASSERT_TRUE(delegate->completed()); 172 ASSERT_TRUE(delegate->completed());
171 EXPECT_EQ(delegate->response().httpStatusCode(), 200); 173 EXPECT_EQ(delegate->response().httpStatusCode(), 200);
172 std::string text = delegate->data(); 174 std::string text = delegate->data();
173 EXPECT_TRUE(text.find("What is this page?") != std::string::npos); 175 EXPECT_TRUE(text.find("What is this page?") != std::string::npos);
174 176
175 // Test 404 response. 177 // Test 404 response.
176 url = server.TestServerPage("files/thisfiledoesntexist.html"); 178 url = server->TestServerPage("files/thisfiledoesntexist.html");
177 delegate.reset(new FetcherDelegate); 179 delegate.reset(new FetcherDelegate);
178 fetcher.reset(new ResourceFetcher(url, frame, delegate.get())); 180 fetcher.reset(new ResourceFetcher(url, frame, delegate.get()));
179 181
180 delegate->WaitForResponse(); 182 delegate->WaitForResponse();
181 183
182 ASSERT_TRUE(delegate->completed()); 184 ASSERT_TRUE(delegate->completed());
183 EXPECT_EQ(delegate->response().httpStatusCode(), 404); 185 EXPECT_EQ(delegate->response().httpStatusCode(), 404);
184 EXPECT_TRUE(delegate->data().find("Not Found.") != std::string::npos); 186 EXPECT_TRUE(delegate->data().find("Not Found.") != std::string::npos);
185 } 187 }
186 188
187 TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { 189 TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) {
188 UnittestTestServer server; 190 scoped_refptr<UnittestTestServer> server =
191 UnittestTestServer::CreateServer();
192 ASSERT_TRUE(NULL != server.get());
193
189 WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); 194 WebFrame* web_frame = test_shell_->webView()->GetMainFrame();
190 // Not safe, but this is a unittest, so whatever. 195 // Not safe, but this is a unittest, so whatever.
191 WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame); 196 WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame);
192 WebCore::Frame* frame = web_frame_impl->frame(); 197 WebCore::Frame* frame = web_frame_impl->frame();
193 198
194 // Try to fetch a page on a site that doesn't exist. 199 // Try to fetch a page on a site that doesn't exist.
195 GURL url("http://localhost:1339/doesnotexist"); 200 GURL url("http://localhost:1339/doesnotexist");
196 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 201 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate);
197 scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( 202 scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher(
198 url, frame, delegate.get())); 203 url, frame, delegate.get()));
199 204
200 delegate->WaitForResponse(); 205 delegate->WaitForResponse();
201 206
202 // When we fail, we still call the Delegate callback but we pass in empty 207 // When we fail, we still call the Delegate callback but we pass in empty
203 // values. 208 // values.
204 EXPECT_TRUE(delegate->completed()); 209 EXPECT_TRUE(delegate->completed());
205 EXPECT_TRUE(delegate->response().isNull()); 210 EXPECT_TRUE(delegate->response().isNull());
206 EXPECT_EQ(delegate->data(), std::string()); 211 EXPECT_EQ(delegate->data(), std::string());
207 EXPECT_TRUE(delegate->time_elapsed_ms() < kMaxWaitTimeMs); 212 EXPECT_TRUE(delegate->time_elapsed_ms() < kMaxWaitTimeMs);
208 } 213 }
209 214
210 TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { 215 TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) {
211 UnittestTestServer server; 216 scoped_refptr<UnittestTestServer> server =
217 UnittestTestServer::CreateServer();
218 ASSERT_TRUE(NULL != server.get());
212 219
213 WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); 220 WebFrame* web_frame = test_shell_->webView()->GetMainFrame();
214 // Not safe, but this is a unittest, so whatever. 221 // Not safe, but this is a unittest, so whatever.
215 WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame); 222 WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame);
216 WebCore::Frame* frame = web_frame_impl->frame(); 223 WebCore::Frame* frame = web_frame_impl->frame();
217 224
218 // Grab a page that takes at least 1 sec to respond, but set the fetcher to 225 // Grab a page that takes at least 1 sec to respond, but set the fetcher to
219 // timeout in 0 sec. 226 // timeout in 0 sec.
220 GURL url = server.TestServerPage("slow?1"); 227 GURL url = server->TestServerPage("slow?1");
221 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); 228 scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate);
222 scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcherWithTimeout( 229 scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcherWithTimeout(
223 url, frame, 0, delegate.get())); 230 url, frame, 0, delegate.get()));
224 231
225 delegate->WaitForResponse(); 232 delegate->WaitForResponse();
226 233
227 // When we timeout, we still call the Delegate callback but we pass in empty 234 // When we timeout, we still call the Delegate callback but we pass in empty
228 // values. 235 // values.
229 EXPECT_TRUE(delegate->completed()); 236 EXPECT_TRUE(delegate->completed());
230 EXPECT_TRUE(delegate->response().isNull()); 237 EXPECT_TRUE(delegate->response().isNull());
231 EXPECT_EQ(delegate->data(), std::string()); 238 EXPECT_EQ(delegate->data(), std::string());
232 EXPECT_TRUE(delegate->time_elapsed_ms() < kMaxWaitTimeMs); 239 EXPECT_TRUE(delegate->time_elapsed_ms() < kMaxWaitTimeMs);
233 } 240 }
234 241
235 } // namespace 242 } // namespace
OLDNEW
« no previous file with comments | « webkit/glue/mimetype_unittest.cc ('k') | webkit/glue/unittest_test_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698