OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/field_trial.h" |
9 #include "base/port.h" | 11 #include "base/port.h" |
10 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
11 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
15 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
17 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
18 #include "chrome/browser/google/google_util.h" | 20 #include "chrome/browser/google/google_util.h" |
19 #include "chrome/browser/metrics/metrics_log.h" | 21 #include "chrome/browser/metrics/metrics_log.h" |
20 #include "chrome/browser/prefs/browser_prefs.h" | 22 #include "chrome/browser/prefs/browser_prefs.h" |
| 23 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/metrics/proto/profiler_event.pb.h" | 24 #include "chrome/common/metrics/proto/profiler_event.pb.h" |
22 #include "chrome/common/metrics/proto/system_profile.pb.h" | 25 #include "chrome/common/metrics/proto/system_profile.pb.h" |
23 #include "chrome/common/metrics/variations/variations_util.h" | 26 #include "chrome/common/metrics/variations/variations_util.h" |
24 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
25 #include "chrome/installer/util/google_update_settings.h" | 28 #include "chrome/installer/util/google_update_settings.h" |
| 29 #include "components/variations/entropy_provider.h" |
26 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/common/process_type.h" | 31 #include "content/public/common/process_type.h" |
28 #include "content/public/common/webplugininfo.h" | 32 #include "content/public/common/webplugininfo.h" |
29 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/gfx/size.h" | 35 #include "ui/gfx/size.h" |
32 #include "url/gurl.h" | 36 #include "url/gurl.h" |
33 | 37 |
34 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 39 #include "chrome/browser/chromeos/login/fake_user_manager.h" |
| 40 #include "chrome/browser/chromeos/login/user_manager.h" |
35 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" | 41 #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" |
36 #endif // OS_CHROMEOS | 42 #endif // OS_CHROMEOS |
37 | 43 |
38 using base::TimeDelta; | 44 using base::TimeDelta; |
39 using metrics::ProfilerEventProto; | 45 using metrics::ProfilerEventProto; |
40 using tracked_objects::ProcessDataSnapshot; | 46 using tracked_objects::ProcessDataSnapshot; |
41 using tracked_objects::TaskSnapshot; | 47 using tracked_objects::TaskSnapshot; |
42 | 48 |
43 namespace { | 49 namespace { |
44 | 50 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // TODO(isherman): Verify other data written into the protobuf as a result | 173 // TODO(isherman): Verify other data written into the protobuf as a result |
168 // of this call. | 174 // of this call. |
169 } | 175 } |
170 | 176 |
171 virtual void SetUp() OVERRIDE { | 177 virtual void SetUp() OVERRIDE { |
172 #if defined(OS_CHROMEOS) | 178 #if defined(OS_CHROMEOS) |
173 mock_dbus_thread_manager_ = | 179 mock_dbus_thread_manager_ = |
174 new chromeos::MockDBusThreadManagerWithoutGMock(); | 180 new chromeos::MockDBusThreadManagerWithoutGMock(); |
175 chromeos::DBusThreadManager::InitializeForTesting( | 181 chromeos::DBusThreadManager::InitializeForTesting( |
176 mock_dbus_thread_manager_); | 182 mock_dbus_thread_manager_); |
| 183 |
| 184 // Enable multi-profiles. |
| 185 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); |
| 186 field_trial_list_.reset(new base::FieldTrialList( |
| 187 new metrics::SHA1EntropyProvider("42"))); |
| 188 base::FieldTrialList::CreateTrialsFromString( |
| 189 "ChromeOSUseMultiProfiles/Enable/", |
| 190 base::FieldTrialList::ACTIVATE_TRIALS); |
177 #endif // OS_CHROMEOS | 191 #endif // OS_CHROMEOS |
178 } | 192 } |
179 | 193 |
180 virtual void TearDown() OVERRIDE { | 194 virtual void TearDown() OVERRIDE { |
181 // Drain the blocking pool from PostTaskAndReply executed by | 195 // Drain the blocking pool from PostTaskAndReply executed by |
182 // MetrticsLog.network_observer_. | 196 // MetrticsLog.network_observer_. |
183 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 197 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
184 content::RunAllPendingInMessageLoop(); | 198 content::RunAllPendingInMessageLoop(); |
185 | 199 |
186 #if defined(OS_CHROMEOS) | 200 #if defined(OS_CHROMEOS) |
187 chromeos::DBusThreadManager::Shutdown(); | 201 chromeos::DBusThreadManager::Shutdown(); |
188 #endif // OS_CHROMEOS | 202 #endif // OS_CHROMEOS |
189 } | 203 } |
190 | 204 |
191 private: | 205 private: |
192 // This is necessary because eventually some tests call base::RepeatingTimer | 206 // This is necessary because eventually some tests call base::RepeatingTimer |
193 // functions and a message loop is required for that. | 207 // functions and a message loop is required for that. |
194 base::MessageLoop message_loop_; | 208 base::MessageLoop message_loop_; |
195 | 209 |
196 #if defined(OS_CHROMEOS) | 210 #if defined(OS_CHROMEOS) |
197 chromeos::MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager_; | 211 chromeos::MockDBusThreadManagerWithoutGMock* mock_dbus_thread_manager_; |
| 212 scoped_ptr<base::FieldTrialList> field_trial_list_; |
198 #endif // OS_CHROMEOS | 213 #endif // OS_CHROMEOS |
199 }; | 214 }; |
200 | 215 |
201 TEST_F(MetricsLogTest, RecordEnvironment) { | 216 TEST_F(MetricsLogTest, RecordEnvironment) { |
202 // Test that recording the environment works via both of the public methods | 217 // Test that recording the environment works via both of the public methods |
203 // RecordEnvironment() and RecordEnvironmentProto(). | 218 // RecordEnvironment() and RecordEnvironmentProto(). |
204 TestRecordEnvironment(false); | 219 TestRecordEnvironment(false); |
205 TestRecordEnvironment(true); | 220 TestRecordEnvironment(true); |
206 } | 221 } |
207 | 222 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 EXPECT_EQ(113, tracked_object->exec_time_sampled()); | 343 EXPECT_EQ(113, tracked_object->exec_time_sampled()); |
329 EXPECT_EQ(108, tracked_object->queue_time_total()); | 344 EXPECT_EQ(108, tracked_object->queue_time_total()); |
330 EXPECT_EQ(103, tracked_object->queue_time_sampled()); | 345 EXPECT_EQ(103, tracked_object->queue_time_sampled()); |
331 EXPECT_EQ(GG_UINT64_C(7246674144371406371), | 346 EXPECT_EQ(GG_UINT64_C(7246674144371406371), |
332 tracked_object->exec_thread_name_hash()); | 347 tracked_object->exec_thread_name_hash()); |
333 EXPECT_EQ(1177U, tracked_object->process_id()); | 348 EXPECT_EQ(1177U, tracked_object->process_id()); |
334 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, | 349 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, |
335 tracked_object->process_type()); | 350 tracked_object->process_type()); |
336 } | 351 } |
337 } | 352 } |
| 353 |
| 354 #if defined(OS_CHROMEOS) |
| 355 TEST_F(MetricsLogTest, MultiProfileUserCount) { |
| 356 std::string user1("user1@example.com"); |
| 357 std::string user2("user2@example.com"); |
| 358 std::string user3("user3@example.com"); |
| 359 |
| 360 // |scoped_enabler| takes over the lifetime of |user_manager|. |
| 361 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); |
| 362 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); |
| 363 user_manager->AddKioskAppUser(user1); |
| 364 user_manager->AddKioskAppUser(user2); |
| 365 user_manager->AddKioskAppUser(user3); |
| 366 |
| 367 user_manager->LoginUser(user1); |
| 368 user_manager->LoginUser(user3); |
| 369 |
| 370 TestMetricsLog log(kClientId, kSessionId); |
| 371 std::vector<content::WebPluginInfo> plugins; |
| 372 GoogleUpdateMetrics google_update_metrics; |
| 373 log.RecordEnvironmentProto(plugins, google_update_metrics); |
| 374 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count()); |
| 375 } |
| 376 |
| 377 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) { |
| 378 std::string user1("user1@example.com"); |
| 379 std::string user2("user2@example.com"); |
| 380 std::string user3("user3@example.com"); |
| 381 |
| 382 // |scoped_enabler| takes over the lifetime of |user_manager|. |
| 383 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); |
| 384 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); |
| 385 user_manager->AddKioskAppUser(user1); |
| 386 user_manager->AddKioskAppUser(user2); |
| 387 user_manager->AddKioskAppUser(user3); |
| 388 |
| 389 user_manager->LoginUser(user1); |
| 390 |
| 391 TestMetricsLog log(kClientId, kSessionId); |
| 392 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count()); |
| 393 |
| 394 user_manager->LoginUser(user2); |
| 395 log.RecordEnvironmentProto(std::vector<content::WebPluginInfo>(), |
| 396 GoogleUpdateMetrics()); |
| 397 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count()); |
| 398 } |
| 399 #endif // OS_CHROMEOS |
OLD | NEW |