Chromium Code Reviews| 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_.reset(new TestingPrefServiceSimple()); | |
|
Lei Zhang
2016/09/09 20:58:42
Can you use base::MakeUnique() here and below?
Not at Google. Contact bengr
2016/09/09 21:36:37
Done.
| |
| 25 chrome::RegisterLocalState(prefs_->registry()); | |
| 26 TestingBrowserProcess::GetGlobal()->SetLocalState(prefs_.get()); | |
| 27 | |
| 28 io_thread_.reset(new chrome::TestingIOThreadState()); | |
| 29 io_thread_->io_thread_state()->globals()->data_use_ascriber.reset( | |
| 30 new data_use_measurement::ChromeDataUseAscriber()); | |
| 31 service_.reset(new ChromeDataUseAscriberService()); | |
| 32 | |
| 33 base::RunLoop().RunUntilIdle(); | |
| 34 } | |
| 35 | |
| 36 void TearDown() override { | |
| 37 io_thread_.reset(); | |
| 38 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | |
|
Lei Zhang
2016/09/09 20:58:42
s/NULL/nullptr/
Not at Google. Contact bengr
2016/09/09 21:36:37
Done.
| |
| 39 } | |
| 40 | |
| 41 ChromeDataUseAscriber* ascriber() { return service_->ascriber_; } | |
| 42 | |
| 43 private: | |
| 44 // |thread_bundle_| must be the first field to ensure that threads are | |
| 45 // constructed first and destroyed last. | |
| 46 content::TestBrowserThreadBundle thread_bundle_; | |
| 47 std::unique_ptr<ChromeDataUseAscriberService> service_; | |
| 48 std::unique_ptr<chrome::TestingIOThreadState> io_thread_; | |
| 49 std::unique_ptr<TestingPrefServiceSimple> prefs_; | |
| 50 }; | |
| 51 | |
| 52 TEST_F(ChromeDataUseAscriberServiceTest, Initialization) { | |
| 53 EXPECT_NE(nullptr, ascriber()); | |
| 54 } | |
| 55 | |
| 56 } // namespace data_use_measurement | |
| OLD | NEW |