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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 offliner()->DidFinishNavigation(handle.get()); | 361 offliner()->DidFinishNavigation(handle.get()); |
362 // NavigationHandle is always destroyed after finishing navigation. | 362 // NavigationHandle is always destroyed after finishing navigation. |
363 handle.reset(); | 363 handle.reset(); |
364 offliner()->DidStopLoading(); | 364 offliner()->DidStopLoading(); |
365 PumpLoop(); | 365 PumpLoop(); |
366 | 366 |
367 EXPECT_TRUE(completion_callback_called()); | 367 EXPECT_TRUE(completion_callback_called()); |
368 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_RETRY, request_status()); | 368 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_RETRY, request_status()); |
369 } | 369 } |
370 | 370 |
| 371 TEST_F(BackgroundLoaderOfflinerTest, OnlySavesOnceOnMultipleLoads) { |
| 372 base::Time creation_time = base::Time::Now(); |
| 373 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, |
| 374 kUserRequested); |
| 375 EXPECT_TRUE(offliner()->LoadAndSave(request, callback())); |
| 376 // First load |
| 377 CompleteLoading(); |
| 378 // Second load |
| 379 offliner()->DidStopLoading(); |
| 380 PumpLoop(); |
| 381 model()->CompleteSavingAsSuccess(); |
| 382 PumpLoop(); |
| 383 |
| 384 EXPECT_TRUE(completion_callback_called()); |
| 385 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); |
| 386 EXPECT_FALSE(offliner()->is_loading()); |
| 387 EXPECT_FALSE(SaveInProgress()); |
| 388 } |
| 389 |
371 } // namespace offline_pages | 390 } // namespace offline_pages |
OLD | NEW |