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

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

Issue 2836863002: [Offline pages] Removing active_request_ from request coordinator (Closed)
Patch Set: Addressing code review feedback and fixing app status change bug 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/background_loader_offliner.h" 5 #include "chrome/browser/android/offline_pages/background_loader_offliner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "base/test/scoped_feature_list.h" 10 #include "base/test/scoped_feature_list.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 void CompleteLoading() { 157 void CompleteLoading() {
158 offliner()->DocumentOnLoadCompletedInMainFrame(); 158 offliner()->DocumentOnLoadCompletedInMainFrame();
159 PumpLoop(); 159 PumpLoop();
160 } 160 }
161 161
162 private: 162 private:
163 void OnCompletion(const SavePageRequest& request, 163 void OnCompletion(const SavePageRequest& request,
164 Offliner::RequestStatus status); 164 Offliner::RequestStatus status);
165 void OnProgress(const SavePageRequest& request, int64_t bytes); 165 void OnProgress(const SavePageRequest& request, int64_t bytes);
166 void OnCancel(int64_t offline_id); 166 void OnCancel(const SavePageRequest& request);
167 content::TestBrowserThreadBundle thread_bundle_; 167 content::TestBrowserThreadBundle thread_bundle_;
168 TestingProfile profile_; 168 TestingProfile profile_;
169 std::unique_ptr<OfflinerPolicy> policy_; 169 std::unique_ptr<OfflinerPolicy> policy_;
170 std::unique_ptr<TestBackgroundLoaderOffliner> offliner_; 170 std::unique_ptr<TestBackgroundLoaderOffliner> offliner_;
171 MockOfflinePageModel* model_; 171 MockOfflinePageModel* model_;
172 bool completion_callback_called_; 172 bool completion_callback_called_;
173 bool cancel_callback_called_; 173 bool cancel_callback_called_;
174 int64_t progress_; 174 int64_t progress_;
175 Offliner::RequestStatus request_status_; 175 Offliner::RequestStatus request_status_;
176 base::HistogramTester histogram_tester_; 176 base::HistogramTester histogram_tester_;
(...skipping 24 matching lines...) Expand all
201 DCHECK(!completion_callback_called_); // Expect 1 callback per request. 201 DCHECK(!completion_callback_called_); // Expect 1 callback per request.
202 completion_callback_called_ = true; 202 completion_callback_called_ = true;
203 request_status_ = status; 203 request_status_ = status;
204 } 204 }
205 205
206 void BackgroundLoaderOfflinerTest::OnProgress(const SavePageRequest& request, 206 void BackgroundLoaderOfflinerTest::OnProgress(const SavePageRequest& request,
207 int64_t bytes) { 207 int64_t bytes) {
208 progress_ = bytes; 208 progress_ = bytes;
209 } 209 }
210 210
211 void BackgroundLoaderOfflinerTest::OnCancel(int64_t offline_id) { 211 void BackgroundLoaderOfflinerTest::OnCancel(const SavePageRequest& request) {
212 DCHECK(!cancel_callback_called_); 212 DCHECK(!cancel_callback_called_);
213 cancel_callback_called_ = true; 213 cancel_callback_called_ = true;
214 } 214 }
215 215
216 TEST_F(BackgroundLoaderOfflinerTest, 216 TEST_F(BackgroundLoaderOfflinerTest,
217 LoadAndSaveBlockThirdPartyCookiesForCustomTabs) { 217 LoadAndSaveBlockThirdPartyCookiesForCustomTabs) {
218 base::Time creation_time = base::Time::Now(); 218 base::Time creation_time = base::Time::Now();
219 ClientId custom_tabs_client_id("custom_tabs", "88"); 219 ClientId custom_tabs_client_id("custom_tabs", "88");
220 SavePageRequest request(kRequestId, kHttpUrl, custom_tabs_client_id, 220 SavePageRequest request(kRequestId, kHttpUrl, custom_tabs_client_id,
221 creation_time, kUserRequested); 221 creation_time, kUserRequested);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 EXPECT_TRUE(completion_callback_called()); 488 EXPECT_TRUE(completion_callback_called());
489 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); 489 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status());
490 EXPECT_FALSE(offliner()->is_loading()); 490 EXPECT_FALSE(offliner()->is_loading());
491 EXPECT_FALSE(SaveInProgress()); 491 EXPECT_FALSE(SaveInProgress());
492 } 492 }
493 493
494 TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithLowBarStartedTriesMet) { 494 TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithLowBarStartedTriesMet) {
495 base::Time creation_time = base::Time::Now(); 495 base::Time creation_time = base::Time::Now();
496 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 496 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
497 kUserRequested); 497 kUserRequested);
498 request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1);
498 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 499 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
499 progress_callback())); 500 progress_callback()));
500 request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1); 501 // Guarantees low bar for saving is met.
501 // Sets lowbar.
502 offliner()->DocumentAvailableInMainFrame(); 502 offliner()->DocumentAvailableInMainFrame();
503 // Timeout 503 // Timeout
504 EXPECT_TRUE(offliner()->HandleTimeout(request)); 504 EXPECT_TRUE(offliner()->HandleTimeout(kRequestId));
505 EXPECT_TRUE(SaveInProgress()); 505 EXPECT_TRUE(SaveInProgress());
506 model()->CompleteSavingAsSuccess(); 506 model()->CompleteSavingAsSuccess();
507 PumpLoop(); 507 PumpLoop();
508 EXPECT_EQ(Offliner::RequestStatus::SAVED_ON_LAST_RETRY, request_status()); 508 EXPECT_EQ(Offliner::RequestStatus::SAVED_ON_LAST_RETRY, request_status());
509 } 509 }
510 510
511 TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithLowBarCompletedTriesMet) { 511 TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithLowBarCompletedTriesMet) {
512 base::Time creation_time = base::Time::Now(); 512 base::Time creation_time = base::Time::Now();
513 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 513 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
514 kUserRequested); 514 kUserRequested);
515 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1);
515 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 516 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
516 progress_callback())); 517 progress_callback()));
517 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1); 518 // Guarantees low bar for saving is met.
518 // Sets lowbar.
519 offliner()->DocumentAvailableInMainFrame(); 519 offliner()->DocumentAvailableInMainFrame();
520 // Timeout 520 // Timeout
521 EXPECT_TRUE(offliner()->HandleTimeout(request)); 521 EXPECT_TRUE(offliner()->HandleTimeout(kRequestId));
522 EXPECT_TRUE(SaveInProgress()); 522 EXPECT_TRUE(SaveInProgress());
523 model()->CompleteSavingAsSuccess(); 523 model()->CompleteSavingAsSuccess();
524 PumpLoop(); 524 PumpLoop();
525 EXPECT_EQ(Offliner::RequestStatus::SAVED_ON_LAST_RETRY, request_status()); 525 EXPECT_EQ(Offliner::RequestStatus::SAVED_ON_LAST_RETRY, request_status());
526 } 526 }
527 527
528 TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithNoLowBarStartedTriesMet) { 528 TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithNoLowBarStartedTriesMet) {
529 base::Time creation_time = base::Time::Now(); 529 base::Time creation_time = base::Time::Now();
530 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 530 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
531 kUserRequested); 531 kUserRequested);
532 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 532 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
533 progress_callback())); 533 progress_callback()));
534 request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1); 534 request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1);
535 // Timeout 535 // Timeout
536 EXPECT_FALSE(offliner()->HandleTimeout(request)); 536 EXPECT_FALSE(offliner()->HandleTimeout(kRequestId));
537 EXPECT_FALSE(SaveInProgress()); 537 EXPECT_FALSE(SaveInProgress());
538 } 538 }
539 539
540 TEST_F(BackgroundLoaderOfflinerTest, 540 TEST_F(BackgroundLoaderOfflinerTest,
541 HandleTimeoutWithNoLowBarCompletedTriesMet) { 541 HandleTimeoutWithNoLowBarCompletedTriesMet) {
542 base::Time creation_time = base::Time::Now(); 542 base::Time creation_time = base::Time::Now();
543 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 543 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
544 kUserRequested); 544 kUserRequested);
545 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 545 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
546 progress_callback())); 546 progress_callback()));
547 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1); 547 request.set_completed_attempt_count(policy()->GetMaxCompletedTries() - 1);
548 // Timeout 548 // Timeout
549 EXPECT_FALSE(offliner()->HandleTimeout(request)); 549 EXPECT_FALSE(offliner()->HandleTimeout(kRequestId));
550 EXPECT_FALSE(SaveInProgress()); 550 EXPECT_FALSE(SaveInProgress());
551 } 551 }
552 552
553 TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithLowBarNoRetryLimit) { 553 TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithLowBarNoRetryLimit) {
554 base::Time creation_time = base::Time::Now(); 554 base::Time creation_time = base::Time::Now();
555 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 555 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
556 kUserRequested); 556 kUserRequested);
557 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 557 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
558 progress_callback())); 558 progress_callback()));
559 // Sets lowbar. 559 // Sets lowbar.
560 offliner()->DocumentAvailableInMainFrame(); 560 offliner()->DocumentAvailableInMainFrame();
561 // Timeout 561 // Timeout
562 EXPECT_FALSE(offliner()->HandleTimeout(request)); 562 EXPECT_FALSE(offliner()->HandleTimeout(kRequestId));
563 EXPECT_FALSE(SaveInProgress()); 563 EXPECT_FALSE(SaveInProgress());
564 } 564 }
565 565
566 TEST_F(BackgroundLoaderOfflinerTest, SignalCollectionDisabled) { 566 TEST_F(BackgroundLoaderOfflinerTest, SignalCollectionDisabled) {
567 // Ensure feature flag for Signal collection is off, 567 // Ensure feature flag for Signal collection is off,
568 EXPECT_FALSE(offline_pages::IsOfflinePagesLoadSignalCollectingEnabled()); 568 EXPECT_FALSE(offline_pages::IsOfflinePagesLoadSignalCollectingEnabled());
569 569
570 base::Time creation_time = base::Time::Now(); 570 base::Time creation_time = base::Time::Now();
571 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 571 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
572 kUserRequested); 572 kUserRequested);
(...skipping 25 matching lines...) Expand all
598 CompleteLoading(); 598 CompleteLoading();
599 PumpLoop(); 599 PumpLoop();
600 600
601 // One extra part should be added if the flag is on. 601 // One extra part should be added if the flag is on.
602 content::MHTMLExtraParts* extra_parts = 602 content::MHTMLExtraParts* extra_parts =
603 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); 603 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents());
604 EXPECT_EQ(extra_parts->size(), 1); 604 EXPECT_EQ(extra_parts->size(), 1);
605 } 605 }
606 606
607 } // namespace offline_pages 607 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698