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

Side by Side Diff: chrome/browser/android/offline_pages/prerendering_offliner_unittest.cc

Issue 2818783002: [Offline pages]: Implement background loader to save on last retry, and record last retry success U… (Closed)
Patch Set: Resolving code review comments Created 3 years, 8 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/offline_pages/prerendering_offliner.h" 5 #include "chrome/browser/android/offline_pages/prerendering_offliner.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 void StopLoading() override { 60 void StopLoading() override {
61 mock_loading_ = false; 61 mock_loading_ = false;
62 mock_loaded_ = false; 62 mock_loaded_ = false;
63 } 63 }
64 64
65 bool IsIdle() override { return !mock_loading_ && !mock_loaded_; } 65 bool IsIdle() override { return !mock_loading_ && !mock_loaded_; }
66 bool IsLoaded() override { return mock_loaded_; } 66 bool IsLoaded() override { return mock_loaded_; }
67 bool IsLowbarMet() override { return mock_is_lowbar_met_; } 67 bool IsLowbarMet() override { return mock_is_lowbar_met_; }
68 68
69 void StartSnapshot() override { start_snapshot_called_ = true; } 69 void StartSnapshot() override {
70 start_snapshot_called_ = true;
71 // Call start saving process.
72 web_contents_ = content::WebContentsTester::CreateTestWebContents(
73 new TestingProfile(), NULL);
74 base::ThreadTaskRunnerHandle::Get()->PostTask(
75 FROM_HERE, base::Bind(load_page_callback_,
76 Offliner::RequestStatus::LOADED, web_contents_));
77 }
70 78
71 void CompleteLoadingAsFailed() { 79 void CompleteLoadingAsFailed() {
72 DCHECK(mock_loading_); 80 DCHECK(mock_loading_);
73 mock_loading_ = false; 81 mock_loading_ = false;
74 mock_loaded_ = false; 82 mock_loaded_ = false;
75 base::ThreadTaskRunnerHandle::Get()->PostTask( 83 base::ThreadTaskRunnerHandle::Get()->PostTask(
76 FROM_HERE, 84 FROM_HERE,
77 base::Bind(load_page_callback_, Offliner::RequestStatus::LOADING_FAILED, 85 base::Bind(load_page_callback_, Offliner::RequestStatus::LOADING_FAILED,
78 nullptr /* web_contents */)); 86 nullptr /* web_contents */));
79 } 87 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 473
466 base::Time creation_time = base::Time::Now(); 474 base::Time creation_time = base::Time::Now();
467 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 475 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
468 kUserRequested); 476 kUserRequested);
469 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1); 477 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1);
470 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 478 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
471 progress_callback())); 479 progress_callback()));
472 loader()->set_is_lowbar_met(true); 480 loader()->set_is_lowbar_met(true);
473 EXPECT_TRUE(offliner()->HandleTimeout(request)); 481 EXPECT_TRUE(offliner()->HandleTimeout(request));
474 EXPECT_TRUE(loader()->start_snapshot_called()); 482 EXPECT_TRUE(loader()->start_snapshot_called());
483 PumpLoop();
484 // EXPECT_TRUE(SaveInProgress());
485 model()->CompleteSavingAsSuccess();
486 PumpLoop();
487 EXPECT_TRUE(completion_callback_called());
488 EXPECT_EQ(Offliner::RequestStatus::SAVED_ON_LAST_RETRY, request_status());
475 } 489 }
476 490
477 TEST_F(PrerenderingOfflinerTest, 491 TEST_F(PrerenderingOfflinerTest,
478 HandleTimeoutWithLowbarAndCompletedTriesMetLowEndDevice) { 492 HandleTimeoutWithLowbarAndCompletedTriesMetLowEndDevice) {
479 offliner()->SetLowEndDeviceForTesting(true); 493 offliner()->SetLowEndDeviceForTesting(true);
480 494
481 base::Time creation_time = base::Time::Now(); 495 base::Time creation_time = base::Time::Now();
482 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 496 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
483 kUserRequested); 497 kUserRequested);
484 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1); 498 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1);
(...skipping 12 matching lines...) Expand all
497 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 511 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
498 kUserRequested); 512 kUserRequested);
499 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1); 513 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1);
500 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 514 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
501 progress_callback())); 515 progress_callback()));
502 loader()->set_is_lowbar_met(false); 516 loader()->set_is_lowbar_met(false);
503 EXPECT_FALSE(offliner()->HandleTimeout(request)); 517 EXPECT_FALSE(offliner()->HandleTimeout(request));
504 EXPECT_FALSE(loader()->start_snapshot_called()); 518 EXPECT_FALSE(loader()->start_snapshot_called());
505 } 519 }
506 520
521 TEST_F(PrerenderingOfflinerTest, HandleTimeoutStartedTriesMetWithoutLowbarMet) {
522 offliner()->SetLowEndDeviceForTesting(false);
523
524 base::Time creation_time = base::Time::Now();
525 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
526 kUserRequested);
527 request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1);
528 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
529 progress_callback()));
530 loader()->set_is_lowbar_met(false);
531 EXPECT_FALSE(offliner()->HandleTimeout(request));
532 EXPECT_FALSE(loader()->start_snapshot_called());
533 }
534
507 TEST_F(PrerenderingOfflinerTest, HandleTimeoutWithLowbarAndStartedTriesMet) { 535 TEST_F(PrerenderingOfflinerTest, HandleTimeoutWithLowbarAndStartedTriesMet) {
508 offliner()->SetLowEndDeviceForTesting(false); 536 offliner()->SetLowEndDeviceForTesting(false);
509 537
510 base::Time creation_time = base::Time::Now(); 538 base::Time creation_time = base::Time::Now();
511 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 539 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
512 kUserRequested); 540 kUserRequested);
513 request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1); 541 request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1);
514 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 542 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
515 progress_callback())); 543 progress_callback()));
516 loader()->set_is_lowbar_met(true); 544 loader()->set_is_lowbar_met(true);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 PumpLoop(); 606 PumpLoop();
579 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); 607 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status());
580 608
581 // One extra part should be added if the flag is on. 609 // One extra part should be added if the flag is on.
582 content::MHTMLExtraParts* extra_parts = 610 content::MHTMLExtraParts* extra_parts =
583 content::MHTMLExtraParts::FromWebContents(loader()->web_contents()); 611 content::MHTMLExtraParts::FromWebContents(loader()->web_contents());
584 EXPECT_EQ(extra_parts->size(), 1); 612 EXPECT_EQ(extra_parts->size(), 1);
585 } 613 }
586 614
587 } // namespace offline_pages 615 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/prerendering_offliner.cc ('k') | components/offline_pages/core/background/offliner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698