OLD | NEW |
---|---|
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 Loading... | |
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, 10, 1); | |
481 | |
482 // Tracking session from time=40 to time=70, lifetime of 30 seconds. | |
483 tab_entry_->SetNowOffsetInSeconds(40); | |
484 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1)); | |
485 tab_entry_->SetNowOffsetInSeconds(70); | |
486 EXPECT_TRUE(tab_entry_->EndTracking()); | |
487 | |
488 histogram_tester.ExpectTotalCount(kUMATrackingSessionLifetimeSecondsHistogram, | |
489 2); | |
490 histogram_tester.ExpectBucketCount( | |
491 kUMATrackingSessionLifetimeSecondsHistogram, 30, 1); | |
492 } | |
493 | |
494 TEST_F(MockTabDataUseEntryTest, OldInactiveSessionRemovaltimeHistogram) { | |
495 const char kUMAOldInactiveSessionRemovaltimeSecondsHistogram[] = | |
496 "DataUse.TabModel.OldInactiveSessionRemovaltime"; | |
497 base::HistogramTester histogram_tester; | |
498 const size_t max_sessions_per_tab = | |
499 TabDataUseEntry::GetMaxSessionsPerTabForTests(); | |
500 | |
501 // Start a tracking session at time=20, and end it at time=30. | |
502 tab_entry_->SetNowOffsetInSeconds(20); | |
503 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1)); | |
504 tab_entry_->SetNowOffsetInSeconds(30); | |
505 EXPECT_TRUE(tab_entry_->EndTracking()); | |
506 | |
507 for (size_t session = 1; session < max_sessions_per_tab; session++) { | |
tbansal1
2015/11/16 17:17:38
++session
Raj
2015/11/16 20:09:37
Done.
| |
508 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1)); | |
509 EXPECT_TRUE(tab_entry_->EndTracking()); | |
510 } | |
511 | |
512 // Add one more session at time=60. This removes the first inactive tracking | |
513 // session that ended at time=30, with removal duration of 30 seconds. | |
514 tab_entry_->SetNowOffsetInSeconds(60); | |
515 EXPECT_TRUE(tab_entry_->StartTracking(kTestLabel1)); | |
516 EXPECT_TRUE(tab_entry_->EndTracking()); | |
517 | |
518 histogram_tester.ExpectTotalCount( | |
519 kUMAOldInactiveSessionRemovaltimeSecondsHistogram, 1); | |
520 histogram_tester.ExpectBucketCount( | |
521 kUMAOldInactiveSessionRemovaltimeSecondsHistogram, 30, 1); | |
522 } | |
523 | |
465 } // namespace android | 524 } // namespace android |
466 | 525 |
467 } // namespace chrome | 526 } // namespace chrome |
OLD | NEW |