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

Side by Side Diff: chrome/browser/android/data_usage/data_use_matcher_unittest.cc

Issue 1772273002: Remove one thread hop while fetching matching rules (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits Created 4 years, 9 months 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/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
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),
79 external_data_use_observer_bridge_(
80 new TestExternalDataUseObserverBridge()),
71 data_use_matcher_(base::WeakPtr<DataUseTabModel>(), 81 data_use_matcher_(base::WeakPtr<DataUseTabModel>(),
72 content::BrowserThread::GetMessageLoopProxyForThread( 82 external_data_use_observer_bridge_.get(),
73 content::BrowserThread::IO),
74 base::WeakPtr<ExternalDataUseObserver>(),
75 base::TimeDelta::FromSeconds( 83 base::TimeDelta::FromSeconds(
76 kDefaultMatchingRuleExpirationDurationSeconds)) {} 84 kDefaultMatchingRuleExpirationDurationSeconds)) {}
77 85
78 DataUseMatcher* data_use_matcher() { return &data_use_matcher_; } 86 DataUseMatcher* data_use_matcher() { return &data_use_matcher_; }
79 87
80 void RegisterURLRegexes(const std::vector<std::string>& app_package_name, 88 void RegisterURLRegexes(const std::vector<std::string>& app_package_name,
81 const std::vector<std::string>& domain_path_regex, 89 const std::vector<std::string>& domain_path_regex,
82 const std::vector<std::string>& label) { 90 const std::vector<std::string>& label) {
83 data_use_matcher_.RegisterURLRegexes(app_package_name, domain_path_regex, 91 data_use_matcher_.RegisterURLRegexes(app_package_name, domain_path_regex,
84 label); 92 label);
85 } 93 }
86 94
87 // Returns true if the matching rule at |index| is expired. 95 // Returns true if the matching rule at |index| is expired.
88 bool IsExpired(size_t index) { 96 bool IsExpired(size_t index) {
89 DCHECK_LT(index, data_use_matcher_.matching_rules_.size()); 97 DCHECK_LT(index, data_use_matcher_.matching_rules_.size());
90 return data_use_matcher_.matching_rules_[index]->expiration() < 98 return data_use_matcher_.matching_rules_[index]->expiration() <
91 data_use_matcher_.tick_clock_->NowTicks(); 99 data_use_matcher_.tick_clock_->NowTicks();
92 } 100 }
93 101
94 private: 102 private:
95 content::TestBrowserThreadBundle thread_bundle_; 103 content::TestBrowserThreadBundle thread_bundle_;
104 scoped_ptr<ExternalDataUseObserverBridge> external_data_use_observer_bridge_;
96 DataUseMatcher data_use_matcher_; 105 DataUseMatcher data_use_matcher_;
97 DISALLOW_COPY_AND_ASSIGN(DataUseMatcherTest); 106 DISALLOW_COPY_AND_ASSIGN(DataUseMatcherTest);
98 }; 107 };
99 108
100 TEST_F(DataUseMatcherTest, SingleRegex) { 109 TEST_F(DataUseMatcherTest, SingleRegex) {
101 const struct { 110 const struct {
102 std::string url; 111 std::string url;
103 std::string regex; 112 std::string regex;
104 bool expect_match; 113 bool expect_match;
105 int expect_count_valid_rules; 114 int expect_count_valid_rules;
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 base::TimeDelta::FromMilliseconds(10001)); 541 base::TimeDelta::FromMilliseconds(10001));
533 542
534 EXPECT_TRUE(IsExpired(0)); 543 EXPECT_TRUE(IsExpired(0));
535 EXPECT_FALSE(data_use_matcher()->MatchesURL(GURL(kRegexFoo), &got_label)); 544 EXPECT_FALSE(data_use_matcher()->MatchesURL(GURL(kRegexFoo), &got_label));
536 EXPECT_FALSE(data_use_matcher()->MatchesAppPackageName(kAppFoo, &got_label)); 545 EXPECT_FALSE(data_use_matcher()->MatchesAppPackageName(kAppFoo, &got_label));
537 } 546 }
538 547
539 } // namespace android 548 } // namespace android
540 549
541 } // namespace chrome 550 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/android/data_usage/data_use_matcher.cc ('k') | chrome/browser/android/data_usage/data_use_tab_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698