Chromium Code Reviews| Index: blimp/engine/app/blimp_metrics_service_client_unittest.cc |
| diff --git a/blimp/engine/app/blimp_metrics_service_client_unittest.cc b/blimp/engine/app/blimp_metrics_service_client_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..37c361ff35a91f7243060d23c2e962bf439f508f |
| --- /dev/null |
| +++ b/blimp/engine/app/blimp_metrics_service_client_unittest.cc |
| @@ -0,0 +1,95 @@ |
| +// 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 "blimp/engine/app/blimp_metrics_service_client.h" |
| + |
| +#include <list> |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "base/test/test_simple_task_runner.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#include "components/metrics/metrics_service.h" |
| +#include "components/pref_registry/pref_registry_syncable.h" |
| +#include "components/prefs/in_memory_pref_store.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "components/prefs/pref_service_factory.h" |
| +#include "net/url_request/url_request_context_getter.h" |
| +#include "net/url_request/url_request_test_util.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blimp { |
| +namespace engine { |
| +// Shows notifications which correspond to PersistentPrefStore's reading errors. |
|
Wez
2016/05/01 00:12:59
This function just seems to be a no-op dummy used
|
| +void HandleReadError(PersistentPrefStore::PrefReadError error) { |
| +} |
| + |
| +class BlimpMetricsServiceClientTest : public testing::Test { |
| + protected: |
| + void Initialize(); |
| + void Finalize(); |
|
Wez
2016/05/01 00:12:59
Why not override Setup() and Teardown() from testi
|
| + |
| + void SetUpPrefRegistry(); |
|
Wez
2016/05/01 00:12:59
micro-nit: I believe we normally capitalize "setup
|
| + void SetUpPrefService(); |
| + void SetUpRequestContextGetter(); |
| + |
| + base::MessageLoop message_loop_; |
| + scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; |
| + std::unique_ptr<PrefService> pref_service_; |
| + scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| +}; |
| + |
| +void BlimpMetricsServiceClientTest::Initialize() { |
| + SetUpPrefRegistry(); |
| + SetUpPrefService(); |
| + SetUpRequestContextGetter(); |
| + ASSERT_NE(nullptr, pref_service_.get()); |
|
Wez
2016/05/01 00:12:59
Can you use ASSERT_TRUE(pref_service_) here?
|
| + base::SetRecordActionTaskRunner(message_loop_.task_runner()); |
| + InitializeBlimpMetrics(std::move(pref_service_), request_context_getter_); |
|
Wez
2016/05/01 00:12:59
Since you're passing the pref-service here, and cr
|
| + base::RunLoop().RunUntilIdle(); |
| +} |
| + |
| +void BlimpMetricsServiceClientTest::Finalize() { |
| + FinalizeBlimpMetrics(); |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| + |
| +void BlimpMetricsServiceClientTest::SetUpPrefRegistry() { |
| + pref_registry_ = new user_prefs::PrefRegistrySyncable(); |
| + metrics::MetricsService::RegisterPrefs(pref_registry_.get()); |
| +} |
| + |
| +void BlimpMetricsServiceClientTest::SetUpPrefService() { |
| + PrefServiceFactory pref_service_factory; |
| + pref_service_factory.set_user_prefs(new InMemoryPrefStore()); |
| + pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); |
| + pref_service_ = pref_service_factory.Create(pref_registry_.get()); |
| +} |
| + |
| +void BlimpMetricsServiceClientTest::SetUpRequestContextGetter() { |
| + request_context_getter_ = |
| + new net::TestURLRequestContextGetter(base::ThreadTaskRunnerHandle::Get()); |
| +} |
| + |
| +TEST_F(BlimpMetricsServiceClientTest, InitializeFinalize) { |
| + Initialize(); |
| + |
| + // TODO(jessicag): Check request_context_getter_ set. |
|
Wez
2016/05/01 00:12:59
Is this a reminder to just have ASSERT_TRUE(reques
|
| + // PrefService unique pointer moved to BlimpMetricsServiceClient. |
| + EXPECT_EQ(nullptr, pref_service_.get()); |
| + |
| + // TODO(jessicag): Confirm registration of metrics providers. |
| + // TODO(jessicag): MetricsService initializes recording state. |
| + // TODO(jessicag): Confirm MetricsService::Start() is called. |
|
Wez
2016/05/01 00:12:59
If the MetricsService is too much of a black-box f
|
| + |
| + Finalize(); |
| + |
| + // TODO(jessicag): Ensure MetricsService::Stop() is called. |
| +} |
| + |
| +} // namespace engine |
| +} // namespace blimp |