Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: components/offline_pages/downloads/download_notifying_observer_unittest.cc

Issue 2521353005: [OfflinePages] Call NotifyInterrupted for pending requests (Closed)
Patch Set: Fix indeterminate progress bar for Downloading... Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/offline_pages/downloads/download_notifying_observer.h" 5 #include "components/offline_pages/downloads/download_notifying_observer.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "components/offline_pages/background/save_page_request.h" 8 #include "components/offline_pages/background/save_page_request.h"
9 #include "components/offline_pages/client_namespace_constants.h" 9 #include "components/offline_pages/client_namespace_constants.h"
10 #include "components/offline_pages/client_policy_controller.h" 10 #include "components/offline_pages/client_policy_controller.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DownloadNotifyingObserverTest::~DownloadNotifyingObserverTest() {} 121 DownloadNotifyingObserverTest::~DownloadNotifyingObserverTest() {}
122 122
123 void DownloadNotifyingObserverTest::SetUp() { 123 void DownloadNotifyingObserverTest::SetUp() {
124 std::unique_ptr<TestNotifier> notifier(new TestNotifier); 124 std::unique_ptr<TestNotifier> notifier(new TestNotifier);
125 policy_controller_.reset(new ClientPolicyController()); 125 policy_controller_.reset(new ClientPolicyController());
126 notifier_ = notifier.get(); 126 notifier_ = notifier.get();
127 observer_.reset(new DownloadNotifyingObserver(std::move(notifier), 127 observer_.reset(new DownloadNotifyingObserver(std::move(notifier),
128 policy_controller_.get())); 128 policy_controller_.get()));
129 } 129 }
130 130
131 TEST_F(DownloadNotifyingObserverTest, OnAdded) { 131 TEST_F(DownloadNotifyingObserverTest, OnAddedAsAvailable) {
132 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, 132 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId,
133 kTestCreationTime, kTestUserRequested); 133 kTestCreationTime, kTestUserRequested);
134 request.set_request_state(SavePageRequest::RequestState::AVAILABLE);
135 observer()->OnAdded(request);
136 EXPECT_EQ(LastNotificationType::DOWNLOAD_INTERRUPTED,
137 notifier()->last_notification_type());
138 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid);
139 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url);
140 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time);
141 }
142
143 TEST_F(DownloadNotifyingObserverTest, OnAddedAsOffling) {
fgorski 2016/11/29 17:50:59 Technically nothing prevents us from adding as pau
dougarnett 2016/11/29 20:43:30 Done.
144 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId,
145 kTestCreationTime, kTestUserRequested);
146 request.set_request_state(SavePageRequest::RequestState::OFFLINING);
134 observer()->OnAdded(request); 147 observer()->OnAdded(request);
135 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, 148 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS,
136 notifier()->last_notification_type()); 149 notifier()->last_notification_type());
137 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); 150 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid);
138 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); 151 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url);
139 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); 152 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time);
140 } 153 }
141 154
142 TEST_F(DownloadNotifyingObserverTest, OnChangedToPaused) { 155 TEST_F(DownloadNotifyingObserverTest, OnChangedToPaused) {
143 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, 156 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId,
144 kTestCreationTime, kTestUserRequested); 157 kTestCreationTime, kTestUserRequested);
145 request.set_request_state(SavePageRequest::RequestState::PAUSED); 158 request.set_request_state(SavePageRequest::RequestState::PAUSED);
146 observer()->OnChanged(request); 159 observer()->OnChanged(request);
147 EXPECT_EQ(LastNotificationType::DOWNLOAD_PAUSED, 160 EXPECT_EQ(LastNotificationType::DOWNLOAD_PAUSED,
148 notifier()->last_notification_type()); 161 notifier()->last_notification_type());
149 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); 162 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid);
150 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); 163 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url);
151 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); 164 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time);
152 } 165 }
153 166
154 TEST_F(DownloadNotifyingObserverTest, OnChangedToAvailable) { 167 TEST_F(DownloadNotifyingObserverTest, OnChangedToAvailable) {
155 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, 168 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId,
156 kTestCreationTime, kTestUserRequested); 169 kTestCreationTime, kTestUserRequested);
157 request.set_request_state(SavePageRequest::RequestState::AVAILABLE); 170 request.set_request_state(SavePageRequest::RequestState::AVAILABLE);
158 observer()->OnChanged(request); 171 observer()->OnChanged(request);
172 EXPECT_EQ(LastNotificationType::DOWNLOAD_INTERRUPTED,
173 notifier()->last_notification_type());
174 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid);
175 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url);
176 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time);
177 }
178
179 TEST_F(DownloadNotifyingObserverTest, OnChangedToOfflining) {
180 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId,
181 kTestCreationTime, kTestUserRequested);
182 request.set_request_state(SavePageRequest::RequestState::OFFLINING);
183 observer()->OnChanged(request);
159 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS, 184 EXPECT_EQ(LastNotificationType::DOWNLOAD_PROGRESS,
160 notifier()->last_notification_type()); 185 notifier()->last_notification_type());
161 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid); 186 EXPECT_EQ(kTestGuid, notifier()->download_item()->guid);
162 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url); 187 EXPECT_EQ(GURL(kTestUrl), notifier()->download_item()->url);
163 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time); 188 EXPECT_EQ(kTestCreationTime, notifier()->download_item()->start_time);
164 } 189 }
165 190
166 TEST_F(DownloadNotifyingObserverTest, OnCompletedSuccess) { 191 TEST_F(DownloadNotifyingObserverTest, OnCompletedSuccess) {
167 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId, 192 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), kTestClientId,
168 kTestCreationTime, kTestUserRequested); 193 kTestCreationTime, kTestUserRequested);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 for (auto name_space : name_spaces) { 267 for (auto name_space : name_spaces) {
243 ClientId invisible_client_id(name_space, kTestGuid); 268 ClientId invisible_client_id(name_space, kTestGuid);
244 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id, 269 SavePageRequest request(kTestOfflineId, GURL(kTestUrl), invisible_client_id,
245 kTestCreationTime, kTestUserRequested); 270 kTestCreationTime, kTestUserRequested);
246 observer()->OnAdded(request); 271 observer()->OnAdded(request);
247 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type()); 272 EXPECT_EQ(LastNotificationType::NONE, notifier()->last_notification_type());
248 } 273 }
249 } 274 }
250 275
251 } // namespace offline_pages 276 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698