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

Side by Side Diff: chrome/browser/metrics/chromeos_metrics_provider_unittest.cc

Issue 292433015: Refactor MetricsLogChromeOS to ChromeOSMetricsProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build fixes Created 6 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 2014 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 "chrome/browser/metrics/chromeos_metrics_provider.h"
6
7 #include <string>
8
9 #include "base/basictypes.h"
10 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
11 #include "chrome/browser/chromeos/login/users/user_manager.h"
12 #include "chrome/browser/metrics/chromeos_metrics_provider.h"
13 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
14 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
15 #include "chromeos/dbus/fake_bluetooth_device_client.h"
16 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h"
17 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h"
18 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h"
19 #include "chromeos/dbus/fake_bluetooth_input_client.h"
20 #include "chromeos/dbus/fake_dbus_thread_manager.h"
21 #include "components/metrics/proto/system_profile.pb.h"
22 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "content/public/test/test_utils.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 using chromeos::DBusThreadManager;
27 using chromeos::BluetoothAdapterClient;
28 using chromeos::BluetoothAgentManagerClient;
29 using chromeos::BluetoothDeviceClient;
30 using chromeos::BluetoothGattCharacteristicClient;
31 using chromeos::BluetoothGattDescriptorClient;
32 using chromeos::BluetoothGattServiceClient;
33 using chromeos::BluetoothInputClient;
34 using chromeos::FakeBluetoothAdapterClient;
35 using chromeos::FakeBluetoothAgentManagerClient;
36 using chromeos::FakeBluetoothDeviceClient;
37 using chromeos::FakeBluetoothGattCharacteristicClient;
38 using chromeos::FakeBluetoothGattDescriptorClient;
39 using chromeos::FakeBluetoothGattServiceClient;
40 using chromeos::FakeBluetoothInputClient;
41 using chromeos::FakeDBusThreadManager;
42
43 class ChromeOSMetricsProviderTest : public testing::Test {
44 public:
45 ChromeOSMetricsProviderTest() {}
46
47 protected:
48 virtual void SetUp() OVERRIDE {
49 // Set up the fake Bluetooth environment,
50 scoped_ptr<FakeDBusThreadManager> fake_dbus_thread_manager(
51 new FakeDBusThreadManager);
52 fake_dbus_thread_manager->SetBluetoothAdapterClient(
53 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient));
54 fake_dbus_thread_manager->SetBluetoothDeviceClient(
55 scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient));
56 fake_dbus_thread_manager->SetBluetoothGattCharacteristicClient(
57 scoped_ptr<BluetoothGattCharacteristicClient>(
58 new FakeBluetoothGattCharacteristicClient));
59 fake_dbus_thread_manager->SetBluetoothGattDescriptorClient(
60 scoped_ptr<BluetoothGattDescriptorClient>(
61 new FakeBluetoothGattDescriptorClient));
62 fake_dbus_thread_manager->SetBluetoothGattServiceClient(
63 scoped_ptr<BluetoothGattServiceClient>(
64 new FakeBluetoothGattServiceClient));
65 fake_dbus_thread_manager->SetBluetoothInputClient(
66 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient));
67 fake_dbus_thread_manager->SetBluetoothAgentManagerClient(
68 scoped_ptr<BluetoothAgentManagerClient>(
69 new FakeBluetoothAgentManagerClient));
70 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager.release());
71
72 // Grab pointers to members of the thread manager for easier testing.
73 fake_bluetooth_adapter_client_ = static_cast<FakeBluetoothAdapterClient*>(
74 DBusThreadManager::Get()->GetBluetoothAdapterClient());
75 fake_bluetooth_device_client_ = static_cast<FakeBluetoothDeviceClient*>(
76 DBusThreadManager::Get()->GetBluetoothDeviceClient());
77 }
78
79 virtual void TearDown() OVERRIDE { DBusThreadManager::Shutdown(); }
80
81 protected:
82 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_;
83 FakeBluetoothDeviceClient* fake_bluetooth_device_client_;
84
85 private:
86 content::TestBrowserThreadBundle thread_bundle_;
87
88 DISALLOW_COPY_AND_ASSIGN(ChromeOSMetricsProviderTest);
89 };
90
91 TEST_F(ChromeOSMetricsProviderTest, MultiProfileUserCount) {
92 std::string user1("user1@example.com");
93 std::string user2("user2@example.com");
94 std::string user3("user3@example.com");
95
96 // |scoped_enabler| takes over the lifetime of |user_manager|.
97 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
98 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
99 user_manager->AddKioskAppUser(user1);
100 user_manager->AddKioskAppUser(user2);
101 user_manager->AddKioskAppUser(user3);
102
103 user_manager->LoginUser(user1);
104 user_manager->LoginUser(user3);
105
106 ChromeOSMetricsProvider provider;
107 provider.OnDidCreateMetricsLog();
108 metrics::SystemProfileProto system_profile;
109 provider.ProvideSystemProfileMetrics(&system_profile);
110 EXPECT_EQ(2u, system_profile.multi_profile_user_count());
111 }
112
113 TEST_F(ChromeOSMetricsProviderTest, MultiProfileCountInvalidated) {
114 std::string user1("user1@example.com");
115 std::string user2("user2@example.com");
116 std::string user3("user3@example.com");
117
118 // |scoped_enabler| takes over the lifetime of |user_manager|.
119 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
120 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
121 user_manager->AddKioskAppUser(user1);
122 user_manager->AddKioskAppUser(user2);
123 user_manager->AddKioskAppUser(user3);
124
125 user_manager->LoginUser(user1);
126
127 ChromeOSMetricsProvider provider;
128 provider.OnDidCreateMetricsLog();
129
130 metrics::SystemProfileProto system_profile;
131 provider.ProvideSystemProfileMetrics(&system_profile);
132 EXPECT_EQ(1u, system_profile.multi_profile_user_count());
133
134 user_manager->LoginUser(user2);
135 provider.ProvideSystemProfileMetrics(&system_profile);
136 EXPECT_EQ(0u, system_profile.multi_profile_user_count());
137 }
138
139 TEST_F(ChromeOSMetricsProviderTest, BluetoothHardwareDisabled) {
140 ChromeOSMetricsProvider provider;
141 provider.OnDidCreateMetricsLog();
142 metrics::SystemProfileProto system_profile;
143 provider.ProvideSystemProfileMetrics(&system_profile);
144
145 EXPECT_TRUE(system_profile.has_hardware());
146 EXPECT_TRUE(system_profile.hardware().has_bluetooth());
147
148 EXPECT_TRUE(system_profile.hardware().bluetooth().is_present());
149 EXPECT_FALSE(system_profile.hardware().bluetooth().is_enabled());
150 }
151
152 TEST_F(ChromeOSMetricsProviderTest, BluetoothHardwareEnabled) {
153 FakeBluetoothAdapterClient::Properties* properties =
154 fake_bluetooth_adapter_client_->GetProperties(
155 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
156 properties->powered.ReplaceValue(true);
157
158 ChromeOSMetricsProvider provider;
159 metrics::SystemProfileProto system_profile;
160 provider.ProvideSystemProfileMetrics(&system_profile);
161
162 EXPECT_TRUE(system_profile.has_hardware());
163 EXPECT_TRUE(system_profile.hardware().has_bluetooth());
164
165 EXPECT_TRUE(system_profile.hardware().bluetooth().is_present());
166 EXPECT_TRUE(system_profile.hardware().bluetooth().is_enabled());
167 }
168
169 TEST_F(ChromeOSMetricsProviderTest, BluetoothPairedDevices) {
170 // The fake bluetooth adapter class already claims to be paired with one
171 // device when initialized. Add a second and third fake device to it so we
172 // can test the cases where a device is not paired (LE device, generally)
173 // and a device that does not have Device ID information.
174 fake_bluetooth_device_client_->CreateDevice(
175 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
176 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath));
177
178 fake_bluetooth_device_client_->CreateDevice(
179 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
180 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath));
181
182 FakeBluetoothDeviceClient::Properties* properties =
183 fake_bluetooth_device_client_->GetProperties(
184 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath));
185 properties->paired.ReplaceValue(true);
186
187 ChromeOSMetricsProvider provider;
188 provider.OnDidCreateMetricsLog();
189 metrics::SystemProfileProto system_profile;
190 provider.ProvideSystemProfileMetrics(&system_profile);
191
192 ASSERT_TRUE(system_profile.has_hardware());
193 ASSERT_TRUE(system_profile.hardware().has_bluetooth());
194
195 // Only two of the devices should appear.
196 EXPECT_EQ(2, system_profile.hardware().bluetooth().paired_device_size());
197
198 typedef metrics::SystemProfileProto::Hardware::Bluetooth::PairedDevice
199 PairedDevice;
200
201 // First device should match the Paired Device object, complete with
202 // parsed Device ID information.
203 PairedDevice device1 = system_profile.hardware().bluetooth().paired_device(0);
204
205 EXPECT_EQ(FakeBluetoothDeviceClient::kPairedDeviceClass,
206 device1.bluetooth_class());
207 EXPECT_EQ(PairedDevice::DEVICE_COMPUTER, device1.type());
208 EXPECT_EQ(0x001122U, device1.vendor_prefix());
209 EXPECT_EQ(PairedDevice::VENDOR_ID_USB, device1.vendor_id_source());
210 EXPECT_EQ(0x05ACU, device1.vendor_id());
211 EXPECT_EQ(0x030DU, device1.product_id());
212 EXPECT_EQ(0x0306U, device1.device_id());
213
214 // Second device should match the Confirm Passkey object, this has
215 // no Device ID information.
216 PairedDevice device2 = system_profile.hardware().bluetooth().paired_device(1);
217
218 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass,
219 device2.bluetooth_class());
220 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type());
221 EXPECT_EQ(0x207D74U, device2.vendor_prefix());
222 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source());
223 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chromeos_metrics_provider.cc ('k') | chrome/browser/metrics/metrics_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698