| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 EXPECT_FALSE(completion_callback_called()); | 213 EXPECT_FALSE(completion_callback_called()); |
| 214 EXPECT_FALSE(SaveInProgress()); | 214 EXPECT_FALSE(SaveInProgress()); |
| 215 EXPECT_FALSE(offliner()->is_loading()); // Offliner reset. | 215 EXPECT_FALSE(offliner()->is_loading()); // Offliner reset. |
| 216 } | 216 } |
| 217 | 217 |
| 218 TEST_F(BackgroundLoaderOfflinerTest, LoadedButSaveFails) { | 218 TEST_F(BackgroundLoaderOfflinerTest, LoadedButSaveFails) { |
| 219 base::Time creation_time = base::Time::Now(); | 219 base::Time creation_time = base::Time::Now(); |
| 220 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, | 220 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, |
| 221 kUserRequested); | 221 kUserRequested); |
| 222 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); | 222 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); |
| 223 EXPECT_TRUE(offliner()->is_loading()); | |
| 224 | 223 |
| 225 CompleteLoading(); | 224 CompleteLoading(); |
| 226 PumpLoop(); | 225 PumpLoop(); |
| 227 model()->CompleteSavingAsArchiveCreationFailed(); | 226 model()->CompleteSavingAsArchiveCreationFailed(); |
| 228 PumpLoop(); | 227 PumpLoop(); |
| 228 |
| 229 EXPECT_TRUE(completion_callback_called()); | 229 EXPECT_TRUE(completion_callback_called()); |
| 230 EXPECT_EQ(Offliner::RequestStatus::SAVE_FAILED, request_status()); | 230 EXPECT_EQ(Offliner::RequestStatus::SAVE_FAILED, request_status()); |
| 231 EXPECT_FALSE(offliner()->is_loading()); | 231 EXPECT_FALSE(offliner()->is_loading()); |
| 232 EXPECT_FALSE(SaveInProgress()); | 232 EXPECT_FALSE(SaveInProgress()); |
| 233 } | 233 } |
| 234 | 234 |
| 235 TEST_F(BackgroundLoaderOfflinerTest, LoadAndSaveSuccess) { | 235 TEST_F(BackgroundLoaderOfflinerTest, LoadAndSaveSuccess) { |
| 236 base::Time creation_time = base::Time::Now(); | 236 base::Time creation_time = base::Time::Now(); |
| 237 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, | 237 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, |
| 238 kUserRequested); | 238 kUserRequested); |
| 239 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); | 239 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); |
| 240 | 240 |
| 241 CompleteLoading(); | 241 CompleteLoading(); |
| 242 PumpLoop(); | 242 PumpLoop(); |
| 243 EXPECT_FALSE(completion_callback_called()); | |
| 244 EXPECT_TRUE(SaveInProgress()); | |
| 245 | |
| 246 model()->CompleteSavingAsSuccess(); | 243 model()->CompleteSavingAsSuccess(); |
| 247 PumpLoop(); | 244 PumpLoop(); |
| 245 |
| 248 EXPECT_TRUE(completion_callback_called()); | 246 EXPECT_TRUE(completion_callback_called()); |
| 249 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); | 247 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); |
| 250 EXPECT_FALSE(offliner()->is_loading()); | 248 EXPECT_FALSE(offliner()->is_loading()); |
| 251 EXPECT_FALSE(SaveInProgress()); | 249 EXPECT_FALSE(SaveInProgress()); |
| 252 } | 250 } |
| 253 | 251 |
| 254 TEST_F(BackgroundLoaderOfflinerTest, FailsOnInvalidURL) { | 252 TEST_F(BackgroundLoaderOfflinerTest, FailsOnInvalidURL) { |
| 255 base::Time creation_time = base::Time::Now(); | 253 base::Time creation_time = base::Time::Now(); |
| 256 SavePageRequest request(kRequestId, kFileUrl, kClientId, creation_time, | 254 SavePageRequest request(kRequestId, kFileUrl, kClientId, creation_time, |
| 257 kUserRequested); | 255 kUserRequested); |
| 258 EXPECT_FALSE(offliner()->LoadAndSave(request, callback())); | 256 EXPECT_FALSE(offliner()->LoadAndSave(request, callback())); |
| 259 } | 257 } |
| 260 | 258 |
| 261 } // namespace offline_pages | 259 } // namespace offline_pages |
| OLD | NEW |