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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
| 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" |
13 #include "base/macros.h" | 15 #include "base/macros.h" |
14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
15 #include "base/test/histogram_tester.h" | 17 #include "base/test/histogram_tester.h" |
16 #include "base/time/tick_clock.h" | 18 #include "base/time/tick_clock.h" |
17 #include "base/time/time.h" | 19 #include "base/time/time.h" |
18 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | 20 #include "chrome/browser/android/data_usage/data_use_tab_model.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 // Tracking labels for tests. | 25 // Tracking labels for tests. |
24 const std::string kTestLabel1 = "label_1"; | 26 const char kTestLabel1[] = "label_1"; |
25 const std::string kTestLabel2 = "label_2"; | 27 const char kTestLabel2[] = "label_2"; |
26 const std::string kTestLabel3 = "label_3"; | 28 const char kTestLabel3[] = "label_3"; |
27 | 29 |
28 enum TabEntrySessionSize { ZERO = 0, ONE, TWO, THREE }; | 30 enum TabEntrySessionSize { ZERO = 0, ONE, TWO, THREE }; |
29 | 31 |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 namespace chrome { | 34 namespace chrome { |
33 | 35 |
34 namespace android { | 36 namespace android { |
35 | 37 |
36 // Test version of |TickClock|. | 38 // Test version of |TickClock|. |
(...skipping 23 matching lines...) Expand all Loading... |
60 // Represents the delta offset to be added to current time that is returned by | 62 // Represents the delta offset to be added to current time that is returned by |
61 // NowTicks. | 63 // NowTicks. |
62 base::TimeDelta now_offset_; | 64 base::TimeDelta now_offset_; |
63 | 65 |
64 DISALLOW_COPY_AND_ASSIGN(SimpleOffsetTestTickClock); | 66 DISALLOW_COPY_AND_ASSIGN(SimpleOffsetTestTickClock); |
65 }; | 67 }; |
66 | 68 |
67 class TabDataUseEntryTest : public testing::Test { | 69 class TabDataUseEntryTest : public testing::Test { |
68 public: | 70 public: |
69 TabDataUseEntryTest() { | 71 TabDataUseEntryTest() { |
70 tab_model_.reset(new DataUseTabModel()); | 72 tab_model_.reset(new DataUseTabModel( |
| 73 base::Bind(&TabDataUseEntryTest::FetchMatchingRules, |
| 74 base::Unretained(this)), |
| 75 base::Bind(&TabDataUseEntryTest::OnMatchingRulesFetched, |
| 76 base::Unretained(this)))); |
71 tick_clock_ = new SimpleOffsetTestTickClock(); | 77 tick_clock_ = new SimpleOffsetTestTickClock(); |
72 tab_model_->tick_clock_.reset(tick_clock_); | 78 tab_model_->tick_clock_.reset(tick_clock_); |
73 tab_entry_.reset(new TabDataUseEntry(tab_model_.get())); | 79 tab_entry_.reset(new TabDataUseEntry(tab_model_.get())); |
74 } | 80 } |
75 | 81 |
| 82 void FetchMatchingRules() {} |
| 83 |
| 84 void OnMatchingRulesFetched(bool is_valid) {} |
| 85 |
76 size_t GetMaxSessionsPerTab() const { | 86 size_t GetMaxSessionsPerTab() const { |
77 return tab_model_->max_sessions_per_tab(); | 87 return tab_model_->max_sessions_per_tab(); |
78 } | 88 } |
79 | 89 |
80 const base::TimeDelta& GetClosedTabExpirationDuration() const { | 90 const base::TimeDelta& GetClosedTabExpirationDuration() const { |
81 return tab_model_->closed_tab_expiration_duration(); | 91 return tab_model_->closed_tab_expiration_duration(); |
82 } | 92 } |
83 | 93 |
84 const base::TimeDelta& GetOpenTabExpirationDuration() const { | 94 const base::TimeDelta& GetOpenTabExpirationDuration() const { |
85 return tab_model_->open_tab_expiration_duration(); | 95 return tab_model_->open_tab_expiration_duration(); |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 EXPECT_TRUE(tab_entry_->EndTracking()); | 550 EXPECT_TRUE(tab_entry_->EndTracking()); |
541 | 551 |
542 histogram_tester.ExpectUniqueSample( | 552 histogram_tester.ExpectUniqueSample( |
543 kUMAOldInactiveSessionRemovalDurationSecondsHistogram, | 553 kUMAOldInactiveSessionRemovalDurationSecondsHistogram, |
544 base::TimeDelta::FromSeconds(30).InMilliseconds(), 1); | 554 base::TimeDelta::FromSeconds(30).InMilliseconds(), 1); |
545 } | 555 } |
546 | 556 |
547 } // namespace android | 557 } // namespace android |
548 | 558 |
549 } // namespace chrome | 559 } // namespace chrome |
OLD | NEW |