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

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: comments 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 {
40 // Set up PrefRegistry 42 // Set up NotificationService for StabilityMetricsHelper to use.
43 notification_service_.reset(content::NotificationService::Create());
44
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(base::ThreadTaskRunnerHandle::Get());
57 63
58 // Set up BlimpMetricsServiceClient 64 // Set up BlimpMetricsServiceClient
59 client_.reset(new BlimpMetricsServiceClient(pref_service_.get(), 65 client_.reset(new BlimpMetricsServiceClient(pref_service_.get(),
60 request_context_getter_)); 66 request_context_getter_));
61 base::RunLoop().RunUntilIdle(); 67 base::RunLoop().RunUntilIdle();
62 68
63 // Checks of InitializeBlimpMetrics. 69 // Checks of InitializeBlimpMetrics.
64 // TODO(jessicag): Check request_context_getter_ set. 70 // TODO(jessicag): Check request_context_getter_ set.
65 // PrefService unique pointer set up by BlimpMetricsServiceClient. 71 // PrefService unique pointer set up by BlimpMetricsServiceClient.
66 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS, 72 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS,
(...skipping 14 matching lines...) Expand all
81 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS, 87 EXPECT_EQ(PrefService::INITIALIZATION_STATUS_SUCCESS,
82 pref_service_->GetInitializationStatus()); 88 pref_service_->GetInitializationStatus());
83 89
84 // Clean up static variable in MetricService to avoid impacting other tests. 90 // Clean up static variable in MetricService to avoid impacting other tests.
85 metrics::MetricsService::SetExecutionPhase( 91 metrics::MetricsService::SetExecutionPhase(
86 metrics::MetricsService::UNINITIALIZED_PHASE, 92 metrics::MetricsService::UNINITIALIZED_PHASE,
87 pref_service_.get()); 93 pref_service_.get());
88 } 94 }
89 95
90 private: 96 private:
91 base::MessageLoop message_loop_; 97 content::TestBrowserThreadBundle thread_bundle_;
98 std::unique_ptr<content::NotificationService> notification_service_;
92 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; 99 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
93 std::unique_ptr<PrefService> pref_service_; 100 std::unique_ptr<PrefService> pref_service_;
94 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 101 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
95 std::unique_ptr<BlimpMetricsServiceClient> client_; 102 std::unique_ptr<BlimpMetricsServiceClient> client_;
96 103
97 DISALLOW_COPY_AND_ASSIGN(BlimpMetricsServiceClientTest); 104 DISALLOW_COPY_AND_ASSIGN(BlimpMetricsServiceClientTest);
98 }; 105 };
99 106
100 TEST_F(BlimpMetricsServiceClientTest, CtorDtor) { 107 TEST_F(BlimpMetricsServiceClientTest, CtorDtor) {
101 // Confirm construction and destruction work as expected. 108 // Confirm construction and destruction work as expected.
102 } 109 }
103 110
104 } // namespace engine 111 } // namespace engine
105 } // namespace blimp 112 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/engine/app/blimp_metrics_service_client.cc ('k') | blimp/engine/app/blimp_stability_metrics_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698