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

Side by Side Diff: chrome/browser/captive_portal/captive_portal_browsertest.cc

Issue 10855209: Refactoring: ProtocolHandler::MaybeCreateJob takes NetworkDelegate as argument (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest merge Created 8 years, 3 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
OLDNEW
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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 private: 128 private:
129 friend class URLRequestMockCaptivePortalJobFactory; 129 friend class URLRequestMockCaptivePortalJobFactory;
130 130
131 // Operation to perform on jobs when removing them from |job_list_|. 131 // Operation to perform on jobs when removing them from |job_list_|.
132 enum EndJobOperation { 132 enum EndJobOperation {
133 FAIL_JOBS, 133 FAIL_JOBS,
134 ABANDON_JOBS, 134 ABANDON_JOBS,
135 }; 135 };
136 136
137 explicit URLRequestTimeoutOnDemandJob(net::URLRequest* request); 137 URLRequestTimeoutOnDemandJob(net::URLRequest* request,
138 net::NetworkDelegate* network_delegate);
138 virtual ~URLRequestTimeoutOnDemandJob(); 139 virtual ~URLRequestTimeoutOnDemandJob();
139 140
140 // Attempts to removes |this| from |jobs_|. Returns true if it was removed 141 // Attempts to removes |this| from |jobs_|. Returns true if it was removed
141 // from the list. 142 // from the list.
142 bool RemoveFromList(); 143 bool RemoveFromList();
143 144
144 static void WaitForJobsOnIOThread(int num_jobs); 145 static void WaitForJobsOnIOThread(int num_jobs);
145 static void FailOrAbandonJobsOnIOThread( 146 static void FailOrAbandonJobsOnIOThread(
146 int expected_num_jobs, 147 int expected_num_jobs,
147 EndJobOperation end_job_operation); 148 EndJobOperation end_job_operation);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // static 220 // static
220 void URLRequestTimeoutOnDemandJob::AbandonJobs(int expected_num_jobs) { 221 void URLRequestTimeoutOnDemandJob::AbandonJobs(int expected_num_jobs) {
221 content::BrowserThread::PostTask( 222 content::BrowserThread::PostTask(
222 content::BrowserThread::IO, FROM_HERE, 223 content::BrowserThread::IO, FROM_HERE,
223 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, 224 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread,
224 expected_num_jobs, 225 expected_num_jobs,
225 ABANDON_JOBS)); 226 ABANDON_JOBS));
226 } 227 }
227 228
228 URLRequestTimeoutOnDemandJob::URLRequestTimeoutOnDemandJob( 229 URLRequestTimeoutOnDemandJob::URLRequestTimeoutOnDemandJob(
229 net::URLRequest* request) 230 net::URLRequest* request, net::NetworkDelegate* network_delegate)
230 : net::URLRequestJob(request, request->context()->network_delegate()), 231 : net::URLRequestJob(request, network_delegate),
231 next_job_(NULL) { 232 next_job_(NULL) {
232 } 233 }
233 234
234 URLRequestTimeoutOnDemandJob::~URLRequestTimeoutOnDemandJob() { 235 URLRequestTimeoutOnDemandJob::~URLRequestTimeoutOnDemandJob() {
235 // All hanging jobs should have failed or been abandoned before being 236 // All hanging jobs should have failed or been abandoned before being
236 // destroyed. 237 // destroyed.
237 EXPECT_FALSE(RemoveFromList()); 238 EXPECT_FALSE(RemoveFromList());
238 } 239 }
239 240
240 bool URLRequestTimeoutOnDemandJob::RemoveFromList() { 241 bool URLRequestTimeoutOnDemandJob::RemoveFromList() {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // These do all the work of the corresponding public functions, with the only 337 // These do all the work of the corresponding public functions, with the only
337 // difference being that they must be called on the IO thread. 338 // difference being that they must be called on the IO thread.
338 static void AddUrlHandlersOnIOThread(); 339 static void AddUrlHandlersOnIOThread();
339 static void SetBehindCaptivePortalOnIOThread(bool behind_captive_portal); 340 static void SetBehindCaptivePortalOnIOThread(bool behind_captive_portal);
340 341
341 // Returns a URLRequestJob that reflects the current captive portal state 342 // Returns a URLRequestJob that reflects the current captive portal state
342 // for the URLs: kMockCaptivePortalTestUrl, kMockHttpsUrl, and 343 // for the URLs: kMockCaptivePortalTestUrl, kMockHttpsUrl, and
343 // kMockHttpsQuickTimeoutUrl. See documentation of individual URLs for 344 // kMockHttpsQuickTimeoutUrl. See documentation of individual URLs for
344 // actual behavior. 345 // actual behavior.
345 static net::URLRequestJob* Factory(net::URLRequest* request, 346 static net::URLRequestJob* Factory(net::URLRequest* request,
347 net::NetworkDelegate* network_delegate,
346 const std::string& scheme); 348 const std::string& scheme);
347 349
348 static bool behind_captive_portal_; 350 static bool behind_captive_portal_;
349 351
350 DISALLOW_IMPLICIT_CONSTRUCTORS(URLRequestMockCaptivePortalJobFactory); 352 DISALLOW_IMPLICIT_CONSTRUCTORS(URLRequestMockCaptivePortalJobFactory);
351 }; 353 };
352 354
353 bool URLRequestMockCaptivePortalJobFactory::behind_captive_portal_ = true; 355 bool URLRequestMockCaptivePortalJobFactory::behind_captive_portal_ = true;
354 356
355 // static 357 // static
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // static 393 // static
392 void URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortalOnIOThread( 394 void URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortalOnIOThread(
393 bool behind_captive_portal) { 395 bool behind_captive_portal) {
394 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 396 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
395 behind_captive_portal_ = behind_captive_portal; 397 behind_captive_portal_ = behind_captive_portal;
396 } 398 }
397 399
398 // static 400 // static
399 net::URLRequestJob* URLRequestMockCaptivePortalJobFactory::Factory( 401 net::URLRequestJob* URLRequestMockCaptivePortalJobFactory::Factory(
400 net::URLRequest* request, 402 net::URLRequest* request,
403 net::NetworkDelegate* network_delegate,
401 const std::string& scheme) { 404 const std::string& scheme) {
402 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 405 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
403 406
404 // The PathService is threadsafe. 407 // The PathService is threadsafe.
405 FilePath root_http; 408 FilePath root_http;
406 PathService::Get(chrome::DIR_TEST_DATA, &root_http); 409 PathService::Get(chrome::DIR_TEST_DATA, &root_http);
407 410
408 if (request->url() == GURL(kMockHttpsUrl) || 411 if (request->url() == GURL(kMockHttpsUrl) ||
409 request->url() == GURL(kMockHttpsUrl2)) { 412 request->url() == GURL(kMockHttpsUrl2)) {
410 if (behind_captive_portal_) 413 if (behind_captive_portal_)
411 return new URLRequestTimeoutOnDemandJob(request); 414 return new URLRequestTimeoutOnDemandJob(request, network_delegate);
412 // Once logged in to the portal, HTTPS requests return the page that was 415 // Once logged in to the portal, HTTPS requests return the page that was
413 // actually requested. 416 // actually requested.
414 return new URLRequestMockHTTPJob( 417 return new URLRequestMockHTTPJob(
415 request, 418 request,
419 network_delegate,
416 root_http.Append(FILE_PATH_LITERAL("title2.html"))); 420 root_http.Append(FILE_PATH_LITERAL("title2.html")));
417 } else if (request->url() == GURL(kMockHttpsQuickTimeoutUrl)) { 421 } else if (request->url() == GURL(kMockHttpsQuickTimeoutUrl)) {
418 if (behind_captive_portal_) 422 if (behind_captive_portal_)
419 return new URLRequestFailedJob(request, net::ERR_CONNECTION_TIMED_OUT); 423 return new URLRequestFailedJob(
424 request, network_delegate, net::ERR_CONNECTION_TIMED_OUT);
420 // Once logged in to the portal, HTTPS requests return the page that was 425 // Once logged in to the portal, HTTPS requests return the page that was
421 // actually requested. 426 // actually requested.
422 return new URLRequestMockHTTPJob( 427 return new URLRequestMockHTTPJob(
423 request, 428 request,
429 network_delegate,
424 root_http.Append(FILE_PATH_LITERAL("title2.html"))); 430 root_http.Append(FILE_PATH_LITERAL("title2.html")));
425 } else { 431 } else {
426 // The URL should be the captive portal test URL. 432 // The URL should be the captive portal test URL.
427 EXPECT_EQ(GURL(kMockCaptivePortalTestUrl), request->url()); 433 EXPECT_EQ(GURL(kMockCaptivePortalTestUrl), request->url());
428 434
429 if (behind_captive_portal_) { 435 if (behind_captive_portal_) {
430 // Prior to logging in to the portal, HTTP requests go to the login page. 436 // Prior to logging in to the portal, HTTP requests go to the login page.
431 return new URLRequestMockHTTPJob( 437 return new URLRequestMockHTTPJob(
432 request, 438 request,
439 network_delegate,
433 root_http.Append(FILE_PATH_LITERAL("captive_portal/login.html"))); 440 root_http.Append(FILE_PATH_LITERAL("captive_portal/login.html")));
434 } 441 }
435 442
436 // After logging in to the portal, the test URL returns a 204 response. 443 // After logging in to the portal, the test URL returns a 204 response.
437 return new URLRequestMockHTTPJob( 444 return new URLRequestMockHTTPJob(
438 request, 445 request,
446 network_delegate,
439 root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html"))); 447 root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html")));
440 } 448 }
441 } 449 }
442 450
443 // Creates a server-side redirect for use with the TestServer. 451 // Creates a server-side redirect for use with the TestServer.
444 std::string CreateServerRedirect(const std::string& dest_url) { 452 std::string CreateServerRedirect(const std::string& dest_url) {
445 const char* const kServerRedirectBase = "server-redirect?"; 453 const char* const kServerRedirectBase = "server-redirect?";
446 return kServerRedirectBase + dest_url; 454 return kServerRedirectBase + dest_url;
447 } 455 }
448 456
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 base::Bind(&AddHstsHost, 2077 base::Bind(&AddHstsHost,
2070 make_scoped_refptr(browser()->profile()->GetRequestContext()), 2078 make_scoped_refptr(browser()->profile()->GetRequestContext()),
2071 http_timeout_url.host())); 2079 http_timeout_url.host()));
2072 2080
2073 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url); 2081 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url);
2074 Login(browser(), 1, 0); 2082 Login(browser(), 1, 0);
2075 FailLoadsAfterLogin(browser(), 1); 2083 FailLoadsAfterLogin(browser(), 1);
2076 } 2084 }
2077 2085
2078 } // namespace captive_portal 2086 } // namespace captive_portal
OLDNEW
« no previous file with comments | « chrome/browser/automation/url_request_automation_job.cc ('k') | chrome/browser/chromeos/gdata/gdata_protocol_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698