OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_reporter.h" | 5 #include "chrome/browser/android/data_usage/external_data_use_reporter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/test/histogram_tester.h" | 19 #include "base/test/histogram_tester.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "chrome/browser/android/data_usage/data_use_tab_model.h" | 21 #include "chrome/browser/android/data_usage/data_use_tab_model.h" |
22 #include "chrome/browser/android/data_usage/external_data_use_observer.h" | 22 #include "chrome/browser/android/data_usage/external_data_use_observer.h" |
| 23 #include "chrome/test/base/testing_browser_process.h" |
| 24 #include "chrome/test/base/testing_profile.h" |
| 25 #include "chrome/test/base/testing_profile_manager.h" |
23 #include "components/data_usage/core/data_use.h" | 26 #include "components/data_usage/core/data_use.h" |
24 #include "components/data_usage/core/data_use_aggregator.h" | 27 #include "components/data_usage/core/data_use_aggregator.h" |
25 #include "components/sessions/core/session_id.h" | 28 #include "components/sessions/core/session_id.h" |
26 #include "components/variations/variations_associated_data.h" | 29 #include "components/variations/variations_associated_data.h" |
27 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
29 #include "net/base/network_change_notifier.h" | 32 #include "net/base/network_change_notifier.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "url/gurl.h" | 34 #include "url/gurl.h" |
32 | 35 |
(...skipping 18 matching lines...) Expand all Loading... |
51 | 54 |
52 namespace chrome { | 55 namespace chrome { |
53 | 56 |
54 namespace android { | 57 namespace android { |
55 | 58 |
56 class ExternalDataUseReporterTest : public testing::Test { | 59 class ExternalDataUseReporterTest : public testing::Test { |
57 public: | 60 public: |
58 void SetUp() override { | 61 void SetUp() override { |
59 thread_bundle_.reset(new content::TestBrowserThreadBundle( | 62 thread_bundle_.reset(new content::TestBrowserThreadBundle( |
60 content::TestBrowserThreadBundle::IO_MAINLOOP)); | 63 content::TestBrowserThreadBundle::IO_MAINLOOP)); |
| 64 profile_manager_.reset( |
| 65 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 66 EXPECT_TRUE(profile_manager_->SetUp()); |
| 67 profile_ = profile_manager_->CreateTestingProfile("p1"); |
| 68 |
61 io_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( | 69 io_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( |
62 content::BrowserThread::IO); | 70 content::BrowserThread::IO); |
63 ui_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( | 71 ui_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( |
64 content::BrowserThread::UI); | 72 content::BrowserThread::UI); |
65 data_use_aggregator_.reset( | 73 data_use_aggregator_.reset( |
66 new data_usage::DataUseAggregator(nullptr, nullptr)); | 74 new data_usage::DataUseAggregator(nullptr, nullptr)); |
67 external_data_use_observer_.reset(new ExternalDataUseObserver( | 75 external_data_use_observer_.reset(new ExternalDataUseObserver( |
68 data_use_aggregator_.get(), io_task_runner_.get(), | 76 data_use_aggregator_.get(), io_task_runner_.get(), |
69 ui_task_runner_.get())); | 77 ui_task_runner_.get())); |
70 // Wait for |external_data_use_observer_| to create the Java object. | 78 // Wait for |external_data_use_observer_| to create the Java object. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 161 |
154 int64_t default_download_bytes() const { | 162 int64_t default_download_bytes() const { |
155 return external_data_use_reporter()->data_use_report_min_bytes_; | 163 return external_data_use_reporter()->data_use_report_min_bytes_; |
156 } | 164 } |
157 | 165 |
158 private: | 166 private: |
159 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_; | 167 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
160 std::unique_ptr<data_usage::DataUseAggregator> data_use_aggregator_; | 168 std::unique_ptr<data_usage::DataUseAggregator> data_use_aggregator_; |
161 std::unique_ptr<ExternalDataUseObserver> external_data_use_observer_; | 169 std::unique_ptr<ExternalDataUseObserver> external_data_use_observer_; |
162 | 170 |
| 171 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 172 |
| 173 // Test profile used by the tests is owned by |profile_manager_|. |
| 174 TestingProfile* profile_; |
| 175 |
163 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 176 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
164 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 177 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
165 }; | 178 }; |
166 | 179 |
167 // Verifies that buffer size does not exceed the specified limit. | 180 // Verifies that buffer size does not exceed the specified limit. |
168 TEST_F(ExternalDataUseReporterTest, BufferSize) { | 181 TEST_F(ExternalDataUseReporterTest, BufferSize) { |
169 base::HistogramTester histogram_tester; | 182 base::HistogramTester histogram_tester; |
170 | 183 |
171 AddDefaultMatchingRule(); | 184 AddDefaultMatchingRule(); |
172 TriggerTabTrackingOnDefaultTab(); | 185 TriggerTabTrackingOnDefaultTab(); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 EXPECT_EQ( | 560 EXPECT_EQ( |
548 base::TimeDelta::FromMilliseconds(kDefaultMaxDataReportSubmitWaitMsec), | 561 base::TimeDelta::FromMilliseconds(kDefaultMaxDataReportSubmitWaitMsec), |
549 external_data_use_reporter()->data_report_submit_timeout_); | 562 external_data_use_reporter()->data_report_submit_timeout_); |
550 EXPECT_EQ(kDataUseReportMinBytes, | 563 EXPECT_EQ(kDataUseReportMinBytes, |
551 external_data_use_reporter()->data_use_report_min_bytes_); | 564 external_data_use_reporter()->data_use_report_min_bytes_); |
552 } | 565 } |
553 | 566 |
554 } // namespace android | 567 } // namespace android |
555 | 568 |
556 } // namespace chrome | 569 } // namespace chrome |
OLD | NEW |