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/data_use_matcher.h" | 5 #include "chrome/browser/android/data_usage/data_use_matcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
17 #include "base/time/tick_clock.h" | 17 #include "base/time/tick_clock.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "chrome/browser/android/data_usage/external_data_use_observer.h" | 19 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 const char kUMAMatchingRulesCountValidHistogram[] = | 27 const char kUMAMatchingRulesCountValidHistogram[] = |
28 "DataUsage.MatchingRulesCount.Valid"; | 28 "DataUsage.MatchingRulesCount.Valid"; |
29 const char kUMAMatchingRulesCountInvalidHistogram[] = | 29 const char kUMAMatchingRulesCountInvalidHistogram[] = |
(...skipping 19 matching lines...) Expand all Loading... |
49 void set_now_ticks(const base::TimeTicks& now_ticks) { | 49 void set_now_ticks(const base::TimeTicks& now_ticks) { |
50 now_ticks_ = now_ticks; | 50 now_ticks_ = now_ticks; |
51 } | 51 } |
52 | 52 |
53 private: | 53 private: |
54 base::TimeTicks now_ticks_; | 54 base::TimeTicks now_ticks_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(NowTestTickClock); | 56 DISALLOW_COPY_AND_ASSIGN(NowTestTickClock); |
57 }; | 57 }; |
58 | 58 |
| 59 class TestExternalDataUseObserverBridge |
| 60 : public chrome::android::ExternalDataUseObserverBridge { |
| 61 public: |
| 62 TestExternalDataUseObserverBridge() {} |
| 63 void FetchMatchingRules() const override {} |
| 64 void ShouldRegisterAsDataUseObserver(bool should_register) const override{}; |
| 65 }; |
| 66 |
59 } // namespace | 67 } // namespace |
60 | 68 |
61 namespace chrome { | 69 namespace chrome { |
62 | 70 |
63 namespace android { | 71 namespace android { |
64 | 72 |
65 class ExternalDataUseObserver; | 73 class ExternalDataUseObserver; |
66 | 74 |
67 class DataUseMatcherTest : public testing::Test { | 75 class DataUseMatcherTest : public testing::Test { |
68 public: | 76 public: |
69 DataUseMatcherTest() | 77 DataUseMatcherTest() |
70 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 78 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
71 data_use_matcher_(base::WeakPtr<DataUseTabModel>(), | 79 data_use_matcher_(base::WeakPtr<DataUseTabModel>(), |
72 content::BrowserThread::GetMessageLoopProxyForThread( | 80 new TestExternalDataUseObserverBridge(), |
73 content::BrowserThread::IO), | |
74 base::WeakPtr<ExternalDataUseObserver>(), | |
75 base::TimeDelta::FromSeconds( | 81 base::TimeDelta::FromSeconds( |
76 kDefaultMatchingRuleExpirationDurationSeconds)) {} | 82 kDefaultMatchingRuleExpirationDurationSeconds)) {} |
77 | 83 |
78 DataUseMatcher* data_use_matcher() { return &data_use_matcher_; } | 84 DataUseMatcher* data_use_matcher() { return &data_use_matcher_; } |
79 | 85 |
80 void RegisterURLRegexes(const std::vector<std::string>& app_package_name, | 86 void RegisterURLRegexes(const std::vector<std::string>& app_package_name, |
81 const std::vector<std::string>& domain_path_regex, | 87 const std::vector<std::string>& domain_path_regex, |
82 const std::vector<std::string>& label) { | 88 const std::vector<std::string>& label) { |
83 data_use_matcher_.RegisterURLRegexes(app_package_name, domain_path_regex, | 89 data_use_matcher_.RegisterURLRegexes(app_package_name, domain_path_regex, |
84 label); | 90 label); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 base::TimeDelta::FromMilliseconds(10001)); | 538 base::TimeDelta::FromMilliseconds(10001)); |
533 | 539 |
534 EXPECT_TRUE(IsExpired(0)); | 540 EXPECT_TRUE(IsExpired(0)); |
535 EXPECT_FALSE(data_use_matcher()->MatchesURL(GURL(kRegexFoo), &got_label)); | 541 EXPECT_FALSE(data_use_matcher()->MatchesURL(GURL(kRegexFoo), &got_label)); |
536 EXPECT_FALSE(data_use_matcher()->MatchesAppPackageName(kAppFoo, &got_label)); | 542 EXPECT_FALSE(data_use_matcher()->MatchesAppPackageName(kAppFoo, &got_label)); |
537 } | 543 } |
538 | 544 |
539 } // namespace android | 545 } // namespace android |
540 | 546 |
541 } // namespace chrome | 547 } // namespace chrome |
OLD | NEW |