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

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: Rearrange device settings list. Created 5 years, 9 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/cros_settings.h"
25 #include "chrome/browser/chromeos/settings/device_settings_service.h" 26 #include "chrome/browser/chromeos/settings/device_settings_service.h"
26 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 27 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chrome/test/base/testing_browser_process.h" 29 #include "chrome/test/base/testing_browser_process.h"
29 #include "chromeos/dbus/cros_disks_client.h" 30 #include "chromeos/dbus/cros_disks_client.h"
30 #include "chromeos/dbus/dbus_thread_manager.h" 31 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 EXPECT_CALL(*mock_disk_mount_manager, mount_points()) 262 EXPECT_CALL(*mock_disk_mount_manager, mount_points())
262 .WillRepeatedly(ReturnRef(mount_point_map_)); 263 .WillRepeatedly(ReturnRef(mount_point_map_));
263 264
264 // DiskMountManager takes ownership of the MockDiskMountManager. 265 // DiskMountManager takes ownership of the MockDiskMountManager.
265 DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release()); 266 DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release());
266 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry()); 267 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry());
267 268
268 // Remove the real DeviceSettingsProvider and replace it with a stub. 269 // Remove the real DeviceSettingsProvider and replace it with a stub.
269 cros_settings_ = chromeos::CrosSettings::Get(); 270 cros_settings_ = chromeos::CrosSettings::Get();
270 device_settings_provider_ = 271 device_settings_provider_ =
271 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); 272 cros_settings_->GetProvider(chromeos::kReportDeviceActivityTimes);
272 EXPECT_TRUE(device_settings_provider_ != NULL); 273 EXPECT_TRUE(device_settings_provider_ != NULL);
273 EXPECT_TRUE( 274 EXPECT_TRUE(
274 cros_settings_->RemoveSettingsProvider(device_settings_provider_)); 275 cros_settings_->RemoveSettingsProvider(device_settings_provider_));
275 cros_settings_->AddSettingsProvider(&stub_settings_provider_); 276 cros_settings_->AddSettingsProvider(&stub_settings_provider_);
277 owner_settings_service_.reset(
278 new chromeos::FakeOwnerSettingsService(nullptr));
276 279
277 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); 280 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo));
278 } 281 }
279 282
280 void AddMountPoint(const std::string& mount_point) { 283 void AddMountPoint(const std::string& mount_point) {
281 mount_point_map_.insert(DiskMountManager::MountPointMap::value_type( 284 mount_point_map_.insert(DiskMountManager::MountPointMap::value_type(
282 mount_point, 285 mount_point,
283 DiskMountManager::MountPointInfo( 286 DiskMountManager::MountPointInfo(
284 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE, 287 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE,
285 chromeos::disks::MOUNT_CONDITION_NONE))); 288 chromeos::disks::MOUNT_CONDITION_NONE)));
286 } 289 }
287 290
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 EXPECT_TRUE(status_.has_device_location()); 357 EXPECT_TRUE(status_.has_device_location());
355 em::DeviceLocation location = status_.device_location(); 358 em::DeviceLocation location = status_.device_location();
356 EXPECT_TRUE(location.has_error_code()); 359 EXPECT_TRUE(location.has_error_code());
357 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE, 360 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE,
358 location.error_code()); 361 location.error_code());
359 } 362 }
360 363
361 void MockRunningKioskApp(const DeviceLocalAccount& account) { 364 void MockRunningKioskApp(const DeviceLocalAccount& account) {
362 std::vector<DeviceLocalAccount> accounts; 365 std::vector<DeviceLocalAccount> accounts;
363 accounts.push_back(account); 366 accounts.push_back(account);
364 SetDeviceLocalAccounts(cros_settings_, accounts); 367 SetDeviceLocalAccounts(owner_settings_service_.get(), accounts);
365 user_manager_->CreateKioskAppUser(account.user_id); 368 user_manager_->CreateKioskAppUser(account.user_id);
366 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly( 369 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly(
367 Return(true)); 370 Return(true));
368 } 371 }
369 372
370 protected: 373 protected:
371 // Convenience method. 374 // Convenience method.
372 int64 ActivePeriodMilliseconds() { 375 int64 ActivePeriodMilliseconds() {
373 return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000; 376 return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000;
374 } 377 }
375 378
376 // Since this is a unit test running in browser_tests we must do additional 379 // Since this is a unit test running in browser_tests we must do additional
377 // unit test setup and make a TestingBrowserProcess. Must be first member. 380 // unit test setup and make a TestingBrowserProcess. Must be first member.
378 TestingBrowserProcessInitializer initializer_; 381 TestingBrowserProcessInitializer initializer_;
379 base::MessageLoopForUI message_loop_; 382 base::MessageLoopForUI message_loop_;
380 content::TestBrowserThread ui_thread_; 383 content::TestBrowserThread ui_thread_;
381 content::TestBrowserThread file_thread_; 384 content::TestBrowserThread file_thread_;
382 content::TestBrowserThread io_thread_; 385 content::TestBrowserThread io_thread_;
383 386
384 ScopedStubEnterpriseInstallAttributes install_attributes_; 387 ScopedStubEnterpriseInstallAttributes install_attributes_;
385 TestingPrefServiceSimple prefs_; 388 TestingPrefServiceSimple prefs_;
386 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; 389 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_;
387 DiskMountManager::MountPointMap mount_point_map_; 390 DiskMountManager::MountPointMap mount_point_map_;
388 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 391 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
389 chromeos::ScopedTestCrosSettings test_cros_settings_; 392 chromeos::ScopedTestCrosSettings test_cros_settings_;
390 chromeos::CrosSettings* cros_settings_; 393 chromeos::CrosSettings* cros_settings_;
391 chromeos::CrosSettingsProvider* device_settings_provider_; 394 chromeos::CrosSettingsProvider* device_settings_provider_;
392 chromeos::StubCrosSettingsProvider stub_settings_provider_; 395 chromeos::StubCrosSettingsProvider stub_settings_provider_;
396 scoped_ptr<chromeos::FakeOwnerSettingsService> owner_settings_service_;
393 chromeos::MockUserManager* user_manager_; 397 chromeos::MockUserManager* user_manager_;
394 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 398 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
395 em::DeviceStatusReportRequest status_; 399 em::DeviceStatusReportRequest status_;
396 scoped_ptr<TestingDeviceStatusCollector> status_collector_; 400 scoped_ptr<TestingDeviceStatusCollector> status_collector_;
397 const policy::DeviceLocalAccount fake_device_local_account_; 401 const policy::DeviceLocalAccount fake_device_local_account_;
398 }; 402 };
399 403
400 TEST_F(DeviceStatusCollectorTest, AllIdle) { 404 TEST_F(DeviceStatusCollectorTest, AllIdle) {
401 ui::IdleState test_states[] = { 405 ui::IdleState test_states[] = {
402 ui::IDLE_STATE_IDLE, 406 ui::IDLE_STATE_IDLE,
403 ui::IDLE_STATE_IDLE, 407 ui::IDLE_STATE_IDLE,
404 ui::IDLE_STATE_IDLE 408 ui::IDLE_STATE_IDLE
405 }; 409 };
406 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 410 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
411 true);
407 412
408 // Test reporting with no data. 413 // Test reporting with no data.
409 GetStatus(); 414 GetStatus();
410 EXPECT_EQ(0, status_.active_period_size()); 415 EXPECT_EQ(0, status_.active_period_size());
411 EXPECT_EQ(0, GetActiveMilliseconds(status_)); 416 EXPECT_EQ(0, GetActiveMilliseconds(status_));
412 417
413 // Test reporting with a single idle sample. 418 // Test reporting with a single idle sample.
414 status_collector_->Simulate(test_states, 1); 419 status_collector_->Simulate(test_states, 1);
415 GetStatus(); 420 GetStatus();
416 EXPECT_EQ(0, status_.active_period_size()); 421 EXPECT_EQ(0, status_.active_period_size());
417 EXPECT_EQ(0, GetActiveMilliseconds(status_)); 422 EXPECT_EQ(0, GetActiveMilliseconds(status_));
418 423
419 // Test reporting with multiple consecutive idle samples. 424 // Test reporting with multiple consecutive idle samples.
420 status_collector_->Simulate(test_states, 425 status_collector_->Simulate(test_states,
421 sizeof(test_states) / sizeof(ui::IdleState)); 426 sizeof(test_states) / sizeof(ui::IdleState));
422 GetStatus(); 427 GetStatus();
423 EXPECT_EQ(0, status_.active_period_size()); 428 EXPECT_EQ(0, status_.active_period_size());
424 EXPECT_EQ(0, GetActiveMilliseconds(status_)); 429 EXPECT_EQ(0, GetActiveMilliseconds(status_));
425 } 430 }
426 431
427 TEST_F(DeviceStatusCollectorTest, AllActive) { 432 TEST_F(DeviceStatusCollectorTest, AllActive) {
428 ui::IdleState test_states[] = { 433 ui::IdleState test_states[] = {
429 ui::IDLE_STATE_ACTIVE, 434 ui::IDLE_STATE_ACTIVE,
430 ui::IDLE_STATE_ACTIVE, 435 ui::IDLE_STATE_ACTIVE,
431 ui::IDLE_STATE_ACTIVE 436 ui::IDLE_STATE_ACTIVE
432 }; 437 };
433 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 438 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
439 true);
434 440
435 // Test a single active sample. 441 // Test a single active sample.
436 status_collector_->Simulate(test_states, 1); 442 status_collector_->Simulate(test_states, 1);
437 GetStatus(); 443 GetStatus();
438 EXPECT_EQ(1, status_.active_period_size()); 444 EXPECT_EQ(1, status_.active_period_size());
439 EXPECT_EQ(1 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 445 EXPECT_EQ(1 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
440 status_.clear_active_period(); // Clear the result protobuf. 446 status_.clear_active_period(); // Clear the result protobuf.
441 447
442 // Test multiple consecutive active samples. 448 // Test multiple consecutive active samples.
443 status_collector_->Simulate(test_states, 449 status_collector_->Simulate(test_states,
444 sizeof(test_states) / sizeof(ui::IdleState)); 450 sizeof(test_states) / sizeof(ui::IdleState));
445 GetStatus(); 451 GetStatus();
446 EXPECT_EQ(1, status_.active_period_size()); 452 EXPECT_EQ(1, status_.active_period_size());
447 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 453 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
448 } 454 }
449 455
450 TEST_F(DeviceStatusCollectorTest, MixedStates) { 456 TEST_F(DeviceStatusCollectorTest, MixedStates) {
451 ui::IdleState test_states[] = { 457 ui::IdleState test_states[] = {
452 ui::IDLE_STATE_ACTIVE, 458 ui::IDLE_STATE_ACTIVE,
453 ui::IDLE_STATE_IDLE, 459 ui::IDLE_STATE_IDLE,
454 ui::IDLE_STATE_ACTIVE, 460 ui::IDLE_STATE_ACTIVE,
455 ui::IDLE_STATE_ACTIVE, 461 ui::IDLE_STATE_ACTIVE,
456 ui::IDLE_STATE_IDLE, 462 ui::IDLE_STATE_IDLE,
457 ui::IDLE_STATE_IDLE, 463 ui::IDLE_STATE_IDLE,
458 ui::IDLE_STATE_ACTIVE 464 ui::IDLE_STATE_ACTIVE
459 }; 465 };
460 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 466 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
467 true);
461 status_collector_->Simulate(test_states, 468 status_collector_->Simulate(test_states,
462 sizeof(test_states) / sizeof(ui::IdleState)); 469 sizeof(test_states) / sizeof(ui::IdleState));
463 GetStatus(); 470 GetStatus();
464 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 471 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
465 } 472 }
466 473
467 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { 474 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) {
468 ui::IdleState test_states[] = { 475 ui::IdleState test_states[] = {
469 ui::IDLE_STATE_ACTIVE, 476 ui::IDLE_STATE_ACTIVE,
470 ui::IDLE_STATE_IDLE, 477 ui::IDLE_STATE_IDLE,
471 ui::IDLE_STATE_ACTIVE, 478 ui::IDLE_STATE_ACTIVE,
472 ui::IDLE_STATE_ACTIVE, 479 ui::IDLE_STATE_ACTIVE,
473 ui::IDLE_STATE_IDLE, 480 ui::IDLE_STATE_IDLE,
474 ui::IDLE_STATE_IDLE 481 ui::IDLE_STATE_IDLE
475 }; 482 };
476 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 483 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
484 true);
477 status_collector_->Simulate(test_states, 485 status_collector_->Simulate(test_states,
478 sizeof(test_states) / sizeof(ui::IdleState)); 486 sizeof(test_states) / sizeof(ui::IdleState));
479 487
480 // Process the list a second time after restarting the collector. It should be 488 // Process the list a second time after restarting the collector. It should be
481 // able to count the active periods found by the original collector, because 489 // able to count the active periods found by the original collector, because
482 // the results are stored in a pref. 490 // the results are stored in a pref.
483 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); 491 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo));
484 status_collector_->Simulate(test_states, 492 status_collector_->Simulate(test_states,
485 sizeof(test_states) / sizeof(ui::IdleState)); 493 sizeof(test_states) / sizeof(ui::IdleState));
486 494
487 GetStatus(); 495 GetStatus();
488 EXPECT_EQ(6 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 496 EXPECT_EQ(6 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
489 } 497 }
490 498
491 TEST_F(DeviceStatusCollectorTest, Times) { 499 TEST_F(DeviceStatusCollectorTest, Times) {
492 ui::IdleState test_states[] = { 500 ui::IdleState test_states[] = {
493 ui::IDLE_STATE_ACTIVE, 501 ui::IDLE_STATE_ACTIVE,
494 ui::IDLE_STATE_IDLE, 502 ui::IDLE_STATE_IDLE,
495 ui::IDLE_STATE_ACTIVE, 503 ui::IDLE_STATE_ACTIVE,
496 ui::IDLE_STATE_ACTIVE, 504 ui::IDLE_STATE_ACTIVE,
497 ui::IDLE_STATE_IDLE, 505 ui::IDLE_STATE_IDLE,
498 ui::IDLE_STATE_IDLE 506 ui::IDLE_STATE_IDLE
499 }; 507 };
500 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 508 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
509 true);
501 status_collector_->Simulate(test_states, 510 status_collector_->Simulate(test_states,
502 sizeof(test_states) / sizeof(ui::IdleState)); 511 sizeof(test_states) / sizeof(ui::IdleState));
503 GetStatus(); 512 GetStatus();
504 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 513 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
505 } 514 }
506 515
507 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { 516 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) {
508 ui::IdleState test_states[] = { 517 ui::IdleState test_states[] = {
509 ui::IDLE_STATE_ACTIVE, 518 ui::IDLE_STATE_ACTIVE,
510 ui::IDLE_STATE_IDLE 519 ui::IDLE_STATE_IDLE
511 }; 520 };
512 const int kMaxDays = 10; 521 const int kMaxDays = 10;
513 522
514 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 523 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
524 true);
515 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); 525 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1);
516 status_collector_->set_max_stored_future_activity_days(1); 526 status_collector_->set_max_stored_future_activity_days(1);
517 Time baseline = Time::Now().LocalMidnight(); 527 Time baseline = Time::Now().LocalMidnight();
518 528
519 // Simulate 12 active periods. 529 // Simulate 12 active periods.
520 for (int i = 0; i < kMaxDays + 2; i++) { 530 for (int i = 0; i < kMaxDays + 2; i++) {
521 status_collector_->Simulate(test_states, 531 status_collector_->Simulate(test_states,
522 sizeof(test_states) / sizeof(ui::IdleState)); 532 sizeof(test_states) / sizeof(ui::IdleState));
523 // Advance the simulated clock by a day. 533 // Advance the simulated clock by a day.
524 baseline += TimeDelta::FromDays(1); 534 baseline += TimeDelta::FromDays(1);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 }; 569 };
560 status_collector_->Simulate(test_states, 570 status_collector_->Simulate(test_states,
561 sizeof(test_states) / sizeof(ui::IdleState)); 571 sizeof(test_states) / sizeof(ui::IdleState));
562 GetStatus(); 572 GetStatus();
563 EXPECT_EQ(1, status_.active_period_size()); 573 EXPECT_EQ(1, status_.active_period_size());
564 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 574 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
565 } 575 }
566 576
567 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { 577 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) {
568 // Device activity times should not be reported if explicitly disabled. 578 // Device activity times should not be reported if explicitly disabled.
569 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, false); 579 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
580 false);
570 581
571 ui::IdleState test_states[] = { 582 ui::IdleState test_states[] = {
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 ui::IDLE_STATE_ACTIVE
575 }; 586 };
576 status_collector_->Simulate(test_states, 587 status_collector_->Simulate(test_states,
577 sizeof(test_states) / sizeof(ui::IdleState)); 588 sizeof(test_states) / sizeof(ui::IdleState));
578 GetStatus(); 589 GetStatus();
579 EXPECT_EQ(0, status_.active_period_size()); 590 EXPECT_EQ(0, status_.active_period_size());
580 EXPECT_EQ(0, GetActiveMilliseconds(status_)); 591 EXPECT_EQ(0, GetActiveMilliseconds(status_));
581 } 592 }
582 593
583 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { 594 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) {
584 ui::IdleState test_states[] = { 595 ui::IdleState test_states[] = {
585 ui::IDLE_STATE_ACTIVE 596 ui::IDLE_STATE_ACTIVE
586 }; 597 };
587 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 598 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
599 true);
588 600
589 // Set the baseline time to 10 seconds after midnight. 601 // Set the baseline time to 10 seconds after midnight.
590 status_collector_->SetBaselineTime( 602 status_collector_->SetBaselineTime(
591 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); 603 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10));
592 604
593 status_collector_->Simulate(test_states, 1); 605 status_collector_->Simulate(test_states, 1);
594 GetStatus(); 606 GetStatus();
595 ASSERT_EQ(2, status_.active_period_size()); 607 ASSERT_EQ(2, status_.active_period_size());
596 608
597 em::ActiveTimePeriod period0 = status_.active_period(0); 609 em::ActiveTimePeriod period0 = status_.active_period(0);
(...skipping 11 matching lines...) Expand all
609 kMillisecondsPerDay); 621 kMillisecondsPerDay);
610 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(), 622 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(),
611 kMillisecondsPerDay); 623 kMillisecondsPerDay);
612 } 624 }
613 625
614 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { 626 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) {
615 ui::IdleState test_states[] = { 627 ui::IdleState test_states[] = {
616 ui::IDLE_STATE_ACTIVE, 628 ui::IDLE_STATE_ACTIVE,
617 ui::IDLE_STATE_ACTIVE, 629 ui::IDLE_STATE_ACTIVE,
618 }; 630 };
619 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); 631 owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
632 true);
620 633
621 status_collector_->Simulate(test_states, 2); 634 status_collector_->Simulate(test_states, 2);
622 GetStatus(); 635 GetStatus();
623 EXPECT_EQ(2 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 636 EXPECT_EQ(2 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
624 em::DeviceStatusReportRequest first_status(status_); 637 em::DeviceStatusReportRequest first_status(status_);
625 638
626 // The collector returns the same status again. 639 // The collector returns the same status again.
627 GetStatus(); 640 GetStatus();
628 EXPECT_EQ(first_status.SerializeAsString(), status_.SerializeAsString()); 641 EXPECT_EQ(first_status.SerializeAsString(), status_.SerializeAsString());
629 642
630 // After indicating a successful submit, the submitted status gets cleared, 643 // After indicating a successful submit, the submitted status gets cleared,
631 // but what got collected meanwhile sticks around. 644 // but what got collected meanwhile sticks around.
632 status_collector_->Simulate(test_states, 1); 645 status_collector_->Simulate(test_states, 1);
633 status_collector_->OnSubmittedSuccessfully(); 646 status_collector_->OnSubmittedSuccessfully();
634 GetStatus(); 647 GetStatus();
635 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); 648 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
636 } 649 }
637 650
638 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { 651 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) {
639 // Test that boot mode data is reported by default. 652 // Test that boot mode data is reported by default.
640 fake_statistics_provider_.SetMachineStatistic( 653 fake_statistics_provider_.SetMachineStatistic(
641 chromeos::system::kDevSwitchBootKey, 654 chromeos::system::kDevSwitchBootKey,
642 chromeos::system::kDevSwitchBootValueVerified); 655 chromeos::system::kDevSwitchBootValueVerified);
643 GetStatus(); 656 GetStatus();
644 EXPECT_EQ("Verified", status_.boot_mode()); 657 EXPECT_EQ("Verified", status_.boot_mode());
645 658
646 // Test that boot mode data is not reported if the pref turned off. 659 // Test that boot mode data is not reported if the pref turned off.
647 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, false); 660 owner_settings_service_->SetBoolean(chromeos::kReportDeviceBootMode, false);
648 661
649 GetStatus(); 662 GetStatus();
650 EXPECT_FALSE(status_.has_boot_mode()); 663 EXPECT_FALSE(status_.has_boot_mode());
651 664
652 // Turn the pref on, and check that the status is reported iff the 665 // Turn the pref on, and check that the status is reported iff the
653 // statistics provider returns valid data. 666 // statistics provider returns valid data.
654 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, true); 667 owner_settings_service_->SetBoolean(chromeos::kReportDeviceBootMode, true);
655 668
656 fake_statistics_provider_.SetMachineStatistic( 669 fake_statistics_provider_.SetMachineStatistic(
657 chromeos::system::kDevSwitchBootKey, "(error)"); 670 chromeos::system::kDevSwitchBootKey, "(error)");
658 GetStatus(); 671 GetStatus();
659 EXPECT_FALSE(status_.has_boot_mode()); 672 EXPECT_FALSE(status_.has_boot_mode());
660 673
661 fake_statistics_provider_.SetMachineStatistic( 674 fake_statistics_provider_.SetMachineStatistic(
662 chromeos::system::kDevSwitchBootKey, " "); 675 chromeos::system::kDevSwitchBootKey, " ");
663 GetStatus(); 676 GetStatus();
664 EXPECT_FALSE(status_.has_boot_mode()); 677 EXPECT_FALSE(status_.has_boot_mode());
(...skipping 13 matching lines...) Expand all
678 691
679 TEST_F(DeviceStatusCollectorTest, VersionInfo) { 692 TEST_F(DeviceStatusCollectorTest, VersionInfo) {
680 // Expect the version info to be reported by default. 693 // Expect the version info to be reported by default.
681 GetStatus(); 694 GetStatus();
682 EXPECT_TRUE(status_.has_browser_version()); 695 EXPECT_TRUE(status_.has_browser_version());
683 EXPECT_TRUE(status_.has_os_version()); 696 EXPECT_TRUE(status_.has_os_version());
684 EXPECT_TRUE(status_.has_firmware_version()); 697 EXPECT_TRUE(status_.has_firmware_version());
685 698
686 // When the pref to collect this data is not enabled, expect that none of 699 // When the pref to collect this data is not enabled, expect that none of
687 // the fields are present in the protobuf. 700 // the fields are present in the protobuf.
688 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, false); 701 owner_settings_service_->SetBoolean(chromeos::kReportDeviceVersionInfo,
702 false);
689 GetStatus(); 703 GetStatus();
690 EXPECT_FALSE(status_.has_browser_version()); 704 EXPECT_FALSE(status_.has_browser_version());
691 EXPECT_FALSE(status_.has_os_version()); 705 EXPECT_FALSE(status_.has_os_version());
692 EXPECT_FALSE(status_.has_firmware_version()); 706 EXPECT_FALSE(status_.has_firmware_version());
693 707
694 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, true); 708 owner_settings_service_->SetBoolean(chromeos::kReportDeviceVersionInfo, true);
695 GetStatus(); 709 GetStatus();
696 EXPECT_TRUE(status_.has_browser_version()); 710 EXPECT_TRUE(status_.has_browser_version());
697 EXPECT_TRUE(status_.has_os_version()); 711 EXPECT_TRUE(status_.has_os_version());
698 EXPECT_TRUE(status_.has_firmware_version()); 712 EXPECT_TRUE(status_.has_firmware_version());
699 713
700 // Check that the browser version is not empty. OS version & firmware 714 // Check that the browser version is not empty. OS version & firmware
701 // don't have any reasonable values inside the unit test, so those 715 // don't have any reasonable values inside the unit test, so those
702 // aren't checked. 716 // aren't checked.
703 EXPECT_NE("", status_.browser_version()); 717 EXPECT_NE("", status_.browser_version());
704 } 718 }
(...skipping 11 matching lines...) Expand all
716 invalid_fix.timestamp = Time::Now(); 730 invalid_fix.timestamp = Time::Now();
717 731
718 // Check that when device location reporting is disabled, no location is 732 // Check that when device location reporting is disabled, no location is
719 // reported. 733 // reported.
720 SetMockPositionToReturnNext(valid_fix); 734 SetMockPositionToReturnNext(valid_fix);
721 CheckThatNoLocationIsReported(); 735 CheckThatNoLocationIsReported();
722 736
723 // Check that when device location reporting is enabled and a valid fix is 737 // Check that when device location reporting is enabled and a valid fix is
724 // available, the location is reported and is stored in local state. 738 // available, the location is reported and is stored in local state.
725 SetMockPositionToReturnNext(valid_fix); 739 SetMockPositionToReturnNext(valid_fix);
726 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); 740 owner_settings_service_->SetBoolean(chromeos::kReportDeviceLocation, true);
727 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); 741 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty());
728 CheckThatAValidLocationIsReported(); 742 CheckThatAValidLocationIsReported();
729 743
730 // Restart the status collector. Check that the last known location has been 744 // Restart the status collector. Check that the last known location has been
731 // retrieved from local state without requesting a geolocation update. 745 // retrieved from local state without requesting a geolocation update.
732 SetMockPositionToReturnNext(valid_fix); 746 SetMockPositionToReturnNext(valid_fix);
733 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); 747 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo));
734 CheckThatAValidLocationIsReported(); 748 CheckThatAValidLocationIsReported();
735 EXPECT_TRUE(mock_position_to_return_next.get()); 749 EXPECT_TRUE(mock_position_to_return_next.get());
736 750
737 // Check that after disabling location reporting again, the last known 751 // Check that after disabling location reporting again, the last known
738 // location has been cleared from local state and is no longer reported. 752 // location has been cleared from local state and is no longer reported.
739 SetMockPositionToReturnNext(valid_fix); 753 SetMockPositionToReturnNext(valid_fix);
740 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, false); 754 owner_settings_service_->SetBoolean(chromeos::kReportDeviceLocation, false);
741 // Allow the new pref to propagate to the status collector. 755 // Allow the new pref to propagate to the status collector.
742 message_loop_.RunUntilIdle(); 756 message_loop_.RunUntilIdle();
743 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); 757 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty());
744 CheckThatNoLocationIsReported(); 758 CheckThatNoLocationIsReported();
745 759
746 // Check that after enabling location reporting again, an error is reported 760 // Check that after enabling location reporting again, an error is reported
747 // if no valid fix is available. 761 // if no valid fix is available.
748 SetMockPositionToReturnNext(invalid_fix); 762 SetMockPositionToReturnNext(invalid_fix);
749 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); 763 owner_settings_service_->SetBoolean(chromeos::kReportDeviceLocation, true);
750 // Allow the new pref to propagate to the status collector. 764 // Allow the new pref to propagate to the status collector.
751 message_loop_.RunUntilIdle(); 765 message_loop_.RunUntilIdle();
752 CheckThatALocationErrorIsReported(); 766 CheckThatALocationErrorIsReported();
753 } 767 }
754 768
755 TEST_F(DeviceStatusCollectorTest, ReportUsers) { 769 TEST_F(DeviceStatusCollectorTest, ReportUsers) {
756 user_manager_->CreatePublicAccountUser("public@localhost"); 770 user_manager_->CreatePublicAccountUser("public@localhost");
757 user_manager_->AddUser("user0@managed.com"); 771 user_manager_->AddUser("user0@managed.com");
758 user_manager_->AddUser("user1@managed.com"); 772 user_manager_->AddUser("user1@managed.com");
759 user_manager_->AddUser("user2@managed.com"); 773 user_manager_->AddUser("user2@managed.com");
760 user_manager_->AddUser("user3@unmanaged.com"); 774 user_manager_->AddUser("user3@unmanaged.com");
761 user_manager_->AddUser("user4@managed.com"); 775 user_manager_->AddUser("user4@managed.com");
762 user_manager_->AddUser("user5@managed.com"); 776 user_manager_->AddUser("user5@managed.com");
763 777
764 // Verify that users are reported by default. 778 // Verify that users are reported by default.
765 GetStatus(); 779 GetStatus();
766 EXPECT_EQ(6, status_.user_size()); 780 EXPECT_EQ(6, status_.user_size());
767 781
768 // Verify that users are reported after enabling the setting. 782 // Verify that users are reported after enabling the setting.
769 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, true); 783 owner_settings_service_->SetBoolean(chromeos::kReportDeviceUsers, true);
770 GetStatus(); 784 GetStatus();
771 EXPECT_EQ(6, status_.user_size()); 785 EXPECT_EQ(6, status_.user_size());
772 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); 786 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type());
773 EXPECT_EQ("user0@managed.com", status_.user(0).email()); 787 EXPECT_EQ("user0@managed.com", status_.user(0).email());
774 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type()); 788 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type());
775 EXPECT_EQ("user1@managed.com", status_.user(1).email()); 789 EXPECT_EQ("user1@managed.com", status_.user(1).email());
776 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type()); 790 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type());
777 EXPECT_EQ("user2@managed.com", status_.user(2).email()); 791 EXPECT_EQ("user2@managed.com", status_.user(2).email());
778 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, status_.user(3).type()); 792 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, status_.user(3).type());
779 EXPECT_FALSE(status_.user(3).has_email()); 793 EXPECT_FALSE(status_.user(3).has_email());
780 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(4).type()); 794 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(4).type());
781 EXPECT_EQ("user4@managed.com", status_.user(4).email()); 795 EXPECT_EQ("user4@managed.com", status_.user(4).email());
782 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(5).type()); 796 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(5).type());
783 EXPECT_EQ("user5@managed.com", status_.user(5).email()); 797 EXPECT_EQ("user5@managed.com", status_.user(5).email());
784 798
785 // Verify that users are no longer reported if setting is disabled. 799 // Verify that users are no longer reported if setting is disabled.
786 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, false); 800 owner_settings_service_->SetBoolean(chromeos::kReportDeviceUsers, false);
787 GetStatus(); 801 GetStatus();
788 EXPECT_EQ(0, status_.user_size()); 802 EXPECT_EQ(0, status_.user_size());
789 } 803 }
790 804
791 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { 805 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) {
792 std::vector<std::string> expected_mount_points; 806 std::vector<std::string> expected_mount_points;
793 std::vector<em::VolumeInfo> expected_volume_info; 807 std::vector<em::VolumeInfo> expected_volume_info;
794 int size = 12345678; 808 int size = 12345678;
795 for (const auto& mount_info : 809 for (const auto& mount_info :
796 DiskMountManager::GetInstance()->mount_points()) { 810 DiskMountManager::GetInstance()->mount_points()) {
(...skipping 24 matching lines...) Expand all
821 EXPECT_EQ(expected_info.storage_free(), info.storage_free()); 835 EXPECT_EQ(expected_info.storage_free(), info.storage_free());
822 found = true; 836 found = true;
823 break; 837 break;
824 } 838 }
825 } 839 }
826 EXPECT_TRUE(found) << "No matching VolumeInfo for " 840 EXPECT_TRUE(found) << "No matching VolumeInfo for "
827 << expected_info.volume_id(); 841 << expected_info.volume_id();
828 } 842 }
829 843
830 // Now turn off hardware status reporting - should have no data. 844 // Now turn off hardware status reporting - should have no data.
831 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); 845 owner_settings_service_->SetBoolean(chromeos::kReportDeviceHardwareStatus,
846 false);
832 GetStatus(); 847 GetStatus();
833 EXPECT_EQ(0, status_.volume_info_size()); 848 EXPECT_EQ(0, status_.volume_info_size());
834 } 849 }
835 850
836 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { 851 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) {
837 status_collector_->RefreshSampleResourceUsage(); 852 status_collector_->RefreshSampleResourceUsage();
838 GetStatus(); 853 GetStatus();
839 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), 854 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples),
840 status_.system_ram_free().size()); 855 status_.system_ram_free().size());
841 EXPECT_TRUE(status_.has_system_ram_total()); 856 EXPECT_TRUE(status_.has_system_ram_total());
(...skipping 15 matching lines...) Expand all
857 // Now set CPU usage to 0. 872 // Now set CPU usage to 0.
858 const int idle_cpu_usage = 0; 873 const int idle_cpu_usage = 0;
859 status_collector_->set_mock_cpu_usage(idle_cpu_usage, 2); 874 status_collector_->set_mock_cpu_usage(idle_cpu_usage, 2);
860 GetStatus(); 875 GetStatus();
861 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), 876 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples),
862 status_.cpu_utilization_pct().size()); 877 status_.cpu_utilization_pct().size());
863 for (const auto utilization : status_.cpu_utilization_pct()) 878 for (const auto utilization : status_.cpu_utilization_pct())
864 EXPECT_EQ(idle_cpu_usage, utilization); 879 EXPECT_EQ(idle_cpu_usage, utilization);
865 880
866 // Turning off hardware reporting should not report CPU utilization. 881 // Turning off hardware reporting should not report CPU utilization.
867 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); 882 owner_settings_service_->SetBoolean(chromeos::kReportDeviceHardwareStatus,
883 false);
868 GetStatus(); 884 GetStatus();
869 EXPECT_EQ(0, status_.cpu_utilization_pct().size()); 885 EXPECT_EQ(0, status_.cpu_utilization_pct().size());
870 } 886 }
871 887
872 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { 888 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) {
873 // Should not report session status if we don't have an active kiosk app. 889 // Should not report session status if we don't have an active kiosk app.
874 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); 890 owner_settings_service_->SetBoolean(chromeos::kReportDeviceSessionStatus,
891 true);
875 em::SessionStatusReportRequest session_status; 892 em::SessionStatusReportRequest session_status;
876 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); 893 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status));
877 } 894 }
878 895
879 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { 896 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) {
880 // Should not report session status if session status reporting is disabled. 897 // Should not report session status if session status reporting is disabled.
881 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, false); 898 owner_settings_service_->SetBoolean(chromeos::kReportDeviceSessionStatus,
899 false);
882 status_collector_->set_kiosk_account(make_scoped_ptr( 900 status_collector_->set_kiosk_account(make_scoped_ptr(
883 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); 901 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass());
884 // Set up a device-local account for single-app kiosk mode. 902 // Set up a device-local account for single-app kiosk mode.
885 MockRunningKioskApp(fake_device_local_account_); 903 MockRunningKioskApp(fake_device_local_account_);
886 904
887 em::SessionStatusReportRequest session_status; 905 em::SessionStatusReportRequest session_status;
888 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); 906 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status));
889 } 907 }
890 908
891 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { 909 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) {
892 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); 910 owner_settings_service_->SetBoolean(chromeos::kReportDeviceSessionStatus,
911 true);
893 status_collector_->set_kiosk_account(make_scoped_ptr( 912 status_collector_->set_kiosk_account(make_scoped_ptr(
894 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); 913 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass());
895 914
896 // Set up a device-local account for single-app kiosk mode. 915 // Set up a device-local account for single-app kiosk mode.
897 MockRunningKioskApp(fake_device_local_account_); 916 MockRunningKioskApp(fake_device_local_account_);
898 917
899 em::SessionStatusReportRequest session_status; 918 em::SessionStatusReportRequest session_status;
900 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status)); 919 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status));
901 ASSERT_EQ(1, session_status.installed_apps_size()); 920 ASSERT_EQ(1, session_status.installed_apps_size());
902 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id()); 921 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 // Mock that we are in kiosk mode so we report network state. 1134 // Mock that we are in kiosk mode so we report network state.
1116 status_collector_->set_kiosk_account(make_scoped_ptr( 1135 status_collector_->set_kiosk_account(make_scoped_ptr(
1117 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); 1136 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass());
1118 1137
1119 // Interfaces should be reported by default. 1138 // Interfaces should be reported by default.
1120 GetStatus(); 1139 GetStatus();
1121 EXPECT_LT(0, status_.network_interface_size()); 1140 EXPECT_LT(0, status_.network_interface_size());
1122 EXPECT_LT(0, status_.network_state_size()); 1141 EXPECT_LT(0, status_.network_state_size());
1123 1142
1124 // No interfaces should be reported if the policy is off. 1143 // No interfaces should be reported if the policy is off.
1125 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); 1144 owner_settings_service_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces,
1145 false);
1126 GetStatus(); 1146 GetStatus();
1127 EXPECT_EQ(0, status_.network_interface_size()); 1147 EXPECT_EQ(0, status_.network_interface_size());
1128 EXPECT_EQ(0, status_.network_state_size()); 1148 EXPECT_EQ(0, status_.network_state_size());
1129 1149
1130 // Switch the policy on and verify the interface list is present. 1150 // Switch the policy on and verify the interface list is present.
1131 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); 1151 owner_settings_service_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces,
1152 true);
1132 GetStatus(); 1153 GetStatus();
1133 1154
1134 int count = 0; 1155 int count = 0;
1135 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { 1156 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) {
1136 const FakeDeviceData& dev = kFakeDevices[i]; 1157 const FakeDeviceData& dev = kFakeDevices[i];
1137 if (dev.expected_type == -1) 1158 if (dev.expected_type == -1)
1138 continue; 1159 continue;
1139 1160
1140 // Find the corresponding entry in reporting data. 1161 // Find the corresponding entry in reporting data.
1141 bool found_match = false; 1162 bool found_match = false;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 found_match = true; 1206 found_match = true;
1186 break; 1207 break;
1187 } 1208 }
1188 } 1209 }
1189 EXPECT_TRUE(found_match) << "No matching state for fake network " 1210 EXPECT_TRUE(found_match) << "No matching state for fake network "
1190 << " (" << state.name << ")"; 1211 << " (" << state.name << ")";
1191 } 1212 }
1192 } 1213 }
1193 1214
1194 } // namespace policy 1215 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698