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 15 matching lines...) Expand all Loading... |
26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 | 28 |
29 namespace offline_pages { | 29 namespace offline_pages { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const int64_t kRequestId = 7; | 33 const int64_t kRequestId = 7; |
34 const GURL kHttpUrl("http://www.tunafish.com"); | 34 const GURL kHttpUrl("http://www.tunafish.com"); |
35 const GURL kFileUrl("file://salmon.png"); | 35 const GURL kFileUrl("file://salmon.png"); |
36 const ClientId kClientId("AsyncLoading", "88"); | 36 const ClientId kClientId("async_loading", "88"); |
37 const bool kUserRequested = true; | 37 const bool kUserRequested = true; |
38 | 38 |
39 // Mock OfflinePageModel for testing the SavePage calls | 39 // Mock OfflinePageModel for testing the SavePage calls |
40 class MockOfflinePageModel : public StubOfflinePageModel { | 40 class MockOfflinePageModel : public StubOfflinePageModel { |
41 public: | 41 public: |
42 MockOfflinePageModel() : mock_saving_(false) {} | 42 MockOfflinePageModel() : mock_saving_(false) {} |
43 ~MockOfflinePageModel() override {} | 43 ~MockOfflinePageModel() override {} |
44 | 44 |
45 void SavePage(const SavePageParams& save_page_params, | 45 void SavePage(const SavePageParams& save_page_params, |
46 std::unique_ptr<OfflinePageArchiver> archiver, | 46 std::unique_ptr<OfflinePageArchiver> archiver, |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // Create handle with net error code. | 425 // Create handle with net error code. |
426 // Called after calling LoadAndSave so we have web_contents to work with. | 426 // Called after calling LoadAndSave so we have web_contents to work with. |
427 std::unique_ptr<content::NavigationHandle> handle( | 427 std::unique_ptr<content::NavigationHandle> handle( |
428 content::NavigationHandle::CreateNavigationHandleForTesting( | 428 content::NavigationHandle::CreateNavigationHandleForTesting( |
429 kHttpUrl, offliner()->web_contents()->GetMainFrame(), true, | 429 kHttpUrl, offliner()->web_contents()->GetMainFrame(), true, |
430 net::Error::ERR_NAME_NOT_RESOLVED)); | 430 net::Error::ERR_NAME_NOT_RESOLVED)); |
431 // Call DidFinishNavigation with handle that contains error. | 431 // Call DidFinishNavigation with handle that contains error. |
432 offliner()->DidFinishNavigation(handle.get()); | 432 offliner()->DidFinishNavigation(handle.get()); |
433 // NavigationHandle is always destroyed after finishing navigation. | 433 // NavigationHandle is always destroyed after finishing navigation. |
434 handle.reset(); | 434 handle.reset(); |
| 435 histograms().ExpectBucketCount( |
| 436 "OfflinePages.Background.BackgroundLoadingFailedCode.async_loading", |
| 437 105, // ERR_NAME_NOT_RESOLVED |
| 438 1); |
435 offliner()->DidStopLoading(); | 439 offliner()->DidStopLoading(); |
436 PumpLoop(); | 440 PumpLoop(); |
437 | 441 |
438 EXPECT_TRUE(completion_callback_called()); | 442 EXPECT_TRUE(completion_callback_called()); |
439 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_RETRY, request_status()); | 443 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_RETRY, request_status()); |
440 } | 444 } |
441 | 445 |
442 TEST_F(BackgroundLoaderOfflinerTest, NoNextOnInternetDisconnected) { | 446 TEST_F(BackgroundLoaderOfflinerTest, NoNextOnInternetDisconnected) { |
443 base::Time creation_time = base::Time::Now(); | 447 base::Time creation_time = base::Time::Now(); |
444 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, | 448 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 model()->CompleteSavingAsSuccess(); | 481 model()->CompleteSavingAsSuccess(); |
478 PumpLoop(); | 482 PumpLoop(); |
479 | 483 |
480 EXPECT_TRUE(completion_callback_called()); | 484 EXPECT_TRUE(completion_callback_called()); |
481 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); | 485 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); |
482 EXPECT_FALSE(offliner()->is_loading()); | 486 EXPECT_FALSE(offliner()->is_loading()); |
483 EXPECT_FALSE(SaveInProgress()); | 487 EXPECT_FALSE(SaveInProgress()); |
484 } | 488 } |
485 | 489 |
486 } // namespace offline_pages | 490 } // namespace offline_pages |
OLD | NEW |