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

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: Follow up on comments. 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
28 namespace {
29 // Shows notifications which correspond to PersistentPrefStore's reading errors.
30 void HandleReadError(PersistentPrefStore::PrefReadError error) {
31 }
32 } // namespace
33
34 class BlimpMetricsServiceClientTest : public testing::Test {
35 public:
36 BlimpMetricsServiceClientTest() {}
37
38 protected:
39 void SetUp() override {
40 // Set up PrefRegistry
41 pref_registry_ = new user_prefs::PrefRegistrySyncable();
42 metrics::MetricsService::RegisterPrefs(pref_registry_.get());
43
44 // Set up PrefService
45 PrefServiceFactory pref_service_factory;
46 pref_service_factory.set_user_prefs(new InMemoryPrefStore());
47 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError));
48 pref_service_ = pref_service_factory.Create(pref_registry_.get());
49 ASSERT_NE(nullptr, pref_service_.get());
50
51 // Set up RequestContextGetter
52 request_context_getter_ = new net::TestURLRequestContextGetter(
53 base::ThreadTaskRunnerHandle::Get());
54
55 // Set task runner global for MetricsService
56 base::SetRecordActionTaskRunner(message_loop_.task_runner());
57
58 // Set up BlimpMetricsServiceClient
59 client_.reset(new BlimpMetricsServiceClient(pref_service_.get(),
60 request_context_getter_));
61 base::RunLoop().RunUntilIdle();
62
63 // Checks of InitializeBlimpMetrics.
64 // TODO(jessicag): Check request_context_getter_ set.
65 // PrefService unique pointer set up by BlimpMetricsServiceClient.
66 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS,
67 pref_service_->GetInitializationStatus());
68
69 // TODO(jessicag): Confirm registration of metrics providers.
70 // TODO(jessicag): MetricsService initializes recording state.
71 // TODO(jessicag): Confirm MetricsService::Start() is called.
72 }
73
74 void TearDown() override {
75 // Trigger BlimpMetricsServiceClientTest destructor.
76 client_.reset();
77 ASSERT_EQ(nullptr, client_.get());
78 base::RunLoop().RunUntilIdle();
79
80 // PrefService unaffected
81 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS,
82 pref_service_->GetInitializationStatus());
83
84 // Clean up static variable in MetricService to avoid impacting other tests.
85 metrics::MetricsService::SetExecutionPhase(
86 metrics::MetricsService::UNINITIALIZED_PHASE,
87 pref_service_.get());
88 }
89
90 private:
91 base::MessageLoop message_loop_;
92 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
93 std::unique_ptr<PrefService> pref_service_;
94 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
95 std::unique_ptr<BlimpMetricsServiceClient> client_;
96
97 DISALLOW_COPY_AND_ASSIGN(BlimpMetricsServiceClientTest);
98 };
99
100 TEST_F(BlimpMetricsServiceClientTest, CtorDtor) {
101 // Confirm construction and destruction work as expected.
102 }
103
104 } // namespace engine
105 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/engine/app/blimp_metrics_service_client.cc ('k') | blimp/engine/common/blimp_browser_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698