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

Unified Diff: chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc

Issue 2818783002: [Offline pages]: Implement background loader to save on last retry, and record last retry success U… (Closed)
Patch Set: request coordinator update 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc
diff --git a/chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc b/chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc
index d9078c44a7ba5dcf554c2d39ba8ee7d5c9fbac0f..f98b4c334136af964a1e8aafb9123db7c7a2084f 100644
--- a/chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc
+++ b/chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc
@@ -16,6 +16,7 @@
#include "components/content_settings/core/common/pref_names.h"
#include "components/offline_pages/content/background_loader/background_loader_contents_stub.h"
#include "components/offline_pages/core/background/offliner.h"
+#include "components/offline_pages/core/background/offliner_policy.h"
#include "components/offline_pages/core/background/save_page_request.h"
#include "components/offline_pages/core/stub_offline_page_model.h"
#include "components/prefs/pref_service.h"
@@ -146,6 +147,7 @@ class BackgroundLoaderOfflinerTest : public testing::Test {
MockOfflinePageModel* model() const { return model_; }
const base::HistogramTester& histograms() const { return histogram_tester_; }
int64_t progress() { return progress_; }
+ OfflinerPolicy* policy() const { return policy_.get(); }
void PumpLoop() { base::RunLoop().RunUntilIdle(); }
@@ -161,6 +163,7 @@ class BackgroundLoaderOfflinerTest : public testing::Test {
void OnCancel(int64_t offline_id);
content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
+ std::unique_ptr<OfflinerPolicy> policy_;
std::unique_ptr<TestBackgroundLoaderOffliner> offliner_;
MockOfflinePageModel* model_;
bool completion_callback_called_;
@@ -183,7 +186,9 @@ BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {}
void BackgroundLoaderOfflinerTest::SetUp() {
model_ = new MockOfflinePageModel();
- offliner_.reset(new TestBackgroundLoaderOffliner(profile(), nullptr, model_));
+ policy_.reset(new OfflinerPolicy());
+ offliner_.reset(
+ new TestBackgroundLoaderOffliner(profile(), policy_.get(), model_));
offliner_->SetPageDelayForTest(0L);
}
@@ -483,4 +488,44 @@ TEST_F(BackgroundLoaderOfflinerTest, OnlySavesOnceOnMultipleLoads) {
EXPECT_FALSE(SaveInProgress());
}
+TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithLowBarStartedTriesMet) {
Pete Williamson 2017/04/13 22:57:15 Should we have a test where we get a last timeout,
chili 2017/04/15 00:34:59 That is the situation in HandleTimeoutWithStartedT
+ base::Time creation_time = base::Time::Now();
+ SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
+ kUserRequested);
+ EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
+ progress_callback()));
+ request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1);
+ // Sets lowbar.
+ offliner()->DocumentAvailableInMainFrame();
+ // Timeout
+ EXPECT_TRUE(offliner()->HandleTimeout(request));
+ EXPECT_TRUE(SaveInProgress());
+ model()->CompleteSavingAsSuccess();
+ PumpLoop();
+ EXPECT_EQ(Offliner::RequestStatus::SAVED_ON_LAST_RETRY, request_status());
+}
+
+TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithStartedTriesMet) {
Pete Williamson 2017/04/13 22:57:15 Should we test both started and finished attempt c
romax 2017/04/13 23:17:14 I think the test is missing for the prerendering_o
chili 2017/04/15 00:34:59 Done.
+ base::Time creation_time = base::Time::Now();
+ SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
+ kUserRequested);
+ EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
+ progress_callback()));
+ request.set_started_attempt_count(policy()->GetMaxStartedTries() - 1);
+ // Timeout
+ EXPECT_FALSE(offliner()->HandleTimeout(request));
+ EXPECT_FALSE(SaveInProgress());
+}
+
+TEST_F(BackgroundLoaderOfflinerTest, HandleTimeoutWithLowBar) {
Pete Williamson 2017/04/13 22:57:15 Nit - this test name might be better as HandleTim
+ base::Time creation_time = base::Time::Now();
+ SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
+ kUserRequested);
+ EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
+ progress_callback()));
+ // Timeout
+ EXPECT_FALSE(offliner()->HandleTimeout(request));
+ EXPECT_FALSE(SaveInProgress());
+}
+
} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698