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