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

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

Issue 2045073002: Export stability metrics to UMA from Blimp engine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unnecessary header Created 4 years, 6 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/engine/app/blimp_metrics_service_client.h" 5 #include "blimp/engine/app/blimp_metrics_service_client.h"
6 6
7 #include <list> 7 #include <list>
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 11 #include "base/run_loop.h"
13 #include "base/test/test_simple_task_runner.h" 12 #include "base/test/test_simple_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
15 #include "components/metrics/metrics_service.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" 16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "components/prefs/in_memory_pref_store.h" 17 #include "components/prefs/in_memory_pref_store.h"
18 #include "components/prefs/pref_service.h" 18 #include "components/prefs/pref_service.h"
19 #include "components/prefs/pref_service_factory.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"
20 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
21 #include "net/url_request/url_request_test_util.h" 23 #include "net/url_request/url_request_test_util.h"
22 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
24 26
25 namespace blimp { 27 namespace blimp {
26 namespace engine { 28 namespace engine {
27 29
28 namespace { 30 namespace {
29 // Shows notifications which correspond to PersistentPrefStore's reading errors. 31 // Shows notifications which correspond to PersistentPrefStore's reading errors.
30 void HandleReadError(PersistentPrefStore::PrefReadError error) { 32 void HandleReadError(PersistentPrefStore::PrefReadError error) {
31 } 33 }
32 } // namespace 34 } // namespace
33 35
34 class BlimpMetricsServiceClientTest : public testing::Test { 36 class BlimpMetricsServiceClientTest : public testing::Test {
35 public: 37 public:
36 BlimpMetricsServiceClientTest() {} 38 BlimpMetricsServiceClientTest() {}
37 39
38 protected: 40 protected:
39 void SetUp() override { 41 void SetUp() override {
42 // Set up NotificationService
43 notification_service_.reset(content::NotificationService::Create());
44
40 // Set up PrefRegistry 45 // Set up PrefRegistry
41 pref_registry_ = new user_prefs::PrefRegistrySyncable(); 46 pref_registry_ = new user_prefs::PrefRegistrySyncable();
42 metrics::MetricsService::RegisterPrefs(pref_registry_.get()); 47 metrics::MetricsService::RegisterPrefs(pref_registry_.get());
48 metrics::StabilityMetricsHelper::RegisterPrefs(pref_registry_.get());
43 49
44 // Set up PrefService 50 // Set up PrefService
45 PrefServiceFactory pref_service_factory; 51 PrefServiceFactory pref_service_factory;
46 pref_service_factory.set_user_prefs(new InMemoryPrefStore()); 52 pref_service_factory.set_user_prefs(new InMemoryPrefStore());
47 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError)); 53 pref_service_factory.set_read_error_callback(base::Bind(&HandleReadError));
48 pref_service_ = pref_service_factory.Create(pref_registry_.get()); 54 pref_service_ = pref_service_factory.Create(pref_registry_.get());
49 ASSERT_NE(nullptr, pref_service_.get()); 55 ASSERT_NE(nullptr, pref_service_.get());
50 56
51 // Set up RequestContextGetter 57 // Set up RequestContextGetter
52 request_context_getter_ = new net::TestURLRequestContextGetter( 58 request_context_getter_ = new net::TestURLRequestContextGetter(
53 base::ThreadTaskRunnerHandle::Get()); 59 base::ThreadTaskRunnerHandle::Get());
54 60
55 // Set task runner global for MetricsService 61 // Set task runner global for MetricsService
56 base::SetRecordActionTaskRunner(message_loop_.task_runner()); 62 base::SetRecordActionTaskRunner(
63 base::MessageLoop::current()->task_runner());
57 64
58 // Set up BlimpMetricsServiceClient 65 // Set up BlimpMetricsServiceClient
59 client_.reset(new BlimpMetricsServiceClient(pref_service_.get(), 66 client_.reset(new BlimpMetricsServiceClient(pref_service_.get(),
60 request_context_getter_)); 67 request_context_getter_));
61 base::RunLoop().RunUntilIdle(); 68 base::RunLoop().RunUntilIdle();
62 69
63 // Checks of InitializeBlimpMetrics. 70 // Checks of InitializeBlimpMetrics.
64 // TODO(jessicag): Check request_context_getter_ set. 71 // TODO(jessicag): Check request_context_getter_ set.
65 // PrefService unique pointer set up by BlimpMetricsServiceClient. 72 // PrefService unique pointer set up by BlimpMetricsServiceClient.
66 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS, 73 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS,
(...skipping 14 matching lines...) Expand all
81 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS, 88 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS,
82 pref_service_->GetInitializationStatus()); 89 pref_service_->GetInitializationStatus());
83 90
84 // Clean up static variable in MetricService to avoid impacting other tests. 91 // Clean up static variable in MetricService to avoid impacting other tests.
85 metrics::MetricsService::SetExecutionPhase( 92 metrics::MetricsService::SetExecutionPhase(
86 metrics::MetricsService::UNINITIALIZED_PHASE, 93 metrics::MetricsService::UNINITIALIZED_PHASE,
87 pref_service_.get()); 94 pref_service_.get());
88 } 95 }
89 96
90 private: 97 private:
91 base::MessageLoop message_loop_; 98 content::TestBrowserThreadBundle thread_bundle_;
99 std::unique_ptr<content::NotificationService> notification_service_;
92 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; 100 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
93 std::unique_ptr<PrefService> pref_service_; 101 std::unique_ptr<PrefService> pref_service_;
102 // Needed for stability metrics provider.
Jess 2016/06/09 18:09:59 Actually it is needed by the client for several ot
xyzzyz 2016/06/09 20:01:25 This comment was meant to refer to NotificationSer
94 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 103 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
95 std::unique_ptr<BlimpMetricsServiceClient> client_; 104 std::unique_ptr<BlimpMetricsServiceClient> client_;
96 105
97 DISALLOW_COPY_AND_ASSIGN(BlimpMetricsServiceClientTest); 106 DISALLOW_COPY_AND_ASSIGN(BlimpMetricsServiceClientTest);
98 }; 107 };
99 108
100 TEST_F(BlimpMetricsServiceClientTest, CtorDtor) { 109 TEST_F(BlimpMetricsServiceClientTest, CtorDtor) {
101 // Confirm construction and destruction work as expected. 110 // Confirm construction and destruction work as expected.
102 } 111 }
103 112
104 } // namespace engine 113 } // namespace engine
105 } // namespace blimp 114 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698