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, | |
82 OfflinePageModel* offline_page_model); | 81 OfflinePageModel* offline_page_model); |
83 ~TestBackgroundLoaderOffliner() override; | 82 ~TestBackgroundLoaderOffliner() override; |
84 content::WebContentsTester* web_contents() { | 83 content::WebContentsTester* web_contents() { |
85 return content::WebContentsTester::For(stub_->web_contents()); | 84 return content::WebContentsTester::For(stub_->web_contents()); |
86 } | 85 } |
87 | 86 |
88 bool is_loading() { return stub_->is_loading(); } | 87 bool is_loading() { return stub_->is_loading(); } |
89 | 88 |
90 protected: | 89 protected: |
91 void ResetState() override; | 90 void ResetState() override; |
92 | 91 |
93 private: | 92 private: |
94 background_loader::BackgroundLoaderContentsStub* stub_; | 93 background_loader::BackgroundLoaderContentsStub* stub_; |
95 }; | 94 }; |
96 | 95 |
97 TestBackgroundLoaderOffliner::TestBackgroundLoaderOffliner( | 96 TestBackgroundLoaderOffliner::TestBackgroundLoaderOffliner( |
98 content::BrowserContext* browser_context, | 97 content::BrowserContext* browser_context, |
99 const OfflinerPolicy* policy, | |
100 OfflinePageModel* offline_page_model) | 98 OfflinePageModel* offline_page_model) |
101 : BackgroundLoaderOffliner(browser_context, policy, offline_page_model) {} | 99 : BackgroundLoaderOffliner(browser_context, offline_page_model) {} |
102 | 100 |
103 TestBackgroundLoaderOffliner::~TestBackgroundLoaderOffliner() {} | 101 TestBackgroundLoaderOffliner::~TestBackgroundLoaderOffliner() {} |
104 | 102 |
105 void TestBackgroundLoaderOffliner::ResetState() { | 103 void TestBackgroundLoaderOffliner::ResetState() { |
106 pending_request_.reset(); | 104 pending_request_.reset(); |
107 stub_ = new background_loader::BackgroundLoaderContentsStub(browser_context_); | 105 stub_ = new background_loader::BackgroundLoaderContentsStub(browser_context_); |
108 loader_.reset(stub_); | 106 loader_.reset(stub_); |
109 content::WebContentsObserver::Observe(stub_->web_contents()); | 107 content::WebContentsObserver::Observe(stub_->web_contents()); |
110 } | 108 } |
111 | 109 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 146 |
149 BackgroundLoaderOfflinerTest::BackgroundLoaderOfflinerTest() | 147 BackgroundLoaderOfflinerTest::BackgroundLoaderOfflinerTest() |
150 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 148 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
151 completion_callback_called_(false), | 149 completion_callback_called_(false), |
152 request_status_(Offliner::RequestStatus::UNKNOWN) {} | 150 request_status_(Offliner::RequestStatus::UNKNOWN) {} |
153 | 151 |
154 BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {} | 152 BackgroundLoaderOfflinerTest::~BackgroundLoaderOfflinerTest() {} |
155 | 153 |
156 void BackgroundLoaderOfflinerTest::SetUp() { | 154 void BackgroundLoaderOfflinerTest::SetUp() { |
157 model_ = new MockOfflinePageModel(); | 155 model_ = new MockOfflinePageModel(); |
158 offliner_.reset(new TestBackgroundLoaderOffliner(profile(), nullptr, model_)); | 156 offliner_.reset(new TestBackgroundLoaderOffliner(profile(), model_)); |
159 } | 157 } |
160 | 158 |
161 void BackgroundLoaderOfflinerTest::OnCompletion( | 159 void BackgroundLoaderOfflinerTest::OnCompletion( |
162 const SavePageRequest& request, | 160 const SavePageRequest& request, |
163 Offliner::RequestStatus status) { | 161 Offliner::RequestStatus status) { |
164 DCHECK(!completion_callback_called_); // Expect 1 callback per request. | 162 DCHECK(!completion_callback_called_); // Expect 1 callback per request. |
165 completion_callback_called_ = true; | 163 completion_callback_called_ = true; |
166 request_status_ = status; | 164 request_status_ = status; |
167 } | 165 } |
168 | 166 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, | 283 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, |
286 kUserRequested); | 284 kUserRequested); |
287 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); | 285 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); |
288 offliner()->WebContentsDestroyed(); | 286 offliner()->WebContentsDestroyed(); |
289 | 287 |
290 EXPECT_TRUE(completion_callback_called()); | 288 EXPECT_TRUE(completion_callback_called()); |
291 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED, request_status()); | 289 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED, request_status()); |
292 } | 290 } |
293 | 291 |
294 } // namespace offline_pages | 292 } // namespace offline_pages |
OLD | NEW |