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

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

Issue 2916253002: Add UMA to determine how often we offline a page with previews. (Closed)
Patch Set: Created 3 years, 6 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/offline_pages/background_loader_offliner.h" 5 #include "chrome/browser/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_feature_list.h" 10 #include "base/test/scoped_feature_list.h"
11 #include "base/test/scoped_mock_time_message_loop_task_runner.h" 11 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/android/offline_pages/offliner_helper.h" 13 #include "chrome/browser/android/offline_pages/offliner_helper.h"
14 #include "chrome/browser/loader/chrome_navigation_data.h"
14 #include "chrome/browser/net/prediction_options.h" 15 #include "chrome/browser/net/prediction_options.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
17 #include "components/content_settings/core/common/pref_names.h" 18 #include "components/content_settings/core/common/pref_names.h"
18 #include "components/offline_pages/content/background_loader/background_loader_c ontents_stub.h" 19 #include "components/offline_pages/content/background_loader/background_loader_c ontents_stub.h"
19 #include "components/offline_pages/core/background/load_termination_listener.h" 20 #include "components/offline_pages/core/background/load_termination_listener.h"
20 #include "components/offline_pages/core/background/offliner.h" 21 #include "components/offline_pages/core/background/offliner.h"
21 #include "components/offline_pages/core/background/offliner_policy.h" 22 #include "components/offline_pages/core/background/offliner_policy.h"
22 #include "components/offline_pages/core/background/save_page_request.h" 23 #include "components/offline_pages/core/background/save_page_request.h"
23 #include "components/offline_pages/core/offline_page_feature.h" 24 #include "components/offline_pages/core/offline_page_feature.h"
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 offliner()->DidFinishNavigation(handle.get()); 564 offliner()->DidFinishNavigation(handle.get());
564 // NavigationHandle is always destroyed after finishing navigation. 565 // NavigationHandle is always destroyed after finishing navigation.
565 handle.reset(); 566 handle.reset();
566 CompleteLoading(); 567 CompleteLoading();
567 PumpLoop(); 568 PumpLoop();
568 569
569 EXPECT_TRUE(completion_callback_called()); 570 EXPECT_TRUE(completion_callback_called());
570 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_NEXT, request_status()); 571 EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_NEXT, request_status());
571 } 572 }
572 573
574 TEST_F(BackgroundLoaderOfflinerTest, OffliningPreviewsStatusHistogram) {
575 base::Time creation_time = base::Time::Now();
576 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
577 kUserRequested);
578 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
579 progress_callback()));
580
581 // Called after calling LoadAndSave so we have web_contents to work with.
582 std::unique_ptr<content::NavigationHandle> handle(
583 content::NavigationHandle::CreateNavigationHandleForTesting(
584 kHttpUrl, offliner()->web_contents()->GetMainFrame(), true,
585 net::Error::OK));
586 // Call DidFinishNavigation with handle.
587 offliner()->DidFinishNavigation(handle.get());
588
589 histograms().ExpectBucketCount(
590 "OfflinePages.Background.OffliningPreviewStatus.async_loading",
591 0, // PreviewsOff
RyanSturm 2017/06/02 20:50:34 Seems like you should have a test for PreviewsOn a
Pete Williamson 2017/06/02 21:40:32 I did try that, but it turns out to be problematic
RyanSturm 2017/06/02 22:14:25 I think that header is already added to this unitt
Pete Williamson 2017/06/02 23:17:41 Yep, that worked, test added. We now test both of
592 1);
593 }
594
573 TEST_F(BackgroundLoaderOfflinerTest, OnlySavesOnceOnMultipleLoads) { 595 TEST_F(BackgroundLoaderOfflinerTest, OnlySavesOnceOnMultipleLoads) {
574 base::Time creation_time = base::Time::Now(); 596 base::Time creation_time = base::Time::Now();
575 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time, 597 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
576 kUserRequested); 598 kUserRequested);
577 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(), 599 EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
578 progress_callback())); 600 progress_callback()));
579 // First load 601 // First load
580 CompleteLoading(); 602 CompleteLoading();
581 // Second load 603 // Second load
582 CompleteLoading(); 604 CompleteLoading();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 CompleteLoading(); 719 CompleteLoading();
698 PumpLoop(); 720 PumpLoop();
699 721
700 // One extra part should be added if the flag is on. 722 // One extra part should be added if the flag is on.
701 content::MHTMLExtraParts* extra_parts = 723 content::MHTMLExtraParts* extra_parts =
702 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents()); 724 content::MHTMLExtraParts::FromWebContents(offliner()->web_contents());
703 EXPECT_EQ(extra_parts->size(), 1); 725 EXPECT_EQ(extra_parts->size(), 1);
704 } 726 }
705 727
706 } // namespace offline_pages 728 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698