Chromium Code Reviews| Index: chrome/browser/data_use_measurement/chrome_data_use_ascriber_service_unittest.cc |
| diff --git a/chrome/browser/data_use_measurement/chrome_data_use_ascriber_service_unittest.cc b/chrome/browser/data_use_measurement/chrome_data_use_ascriber_service_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d553478889e5e88fd26f945dc2395d9205edab3a |
| --- /dev/null |
| +++ b/chrome/browser/data_use_measurement/chrome_data_use_ascriber_service_unittest.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/data_use_measurement/chrome_data_use_ascriber_service.h" |
| + |
| +#include <memory> |
| + |
| +#include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h" |
| +#include "chrome/browser/io_thread.h" |
| +#include "chrome/browser/prefs/browser_prefs.h" |
| +#include "chrome/test/base/testing_browser_process.h" |
| +#include "chrome/test/base/testing_io_thread_state.h" |
| +#include "components/prefs/testing_pref_service.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace data_use_measurement { |
| + |
| +class ChromeDataUseAscriberServiceTest : public testing::Test { |
| + protected: |
| + void SetUp() override { |
| + 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.
|
| + chrome::RegisterLocalState(prefs_->registry()); |
| + TestingBrowserProcess::GetGlobal()->SetLocalState(prefs_.get()); |
| + |
| + io_thread_.reset(new chrome::TestingIOThreadState()); |
| + io_thread_->io_thread_state()->globals()->data_use_ascriber.reset( |
| + new data_use_measurement::ChromeDataUseAscriber()); |
| + service_.reset(new ChromeDataUseAscriberService()); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| + |
| + void TearDown() override { |
| + io_thread_.reset(); |
| + 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.
|
| + } |
| + |
| + ChromeDataUseAscriber* ascriber() { return service_->ascriber_; } |
| + |
| + private: |
| + // |thread_bundle_| must be the first field to ensure that threads are |
| + // constructed first and destroyed last. |
| + content::TestBrowserThreadBundle thread_bundle_; |
| + std::unique_ptr<ChromeDataUseAscriberService> service_; |
| + std::unique_ptr<chrome::TestingIOThreadState> io_thread_; |
| + std::unique_ptr<TestingPrefServiceSimple> prefs_; |
| +}; |
| + |
| +TEST_F(ChromeDataUseAscriberServiceTest, Initialization) { |
| + EXPECT_NE(nullptr, ascriber()); |
| +} |
| + |
| +} // namespace data_use_measurement |