| OLD | NEW |
| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 bool SaveInProgress() const { return model_->mock_saving(); } | 165 bool SaveInProgress() const { return model_->mock_saving(); } |
| 166 bool DeleteCalled() const { return model_->mock_deleting(); } | 166 bool DeleteCalled() const { return model_->mock_deleting(); } |
| 167 MockOfflinePageModel* model() const { return model_; } | 167 MockOfflinePageModel* model() const { return model_; } |
| 168 const base::HistogramTester& histograms() const { return histogram_tester_; } | 168 const base::HistogramTester& histograms() const { return histogram_tester_; } |
| 169 int64_t progress() { return progress_; } | 169 int64_t progress() { return progress_; } |
| 170 OfflinerPolicy* policy() const { return policy_.get(); } | 170 OfflinerPolicy* policy() const { return policy_.get(); } |
| 171 | 171 |
| 172 void PumpLoop() { base::RunLoop().RunUntilIdle(); } | 172 void PumpLoop() { base::RunLoop().RunUntilIdle(); } |
| 173 | 173 |
| 174 void CompleteLoading() { | 174 void CompleteLoading() { |
| 175 // Reset snapshot controller. |
| 176 std::unique_ptr<SnapshotController> snapshot_controller( |
| 177 new SnapshotController(base::ThreadTaskRunnerHandle::Get(), |
| 178 offliner_.get(), |
| 179 0L /* DelayAfterDocumentAvailable */, |
| 180 0L /* DelayAfterDocumentOnLoad */, |
| 181 false /* DocumentAvailableTriggersSnapshot */)); |
| 182 offliner_->SetSnapshotControllerForTest(std::move(snapshot_controller)); |
| 183 // Call complete loading. |
| 175 offliner()->DocumentOnLoadCompletedInMainFrame(); | 184 offliner()->DocumentOnLoadCompletedInMainFrame(); |
| 176 PumpLoop(); | 185 PumpLoop(); |
| 177 } | 186 } |
| 178 | 187 |
| 179 private: | 188 private: |
| 180 void OnCompletion(const SavePageRequest& request, | 189 void OnCompletion(const SavePageRequest& request, |
| 181 Offliner::RequestStatus status); | 190 Offliner::RequestStatus status); |
| 182 void OnProgress(const SavePageRequest& request, int64_t bytes); | 191 void OnProgress(const SavePageRequest& request, int64_t bytes); |
| 183 void OnCancel(const SavePageRequest& request); | 192 void OnCancel(const SavePageRequest& request); |
| 184 content::TestBrowserThreadBundle thread_bundle_; | 193 content::TestBrowserThreadBundle thread_bundle_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 202 progress_(0LL), | 211 progress_(0LL), |
| 203 request_status_(Offliner::RequestStatus::UNKNOWN) {} | 212 request_status_(Offliner::RequestStatus::UNKNOWN) {} |
| 204 | 213 |
| 205 BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {} | 214 BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {} |
| 206 | 215 |
| 207 void BackgroundLoaderOfflinerTest::SetUp() { | 216 void BackgroundLoaderOfflinerTest::SetUp() { |
| 208 model_ = new MockOfflinePageModel(); | 217 model_ = new MockOfflinePageModel(); |
| 209 policy_.reset(new OfflinerPolicy()); | 218 policy_.reset(new OfflinerPolicy()); |
| 210 offliner_.reset( | 219 offliner_.reset( |
| 211 new TestBackgroundLoaderOffliner(profile(), policy_.get(), model_)); | 220 new TestBackgroundLoaderOffliner(profile(), policy_.get(), model_)); |
| 212 offliner_->SetPageDelayForTest(0L); | |
| 213 } | 221 } |
| 214 | 222 |
| 215 void BackgroundLoaderOfflinerTest::OnCompletion( | 223 void BackgroundLoaderOfflinerTest::OnCompletion( |
| 216 const SavePageRequest& request, | 224 const SavePageRequest& request, |
| 217 Offliner::RequestStatus status) { | 225 Offliner::RequestStatus status) { |
| 218 DCHECK(!completion_callback_called_); // Expect 1 callback per request. | 226 DCHECK(!completion_callback_called_); // Expect 1 callback per request. |
| 219 completion_callback_called_ = true; | 227 completion_callback_called_ = true; |
| 220 request_status_ = status; | 228 request_status_ = status; |
| 221 } | 229 } |
| 222 | 230 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 CompleteLoading(); | 642 CompleteLoading(); |
| 635 PumpLoop(); | 643 PumpLoop(); |
| 636 | 644 |
| 637 // One extra part should be added if the flag is on. | 645 // One extra part should be added if the flag is on. |
| 638 content::MHTMLExtraParts* extra_parts = | 646 content::MHTMLExtraParts* extra_parts = |
| 639 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); | 647 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); |
| 640 EXPECT_EQ(extra_parts->size(), 1); | 648 EXPECT_EQ(extra_parts->size(), 1); |
| 641 } | 649 } |
| 642 | 650 |
| 643 } // namespace offline_pages | 651 } // namespace offline_pages |
| OLD | NEW |