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

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

Issue 2861583007: [Offline pages]: Move logic for whether to consider the DocumentAvailableInMainFrame signal to the … (Closed)
Patch Set: Created 3 years, 7 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_mock_time_message_loop_task_runner.h" 10 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 Offliner::RequestStatus request_status() { return request_status_; } 143 Offliner::RequestStatus request_status() { return request_status_; }
144 bool cancel_callback_called() { return cancel_callback_called_; } 144 bool cancel_callback_called() { return cancel_callback_called_; }
145 bool SaveInProgress() const { return model_->mock_saving(); } 145 bool SaveInProgress() const { return model_->mock_saving(); }
146 MockOfflinePageModel* model() const { return model_; } 146 MockOfflinePageModel* model() const { return model_; }
147 const base::HistogramTester& histograms() const { return histogram_tester_; } 147 const base::HistogramTester& histograms() const { return histogram_tester_; }
148 int64_t progress() { return progress_; } 148 int64_t progress() { return progress_; }
149 149
150 void PumpLoop() { base::RunLoop().RunUntilIdle(); } 150 void PumpLoop() { base::RunLoop().RunUntilIdle(); }
151 151
152 void CompleteLoading() { 152 void CompleteLoading() {
153 // Reset snapshot controller.
154 std::unique_ptr<SnapshotController> snapshot_controller(
155 new SnapshotController(base::ThreadTaskRunnerHandle::Get(),
156 offliner_.get(),
157 0L /* DelayAfterDocumentAvailable */,
158 0L /* DelayAfterDocumentOnLoad */,
159 false /* DocumentAvailableTriggersSnapshot */));
160 offliner_->SetSnapshotControllerForTest(std::move(snapshot_controller));
161 // Call complete loading.
153 offliner()->DocumentOnLoadCompletedInMainFrame(); 162 offliner()->DocumentOnLoadCompletedInMainFrame();
154 PumpLoop(); 163 PumpLoop();
155 } 164 }
156 165
157 private: 166 private:
158 void OnCompletion(const SavePageRequest& request, 167 void OnCompletion(const SavePageRequest& request,
159 Offliner::RequestStatus status); 168 Offliner::RequestStatus status);
160 void OnProgress(const SavePageRequest& request, int64_t bytes); 169 void OnProgress(const SavePageRequest& request, int64_t bytes);
161 void OnCancel(int64_t offline_id); 170 void OnCancel(int64_t offline_id);
162 content::TestBrowserThreadBundle thread_bundle_; 171 content::TestBrowserThreadBundle thread_bundle_;
(...skipping 14 matching lines...) Expand all
177 completion_callback_called_(false), 186 completion_callback_called_(false),
178 cancel_callback_called_(false), 187 cancel_callback_called_(false),
179 progress_(0LL), 188 progress_(0LL),
180 request_status_(Offliner::RequestStatus::UNKNOWN) {} 189 request_status_(Offliner::RequestStatus::UNKNOWN) {}
181 190
182 BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {} 191 BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {}
183 192
184 void BackgroundLoaderOfflinerTest::SetUp() { 193 void BackgroundLoaderOfflinerTest::SetUp() {
185 model_ = new MockOfflinePageModel(); 194 model_ = new MockOfflinePageModel();
186 offliner_.reset(new TestBackgroundLoaderOffliner(profile(), nullptr, model_)); 195 offliner_.reset(new TestBackgroundLoaderOffliner(profile(), nullptr, model_));
187 offliner_->SetPageDelayForTest(0L);
188 } 196 }
189 197
190 void BackgroundLoaderOfflinerTest::OnCompletion( 198 void BackgroundLoaderOfflinerTest::OnCompletion(
191 const SavePageRequest& request, 199 const SavePageRequest& request,
192 Offliner::RequestStatus status) { 200 Offliner::RequestStatus status) {
193 DCHECK(!completion_callback_called_); // Expect 1 callback per request. 201 DCHECK(!completion_callback_called_); // Expect 1 callback per request.
194 completion_callback_called_ = true; 202 completion_callback_called_ = true;
195 request_status_ = status; 203 request_status_ = status;
196 } 204 }
197 205
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 model()->CompleteSavingAsSuccess(); 485 model()->CompleteSavingAsSuccess();
478 PumpLoop(); 486 PumpLoop();
479 487
480 EXPECT_TRUE(completion_callback_called()); 488 EXPECT_TRUE(completion_callback_called());
481 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); 489 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status());
482 EXPECT_FALSE(offliner()->is_loading()); 490 EXPECT_FALSE(offliner()->is_loading());
483 EXPECT_FALSE(SaveInProgress()); 491 EXPECT_FALSE(SaveInProgress());
484 } 492 }
485 493
486 } // namespace offline_pages 494 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698