Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: blimp/engine/app/blimp_metrics_service_client_unittest.cc

Issue 1945393002: Create and integrate a metrics service client into Blimp engine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Additional comments follow up. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
28 void HandleReadError(PersistentPrefStore::PrefReadError error) {
Bernhard Bauer 2016/05/11 08:53:14 Put this into an anonymous namespace?
Jess 2016/05/11 17:07:25 Done.
29 }
30
31 class BlimpMetricsServiceClientTest : public testing::Test {
32 protected:
33 void SetUp() override;
Kevin M 2016/05/11 17:08:42 optional nit: since this is in a .cc file, you can
Jess 2016/05/11 20:17:30 Done.
34 void TearDown() override;
35
36 void SetUpPrefRegistry();
Kevin M 2016/05/11 17:08:42 nit: Can you just merge these into commented regio
Jess 2016/05/11 20:17:30 Done.
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 std::unique_ptr<BlimpMetricsServiceClient> client_;
Kevin M 2016/05/11 17:08:42 DISALLOW_COPY_AND_ASSIGN(...);
Jess 2016/05/11 20:17:30 Done.
45 };
46
47 void BlimpMetricsServiceClientTest::SetUp() {
48 // Set up all deps and then InitializeBlimpMetrics.
49 SetUpPrefRegistry();
50 SetUpPrefService();
51 SetUpRequestContextGetter();
52 base::SetRecordActionTaskRunner(message_loop_.task_runner());
53 client_.reset(new BlimpMetricsServiceClient(pref_service_.get(),
54 request_context_getter_));
55 base::RunLoop().RunUntilIdle();
56
57 // Checks of InitializeBlimpMetrics.
58 // TODO(jessicag): Check request_context_getter_ set.
59 // PrefService unique pointer set up by BlimpMetricsServiceClient.
60 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS,
61 pref_service_->GetInitializationStatus());
62
63 // TODO(jessicag): Confirm registration of metrics providers.
64 // TODO(jessicag): MetricsService initializes recording state.
65 // TODO(jessicag): Confirm MetricsService::Start() is called.
66 }
67
68 void BlimpMetricsServiceClientTest::TearDown() {
69 // Trigger BlimpMetricsServiceClientTest destructor.
70 client_.reset();
71 ASSERT_EQ(nullptr, client_.get());
72 base::RunLoop().RunUntilIdle();
73 // TODO(jessicag): Ensure MetricsService::Stop() is called.
74
75 // PrefService unaffected
76 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS,
77 pref_service_->GetInitializationStatus());
78
79 // Clean up static variable in MetricService to avoid impacting other tests.
80 metrics::MetricsService::SetExecutionPhase(
81 metrics::MetricsService::UNINITIALIZED_PHASE,
82 pref_service_.get());
83 }
84
85 void BlimpMetricsServiceClientTest::SetUpPrefRegistry() {
86 pref_registry_ = new user_prefs::PrefRegistrySyncable();
87 metrics::MetricsService::RegisterPrefs(pref_registry_.get());
88 }
89
90 void BlimpMetricsServiceClientTest::SetUpPrefService() {
91 PrefServiceFactory pref_service_factory;
92 pref_service_factory.set_user_prefs(new InMemoryPrefStore());
93 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError));
94 pref_service_ = pref_service_factory.Create(pref_registry_.get());
95 ASSERT_NE(nullptr, pref_service_.get());
96 }
97
98 void BlimpMetricsServiceClientTest::SetUpRequestContextGetter() {
99 request_context_getter_ =
100 new net::TestURLRequestContextGetter(base::ThreadTaskRunnerHandle::Get());
101 }
102
103 TEST_F(BlimpMetricsServiceClientTest, CtorDtor) {
104 // Confirm construction and destruction work as expected.
105 }
106
107 } // namespace engine
108 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698