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