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

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

Issue 2507293006: Report redirect UMA in offline interceptor (Closed)
Patch Set: Created 4 years, 1 month 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/offline_page_request_job.h" 5 #include "chrome/browser/android/offline_pages/offline_page_request_job.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 const ClientId& client_id, 242 const ClientId& client_id,
243 const GURL& original_url, 243 const GURL& original_url,
244 std::unique_ptr<OfflinePageArchiver> archiver); 244 std::unique_ptr<OfflinePageArchiver> archiver);
245 245
246 void InterceptRequest(const GURL& url, 246 void InterceptRequest(const GURL& url,
247 const std::string& method, 247 const std::string& method,
248 const std::string& extra_header_name, 248 const std::string& extra_header_name,
249 const std::string& extra_header_value, 249 const std::string& extra_header_value,
250 content::ResourceType resource_type); 250 content::ResourceType resource_type);
251 251
252 // Expect one count of|result| UMA reported and no more.
fgorski 2016/11/18 23:52:22 nit: space before | Expect exactly one... drop "
jianli 2016/11/19 00:54:05 Done.
252 void ExpectAggregatedRequestResultHistogram( 253 void ExpectAggregatedRequestResultHistogram(
253 OfflinePageRequestJob::AggregatedRequestResult result); 254 OfflinePageRequestJob::AggregatedRequestResult result);
255 // Expect multiple |count| of |result| UMA reported and no more.
fgorski 2016/11/18 23:52:22 Expect exactly |count|... and drop "and no more"
jianli 2016/11/19 00:54:05 Done.
254 void ExpectAggregatedRequestResultHistogramWithCount( 256 void ExpectAggregatedRequestResultHistogramWithCount(
255 OfflinePageRequestJob::AggregatedRequestResult result, int count); 257 OfflinePageRequestJob::AggregatedRequestResult result, int count);
258 // Expect one count of |result| UMA reported. Some other UMAs might also be
259 // reported.
260 void ExpectAggregatedRequestResultHistogramOnMultiBuckets(
fgorski 2016/11/18 23:52:22 This is meant to be exactly one in specific bucket
jianli 2016/11/19 00:54:05 Eexactly one in specific bucket and other buckets
261 OfflinePageRequestJob::AggregatedRequestResult result);
256 262
257 net::TestURLRequestContext* url_request_context() { 263 net::TestURLRequestContext* url_request_context() {
258 return test_url_request_context_.get(); 264 return test_url_request_context_.get();
259 } 265 }
260 Profile* profile() { return profile_; } 266 Profile* profile() { return profile_; }
261 OfflinePageTabHelper* offline_page_tab_helper() const { 267 OfflinePageTabHelper* offline_page_tab_helper() const {
262 return offline_page_tab_helper_; 268 return offline_page_tab_helper_;
263 } 269 }
264 int64_t offline_id() const { return offline_id_; } 270 int64_t offline_id() const { return offline_id_; }
265 int64_t offline_id2() const { return offline_id2_; } 271 int64_t offline_id2() const { return offline_id2_; }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 histogram_tester_.ExpectUniqueSample( 458 histogram_tester_.ExpectUniqueSample(
453 kAggregatedRequestResultHistogram, static_cast<int>(result), 1); 459 kAggregatedRequestResultHistogram, static_cast<int>(result), 1);
454 } 460 }
455 461
456 void OfflinePageRequestJobTest::ExpectAggregatedRequestResultHistogramWithCount( 462 void OfflinePageRequestJobTest::ExpectAggregatedRequestResultHistogramWithCount(
457 OfflinePageRequestJob::AggregatedRequestResult result, int count) { 463 OfflinePageRequestJob::AggregatedRequestResult result, int count) {
458 histogram_tester_.ExpectUniqueSample( 464 histogram_tester_.ExpectUniqueSample(
459 kAggregatedRequestResultHistogram, static_cast<int>(result), count); 465 kAggregatedRequestResultHistogram, static_cast<int>(result), count);
460 } 466 }
461 467
468 void
469 OfflinePageRequestJobTest::ExpectAggregatedRequestResultHistogramOnMultiBuckets(
470 OfflinePageRequestJob::AggregatedRequestResult result) {
471 histogram_tester_.ExpectBucketCount(
472 kAggregatedRequestResultHistogram, static_cast<int>(result), 1);
473 }
474
462 void OfflinePageRequestJobTest::SavePage( 475 void OfflinePageRequestJobTest::SavePage(
463 const GURL& url, 476 const GURL& url,
464 const ClientId& client_id, 477 const ClientId& client_id,
465 const GURL& original_url, 478 const GURL& original_url,
466 std::unique_ptr<OfflinePageArchiver> archiver) { 479 std::unique_ptr<OfflinePageArchiver> archiver) {
467 OfflinePageModel::SavePageParams save_page_params; 480 OfflinePageModel::SavePageParams save_page_params;
468 save_page_params.url = url; 481 save_page_params.url = url;
469 save_page_params.client_id = client_id; 482 save_page_params.client_id = client_id;
470 save_page_params.original_url = original_url; 483 save_page_params.original_url = original_url;
471 OfflinePageModelFactory::GetForBrowserContext(profile())->SavePage( 484 OfflinePageModelFactory::GetForBrowserContext(profile())->SavePage(
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 846
834 // This should trigger redirect first. 847 // This should trigger redirect first.
835 InterceptRequest( 848 InterceptRequest(
836 kTestOriginalUrl, "GET", "", "", content::RESOURCE_TYPE_MAIN_FRAME); 849 kTestOriginalUrl, "GET", "", "", content::RESOURCE_TYPE_MAIN_FRAME);
837 base::RunLoop().Run(); 850 base::RunLoop().Run();
838 851
839 EXPECT_EQ(kTestFileSize3, bytes_read()); 852 EXPECT_EQ(kTestFileSize3, bytes_read());
840 ASSERT_TRUE(offline_page_tab_helper()->GetOfflinePageForTest()); 853 ASSERT_TRUE(offline_page_tab_helper()->GetOfflinePageForTest());
841 EXPECT_EQ(offline_id3(), 854 EXPECT_EQ(offline_id3(),
842 offline_page_tab_helper()->GetOfflinePageForTest()->offline_id); 855 offline_page_tab_helper()->GetOfflinePageForTest()->offline_id);
843 ExpectAggregatedRequestResultHistogram( 856 ExpectAggregatedRequestResultHistogramOnMultiBuckets(
857 OfflinePageRequestJob::AggregatedRequestResult::
858 REDIRECTED_ON_DISCONNECTED_NETWORK);
859 ExpectAggregatedRequestResultHistogramOnMultiBuckets(
844 OfflinePageRequestJob::AggregatedRequestResult:: 860 OfflinePageRequestJob::AggregatedRequestResult::
845 SHOW_OFFLINE_ON_DISCONNECTED_NETWORK); 861 SHOW_OFFLINE_ON_DISCONNECTED_NETWORK);
846 } 862 }
847 863
848 } // namespace offline_pages 864 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698