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

Side by Side Diff: chrome/browser/android/offline_pages/background_loader_offliner_unittest.cc

Issue 2751253004: [Offline Pages] Add UMA to record final offline request status and loading failed error code. (Closed)
Patch Set: fix unit test so DidFinishNavigation is only called once Created 3 years, 9 months 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 "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
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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 EXPECT_TRUE(completion_callback_called()); 414 EXPECT_TRUE(completion_callback_called());
415 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED, request_status()); 415 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED, request_status());
416 } 416 }
417 417
418 TEST_F(BackgroundLoaderOfflinerTest, FailsOnErrorPage) { 418 TEST_F(BackgroundLoaderOfflinerTest, FailsOnErrorPage) {
419 base::Time creation_time = base::Time::Now(); 419 base::Time creation_time = base::Time::Now();
420 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 420 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
421 kUserRequested); 421 kUserRequested);
422 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 422 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
423 progress_callback())); 423 progress_callback()));
424
425 // Create handle with net error code. 424 // Create handle with net error code.
426 // Called after calling LoadAndSave so we have web_contents to work with. 425 // Called after calling LoadAndSave so we have web_contents to work with.
427 std::unique_ptr<content::NavigationHandle> handle( 426 std::unique_ptr<content::NavigationHandle> handle(
428 content::NavigationHandle::CreateNavigationHandleForTesting( 427 content::NavigationHandle::CreateNavigationHandleForTesting(
429 kHttpUrl, offliner()->web_contents()->GetMainFrame(), true, 428 kHttpUrl, offliner()->web_contents()->GetMainFrame(), true,
430 net::Error::ERR_NAME_NOT_RESOLVED)); 429 net::Error::ERR_NAME_NOT_RESOLVED));
431 // Call DidFinishNavigation with handle that contains error. 430 // NavigationHandle destruction will trigger DidFinishNavigation code.
432 offliner()->DidFinishNavigation(handle.get());
433 // NavigationHandle is always destroyed after finishing navigation.
434 handle.reset(); 431 handle.reset();
432 histograms().ExpectBucketCount(
433 "OfflinePages.Background.BackgroundLoadingFailedCode.async_loading",
434 105, // ERR_NAME_NOT_RESOLVED
435 1);
435 offliner()->DidStopLoading(); 436 offliner()->DidStopLoading();
436 PumpLoop(); 437 PumpLoop();
437 438
438 EXPECT_TRUE(completion_callback_called()); 439 EXPECT_TRUE(completion_callback_called());
439 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_RETRY, request_status()); 440 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_RETRY, request_status());
440 } 441 }
441 442
442 TEST_F(BackgroundLoaderOfflinerTest, NoNextOnInternetDisconnected) { 443 TEST_F(BackgroundLoaderOfflinerTest, NoNextOnInternetDisconnected) {
443 base::Time creation_time = base::Time::Now(); 444 base::Time creation_time = base::Time::Now();
444 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 445 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 model()->CompleteSavingAsSuccess(); 478 model()->CompleteSavingAsSuccess();
478 PumpLoop(); 479 PumpLoop();
479 480
480 EXPECT_TRUE(completion_callback_called()); 481 EXPECT_TRUE(completion_callback_called());
481 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status()); 482 EXPECT_EQ(Offliner::RequestStatus::SAVED, request_status());
482 EXPECT_FALSE(offliner()->is_loading()); 483 EXPECT_FALSE(offliner()->is_loading());
483 EXPECT_FALSE(SaveInProgress()); 484 EXPECT_FALSE(SaveInProgress());
484 } 485 }
485 486
486 } // namespace offline_pages 487 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698