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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify a bit. Created 5 years, 8 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 (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 "chrome/browser/chromeos/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/environment.h" 11 #include "base/environment.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/prefs/testing_pref_service.h" 16 #include "base/prefs/testing_pref_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
19 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 19 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
21 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h"
21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
22 #include "chrome/browser/chromeos/policy/device_local_account.h" 23 #include "chrome/browser/chromeos/policy/device_local_account.h"
23 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" 24 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
24 #include "chrome/browser/chromeos/settings/cros_settings.h" 25 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
25 #include "chrome/browser/chromeos/settings/device_settings_service.h"
26 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
27 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
28 #include "chrome/test/base/testing_browser_process.h" 27 #include "chrome/test/base/testing_browser_process.h"
29 #include "chromeos/dbus/cros_disks_client.h" 28 #include "chromeos/dbus/cros_disks_client.h"
30 #include "chromeos/dbus/dbus_thread_manager.h" 29 #include "chromeos/dbus/dbus_thread_manager.h"
31 #include "chromeos/dbus/shill_device_client.h" 30 #include "chromeos/dbus/shill_device_client.h"
32 #include "chromeos/dbus/shill_ipconfig_client.h" 31 #include "chromeos/dbus/shill_ipconfig_client.h"
33 #include "chromeos/dbus/shill_service_client.h" 32 #include "chromeos/dbus/shill_service_client.h"
34 #include "chromeos/disks/disk_mount_manager.h" 33 #include "chromeos/disks/disk_mount_manager.h"
35 #include "chromeos/disks/mock_disk_mount_manager.h" 34 #include "chromeos/disks/mock_disk_mount_manager.h"
36 #include "chromeos/network/network_handler.h" 35 #include "chromeos/network/network_handler.h"
37 #include "chromeos/network/network_state.h" 36 #include "chromeos/network/network_state.h"
38 #include "chromeos/network/network_state_handler.h" 37 #include "chromeos/network/network_state_handler.h"
39 #include "chromeos/settings/cros_settings_names.h" 38 #include "chromeos/settings/cros_settings_names.h"
40 #include "chromeos/settings/cros_settings_provider.h"
41 #include "chromeos/system/fake_statistics_provider.h" 39 #include "chromeos/system/fake_statistics_provider.h"
42 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/geolocation_provider.h" 41 #include "content/public/browser/geolocation_provider.h"
44 #include "content/public/test/test_browser_thread.h" 42 #include "content/public/test/test_browser_thread.h"
45 #include "content/public/test/test_utils.h" 43 #include "content/public/test/test_utils.h"
46 #include "policy/proto/device_management_backend.pb.h" 44 #include "policy/proto/device_management_backend.pb.h"
47 #include "storage/browser/fileapi/external_mount_points.h" 45 #include "storage/browser/fileapi/external_mount_points.h"
48 #include "storage/browser/fileapi/mount_points.h" 46 #include "storage/browser/fileapi/mount_points.h"
49 #include "storage/common/fileapi/file_system_mount_option.h" 47 #include "storage/common/fileapi/file_system_mount_option.h"
50 #include "storage/common/fileapi/file_system_types.h" 48 #include "storage/common/fileapi/file_system_types.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } // namespace 221 } // namespace
224 222
225 namespace policy { 223 namespace policy {
226 224
227 // Though it is a unit test, this test is linked with browser_tests so that it 225 // Though it is a unit test, this test is linked with browser_tests so that it
228 // runs in a separate process. The intention is to avoid overriding the timezone 226 // runs in a separate process. The intention is to avoid overriding the timezone
229 // environment variable for other tests. 227 // environment variable for other tests.
230 class DeviceStatusCollectorTest : public testing::Test { 228 class DeviceStatusCollectorTest : public testing::Test {
231 public: 229 public:
232 DeviceStatusCollectorTest() 230 DeviceStatusCollectorTest()
233 : ui_thread_(content::BrowserThread::UI, &message_loop_), 231 : ui_thread_(content::BrowserThread::UI, &message_loop_),
234 file_thread_(content::BrowserThread::FILE, &message_loop_), 232 file_thread_(content::BrowserThread::FILE, &message_loop_),
235 io_thread_(content::BrowserThread::IO, &message_loop_), 233 io_thread_(content::BrowserThread::IO, &message_loop_),
236 install_attributes_("managed.com", 234 install_attributes_("managed.com",
237 "user@managed.com", 235 "user@managed.com",
238 "device_id", 236 "device_id",
239 DEVICE_MODE_ENTERPRISE), 237 DEVICE_MODE_ENTERPRISE),
240 user_manager_(new chromeos::MockUserManager()), 238 settings_helper_(false),
241 user_manager_enabler_(user_manager_), 239 user_manager_(new chromeos::MockUserManager()),
242 fake_device_local_account_( 240 user_manager_enabler_(user_manager_),
243 policy::DeviceLocalAccount::TYPE_KIOSK_APP, 241 fake_device_local_account_(policy::DeviceLocalAccount::TYPE_KIOSK_APP,
244 kKioskAccountId, 242 kKioskAccountId,
245 kKioskAppId, 243 kKioskAppId,
246 std::string() /* kiosk_app_update_url */) { 244 std::string() /* kiosk_app_update_url */) {
247 // Run this test with a well-known timezone so that Time::LocalMidnight() 245 // Run this test with a well-known timezone so that Time::LocalMidnight()
248 // returns the same values on all machines. 246 // returns the same values on all machines.
249 scoped_ptr<base::Environment> env(base::Environment::Create()); 247 scoped_ptr<base::Environment> env(base::Environment::Create());
250 env->SetVar("TZ", "UTC"); 248 env->SetVar("TZ", "UTC");
251 249
252 // Initialize our mock mounted disk volumes. 250 // Initialize our mock mounted disk volumes.
253 scoped_ptr<chromeos::disks::MockDiskMountManager> mock_disk_mount_manager = 251 scoped_ptr<chromeos::disks::MockDiskMountManager> mock_disk_mount_manager =
254 make_scoped_ptr(new chromeos::disks::MockDiskMountManager()); 252 make_scoped_ptr(new chromeos::disks::MockDiskMountManager());
255 AddMountPoint("/mount/volume1"); 253 AddMountPoint("/mount/volume1");
256 AddMountPoint("/mount/volume2"); 254 AddMountPoint("/mount/volume2");
(...skipping 10 matching lines...) Expand all
267 // Just verify that we are properly setting the mount points. 265 // Just verify that we are properly setting the mount points.
268 std::vector<storage::MountPoints::MountPointInfo> external_mount_points; 266 std::vector<storage::MountPoints::MountPointInfo> external_mount_points;
269 storage::ExternalMountPoints::GetSystemInstance()->AddMountPointInfosTo( 267 storage::ExternalMountPoints::GetSystemInstance()->AddMountPointInfosTo(
270 &external_mount_points); 268 &external_mount_points);
271 EXPECT_FALSE(external_mount_points.empty()); 269 EXPECT_FALSE(external_mount_points.empty());
272 270
273 // DiskMountManager takes ownership of the MockDiskMountManager. 271 // DiskMountManager takes ownership of the MockDiskMountManager.
274 DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release()); 272 DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release());
275 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry()); 273 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry());
276 274
277 // Remove the real DeviceSettingsProvider and replace it with a stub. 275 settings_helper_.ReplaceProvider(chromeos::kReportDeviceActivityTimes);
278 cros_settings_ = chromeos::CrosSettings::Get(); 276 owner_settings_service_.reset(
279 device_settings_provider_ = 277 settings_helper_.CreateOwnerSettingsService(nullptr));
280 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo);
281 EXPECT_TRUE(device_settings_provider_ != NULL);
282 EXPECT_TRUE(
283 cros_settings_->RemoveSettingsProvider(device_settings_provider_));
284 cros_settings_->AddSettingsProvider(&stub_settings_provider_);
285 278
286 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), 279 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo),
287 base::Bind(&GetEmptyCPUStatistics)); 280 base::Bind(&GetEmptyCPUStatistics));
288 } 281 }
289 282
290 void AddMountPoint(const std::string& mount_point) { 283 void AddMountPoint(const std::string& mount_point) {
291 mount_point_map_.insert(DiskMountManager::MountPointMap::value_type( 284 mount_point_map_.insert(DiskMountManager::MountPointMap::value_type(
292 mount_point, 285 mount_point,
293 DiskMountManager::MountPointInfo( 286 DiskMountManager::MountPointInfo(
294 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE, 287 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE,
295 chromeos::disks::MOUNT_CONDITION_NONE))); 288 chromeos::disks::MOUNT_CONDITION_NONE)));
296 } 289 }
297 290
298 ~DeviceStatusCollectorTest() override { 291 ~DeviceStatusCollectorTest() override {
299 // Finish pending tasks. 292 // Finish pending tasks.
300 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 293 content::BrowserThread::GetBlockingPool()->FlushForTesting();
301 message_loop_.RunUntilIdle(); 294 message_loop_.RunUntilIdle();
302 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); 295 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems();
303 DiskMountManager::Shutdown(); 296 DiskMountManager::Shutdown();
304
305 // Restore the real DeviceSettingsProvider.
306 EXPECT_TRUE(
307 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_));
308 cros_settings_->AddSettingsProvider(device_settings_provider_);
309 } 297 }
310 298
311 void SetUp() override { 299 void SetUp() override {
312 // Disable network interface reporting since it requires additional setup. 300 // Disable network interface reporting since it requires additional setup.
313 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); 301 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces,
302 false);
314 } 303 }
315 304
305 void TearDown() override { settings_helper_.RestoreProvider(); }
306
316 void RestartStatusCollector( 307 void RestartStatusCollector(
317 const policy::DeviceStatusCollector::VolumeInfoFetcher& volume_info, 308 const policy::DeviceStatusCollector::VolumeInfoFetcher& volume_info,
318 const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_stats) { 309 const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_stats) {
319 policy::DeviceStatusCollector::LocationUpdateRequester callback = 310 policy::DeviceStatusCollector::LocationUpdateRequester callback =
320 base::Bind(&MockPositionUpdateRequester); 311 base::Bind(&MockPositionUpdateRequester);
321 std::vector<em::VolumeInfo> expected_volume_info; 312 std::vector<em::VolumeInfo> expected_volume_info;
322 status_collector_.reset(new TestingDeviceStatusCollector( 313 status_collector_.reset(new TestingDeviceStatusCollector(
323 &prefs_, &fake_statistics_provider_, callback, volume_info, cpu_stats)); 314 &prefs_, &fake_statistics_provider_, callback, volume_info, cpu_stats));
324 } 315 }
325 316
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 EXPECT_TRUE(status_.has_device_location()); 354 EXPECT_TRUE(status_.has_device_location());
364 em::DeviceLocation location = status_.device_location(); 355 em::DeviceLocation location = status_.device_location();
365 EXPECT_TRUE(location.has_error_code()); 356 EXPECT_TRUE(location.has_error_code());
366 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE, 357 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE,
367 location.error_code()); 358 location.error_code());
368 } 359 }
369 360
370 void MockRunningKioskApp(const DeviceLocalAccount& account) { 361 void MockRunningKioskApp(const DeviceLocalAccount& account) {
371 std::vector<DeviceLocalAccount> accounts; 362 std::vector<DeviceLocalAccount> accounts;
372 accounts.push_back(account); 363 accounts.push_back(account);
373 SetDeviceLocalAccounts(cros_settings_, accounts); 364 SetDeviceLocalAccounts(owner_settings_service_.get(), accounts);
374 user_manager_->CreateKioskAppUser(account.user_id); 365 user_manager_->CreateKioskAppUser(account.user_id);
375 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly( 366 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly(
376 Return(true)); 367 Return(true));
377 } 368 }
378 369
379 protected: 370 protected:
380 // Convenience method. 371 // Convenience method.
381 int64 ActivePeriodMilliseconds() { 372 int64 ActivePeriodMilliseconds() {
382 return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000; 373 return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000;
383 } 374 }
384 375
385 // Since this is a unit test running in browser_tests we must do additional 376 // Since this is a unit test running in browser_tests we must do additional
386 // unit test setup and make a TestingBrowserProcess. Must be first member. 377 // unit test setup and make a TestingBrowserProcess. Must be first member.
387 TestingBrowserProcessInitializer initializer_; 378 TestingBrowserProcessInitializer initializer_;
388 base::MessageLoopForUI message_loop_; 379 base::MessageLoopForUI message_loop_;
389 content::TestBrowserThread ui_thread_; 380 content::TestBrowserThread ui_thread_;
390 content::TestBrowserThread file_thread_; 381 content::TestBrowserThread file_thread_;
391 content::TestBrowserThread io_thread_; 382 content::TestBrowserThread io_thread_;
392 383
393 ScopedStubEnterpriseInstallAttributes install_attributes_; 384 ScopedStubEnterpriseInstallAttributes install_attributes_;
394 TestingPrefServiceSimple prefs_; 385 TestingPrefServiceSimple prefs_;
395 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; 386 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_;
396 DiskMountManager::MountPointMap mount_point_map_; 387 DiskMountManager::MountPointMap mount_point_map_;
397 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 388 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
398 chromeos::ScopedTestCrosSettings test_cros_settings_; 389 chromeos::ScopedTestCrosSettings test_cros_settings_;
399 chromeos::CrosSettings* cros_settings_; 390 chromeos::ScopedCrosSettingsTestHelper settings_helper_;
400 chromeos::CrosSettingsProvider* device_settings_provider_; 391 scoped_ptr<chromeos::FakeOwnerSettingsService> owner_settings_service_;
401 chromeos::StubCrosSettingsProvider stub_settings_provider_;
402 chromeos::MockUserManager* user_manager_; 392 chromeos::MockUserManager* user_manager_;
403 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 393 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
404 em::DeviceStatusReportRequest status_; 394 em::DeviceStatusReportRequest status_;
405 scoped_ptr<TestingDeviceStatusCollector> status_collector_; 395 scoped_ptr<TestingDeviceStatusCollector> status_collector_;
406 const policy::DeviceLocalAccount fake_device_local_account_; 396 const policy::DeviceLocalAccount fake_device_local_account_;
407 }; 397 };
408 398
409 TEST_F(DeviceStatusCollectorTest, AllIdle) { 399 TEST_F(DeviceStatusCollectorTest, AllIdle) {
410 ui::IdleState test_states[] = { 400 ui::IdleState test_states[] = {
411 ui::IDLE_STATE_IDLE, 401 ui::IDLE_STATE_IDLE,
412 ui::IDLE_STATE_IDLE, 402 ui::IDLE_STATE_IDLE,
413 ui::IDLE_STATE_IDLE 403 ui::IDLE_STATE_IDLE
414 }; 404 };
415 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 405 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
416 406
417 // Test reporting with no data. 407 // Test reporting with no data.
418 GetStatus(); 408 GetStatus();
419 EXPECT_EQ(0, status_.active_period_size()); 409 EXPECT_EQ(0, status_.active_period_size());
420 EXPECT_EQ(0, GetActiveMilliseconds(status_)); 410 EXPECT_EQ(0, GetActiveMilliseconds(status_));
421 411
422 // Test reporting with a single idle sample. 412 // Test reporting with a single idle sample.
423 status_collector_->Simulate(test_states, 1); 413 status_collector_->Simulate(test_states, 1);
424 GetStatus(); 414 GetStatus();
425 EXPECT_EQ(0, status_.active_period_size()); 415 EXPECT_EQ(0, status_.active_period_size());
426 EXPECT_EQ(0, GetActiveMilliseconds(status_)); 416 EXPECT_EQ(0, GetActiveMilliseconds(status_));
427 417
428 // Test reporting with multiple consecutive idle samples. 418 // Test reporting with multiple consecutive idle samples.
429 status_collector_->Simulate(test_states, 419 status_collector_->Simulate(test_states,
430 sizeof(test_states) / sizeof(ui::IdleState)); 420 sizeof(test_states) / sizeof(ui::IdleState));
431 GetStatus(); 421 GetStatus();
432 EXPECT_EQ(0, status_.active_period_size()); 422 EXPECT_EQ(0, status_.active_period_size());
433 EXPECT_EQ(0, GetActiveMilliseconds(status_)); 423 EXPECT_EQ(0, GetActiveMilliseconds(status_));
434 } 424 }
435 425
436 TEST_F(DeviceStatusCollectorTest, AllActive) { 426 TEST_F(DeviceStatusCollectorTest, AllActive) {
437 ui::IdleState test_states[] = { 427 ui::IdleState test_states[] = {
438 ui::IDLE_STATE_ACTIVE, 428 ui::IDLE_STATE_ACTIVE,
439 ui::IDLE_STATE_ACTIVE, 429 ui::IDLE_STATE_ACTIVE,
440 ui::IDLE_STATE_ACTIVE 430 ui::IDLE_STATE_ACTIVE
441 }; 431 };
442 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 432 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
443 433
444 // Test a single active sample. 434 // Test a single active sample.
445 status_collector_->Simulate(test_states, 1); 435 status_collector_->Simulate(test_states, 1);
446 GetStatus(); 436 GetStatus();
447 EXPECT_EQ(1, status_.active_period_size()); 437 EXPECT_EQ(1, status_.active_period_size());
448 EXPECT_EQ(1 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 438 EXPECT_EQ(1 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
449 status_.clear_active_period(); // Clear the result protobuf. 439 status_.clear_active_period(); // Clear the result protobuf.
450 440
451 // Test multiple consecutive active samples. 441 // Test multiple consecutive active samples.
452 status_collector_->Simulate(test_states, 442 status_collector_->Simulate(test_states,
453 sizeof(test_states) / sizeof(ui::IdleState)); 443 sizeof(test_states) / sizeof(ui::IdleState));
454 GetStatus(); 444 GetStatus();
455 EXPECT_EQ(1, status_.active_period_size()); 445 EXPECT_EQ(1, status_.active_period_size());
456 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 446 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
457 } 447 }
458 448
459 TEST_F(DeviceStatusCollectorTest, MixedStates) { 449 TEST_F(DeviceStatusCollectorTest, MixedStates) {
460 ui::IdleState test_states[] = { 450 ui::IdleState test_states[] = {
461 ui::IDLE_STATE_ACTIVE, 451 ui::IDLE_STATE_ACTIVE,
462 ui::IDLE_STATE_IDLE, 452 ui::IDLE_STATE_IDLE,
463 ui::IDLE_STATE_ACTIVE, 453 ui::IDLE_STATE_ACTIVE,
464 ui::IDLE_STATE_ACTIVE, 454 ui::IDLE_STATE_ACTIVE,
465 ui::IDLE_STATE_IDLE, 455 ui::IDLE_STATE_IDLE,
466 ui::IDLE_STATE_IDLE, 456 ui::IDLE_STATE_IDLE,
467 ui::IDLE_STATE_ACTIVE 457 ui::IDLE_STATE_ACTIVE
468 }; 458 };
469 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 459 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
470 status_collector_->Simulate(test_states, 460 status_collector_->Simulate(test_states,
471 sizeof(test_states) / sizeof(ui::IdleState)); 461 sizeof(test_states) / sizeof(ui::IdleState));
472 GetStatus(); 462 GetStatus();
473 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 463 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
474 } 464 }
475 465
476 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { 466 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) {
477 ui::IdleState test_states[] = { 467 ui::IdleState test_states[] = {
478 ui::IDLE_STATE_ACTIVE, 468 ui::IDLE_STATE_ACTIVE,
479 ui::IDLE_STATE_IDLE, 469 ui::IDLE_STATE_IDLE,
480 ui::IDLE_STATE_ACTIVE, 470 ui::IDLE_STATE_ACTIVE,
481 ui::IDLE_STATE_ACTIVE, 471 ui::IDLE_STATE_ACTIVE,
482 ui::IDLE_STATE_IDLE, 472 ui::IDLE_STATE_IDLE,
483 ui::IDLE_STATE_IDLE 473 ui::IDLE_STATE_IDLE
484 }; 474 };
485 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 475 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
486 status_collector_->Simulate(test_states, 476 status_collector_->Simulate(test_states,
487 sizeof(test_states) / sizeof(ui::IdleState)); 477 sizeof(test_states) / sizeof(ui::IdleState));
488 478
489 // Process the list a second time after restarting the collector. It should be 479 // Process the list a second time after restarting the collector. It should be
490 // able to count the active periods found by the original collector, because 480 // able to count the active periods found by the original collector, because
491 // the results are stored in a pref. 481 // the results are stored in a pref.
492 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), 482 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo),
493 base::Bind(&GetEmptyCPUStatistics)); 483 base::Bind(&GetEmptyCPUStatistics));
494 status_collector_->Simulate(test_states, 484 status_collector_->Simulate(test_states,
495 sizeof(test_states) / sizeof(ui::IdleState)); 485 sizeof(test_states) / sizeof(ui::IdleState));
496 486
497 GetStatus(); 487 GetStatus();
498 EXPECT_EQ(6 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 488 EXPECT_EQ(6 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
499 } 489 }
500 490
501 TEST_F(DeviceStatusCollectorTest, Times) { 491 TEST_F(DeviceStatusCollectorTest, Times) {
502 ui::IdleState test_states[] = { 492 ui::IdleState test_states[] = {
503 ui::IDLE_STATE_ACTIVE, 493 ui::IDLE_STATE_ACTIVE,
504 ui::IDLE_STATE_IDLE, 494 ui::IDLE_STATE_IDLE,
505 ui::IDLE_STATE_ACTIVE, 495 ui::IDLE_STATE_ACTIVE,
506 ui::IDLE_STATE_ACTIVE, 496 ui::IDLE_STATE_ACTIVE,
507 ui::IDLE_STATE_IDLE, 497 ui::IDLE_STATE_IDLE,
508 ui::IDLE_STATE_IDLE 498 ui::IDLE_STATE_IDLE
509 }; 499 };
510 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 500 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
511 status_collector_->Simulate(test_states, 501 status_collector_->Simulate(test_states,
512 sizeof(test_states) / sizeof(ui::IdleState)); 502 sizeof(test_states) / sizeof(ui::IdleState));
513 GetStatus(); 503 GetStatus();
514 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 504 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
515 } 505 }
516 506
517 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { 507 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) {
518 ui::IdleState test_states[] = { 508 ui::IdleState test_states[] = {
519 ui::IDLE_STATE_ACTIVE, 509 ui::IDLE_STATE_ACTIVE,
520 ui::IDLE_STATE_IDLE 510 ui::IDLE_STATE_IDLE
521 }; 511 };
522 const int kMaxDays = 10; 512 const int kMaxDays = 10;
523 513
524 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 514 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
525 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); 515 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1);
526 status_collector_->set_max_stored_future_activity_days(1); 516 status_collector_->set_max_stored_future_activity_days(1);
527 Time baseline = Time::Now().LocalMidnight(); 517 Time baseline = Time::Now().LocalMidnight();
528 518
529 // Simulate 12 active periods. 519 // Simulate 12 active periods.
530 for (int i = 0; i < kMaxDays + 2; i++) { 520 for (int i = 0; i < kMaxDays + 2; i++) {
531 status_collector_->Simulate(test_states, 521 status_collector_->Simulate(test_states,
532 sizeof(test_states) / sizeof(ui::IdleState)); 522 sizeof(test_states) / sizeof(ui::IdleState));
533 // Advance the simulated clock by a day. 523 // Advance the simulated clock by a day.
534 baseline += TimeDelta::FromDays(1); 524 baseline += TimeDelta::FromDays(1);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 }; 559 };
570 status_collector_->Simulate(test_states, 560 status_collector_->Simulate(test_states,
571 sizeof(test_states) / sizeof(ui::IdleState)); 561 sizeof(test_states) / sizeof(ui::IdleState));
572 GetStatus(); 562 GetStatus();
573 EXPECT_EQ(1, status_.active_period_size()); 563 EXPECT_EQ(1, status_.active_period_size());
574 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 564 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
575 } 565 }
576 566
577 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { 567 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) {
578 // Device activity times should not be reported if explicitly disabled. 568 // Device activity times should not be reported if explicitly disabled.
579 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, false); 569 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, false);
580 570
581 ui::IdleState test_states[] = { 571 ui::IdleState test_states[] = {
582 ui::IDLE_STATE_ACTIVE, 572 ui::IDLE_STATE_ACTIVE,
583 ui::IDLE_STATE_ACTIVE, 573 ui::IDLE_STATE_ACTIVE,
584 ui::IDLE_STATE_ACTIVE 574 ui::IDLE_STATE_ACTIVE
585 }; 575 };
586 status_collector_->Simulate(test_states, 576 status_collector_->Simulate(test_states,
587 sizeof(test_states) / sizeof(ui::IdleState)); 577 sizeof(test_states) / sizeof(ui::IdleState));
588 GetStatus(); 578 GetStatus();
589 EXPECT_EQ(0, status_.active_period_size()); 579 EXPECT_EQ(0, status_.active_period_size());
590 EXPECT_EQ(0, GetActiveMilliseconds(status_)); 580 EXPECT_EQ(0, GetActiveMilliseconds(status_));
591 } 581 }
592 582
593 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { 583 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) {
594 ui::IdleState test_states[] = { 584 ui::IdleState test_states[] = {
595 ui::IDLE_STATE_ACTIVE 585 ui::IDLE_STATE_ACTIVE
596 }; 586 };
597 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 587 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
598 588
599 // Set the baseline time to 10 seconds after midnight. 589 // Set the baseline time to 10 seconds after midnight.
600 status_collector_->SetBaselineTime( 590 status_collector_->SetBaselineTime(
601 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); 591 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10));
602 592
603 status_collector_->Simulate(test_states, 1); 593 status_collector_->Simulate(test_states, 1);
604 GetStatus(); 594 GetStatus();
605 ASSERT_EQ(2, status_.active_period_size()); 595 ASSERT_EQ(2, status_.active_period_size());
606 596
607 em::ActiveTimePeriod period0 = status_.active_period(0); 597 em::ActiveTimePeriod period0 = status_.active_period(0);
(...skipping 11 matching lines...) Expand all
619 kMillisecondsPerDay); 609 kMillisecondsPerDay);
620 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(), 610 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(),
621 kMillisecondsPerDay); 611 kMillisecondsPerDay);
622 } 612 }
623 613
624 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { 614 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) {
625 ui::IdleState test_states[] = { 615 ui::IdleState test_states[] = {
626 ui::IDLE_STATE_ACTIVE, 616 ui::IDLE_STATE_ACTIVE,
627 ui::IDLE_STATE_ACTIVE, 617 ui::IDLE_STATE_ACTIVE,
628 }; 618 };
629 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 619 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
630 620
631 status_collector_->Simulate(test_states, 2); 621 status_collector_->Simulate(test_states, 2);
632 GetStatus(); 622 GetStatus();
633 EXPECT_EQ(2 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 623 EXPECT_EQ(2 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
634 em::DeviceStatusReportRequest first_status(status_); 624 em::DeviceStatusReportRequest first_status(status_);
635 625
636 // The collector returns the same status again. 626 // The collector returns the same status again.
637 GetStatus(); 627 GetStatus();
638 EXPECT_EQ(first_status.SerializeAsString(), status_.SerializeAsString()); 628 EXPECT_EQ(first_status.SerializeAsString(), status_.SerializeAsString());
639 629
640 // After indicating a successful submit, the submitted status gets cleared, 630 // After indicating a successful submit, the submitted status gets cleared,
641 // but what got collected meanwhile sticks around. 631 // but what got collected meanwhile sticks around.
642 status_collector_->Simulate(test_states, 1); 632 status_collector_->Simulate(test_states, 1);
643 status_collector_->OnSubmittedSuccessfully(); 633 status_collector_->OnSubmittedSuccessfully();
644 GetStatus(); 634 GetStatus();
645 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 635 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
646 } 636 }
647 637
648 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { 638 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) {
649 // Test that boot mode data is reported by default. 639 // Test that boot mode data is reported by default.
650 fake_statistics_provider_.SetMachineStatistic( 640 fake_statistics_provider_.SetMachineStatistic(
651 chromeos::system::kDevSwitchBootKey, 641 chromeos::system::kDevSwitchBootKey,
652 chromeos::system::kDevSwitchBootValueVerified); 642 chromeos::system::kDevSwitchBootValueVerified);
653 GetStatus(); 643 GetStatus();
654 EXPECT_EQ("Verified", status_.boot_mode()); 644 EXPECT_EQ("Verified", status_.boot_mode());
655 645
656 // Test that boot mode data is not reported if the pref turned off. 646 // Test that boot mode data is not reported if the pref turned off.
657 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, false); 647 settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, false);
658 648
659 GetStatus(); 649 GetStatus();
660 EXPECT_FALSE(status_.has_boot_mode()); 650 EXPECT_FALSE(status_.has_boot_mode());
661 651
662 // Turn the pref on, and check that the status is reported iff the 652 // Turn the pref on, and check that the status is reported iff the
663 // statistics provider returns valid data. 653 // statistics provider returns valid data.
664 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, true); 654 settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, true);
665 655
666 fake_statistics_provider_.SetMachineStatistic( 656 fake_statistics_provider_.SetMachineStatistic(
667 chromeos::system::kDevSwitchBootKey, "(error)"); 657 chromeos::system::kDevSwitchBootKey, "(error)");
668 GetStatus(); 658 GetStatus();
669 EXPECT_FALSE(status_.has_boot_mode()); 659 EXPECT_FALSE(status_.has_boot_mode());
670 660
671 fake_statistics_provider_.SetMachineStatistic( 661 fake_statistics_provider_.SetMachineStatistic(
672 chromeos::system::kDevSwitchBootKey, " "); 662 chromeos::system::kDevSwitchBootKey, " ");
673 GetStatus(); 663 GetStatus();
674 EXPECT_FALSE(status_.has_boot_mode()); 664 EXPECT_FALSE(status_.has_boot_mode());
(...skipping 13 matching lines...) Expand all
688 678
689 TEST_F(DeviceStatusCollectorTest, VersionInfo) { 679 TEST_F(DeviceStatusCollectorTest, VersionInfo) {
690 // Expect the version info to be reported by default. 680 // Expect the version info to be reported by default.
691 GetStatus(); 681 GetStatus();
692 EXPECT_TRUE(status_.has_browser_version()); 682 EXPECT_TRUE(status_.has_browser_version());
693 EXPECT_TRUE(status_.has_os_version()); 683 EXPECT_TRUE(status_.has_os_version());
694 EXPECT_TRUE(status_.has_firmware_version()); 684 EXPECT_TRUE(status_.has_firmware_version());
695 685
696 // When the pref to collect this data is not enabled, expect that none of 686 // When the pref to collect this data is not enabled, expect that none of
697 // the fields are present in the protobuf. 687 // the fields are present in the protobuf.
698 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, false); 688 settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, false);
699 GetStatus(); 689 GetStatus();
700 EXPECT_FALSE(status_.has_browser_version()); 690 EXPECT_FALSE(status_.has_browser_version());
701 EXPECT_FALSE(status_.has_os_version()); 691 EXPECT_FALSE(status_.has_os_version());
702 EXPECT_FALSE(status_.has_firmware_version()); 692 EXPECT_FALSE(status_.has_firmware_version());
703 693
704 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, true); 694 settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, true);
705 GetStatus(); 695 GetStatus();
706 EXPECT_TRUE(status_.has_browser_version()); 696 EXPECT_TRUE(status_.has_browser_version());
707 EXPECT_TRUE(status_.has_os_version()); 697 EXPECT_TRUE(status_.has_os_version());
708 EXPECT_TRUE(status_.has_firmware_version()); 698 EXPECT_TRUE(status_.has_firmware_version());
709 699
710 // Check that the browser version is not empty. OS version & firmware 700 // Check that the browser version is not empty. OS version & firmware
711 // don't have any reasonable values inside the unit test, so those 701 // don't have any reasonable values inside the unit test, so those
712 // aren't checked. 702 // aren't checked.
713 EXPECT_NE("", status_.browser_version()); 703 EXPECT_NE("", status_.browser_version());
714 } 704 }
(...skipping 11 matching lines...) Expand all
726 invalid_fix.timestamp = Time::Now(); 716 invalid_fix.timestamp = Time::Now();
727 717
728 // Check that when device location reporting is disabled, no location is 718 // Check that when device location reporting is disabled, no location is
729 // reported. 719 // reported.
730 SetMockPositionToReturnNext(valid_fix); 720 SetMockPositionToReturnNext(valid_fix);
731 CheckThatNoLocationIsReported(); 721 CheckThatNoLocationIsReported();
732 722
733 // Check that when device location reporting is enabled and a valid fix is 723 // Check that when device location reporting is enabled and a valid fix is
734 // available, the location is reported and is stored in local state. 724 // available, the location is reported and is stored in local state.
735 SetMockPositionToReturnNext(valid_fix); 725 SetMockPositionToReturnNext(valid_fix);
736 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); 726 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, true);
737 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); 727 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty());
738 CheckThatAValidLocationIsReported(); 728 CheckThatAValidLocationIsReported();
739 729
740 // Restart the status collector. Check that the last known location has been 730 // Restart the status collector. Check that the last known location has been
741 // retrieved from local state without requesting a geolocation update. 731 // retrieved from local state without requesting a geolocation update.
742 SetMockPositionToReturnNext(valid_fix); 732 SetMockPositionToReturnNext(valid_fix);
743 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), 733 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo),
744 base::Bind(&GetEmptyCPUStatistics)); 734 base::Bind(&GetEmptyCPUStatistics));
745 CheckThatAValidLocationIsReported(); 735 CheckThatAValidLocationIsReported();
746 EXPECT_TRUE(mock_position_to_return_next.get()); 736 EXPECT_TRUE(mock_position_to_return_next.get());
747 737
748 // Check that after disabling location reporting again, the last known 738 // Check that after disabling location reporting again, the last known
749 // location has been cleared from local state and is no longer reported. 739 // location has been cleared from local state and is no longer reported.
750 SetMockPositionToReturnNext(valid_fix); 740 SetMockPositionToReturnNext(valid_fix);
751 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, false); 741 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, false);
752 // Allow the new pref to propagate to the status collector. 742 // Allow the new pref to propagate to the status collector.
753 message_loop_.RunUntilIdle(); 743 message_loop_.RunUntilIdle();
754 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); 744 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty());
755 CheckThatNoLocationIsReported(); 745 CheckThatNoLocationIsReported();
756 746
757 // Check that after enabling location reporting again, an error is reported 747 // Check that after enabling location reporting again, an error is reported
758 // if no valid fix is available. 748 // if no valid fix is available.
759 SetMockPositionToReturnNext(invalid_fix); 749 SetMockPositionToReturnNext(invalid_fix);
760 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); 750 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, true);
761 // Allow the new pref to propagate to the status collector. 751 // Allow the new pref to propagate to the status collector.
762 message_loop_.RunUntilIdle(); 752 message_loop_.RunUntilIdle();
763 CheckThatALocationErrorIsReported(); 753 CheckThatALocationErrorIsReported();
764 } 754 }
765 755
766 TEST_F(DeviceStatusCollectorTest, ReportUsers) { 756 TEST_F(DeviceStatusCollectorTest, ReportUsers) {
767 user_manager_->CreatePublicAccountUser("public@localhost"); 757 user_manager_->CreatePublicAccountUser("public@localhost");
768 user_manager_->AddUser("user0@managed.com"); 758 user_manager_->AddUser("user0@managed.com");
769 user_manager_->AddUser("user1@managed.com"); 759 user_manager_->AddUser("user1@managed.com");
770 user_manager_->AddUser("user2@managed.com"); 760 user_manager_->AddUser("user2@managed.com");
771 user_manager_->AddUser("user3@unmanaged.com"); 761 user_manager_->AddUser("user3@unmanaged.com");
772 user_manager_->AddUser("user4@managed.com"); 762 user_manager_->AddUser("user4@managed.com");
773 user_manager_->AddUser("user5@managed.com"); 763 user_manager_->AddUser("user5@managed.com");
774 764
775 // Verify that users are reported by default. 765 // Verify that users are reported by default.
776 GetStatus(); 766 GetStatus();
777 EXPECT_EQ(6, status_.user_size()); 767 EXPECT_EQ(6, status_.user_size());
778 768
779 // Verify that users are reported after enabling the setting. 769 // Verify that users are reported after enabling the setting.
780 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, true); 770 settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, true);
781 GetStatus(); 771 GetStatus();
782 EXPECT_EQ(6, status_.user_size()); 772 EXPECT_EQ(6, status_.user_size());
783 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); 773 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type());
784 EXPECT_EQ("user0@managed.com", status_.user(0).email()); 774 EXPECT_EQ("user0@managed.com", status_.user(0).email());
785 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type()); 775 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type());
786 EXPECT_EQ("user1@managed.com", status_.user(1).email()); 776 EXPECT_EQ("user1@managed.com", status_.user(1).email());
787 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type()); 777 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type());
788 EXPECT_EQ("user2@managed.com", status_.user(2).email()); 778 EXPECT_EQ("user2@managed.com", status_.user(2).email());
789 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, status_.user(3).type()); 779 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, status_.user(3).type());
790 EXPECT_FALSE(status_.user(3).has_email()); 780 EXPECT_FALSE(status_.user(3).has_email());
791 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(4).type()); 781 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(4).type());
792 EXPECT_EQ("user4@managed.com", status_.user(4).email()); 782 EXPECT_EQ("user4@managed.com", status_.user(4).email());
793 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(5).type()); 783 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(5).type());
794 EXPECT_EQ("user5@managed.com", status_.user(5).email()); 784 EXPECT_EQ("user5@managed.com", status_.user(5).email());
795 785
796 // Verify that users are no longer reported if setting is disabled. 786 // Verify that users are no longer reported if setting is disabled.
797 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, false); 787 settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, false);
798 GetStatus(); 788 GetStatus();
799 EXPECT_EQ(0, status_.user_size()); 789 EXPECT_EQ(0, status_.user_size());
800 } 790 }
801 791
802 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { 792 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) {
803 std::vector<std::string> expected_mount_points; 793 std::vector<std::string> expected_mount_points;
804 std::vector<em::VolumeInfo> expected_volume_info; 794 std::vector<em::VolumeInfo> expected_volume_info;
805 int size = 12345678; 795 int size = 12345678;
806 for (const auto& mount_info : 796 for (const auto& mount_info :
807 DiskMountManager::GetInstance()->mount_points()) { 797 DiskMountManager::GetInstance()->mount_points()) {
(...skipping 28 matching lines...) Expand all
836 EXPECT_EQ(expected_info.storage_free(), info.storage_free()); 826 EXPECT_EQ(expected_info.storage_free(), info.storage_free());
837 found = true; 827 found = true;
838 break; 828 break;
839 } 829 }
840 } 830 }
841 EXPECT_TRUE(found) << "No matching VolumeInfo for " 831 EXPECT_TRUE(found) << "No matching VolumeInfo for "
842 << expected_info.volume_id(); 832 << expected_info.volume_id();
843 } 833 }
844 834
845 // Now turn off hardware status reporting - should have no data. 835 // Now turn off hardware status reporting - should have no data.
846 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); 836 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false);
847 GetStatus(); 837 GetStatus();
848 EXPECT_EQ(0, status_.volume_info_size()); 838 EXPECT_EQ(0, status_.volume_info_size());
849 } 839 }
850 840
851 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { 841 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) {
852 // Refresh our samples. Sample more than kMaxHardwareSamples times to 842 // Refresh our samples. Sample more than kMaxHardwareSamples times to
853 // make sure that the code correctly caps the number of cached samples. 843 // make sure that the code correctly caps the number of cached samples.
854 for (int i = 0; i < static_cast<int>( 844 for (int i = 0; i < static_cast<int>(
855 DeviceStatusCollector::kMaxResourceUsageSamples + 1); 845 DeviceStatusCollector::kMaxResourceUsageSamples + 1);
856 ++i) { 846 ++i) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 GetStatus(); 885 GetStatus();
896 886
897 // Should not be more than kMaxResourceUsageSamples, and they should all show 887 // Should not be more than kMaxResourceUsageSamples, and they should all show
898 // the CPU is idle. 888 // the CPU is idle.
899 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), 889 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples),
900 status_.cpu_utilization_pct().size()); 890 status_.cpu_utilization_pct().size());
901 for (const auto utilization : status_.cpu_utilization_pct()) 891 for (const auto utilization : status_.cpu_utilization_pct())
902 EXPECT_EQ(0, utilization); 892 EXPECT_EQ(0, utilization);
903 893
904 // Turning off hardware reporting should not report CPU utilization. 894 // Turning off hardware reporting should not report CPU utilization.
905 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); 895 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false);
906 GetStatus(); 896 GetStatus();
907 EXPECT_EQ(0, status_.cpu_utilization_pct().size()); 897 EXPECT_EQ(0, status_.cpu_utilization_pct().size());
908 } 898 }
909 899
910 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { 900 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) {
911 // Should not report session status if we don't have an active kiosk app. 901 // Should not report session status if we don't have an active kiosk app.
912 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); 902 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true);
913 em::SessionStatusReportRequest session_status; 903 em::SessionStatusReportRequest session_status;
914 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); 904 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status));
915 } 905 }
916 906
917 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { 907 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) {
918 // Should not report session status if session status reporting is disabled. 908 // Should not report session status if session status reporting is disabled.
919 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, false); 909 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false);
920 status_collector_->set_kiosk_account(make_scoped_ptr( 910 status_collector_->set_kiosk_account(make_scoped_ptr(
921 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); 911 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass());
922 // Set up a device-local account for single-app kiosk mode. 912 // Set up a device-local account for single-app kiosk mode.
923 MockRunningKioskApp(fake_device_local_account_); 913 MockRunningKioskApp(fake_device_local_account_);
924 914
925 em::SessionStatusReportRequest session_status; 915 em::SessionStatusReportRequest session_status;
926 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); 916 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status));
927 } 917 }
928 918
929 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { 919 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) {
930 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); 920 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true);
931 status_collector_->set_kiosk_account(make_scoped_ptr( 921 status_collector_->set_kiosk_account(make_scoped_ptr(
932 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); 922 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass());
933 923
934 // Set up a device-local account for single-app kiosk mode. 924 // Set up a device-local account for single-app kiosk mode.
935 MockRunningKioskApp(fake_device_local_account_); 925 MockRunningKioskApp(fake_device_local_account_);
936 926
937 em::SessionStatusReportRequest session_status; 927 em::SessionStatusReportRequest session_status;
938 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status)); 928 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status));
939 ASSERT_EQ(1, session_status.installed_apps_size()); 929 ASSERT_EQ(1, session_status.installed_apps_size());
940 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id()); 930 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 // Mock that we are in kiosk mode so we report network state. 1143 // Mock that we are in kiosk mode so we report network state.
1154 status_collector_->set_kiosk_account(make_scoped_ptr( 1144 status_collector_->set_kiosk_account(make_scoped_ptr(
1155 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); 1145 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass());
1156 1146
1157 // Interfaces should be reported by default. 1147 // Interfaces should be reported by default.
1158 GetStatus(); 1148 GetStatus();
1159 EXPECT_LT(0, status_.network_interface_size()); 1149 EXPECT_LT(0, status_.network_interface_size());
1160 EXPECT_LT(0, status_.network_state_size()); 1150 EXPECT_LT(0, status_.network_state_size());
1161 1151
1162 // No interfaces should be reported if the policy is off. 1152 // No interfaces should be reported if the policy is off.
1163 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); 1153 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false);
1164 GetStatus(); 1154 GetStatus();
1165 EXPECT_EQ(0, status_.network_interface_size()); 1155 EXPECT_EQ(0, status_.network_interface_size());
1166 EXPECT_EQ(0, status_.network_state_size()); 1156 EXPECT_EQ(0, status_.network_state_size());
1167 1157
1168 // Switch the policy on and verify the interface list is present. 1158 // Switch the policy on and verify the interface list is present.
1169 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); 1159 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true);
1170 GetStatus(); 1160 GetStatus();
1171 1161
1172 int count = 0; 1162 int count = 0;
1173 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { 1163 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) {
1174 const FakeDeviceData& dev = kFakeDevices[i]; 1164 const FakeDeviceData& dev = kFakeDevices[i];
1175 if (dev.expected_type == -1) 1165 if (dev.expected_type == -1)
1176 continue; 1166 continue;
1177 1167
1178 // Find the corresponding entry in reporting data. 1168 // Find the corresponding entry in reporting data.
1179 bool found_match = false; 1169 bool found_match = false;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 found_match = true; 1213 found_match = true;
1224 break; 1214 break;
1225 } 1215 }
1226 } 1216 }
1227 EXPECT_TRUE(found_match) << "No matching state for fake network " 1217 EXPECT_TRUE(found_match) << "No matching state for fake network "
1228 << " (" << state.name << ")"; 1218 << " (" << state.name << ")";
1229 } 1219 }
1230 } 1220 }
1231 1221
1232 } // namespace policy 1222 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698