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

Side by Side Diff: chrome/browser/android/data_usage/tab_data_use_entry_unittest.cc

Issue 1444133002: Add UMA histograms for data usage tab model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed jwd comments Created 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/data_usage/tab_data_use_entry.h" 5 #include "chrome/browser/android/data_usage/tab_data_use_entry.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/test/histogram_tester.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace { 17 namespace {
17 18
18 // Tracking labels for tests. 19 // Tracking labels for tests.
19 const std::string kTestLabel1 = "label_1"; 20 const std::string kTestLabel1 = "label_1";
20 const std::string kTestLabel2 = "label_2"; 21 const std::string kTestLabel2 = "label_2";
21 const std::string kTestLabel3 = "label_3"; 22 const std::string kTestLabel3 = "label_3";
22 23
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 EXPECT_FALSE(IsTabEntrySessionExists(oldest_session_label)); 456 EXPECT_FALSE(IsTabEntrySessionExists(oldest_session_label));
456 ExpectTabEntrySessionsSize(max_sessions_per_tab); 457 ExpectTabEntrySessionsSize(max_sessions_per_tab);
457 458
458 // Update next session start time. 459 // Update next session start time.
459 session_start_time += per_session_duration + next_session_start_gap; 460 session_start_time += per_session_duration + next_session_start_gap;
460 ++num_sessions; 461 ++num_sessions;
461 ++oldest_session; 462 ++oldest_session;
462 } 463 }
463 } 464 }
464 465
466 TEST_F(MockTabDataUseEntryTest, TrackingSessionLifetimeHistogram) {
467 const char kUMATrackingSessionLifetimeSecondsHistogram[] =
468 "DataUse.TabModel.TrackingSessionLifetime";
469 base::HistogramTester histogram_tester;
470
471 // Tracking session from time=20 to time=30, lifetime of 10 seconds.
472 tab_entry_->SetNowOffsetInSeconds(20);
473 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
474 tab_entry_->SetNowOffsetInSeconds(30);
475 EXPECT_TRUE(tab_entry_->EndTracking());
476
477 histogram_tester.ExpectTotalCount(kUMATrackingSessionLifetimeSecondsHistogram,
478 1);
479 histogram_tester.ExpectBucketCount(
480 kUMATrackingSessionLifetimeSecondsHistogram,
481 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1);
482
483 // Tracking session from time=40 to time=70, lifetime of 30 seconds.
484 tab_entry_->SetNowOffsetInSeconds(40);
485 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
486 tab_entry_->SetNowOffsetInSeconds(70);
487 EXPECT_TRUE(tab_entry_->EndTracking());
488
489 histogram_tester.ExpectTotalCount(kUMATrackingSessionLifetimeSecondsHistogram,
490 2);
491 histogram_tester.ExpectBucketCount(
492 kUMATrackingSessionLifetimeSecondsHistogram,
493 base::TimeDelta::FromSeconds(30).InMilliseconds(), 1);
494 }
495
496 TEST_F(MockTabDataUseEntryTest, OldInactiveSessionRemovaltimeHistogram) {
497 const char kUMAOldInactiveSessionRemovalDurationSecondsHistogram[] =
498 "DataUse.TabModel.OldInactiveSessionRemovalDuration";
499 base::HistogramTester histogram_tester;
500 const size_t max_sessions_per_tab =
501 TabDataUseEntry::GetMaxSessionsPerTabForTests();
502
503 // Start a tracking session at time=20, and end it at time=30.
504 tab_entry_->SetNowOffsetInSeconds(20);
505 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
506 tab_entry_->SetNowOffsetInSeconds(30);
507 EXPECT_TRUE(tab_entry_->EndTracking());
508
509 for (size_t session = 1; session < max_sessions_per_tab; ++session) {
510 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
511 EXPECT_TRUE(tab_entry_->EndTracking());
512 }
513
514 // Add one more session at time=60. This removes the first inactive tracking
515 // session that ended at time=30, with removal duration of 30 seconds.
516 tab_entry_->SetNowOffsetInSeconds(60);
517 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
518 EXPECT_TRUE(tab_entry_->EndTracking());
519
520 histogram_tester.ExpectTotalCount(
521 kUMAOldInactiveSessionRemovalDurationSecondsHistogram, 1);
522 histogram_tester.ExpectBucketCount(
523 kUMAOldInactiveSessionRemovalDurationSecondsHistogram,
524 base::TimeDelta::FromSeconds(30).InMilliseconds(), 1);
525 }
526
465 } // namespace android 527 } // namespace android
466 528
467 } // namespace chrome 529 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698