| 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/external_data_use_observer.h" | 5 #include "chrome/browser/android/data_usage/external_data_use_observer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | 20 #include "chrome/browser/android/data_usage/data_use_tab_model.h" |
| 21 #include "chrome/test/base/testing_browser_process.h" |
| 22 #include "chrome/test/base/testing_profile.h" |
| 23 #include "chrome/test/base/testing_profile_manager.h" |
| 21 #include "components/data_usage/core/data_use.h" | 24 #include "components/data_usage/core/data_use.h" |
| 22 #include "components/data_usage/core/data_use_aggregator.h" | 25 #include "components/data_usage/core/data_use_aggregator.h" |
| 23 #include "components/sessions/core/session_id.h" | 26 #include "components/sessions/core/session_id.h" |
| 24 #include "components/variations/variations_associated_data.h" | 27 #include "components/variations/variations_associated_data.h" |
| 25 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 27 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 30 | 33 |
| 31 namespace { | 34 namespace { |
| 32 | 35 |
| 33 const char kDefaultLabel[] = "label"; | 36 const char kDefaultLabel[] = "label"; |
| 34 const SessionID::id_type kDefaultTabId = 0; | 37 const SessionID::id_type kDefaultTabId = 0; |
| 35 const char kDefaultURL[] = "http://www.google.com/#q=abc"; | 38 const char kDefaultURL[] = "http://www.google.com/#q=abc"; |
| 36 | 39 |
| 37 } // namespace | 40 } // namespace |
| 38 | 41 |
| 39 namespace chrome { | 42 namespace chrome { |
| 40 | 43 |
| 41 namespace android { | 44 namespace android { |
| 42 | 45 |
| 43 class ExternalDataUseObserverTest : public testing::Test { | 46 class ExternalDataUseObserverTest : public testing::Test { |
| 44 public: | 47 public: |
| 45 void SetUp() override { | 48 void SetUp() override { |
| 46 thread_bundle_.reset(new content::TestBrowserThreadBundle( | 49 thread_bundle_.reset(new content::TestBrowserThreadBundle( |
| 47 content::TestBrowserThreadBundle::IO_MAINLOOP)); | 50 content::TestBrowserThreadBundle::IO_MAINLOOP)); |
| 51 profile_manager_.reset( |
| 52 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 53 EXPECT_TRUE(profile_manager_->SetUp()); |
| 54 profile_ = profile_manager_->CreateTestingProfile("p1"); |
| 55 |
| 48 io_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( | 56 io_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( |
| 49 content::BrowserThread::IO); | 57 content::BrowserThread::IO); |
| 50 ui_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( | 58 ui_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( |
| 51 content::BrowserThread::UI); | 59 content::BrowserThread::UI); |
| 52 data_use_aggregator_.reset( | 60 data_use_aggregator_.reset( |
| 53 new data_usage::DataUseAggregator(nullptr, nullptr)); | 61 new data_usage::DataUseAggregator(nullptr, nullptr)); |
| 54 external_data_use_observer_.reset(new ExternalDataUseObserver( | 62 external_data_use_observer_.reset(new ExternalDataUseObserver( |
| 55 data_use_aggregator_.get(), io_task_runner_.get(), | 63 data_use_aggregator_.get(), io_task_runner_.get(), |
| 56 ui_task_runner_.get())); | 64 ui_task_runner_.get())); |
| 57 // Wait for |external_data_use_observer_| to create the Java object. | 65 // Wait for |external_data_use_observer_| to create the Java object. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 122 |
| 115 ExternalDataUseObserver* external_data_use_observer() const { | 123 ExternalDataUseObserver* external_data_use_observer() const { |
| 116 return external_data_use_observer_.get(); | 124 return external_data_use_observer_.get(); |
| 117 } | 125 } |
| 118 | 126 |
| 119 private: | 127 private: |
| 120 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_; | 128 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
| 121 std::unique_ptr<data_usage::DataUseAggregator> data_use_aggregator_; | 129 std::unique_ptr<data_usage::DataUseAggregator> data_use_aggregator_; |
| 122 std::unique_ptr<ExternalDataUseObserver> external_data_use_observer_; | 130 std::unique_ptr<ExternalDataUseObserver> external_data_use_observer_; |
| 123 | 131 |
| 132 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 133 |
| 134 // Test profile used by the tests is owned by |profile_manager_|. |
| 135 TestingProfile* profile_; |
| 136 |
| 124 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 137 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 125 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 138 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 126 }; | 139 }; |
| 127 | 140 |
| 128 // Verifies that the external data use observer is registered as an observer | 141 // Verifies that the external data use observer is registered as an observer |
| 129 // only when at least one matching rule is present. | 142 // only when at least one matching rule is present. |
| 130 TEST_F(ExternalDataUseObserverTest, RegisteredAsDataUseObserver) { | 143 TEST_F(ExternalDataUseObserverTest, RegisteredAsDataUseObserver) { |
| 131 EXPECT_FALSE(external_data_use_observer()->registered_as_data_use_observer_); | 144 EXPECT_FALSE(external_data_use_observer()->registered_as_data_use_observer_); |
| 132 | 145 |
| 133 AddDefaultMatchingRule(); | 146 AddDefaultMatchingRule(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 257 |
| 245 // Create another ExternalDataUseObserver object. | 258 // Create another ExternalDataUseObserver object. |
| 246 ReplaceExternalDataUseObserver(variation_params); | 259 ReplaceExternalDataUseObserver(variation_params); |
| 247 EXPECT_EQ(base::TimeDelta::FromSeconds(kFetchMatchingRulesDurationSeconds), | 260 EXPECT_EQ(base::TimeDelta::FromSeconds(kFetchMatchingRulesDurationSeconds), |
| 248 external_data_use_observer()->fetch_matching_rules_duration_); | 261 external_data_use_observer()->fetch_matching_rules_duration_); |
| 249 } | 262 } |
| 250 | 263 |
| 251 } // namespace android | 264 } // namespace android |
| 252 | 265 |
| 253 } // namespace chrome | 266 } // namespace chrome |
| OLD | NEW |