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 "blimp/engine/app/blimp_metrics_service_client.h" | |
| 6 | |
| 7 #include <list> | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/run_loop.h" | |
| 13 #include "base/test/test_simple_task_runner.h" | |
| 14 #include "base/thread_task_runner_handle.h" | |
| 15 #include "components/metrics/metrics_service.h" | |
| 16 #include "components/pref_registry/pref_registry_syncable.h" | |
| 17 #include "components/prefs/in_memory_pref_store.h" | |
| 18 #include "components/prefs/pref_service.h" | |
| 19 #include "components/prefs/pref_service_factory.h" | |
| 20 #include "net/url_request/url_request_context_getter.h" | |
| 21 #include "net/url_request/url_request_test_util.h" | |
| 22 #include "testing/gmock/include/gmock/gmock.h" | |
| 23 #include "testing/gtest/include/gtest/gtest.h" | |
| 24 | |
| 25 namespace blimp { | |
| 26 namespace engine { | |
| 27 // 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
| |
| 28 void HandleReadError(PersistentPrefStore::PrefReadError error) { | |
| 29 } | |
| 30 | |
| 31 class BlimpMetricsServiceClientTest : public testing::Test { | |
| 32 protected: | |
| 33 void Initialize(); | |
| 34 void Finalize(); | |
|
Wez
2016/05/01 00:12:59
Why not override Setup() and Teardown() from testi
| |
| 35 | |
| 36 void SetUpPrefRegistry(); | |
|
Wez
2016/05/01 00:12:59
micro-nit: I believe we normally capitalize "setup
| |
| 37 void SetUpPrefService(); | |
| 38 void SetUpRequestContextGetter(); | |
| 39 | |
| 40 base::MessageLoop message_loop_; | |
| 41 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; | |
| 42 std::unique_ptr<PrefService> pref_service_; | |
| 43 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | |
| 44 }; | |
| 45 | |
| 46 void BlimpMetricsServiceClientTest::Initialize() { | |
| 47 SetUpPrefRegistry(); | |
| 48 SetUpPrefService(); | |
| 49 SetUpRequestContextGetter(); | |
| 50 ASSERT_NE(nullptr, pref_service_.get()); | |
|
Wez
2016/05/01 00:12:59
Can you use ASSERT_TRUE(pref_service_) here?
| |
| 51 base::SetRecordActionTaskRunner(message_loop_.task_runner()); | |
| 52 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
| |
| 53 base::RunLoop().RunUntilIdle(); | |
| 54 } | |
| 55 | |
| 56 void BlimpMetricsServiceClientTest::Finalize() { | |
| 57 FinalizeBlimpMetrics(); | |
| 58 base::RunLoop().RunUntilIdle(); | |
| 59 } | |
| 60 | |
| 61 void BlimpMetricsServiceClientTest::SetUpPrefRegistry() { | |
| 62 pref_registry_ = new user_prefs::PrefRegistrySyncable(); | |
| 63 metrics::MetricsService::RegisterPrefs(pref_registry_.get()); | |
| 64 } | |
| 65 | |
| 66 void BlimpMetricsServiceClientTest::SetUpPrefService() { | |
| 67 PrefServiceFactory pref_service_factory; | |
| 68 pref_service_factory.set_user_prefs(new InMemoryPrefStore()); | |
| 69 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | |
| 70 pref_service_ = pref_service_factory.Create(pref_registry_.get()); | |
| 71 } | |
| 72 | |
| 73 void BlimpMetricsServiceClientTest::SetUpRequestContextGetter() { | |
| 74 request_context_getter_ = | |
| 75 new net::TestURLRequestContextGetter(base::ThreadTaskRunnerHandle::Get()); | |
| 76 } | |
| 77 | |
| 78 TEST_F(BlimpMetricsServiceClientTest, InitializeFinalize) { | |
| 79 Initialize(); | |
| 80 | |
| 81 // TODO(jessicag): Check request_context_getter_ set. | |
|
Wez
2016/05/01 00:12:59
Is this a reminder to just have ASSERT_TRUE(reques
| |
| 82 // PrefService unique pointer moved to BlimpMetricsServiceClient. | |
| 83 EXPECT_EQ(nullptr, pref_service_.get()); | |
| 84 | |
| 85 // TODO(jessicag): Confirm registration of metrics providers. | |
| 86 // TODO(jessicag): MetricsService initializes recording state. | |
| 87 // 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
| |
| 88 | |
| 89 Finalize(); | |
| 90 | |
| 91 // TODO(jessicag): Ensure MetricsService::Stop() is called. | |
| 92 } | |
| 93 | |
| 94 } // namespace engine | |
| 95 } // namespace blimp | |
| OLD | NEW |