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

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: Rebased 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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 tab_entry_->SetNowOffsetInSeconds(30 + closed_tab_expiration_seconds); 409 tab_entry_->SetNowOffsetInSeconds(30 + closed_tab_expiration_seconds);
409 EXPECT_FALSE(tab_entry_->IsExpired()); 410 EXPECT_FALSE(tab_entry_->IsExpired());
410 411
411 // Fast forward |closed_tab_expiration_seconds+1| seconds from tab close 412 // Fast forward |closed_tab_expiration_seconds+1| seconds from tab close
412 // time. Tab entry is expired. 413 // time. Tab entry is expired.
413 tab_entry_->SetNowOffsetInSeconds(30 + closed_tab_expiration_seconds + 1); 414 tab_entry_->SetNowOffsetInSeconds(30 + closed_tab_expiration_seconds + 1);
414 EXPECT_TRUE(tab_entry_->IsExpired()); 415 EXPECT_TRUE(tab_entry_->IsExpired());
415 } 416 }
416 417
417 // Checks that tracking session history does not grow beyond 418 // Checks that tracking session history does not grow beyond
418 // GetMaxSessionsPerTabForTests entries, and automatically compacts itself by 419 // GetMaxSessionsPerTab entries, and automatically compacts itself by removing
419 // removing the oldest tracking sessions. 420 // the oldest tracking sessions.
420 TEST_F(MockTabDataUseEntryTest, CompactTabSessionHistory) { 421 TEST_F(MockTabDataUseEntryTest, CompactTabSessionHistory) {
421 const uint32_t per_session_duration = 10; 422 const uint32_t per_session_duration = 10;
422 const uint32_t next_session_start_gap = 10; 423 const uint32_t next_session_start_gap = 10;
423 uint32_t session_start_time = 10; 424 uint32_t session_start_time = 10;
424 uint32_t num_sessions = 1; 425 uint32_t num_sessions = 1;
425 426
426 ExpectTabEntrySessionsSize(TabEntrySessionSize::ZERO); 427 ExpectTabEntrySessionsSize(TabEntrySessionSize::ZERO);
427 428
428 while (num_sessions <= GetMaxSessionsPerTab()) { 429 while (num_sessions <= GetMaxSessionsPerTab()) {
429 // Start tracking session at time=|session_start_time| and end after 430 // Start tracking session at time=|session_start_time| and end after
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 EXPECT_FALSE(IsTabEntrySessionExists(oldest_session_label)); 465 EXPECT_FALSE(IsTabEntrySessionExists(oldest_session_label));
465 ExpectTabEntrySessionsSize(GetMaxSessionsPerTab()); 466 ExpectTabEntrySessionsSize(GetMaxSessionsPerTab());
466 467
467 // Update next session start time. 468 // Update next session start time.
468 session_start_time += per_session_duration + next_session_start_gap; 469 session_start_time += per_session_duration + next_session_start_gap;
469 ++num_sessions; 470 ++num_sessions;
470 ++oldest_session; 471 ++oldest_session;
471 } 472 }
472 } 473 }
473 474
475 TEST_F(MockTabDataUseEntryTest, TrackingSessionLifetimeHistogram) {
476 const char kUMATrackingSessionLifetimeSecondsHistogram[] =
477 "DataUse.TabModel.TrackingSessionLifetime";
478 base::HistogramTester histogram_tester;
479
480 // Tracking session from time=20 to time=30, lifetime of 10 seconds.
481 tab_entry_->SetNowOffsetInSeconds(20);
482 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
483 tab_entry_->SetNowOffsetInSeconds(30);
484 EXPECT_TRUE(tab_entry_->EndTracking());
485
486 histogram_tester.ExpectTotalCount(kUMATrackingSessionLifetimeSecondsHistogram,
487 1);
488 histogram_tester.ExpectBucketCount(
489 kUMATrackingSessionLifetimeSecondsHistogram,
490 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1);
491
492 // Tracking session from time=40 to time=70, lifetime of 30 seconds.
493 tab_entry_->SetNowOffsetInSeconds(40);
494 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
495 tab_entry_->SetNowOffsetInSeconds(70);
496 EXPECT_TRUE(tab_entry_->EndTracking());
497
498 histogram_tester.ExpectTotalCount(kUMATrackingSessionLifetimeSecondsHistogram,
499 2);
500 histogram_tester.ExpectBucketCount(
501 kUMATrackingSessionLifetimeSecondsHistogram,
502 base::TimeDelta::FromSeconds(30).InMilliseconds(), 1);
503 }
504
505 TEST_F(MockTabDataUseEntryTest, OldInactiveSessionRemovaltimeHistogram) {
506 const char kUMAOldInactiveSessionRemovalDurationSecondsHistogram[] =
507 "DataUse.TabModel.OldInactiveSessionRemovalDuration";
508 base::HistogramTester histogram_tester;
509 const size_t max_sessions_per_tab = GetMaxSessionsPerTab();
510
511 // Start a tracking session at time=20, and end it at time=30.
512 tab_entry_->SetNowOffsetInSeconds(20);
513 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
514 tab_entry_->SetNowOffsetInSeconds(30);
515 EXPECT_TRUE(tab_entry_->EndTracking());
516
517 for (size_t session = 1; session < max_sessions_per_tab; ++session) {
518 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
519 EXPECT_TRUE(tab_entry_->EndTracking());
520 }
521
522 // Add one more session at time=60. This removes the first inactive tracking
523 // session that ended at time=30, with removal duration of 30 seconds.
524 tab_entry_->SetNowOffsetInSeconds(60);
525 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1));
526 EXPECT_TRUE(tab_entry_->EndTracking());
527
528 histogram_tester.ExpectTotalCount(
529 kUMAOldInactiveSessionRemovalDurationSecondsHistogram, 1);
530 histogram_tester.ExpectBucketCount(
531 kUMAOldInactiveSessionRemovalDurationSecondsHistogram,
532 base::TimeDelta::FromSeconds(30).InMilliseconds(), 1);
533 }
534
474 } // namespace android 535 } // namespace android
475 536
476 } // namespace chrome 537 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/android/data_usage/tab_data_use_entry.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698