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

Unified 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: Histograms fix 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/offline_pages/background_loader_offliner.cc ('k') | content/public/common/previews_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/offline_pages/background_loader_offliner_unittest.cc
diff --git a/chrome/browser/offline_pages/background_loader_offliner_unittest.cc b/chrome/browser/offline_pages/background_loader_offliner_unittest.cc
index 2482234b4963e8f1be33df80e9115c5c5c6027e5..b76fb25ed127ecbdbdd3c6c37552c50e311bda5e 100644
--- a/chrome/browser/offline_pages/background_loader_offliner_unittest.cc
+++ b/chrome/browser/offline_pages/background_loader_offliner_unittest.cc
@@ -11,6 +11,7 @@
#include "base/test/scoped_mock_time_message_loop_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/android/offline_pages/offliner_helper.h"
+#include "chrome/browser/loader/chrome_navigation_data.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
@@ -570,6 +571,64 @@ TEST_F(BackgroundLoaderOfflinerTest, MAYBE_NoNextOnInternetDisconnected) {
EXPECT_EQ(Offliner::RequestStatus::LOADING_FAILED_NO_NEXT, request_status());
}
+TEST_F(BackgroundLoaderOfflinerTest, OffliningPreviewsStatusOffHistogram) {
+ base::Time creation_time = base::Time::Now();
+ SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
+ kUserRequested);
+ EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
+ progress_callback()));
+
+ // Called after calling LoadAndSave so we have web_contents to work with.
+ std::unique_ptr<content::NavigationHandle> handle(
+ content::NavigationHandle::CreateNavigationHandleForTesting(
+ kHttpUrl, offliner()->web_contents()->GetMainFrame(), true,
+ net::Error::OK));
+ // Set up ChromeNavigationData on the handle.
+ std::unique_ptr<ChromeNavigationData> chrome_navigation_data(
+ new ChromeNavigationData());
+ chrome_navigation_data->set_previews_state(
+ content::PreviewsTypes::PREVIEWS_NO_TRANSFORM);
+ std::unique_ptr<content::NavigationData> navigation_data(
+ chrome_navigation_data.release());
+ // Call DidFinishNavigation with handle.
+ offliner()->DidFinishNavigation(handle.get());
+
+ histograms().ExpectBucketCount(
+ "OfflinePages.Background.OffliningPreviewStatus.async_loading",
+ 0, // Previews Disabled
+ 1);
+}
+
+TEST_F(BackgroundLoaderOfflinerTest, OffliningPreviewsStatusOnHistogram) {
+ base::Time creation_time = base::Time::Now();
+ SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
+ kUserRequested);
+ EXPECT_TRUE(offliner()->LoadAndSave(request, completion_callback(),
+ progress_callback()));
+
+ // Called after calling LoadAndSave so we have web_contents to work with.
+ std::unique_ptr<content::NavigationHandle> handle(
+ content::NavigationHandle::CreateNavigationHandleForTesting(
+ kHttpUrl, offliner()->web_contents()->GetMainFrame(), true,
+ net::Error::OK));
+ // Set up ChromeNavigationData on the handle.
+ std::unique_ptr<ChromeNavigationData> chrome_navigation_data(
+ new ChromeNavigationData());
+ chrome_navigation_data->set_previews_state(
+ content::PreviewsTypes::CLIENT_LOFI_ON);
+ std::unique_ptr<content::NavigationData> navigation_data(
+ chrome_navigation_data.release());
+ offliner()->web_contents_tester()->SetNavigationData(
+ handle.get(), std::move(navigation_data));
+ // Call DidFinishNavigation with handle.
+ offliner()->DidFinishNavigation(handle.get());
+
+ histograms().ExpectBucketCount(
+ "OfflinePages.Background.OffliningPreviewStatus.async_loading",
+ 1, // Previews Enabled
+ 1);
+}
+
TEST_F(BackgroundLoaderOfflinerTest, OnlySavesOnceOnMultipleLoads) {
base::Time creation_time = base::Time::Now();
SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time,
« no previous file with comments | « chrome/browser/offline_pages/background_loader_offliner.cc ('k') | content/public/common/previews_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698