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/run_loop.h" | |
12 #include "base/test/test_simple_task_runner.h" | |
13 #include "base/threading/thread_task_runner_handle.h" | |
14 #include "components/metrics/metrics_service.h" | |
15 #include "components/metrics/stability_metrics_helper.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 "content/public/browser/notification_service.h" | |
21 #include "content/public/test/test_browser_thread_bundle.h" | |
22 #include "net/url_request/url_request_context_getter.h" | |
23 #include "net/url_request/url_request_test_util.h" | |
24 #include "testing/gmock/include/gmock/gmock.h" | |
25 #include "testing/gtest/include/gtest/gtest.h" | |
26 | |
27 namespace blimp { | |
28 namespace engine { | |
29 | |
30 namespace { | |
31 // Shows notifications which correspond to PersistentPrefStore's reading errors. | |
32 void HandleReadError(PersistentPrefStore::PrefReadError error) { | |
33 } | |
34 } // namespace | |
35 | |
36 class BlimpMetricsServiceClientTest : public testing::Test { | |
37 public: | |
38 BlimpMetricsServiceClientTest() {} | |
39 | |
40 protected: | |
41 void SetUp() override { | |
42 // Set up NotificationService for StabilityMetricsHelper to use. | |
43 notification_service_.reset(content::NotificationService::Create()); | |
44 | |
45 // Set up PrefRegistry. | |
46 pref_registry_ = new user_prefs::PrefRegistrySyncable(); | |
47 metrics::MetricsService::RegisterPrefs(pref_registry_.get()); | |
48 metrics::StabilityMetricsHelper::RegisterPrefs(pref_registry_.get()); | |
49 | |
50 // Set up PrefService. | |
51 PrefServiceFactory pref_service_factory; | |
52 pref_service_factory.set_user_prefs(new InMemoryPrefStore()); | |
53 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); | |
54 pref_service_ = pref_service_factory.Create(pref_registry_.get()); | |
55 ASSERT_NE(nullptr, pref_service_.get()); | |
56 | |
57 // Set up RequestContextGetter. | |
58 request_context_getter_ = new net::TestURLRequestContextGetter( | |
59 base::ThreadTaskRunnerHandle::Get()); | |
60 | |
61 // Set task runner global for MetricsService. | |
62 base::SetRecordActionTaskRunner(base::ThreadTaskRunnerHandle::Get()); | |
63 | |
64 // Set up BlimpMetricsServiceClient | |
65 client_.reset(new BlimpMetricsServiceClient(pref_service_.get(), | |
66 request_context_getter_)); | |
67 base::RunLoop().RunUntilIdle(); | |
68 | |
69 // Checks of InitializeBlimpMetrics. | |
70 // TODO(jessicag): Check request_context_getter_ set. | |
71 // PrefService unique pointer set up by BlimpMetricsServiceClient. | |
72 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS, | |
73 pref_service_->GetInitializationStatus()); | |
74 | |
75 // TODO(jessicag): Confirm registration of metrics providers. | |
76 // TODO(jessicag): MetricsService initializes recording state. | |
77 // TODO(jessicag): Confirm MetricsService::Start() is called. | |
78 } | |
79 | |
80 void TearDown() override { | |
81 // Trigger BlimpMetricsServiceClientTest destructor. | |
82 client_.reset(); | |
83 ASSERT_EQ(nullptr, client_.get()); | |
84 base::RunLoop().RunUntilIdle(); | |
85 | |
86 // PrefService unaffected | |
87 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS, | |
88 pref_service_->GetInitializationStatus()); | |
89 | |
90 // Clean up static variable in MetricService to avoid impacting other tests. | |
91 metrics::MetricsService::SetExecutionPhase( | |
92 metrics::MetricsService::UNINITIALIZED_PHASE, | |
93 pref_service_.get()); | |
94 } | |
95 | |
96 private: | |
97 content::TestBrowserThreadBundle thread_bundle_; | |
98 std::unique_ptr<content::NotificationService> notification_service_; | |
99 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; | |
100 std::unique_ptr<PrefService> pref_service_; | |
101 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | |
102 std::unique_ptr<BlimpMetricsServiceClient> client_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(BlimpMetricsServiceClientTest); | |
105 }; | |
106 | |
107 TEST_F(BlimpMetricsServiceClientTest, CtorDtor) { | |
108 // Confirm construction and destruction work as expected. | |
109 } | |
110 | |
111 } // namespace engine | |
112 } // namespace blimp | |
OLD | NEW |