| 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_mock_time_message_loop_task_runner.h" | 10 #include "base/test/scoped_mock_time_message_loop_task_runner.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 content::BrowserContext* browser_context, | 87 content::BrowserContext* browser_context, |
| 88 const OfflinerPolicy* policy, | 88 const OfflinerPolicy* policy, |
| 89 OfflinePageModel* offline_page_model); | 89 OfflinePageModel* offline_page_model); |
| 90 ~TestBackgroundLoaderOffliner() override; | 90 ~TestBackgroundLoaderOffliner() override; |
| 91 content::WebContentsTester* web_contents_tester() { | 91 content::WebContentsTester* web_contents_tester() { |
| 92 return content::WebContentsTester::For(stub_->web_contents()); | 92 return content::WebContentsTester::For(stub_->web_contents()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 content::WebContents* web_contents() { return stub_->web_contents(); } | 95 content::WebContents* web_contents() { return stub_->web_contents(); } |
| 96 | 96 |
| 97 bool is_loading() { return stub_->is_loading(); } | 97 bool is_loading() { return loader_ && stub_->is_loading(); } |
| 98 | 98 |
| 99 protected: | 99 protected: |
| 100 void ResetState() override; | 100 void ResetLoader() override; |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 background_loader::BackgroundLoaderContentsStub* stub_; | 103 background_loader::BackgroundLoaderContentsStub* stub_; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 TestBackgroundLoaderOffliner::TestBackgroundLoaderOffliner( | 106 TestBackgroundLoaderOffliner::TestBackgroundLoaderOffliner( |
| 107 content::BrowserContext* browser_context, | 107 content::BrowserContext* browser_context, |
| 108 const OfflinerPolicy* policy, | 108 const OfflinerPolicy* policy, |
| 109 OfflinePageModel* offline_page_model) | 109 OfflinePageModel* offline_page_model) |
| 110 : BackgroundLoaderOffliner(browser_context, policy, offline_page_model) {} | 110 : BackgroundLoaderOffliner(browser_context, policy, offline_page_model) {} |
| 111 | 111 |
| 112 TestBackgroundLoaderOffliner::~TestBackgroundLoaderOffliner() {} | 112 TestBackgroundLoaderOffliner::~TestBackgroundLoaderOffliner() {} |
| 113 | 113 |
| 114 void TestBackgroundLoaderOffliner::ResetState() { | 114 void TestBackgroundLoaderOffliner::ResetLoader() { |
| 115 pending_request_.reset(); | |
| 116 stub_ = new background_loader::BackgroundLoaderContentsStub(browser_context_); | 115 stub_ = new background_loader::BackgroundLoaderContentsStub(browser_context_); |
| 117 loader_.reset(stub_); | 116 loader_.reset(stub_); |
| 118 content::WebContentsObserver::Observe(stub_->web_contents()); | |
| 119 } | 117 } |
| 120 | 118 |
| 121 class BackgroundLoaderOfflinerTest : public testing::Test { | 119 class BackgroundLoaderOfflinerTest : public testing::Test { |
| 122 public: | 120 public: |
| 123 BackgroundLoaderOfflinerTest(); | 121 BackgroundLoaderOfflinerTest(); |
| 124 ~BackgroundLoaderOfflinerTest() override; | 122 ~BackgroundLoaderOfflinerTest() override; |
| 125 | 123 |
| 126 void SetUp() override; | 124 void SetUp() override; |
| 127 | 125 |
| 128 TestBackgroundLoaderOffliner* offliner() const { return offliner_.get(); } | 126 TestBackgroundLoaderOffliner* offliner() const { return offliner_.get(); } |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 model()->CompleteSavingAsSuccess(); | 483 model()->CompleteSavingAsSuccess(); |
| 486 PumpLoop(); | 484 PumpLoop(); |
| 487 | 485 |
| 488 EXPECT_TRUE(completion_callback_called()); | 486 EXPECT_TRUE(completion_callback_called()); |
| 489 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); | 487 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); |
| 490 EXPECT_FALSE(offliner()->is_loading()); | 488 EXPECT_FALSE(offliner()->is_loading()); |
| 491 EXPECT_FALSE(SaveInProgress()); | 489 EXPECT_FALSE(SaveInProgress()); |
| 492 } | 490 } |
| 493 | 491 |
| 494 } // namespace offline_pages | 492 } // namespace offline_pages |
| OLD | NEW |