| 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/bind.h" |
| 14 #include "base/callback.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 16 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 17 #include "base/time/tick_clock.h" | 19 #include "base/time/tick_clock.h" |
| 18 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "chrome/browser/android/data_usage/data_use_tab_model.h" |
| 19 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" | 22 #include "chrome/browser/android/data_usage/external_data_use_observer_bridge.h" |
| 20 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 24 | 27 |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 const char kUMAMatchingRulesCountValidHistogram[] = | 30 const char kUMAMatchingRulesCountValidHistogram[] = |
| 28 "DataUsage.MatchingRulesCount.Valid"; | 31 "DataUsage.MatchingRulesCount.Valid"; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 namespace android { | 74 namespace android { |
| 72 | 75 |
| 73 class ExternalDataUseObserver; | 76 class ExternalDataUseObserver; |
| 74 | 77 |
| 75 class DataUseMatcherTest : public testing::Test { | 78 class DataUseMatcherTest : public testing::Test { |
| 76 public: | 79 public: |
| 77 DataUseMatcherTest() | 80 DataUseMatcherTest() |
| 78 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 81 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 79 external_data_use_observer_bridge_( | 82 external_data_use_observer_bridge_( |
| 80 new TestExternalDataUseObserverBridge()), | 83 new TestExternalDataUseObserverBridge()), |
| 81 data_use_matcher_(base::WeakPtr<DataUseTabModel>(), | 84 data_use_matcher_( |
| 82 external_data_use_observer_bridge_.get(), | 85 base::Bind(&DataUseTabModel::OnTrackingLabelRemoved, |
| 83 base::TimeDelta::FromSeconds( | 86 base::WeakPtr<DataUseTabModel>()), |
| 84 kDefaultMatchingRuleExpirationDurationSeconds)) {} | 87 base::Bind( |
| 88 &ExternalDataUseObserverBridge::ShouldRegisterAsDataUseObserver, |
| 89 base::Unretained(external_data_use_observer_bridge_.get())), |
| 90 base::TimeDelta::FromSeconds( |
| 91 kDefaultMatchingRuleExpirationDurationSeconds)) {} |
| 85 | 92 |
| 86 DataUseMatcher* data_use_matcher() { return &data_use_matcher_; } | 93 DataUseMatcher* data_use_matcher() { return &data_use_matcher_; } |
| 87 | 94 |
| 88 void RegisterURLRegexes(const std::vector<std::string>& app_package_name, | 95 void RegisterURLRegexes(const std::vector<std::string>& app_package_name, |
| 89 const std::vector<std::string>& domain_path_regex, | 96 const std::vector<std::string>& domain_path_regex, |
| 90 const std::vector<std::string>& label) { | 97 const std::vector<std::string>& label) { |
| 91 data_use_matcher_.RegisterURLRegexes(app_package_name, domain_path_regex, | 98 data_use_matcher_.RegisterURLRegexes(app_package_name, domain_path_regex, |
| 92 label); | 99 label); |
| 93 } | 100 } |
| 94 | 101 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 base::TimeDelta::FromMilliseconds(10001)); | 549 base::TimeDelta::FromMilliseconds(10001)); |
| 543 | 550 |
| 544 EXPECT_TRUE(IsExpired(0)); | 551 EXPECT_TRUE(IsExpired(0)); |
| 545 EXPECT_FALSE(data_use_matcher()->MatchesURL(GURL(kRegexFoo), &got_label)); | 552 EXPECT_FALSE(data_use_matcher()->MatchesURL(GURL(kRegexFoo), &got_label)); |
| 546 EXPECT_FALSE(data_use_matcher()->MatchesAppPackageName(kAppFoo, &got_label)); | 553 EXPECT_FALSE(data_use_matcher()->MatchesAppPackageName(kAppFoo, &got_label)); |
| 547 } | 554 } |
| 548 | 555 |
| 549 } // namespace android | 556 } // namespace android |
| 550 | 557 |
| 551 } // namespace chrome | 558 } // namespace chrome |
| OLD | NEW |