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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ~TestBackgroundLoaderOffliner() override; | 110 ~TestBackgroundLoaderOffliner() override; |
111 content::WebContentsTester* web_contents_tester() { | 111 content::WebContentsTester* web_contents_tester() { |
112 return content::WebContentsTester::For(stub_->web_contents()); | 112 return content::WebContentsTester::For(stub_->web_contents()); |
113 } | 113 } |
114 | 114 |
115 content::WebContents* web_contents() { return stub_->web_contents(); } | 115 content::WebContents* web_contents() { return stub_->web_contents(); } |
116 | 116 |
117 bool is_loading() { return stub_->is_loading(); } | 117 bool is_loading() { return loader_ && stub_->is_loading(); } |
118 | 118 |
119 protected: | 119 protected: |
120 void ResetState() override; | 120 void ResetLoader() override; |
121 | 121 |
122 private: | 122 private: |
123 background_loader::BackgroundLoaderContentsStub* stub_; | 123 background_loader::BackgroundLoaderContentsStub* stub_; |
124 }; | 124 }; |
125 | 125 |
126 TestBackgroundLoaderOffliner::TestBackgroundLoaderOffliner( | 126 TestBackgroundLoaderOffliner::TestBackgroundLoaderOffliner( |
127 content::BrowserContext* browser_context, | 127 content::BrowserContext* browser_context, |
128 const OfflinerPolicy* policy, | 128 const OfflinerPolicy* policy, |
129 OfflinePageModel* offline_page_model) | 129 OfflinePageModel* offline_page_model) |
130 : BackgroundLoaderOffliner(browser_context, policy, offline_page_model) {} | 130 : BackgroundLoaderOffliner(browser_context, policy, offline_page_model) {} |
131 | 131 |
132 TestBackgroundLoaderOffliner::~TestBackgroundLoaderOffliner() {} | 132 TestBackgroundLoaderOffliner::~TestBackgroundLoaderOffliner() {} |
133 | 133 |
134 void TestBackgroundLoaderOffliner::ResetState() { | 134 void TestBackgroundLoaderOffliner::ResetLoader() { |
135 pending_request_.reset(); | |
136 stub_ = new background_loader::BackgroundLoaderContentsStub(browser_context_); | 135 stub_ = new background_loader::BackgroundLoaderContentsStub(browser_context_); |
137 loader_.reset(stub_); | 136 loader_.reset(stub_); |
138 content::WebContentsObserver::Observe(stub_->web_contents()); | |
139 } | 137 } |
140 | 138 |
141 class BackgroundLoaderOfflinerTest : public testing::Test { | 139 class BackgroundLoaderOfflinerTest : public testing::Test { |
142 public: | 140 public: |
143 BackgroundLoaderOfflinerTest(); | 141 BackgroundLoaderOfflinerTest(); |
144 ~BackgroundLoaderOfflinerTest() override; | 142 ~BackgroundLoaderOfflinerTest() override; |
145 | 143 |
146 void SetUp() override; | 144 void SetUp() override; |
147 | 145 |
148 TestBackgroundLoaderOffliner* offliner() const { return offliner_.get(); } | 146 TestBackgroundLoaderOffliner* offliner() const { return offliner_.get(); } |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 CompleteLoading(); | 640 CompleteLoading(); |
643 PumpLoop(); | 641 PumpLoop(); |
644 | 642 |
645 // One extra part should be added if the flag is on. | 643 // One extra part should be added if the flag is on. |
646 content::MHTMLExtraParts* extra_parts = | 644 content::MHTMLExtraParts* extra_parts = |
647 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); | 645 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); |
648 EXPECT_EQ(extra_parts->size(), 1); | 646 EXPECT_EQ(extra_parts->size(), 1); |
649 } | 647 } |
650 | 648 |
651 } // namespace offline_pages | 649 } // namespace offline_pages |
OLD | NEW |