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 "chrome/browser/prerender/prerender_test_utils.h" | 5 #include "chrome/browser/prerender/prerender_test_utils.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" | 9 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" |
10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 : waiter_(waiter) {} | 350 : waiter_(waiter) {} |
351 | 351 |
352 DestructionWaiter::DestructionMarker::~DestructionMarker() {} | 352 DestructionWaiter::DestructionMarker::~DestructionMarker() {} |
353 | 353 |
354 void DestructionWaiter::DestructionMarker::OnPrerenderStop( | 354 void DestructionWaiter::DestructionMarker::OnPrerenderStop( |
355 PrerenderContents* contents) { | 355 PrerenderContents* contents) { |
356 waiter_->MarkDestruction(contents->final_status()); | 356 waiter_->MarkDestruction(contents->final_status()); |
357 } | 357 } |
358 | 358 |
359 TestPrerender::TestPrerender() | 359 TestPrerender::TestPrerender() |
360 : contents_(nullptr), number_of_loads_(0), expected_number_of_loads_(0) {} | 360 : contents_(nullptr), |
| 361 number_of_loads_(0), |
| 362 expected_number_of_loads_(0), |
| 363 started_(false), |
| 364 stopped_(false) {} |
361 | 365 |
362 TestPrerender::~TestPrerender() { | 366 TestPrerender::~TestPrerender() { |
363 if (contents_) | 367 if (contents_) |
364 contents_->RemoveObserver(this); | 368 contents_->RemoveObserver(this); |
365 } | 369 } |
366 | 370 |
| 371 void TestPrerender::WaitForCreate() { |
| 372 if (contents_) |
| 373 return; |
| 374 create_loop_.Run(); |
| 375 } |
| 376 |
| 377 void TestPrerender::WaitForStart() { |
| 378 if (started_) |
| 379 return; |
| 380 start_loop_.Run(); |
| 381 } |
| 382 |
| 383 void TestPrerender::WaitForStop() { |
| 384 if (stopped_) |
| 385 return; |
| 386 stop_loop_.Run(); |
| 387 } |
| 388 |
367 void TestPrerender::WaitForLoads(int expected_number_of_loads) { | 389 void TestPrerender::WaitForLoads(int expected_number_of_loads) { |
368 DCHECK(!load_waiter_); | 390 DCHECK(!load_waiter_); |
369 DCHECK(!expected_number_of_loads_); | 391 DCHECK(!expected_number_of_loads_); |
370 if (number_of_loads_ < expected_number_of_loads) { | 392 if (number_of_loads_ < expected_number_of_loads) { |
371 load_waiter_.reset(new base::RunLoop); | 393 load_waiter_.reset(new base::RunLoop); |
372 expected_number_of_loads_ = expected_number_of_loads; | 394 expected_number_of_loads_ = expected_number_of_loads; |
373 load_waiter_->Run(); | 395 load_waiter_->Run(); |
374 load_waiter_.reset(); | 396 load_waiter_.reset(); |
375 expected_number_of_loads_ = 0; | 397 expected_number_of_loads_ = 0; |
376 } | 398 } |
377 EXPECT_LE(expected_number_of_loads, number_of_loads_); | 399 EXPECT_LE(expected_number_of_loads, number_of_loads_); |
378 } | 400 } |
379 | 401 |
380 void TestPrerender::OnPrerenderCreated(TestPrerenderContents* contents) { | 402 void TestPrerender::OnPrerenderCreated(TestPrerenderContents* contents) { |
381 DCHECK(!contents_); | 403 DCHECK(!contents_); |
382 contents_ = contents; | 404 contents_ = contents; |
383 contents_->AddObserver(this); | 405 contents_->AddObserver(this); |
384 create_loop_.Quit(); | 406 create_loop_.Quit(); |
385 } | 407 } |
386 | 408 |
387 void TestPrerender::OnPrerenderStart(PrerenderContents* contents) { | 409 void TestPrerender::OnPrerenderStart(PrerenderContents* contents) { |
| 410 started_ = true; |
388 start_loop_.Quit(); | 411 start_loop_.Quit(); |
389 } | 412 } |
390 | 413 |
391 void TestPrerender::OnPrerenderStopLoading(PrerenderContents* contents) { | 414 void TestPrerender::OnPrerenderStopLoading(PrerenderContents* contents) { |
392 number_of_loads_++; | 415 number_of_loads_++; |
393 if (load_waiter_ && number_of_loads_ >= expected_number_of_loads_) | 416 if (load_waiter_ && number_of_loads_ >= expected_number_of_loads_) |
394 load_waiter_->Quit(); | 417 load_waiter_->Quit(); |
395 } | 418 } |
396 | 419 |
397 void TestPrerender::OnPrerenderStop(PrerenderContents* contents) { | 420 void TestPrerender::OnPrerenderStop(PrerenderContents* contents) { |
398 DCHECK(contents_); | 421 DCHECK(contents_); |
399 contents_ = nullptr; | 422 contents_ = nullptr; |
| 423 stopped_ = true; |
400 stop_loop_.Quit(); | 424 stop_loop_.Quit(); |
401 // If there is a WaitForLoads call and it has yet to see the expected number | 425 // If there is a WaitForLoads call and it has yet to see the expected number |
402 // of loads, stop the loop so the test fails instead of timing out. | 426 // of loads, stop the loop so the test fails instead of timing out. |
403 if (load_waiter_) | 427 if (load_waiter_) |
404 load_waiter_->Quit(); | 428 load_waiter_->Quit(); |
405 } | 429 } |
406 | 430 |
407 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} | 431 TestPrerenderContentsFactory::TestPrerenderContentsFactory() {} |
408 | 432 |
409 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { | 433 TestPrerenderContentsFactory::~TestPrerenderContentsFactory() { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { | 671 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file) { |
648 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 672 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
649 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 673 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
650 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( | 674 url, net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile( |
651 file, content::BrowserThread::GetBlockingPool())); | 675 file, content::BrowserThread::GetBlockingPool())); |
652 } | 676 } |
653 | 677 |
654 } // namespace test_utils | 678 } // namespace test_utils |
655 | 679 |
656 } // namespace prerender | 680 } // namespace prerender |
OLD | NEW |