| 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/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 // A BackgroundLoader that we can run tests on. | 72 // A BackgroundLoader that we can run tests on. |
| 73 // Overrides the ResetState so we don't actually try to create any web contents. | 73 // Overrides the ResetState so we don't actually try to create any web contents. |
| 74 // This is a temporary solution to test core BackgroundLoaderOffliner | 74 // This is a temporary solution to test core BackgroundLoaderOffliner |
| 75 // functionality until we straighten out assumptions made by RequestCoordinator | 75 // functionality until we straighten out assumptions made by RequestCoordinator |
| 76 // so that the ResetState method is no longer needed. | 76 // so that the ResetState method is no longer needed. |
| 77 class TestBackgroundLoaderOffliner : public BackgroundLoaderOffliner { | 77 class TestBackgroundLoaderOffliner : public BackgroundLoaderOffliner { |
| 78 public: | 78 public: |
| 79 explicit TestBackgroundLoaderOffliner( | 79 explicit TestBackgroundLoaderOffliner( |
| 80 content::BrowserContext* browser_context, | 80 content::BrowserContext* browser_context, |
| 81 const OfflinerPolicy* policy, |
| 81 OfflinePageModel* offline_page_model); | 82 OfflinePageModel* offline_page_model); |
| 82 ~TestBackgroundLoaderOffliner() override; | 83 ~TestBackgroundLoaderOffliner() override; |
| 83 content::WebContentsTester* web_contents() { | 84 content::WebContentsTester* web_contents() { |
| 84 return content::WebContentsTester::For(stub_->web_contents()); | 85 return content::WebContentsTester::For(stub_->web_contents()); |
| 85 } | 86 } |
| 86 | 87 |
| 87 bool is_loading() { return stub_->is_loading(); } | 88 bool is_loading() { return stub_->is_loading(); } |
| 88 | 89 |
| 89 protected: | 90 protected: |
| 90 void ResetState() override; | 91 void ResetState() override; |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 background_loader::BackgroundLoaderContentsStub* stub_; | 94 background_loader::BackgroundLoaderContentsStub* stub_; |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 TestBackgroundLoaderOffliner::TestBackgroundLoaderOffliner( | 97 TestBackgroundLoaderOffliner::TestBackgroundLoaderOffliner( |
| 97 content::BrowserContext* browser_context, | 98 content::BrowserContext* browser_context, |
| 99 const OfflinerPolicy* policy, |
| 98 OfflinePageModel* offline_page_model) | 100 OfflinePageModel* offline_page_model) |
| 99 : BackgroundLoaderOffliner(browser_context, offline_page_model) {} | 101 : BackgroundLoaderOffliner(browser_context, policy, offline_page_model) {} |
| 100 | 102 |
| 101 TestBackgroundLoaderOffliner::~TestBackgroundLoaderOffliner() {} | 103 TestBackgroundLoaderOffliner::~TestBackgroundLoaderOffliner() {} |
| 102 | 104 |
| 103 void TestBackgroundLoaderOffliner::ResetState() { | 105 void TestBackgroundLoaderOffliner::ResetState() { |
| 104 pending_request_.reset(); | 106 pending_request_.reset(); |
| 105 stub_ = new background_loader::BackgroundLoaderContentsStub(browser_context_); | 107 stub_ = new background_loader::BackgroundLoaderContentsStub(browser_context_); |
| 106 loader_.reset(stub_); | 108 loader_.reset(stub_); |
| 107 content::WebContentsObserver::Observe(stub_->web_contents()); | 109 content::WebContentsObserver::Observe(stub_->web_contents()); |
| 108 } | 110 } |
| 109 | 111 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 148 |
| 147 BackgroundLoaderOfflinerTest::BackgroundLoaderOfflinerTest() | 149 BackgroundLoaderOfflinerTest::BackgroundLoaderOfflinerTest() |
| 148 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 150 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 149 completion_callback_called_(false), | 151 completion_callback_called_(false), |
| 150 request_status_(Offliner::RequestStatus::UNKNOWN) {} | 152 request_status_(Offliner::RequestStatus::UNKNOWN) {} |
| 151 | 153 |
| 152 BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {} | 154 BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {} |
| 153 | 155 |
| 154 void BackgroundLoaderOfflinerTest::SetUp() { | 156 void BackgroundLoaderOfflinerTest::SetUp() { |
| 155 model_ = new MockOfflinePageModel(); | 157 model_ = new MockOfflinePageModel(); |
| 156 offliner_.reset(new TestBackgroundLoaderOffliner(profile(), model_)); | 158 offliner_.reset(new TestBackgroundLoaderOffliner(profile(), nullptr, model_)); |
| 157 } | 159 } |
| 158 | 160 |
| 159 void BackgroundLoaderOfflinerTest::OnCompletion( | 161 void BackgroundLoaderOfflinerTest::OnCompletion( |
| 160 const SavePageRequest& request, | 162 const SavePageRequest& request, |
| 161 Offliner::RequestStatus status) { | 163 Offliner::RequestStatus status) { |
| 162 DCHECK(!completion_callback_called_); // Expect 1 callback per request. | 164 DCHECK(!completion_callback_called_); // Expect 1 callback per request. |
| 163 completion_callback_called_ = true; | 165 completion_callback_called_ = true; |
| 164 request_status_ = status; | 166 request_status_ = status; |
| 165 } | 167 } |
| 166 | 168 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, | 285 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, |
| 284 kUserRequested); | 286 kUserRequested); |
| 285 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); | 287 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); |
| 286 offliner()->WebContentsDestroyed(); | 288 offliner()->WebContentsDestroyed(); |
| 287 | 289 |
| 288 EXPECT_TRUE(completion_callback_called()); | 290 EXPECT_TRUE(completion_callback_called()); |
| 289 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED, request_status()); | 291 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED, request_status()); |
| 290 } | 292 } |
| 291 | 293 |
| 292 } // namespace offline_pages | 294 } // namespace offline_pages |
| OLD | NEW |