OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber_service.h
" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h" |
| 10 #include "chrome/browser/io_thread.h" |
| 11 #include "chrome/browser/prefs/browser_prefs.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "chrome/test/base/testing_io_thread_state.h" |
| 14 #include "components/prefs/testing_pref_service.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "content/public/test/test_utils.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 namespace data_use_measurement { |
| 20 |
| 21 class ChromeDataUseAscriberServiceTest : public testing::Test { |
| 22 protected: |
| 23 void SetUp() override { |
| 24 prefs_ = base::MakeUnique<TestingPrefServiceSimple>(); |
| 25 chrome::RegisterLocalState(prefs_->registry()); |
| 26 TestingBrowserProcess::GetGlobal()->SetLocalState(prefs_.get()); |
| 27 |
| 28 testing_io_thread_state_ = base::MakeUnique<chrome::TestingIOThreadState>(); |
| 29 testing_io_thread_state_->io_thread_state() |
| 30 ->globals() |
| 31 ->data_use_ascriber.reset( |
| 32 new data_use_measurement::ChromeDataUseAscriber()); |
| 33 service_ = base::MakeUnique<ChromeDataUseAscriberService>(); |
| 34 |
| 35 base::RunLoop().RunUntilIdle(); |
| 36 } |
| 37 |
| 38 void TearDown() override { |
| 39 testing_io_thread_state_.reset(); |
| 40 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
| 41 } |
| 42 |
| 43 ChromeDataUseAscriber* ascriber() { return service_->ascriber_; } |
| 44 |
| 45 private: |
| 46 // |thread_bundle_| must be the first field to ensure that threads are |
| 47 // constructed first and destroyed last. |
| 48 content::TestBrowserThreadBundle thread_bundle_; |
| 49 std::unique_ptr<ChromeDataUseAscriberService> service_; |
| 50 std::unique_ptr<chrome::TestingIOThreadState> testing_io_thread_state_; |
| 51 std::unique_ptr<TestingPrefServiceSimple> prefs_; |
| 52 }; |
| 53 |
| 54 TEST_F(ChromeDataUseAscriberServiceTest, Initialization) { |
| 55 EXPECT_NE(nullptr, ascriber()); |
| 56 } |
| 57 |
| 58 } // namespace data_use_measurement |
OLD | NEW |