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

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

Issue 2869673003: Fix system active time reporting for app kiosks (Closed)
Patch Set: Removed a duplicate test Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/policy/device_status_collector.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 29 matching lines...) Expand all
40 #include "chrome/test/base/testing_profile_manager.h" 40 #include "chrome/test/base/testing_profile_manager.h"
41 #include "chromeos/audio/cras_audio_handler.h" 41 #include "chromeos/audio/cras_audio_handler.h"
42 #include "chromeos/dbus/cros_disks_client.h" 42 #include "chromeos/dbus/cros_disks_client.h"
43 #include "chromeos/dbus/dbus_thread_manager.h" 43 #include "chromeos/dbus/dbus_thread_manager.h"
44 #include "chromeos/dbus/fake_update_engine_client.h" 44 #include "chromeos/dbus/fake_update_engine_client.h"
45 #include "chromeos/dbus/shill_device_client.h" 45 #include "chromeos/dbus/shill_device_client.h"
46 #include "chromeos/dbus/shill_ipconfig_client.h" 46 #include "chromeos/dbus/shill_ipconfig_client.h"
47 #include "chromeos/dbus/shill_service_client.h" 47 #include "chromeos/dbus/shill_service_client.h"
48 #include "chromeos/disks/disk_mount_manager.h" 48 #include "chromeos/disks/disk_mount_manager.h"
49 #include "chromeos/disks/mock_disk_mount_manager.h" 49 #include "chromeos/disks/mock_disk_mount_manager.h"
50 #include "chromeos/login/login_state.h"
50 #include "chromeos/network/network_handler.h" 51 #include "chromeos/network/network_handler.h"
51 #include "chromeos/network/network_state.h" 52 #include "chromeos/network/network_state.h"
52 #include "chromeos/network/network_state_handler.h" 53 #include "chromeos/network/network_state_handler.h"
53 #include "chromeos/settings/cros_settings_names.h" 54 #include "chromeos/settings/cros_settings_names.h"
54 #include "chromeos/system/fake_statistics_provider.h" 55 #include "chromeos/system/fake_statistics_provider.h"
55 #include "components/policy/proto/device_management_backend.pb.h" 56 #include "components/policy/proto/device_management_backend.pb.h"
56 #include "components/prefs/pref_service.h" 57 #include "components/prefs/pref_service.h"
57 #include "components/prefs/testing_pref_service.h" 58 #include "components/prefs/testing_pref_service.h"
58 #include "content/public/browser/browser_thread.h" 59 #include "content/public/browser/browser_thread.h"
59 #include "content/public/test/test_browser_thread_bundle.h" 60 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); 338 TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
338 chromeos::KioskAppManager::RegisterPrefs(local_state_.registry()); 339 chromeos::KioskAppManager::RegisterPrefs(local_state_.registry());
339 340
340 // Use FakeUpdateEngineClient. 341 // Use FakeUpdateEngineClient.
341 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = 342 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter =
342 chromeos::DBusThreadManager::GetSetterForTesting(); 343 chromeos::DBusThreadManager::GetSetterForTesting();
343 dbus_setter->SetUpdateEngineClient( 344 dbus_setter->SetUpdateEngineClient(
344 base::WrapUnique<chromeos::UpdateEngineClient>(update_engine_client_)); 345 base::WrapUnique<chromeos::UpdateEngineClient>(update_engine_client_));
345 346
346 chromeos::CrasAudioHandler::InitializeForTesting(); 347 chromeos::CrasAudioHandler::InitializeForTesting();
348 chromeos::LoginState::Initialize();
347 } 349 }
348 350
349 void AddMountPoint(const std::string& mount_point) { 351 void AddMountPoint(const std::string& mount_point) {
350 mount_point_map_.insert(DiskMountManager::MountPointMap::value_type( 352 mount_point_map_.insert(DiskMountManager::MountPointMap::value_type(
351 mount_point, 353 mount_point,
352 DiskMountManager::MountPointInfo( 354 DiskMountManager::MountPointInfo(
353 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE, 355 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE,
354 chromeos::disks::MOUNT_CONDITION_NONE))); 356 chromeos::disks::MOUNT_CONDITION_NONE)));
355 } 357 }
356 358
357 ~DeviceStatusCollectorTest() override { 359 ~DeviceStatusCollectorTest() override {
360 chromeos::LoginState::Shutdown();
358 chromeos::CrasAudioHandler::Shutdown(); 361 chromeos::CrasAudioHandler::Shutdown();
359 chromeos::KioskAppManager::Shutdown(); 362 chromeos::KioskAppManager::Shutdown();
360 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); 363 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
361 364
362 // Finish pending tasks. 365 // Finish pending tasks.
363 content::RunAllBlockingPoolTasksUntilIdle(); 366 content::RunAllBlockingPoolTasksUntilIdle();
364 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); 367 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems();
365 DiskMountManager::Shutdown(); 368 DiskMountManager::Shutdown();
366 } 369 }
367 370
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 ui::IDLE_STATE_ACTIVE 576 ui::IDLE_STATE_ACTIVE
574 }; 577 };
575 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); 578 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
576 status_collector_->Simulate(test_states, 579 status_collector_->Simulate(test_states,
577 sizeof(test_states) / sizeof(ui::IdleState)); 580 sizeof(test_states) / sizeof(ui::IdleState));
578 GetStatus(); 581 GetStatus();
579 EXPECT_EQ(4 * ActivePeriodMilliseconds(), 582 EXPECT_EQ(4 * ActivePeriodMilliseconds(),
580 GetActiveMilliseconds(device_status_)); 583 GetActiveMilliseconds(device_status_));
581 } 584 }
582 585
586 // For kiosks report total uptime instead of only active periods.
587 TEST_F(DeviceStatusCollectorTest, MixedStatesForKiosk) {
588 ui::IdleState test_states[] = {
589 ui::IDLE_STATE_ACTIVE,
590 ui::IDLE_STATE_IDLE,
591 ui::IDLE_STATE_ACTIVE,
592 ui::IDLE_STATE_ACTIVE,
593 ui::IDLE_STATE_IDLE,
594 ui::IDLE_STATE_IDLE,
595 };
596 chromeos::LoginState::Get()->SetLoggedInState(
597 chromeos::LoginState::LOGGED_IN_ACTIVE,
598 chromeos::LoginState::LOGGED_IN_USER_KIOSK_APP);
599 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
600 status_collector_->Simulate(test_states,
601 sizeof(test_states) / sizeof(ui::IdleState));
602 GetStatus();
603 EXPECT_EQ(6 * ActivePeriodMilliseconds(),
604 GetActiveMilliseconds(device_status_));
605 }
606
607 // For Arc kiosks report total uptime instead of only active periods.
608 TEST_F(DeviceStatusCollectorTest, MixedStatesForArcKiosk) {
609 ui::IdleState test_states[] = {
610 ui::IDLE_STATE_ACTIVE,
611 ui::IDLE_STATE_IDLE,
612 ui::IDLE_STATE_ACTIVE,
613 ui::IDLE_STATE_ACTIVE,
614 ui::IDLE_STATE_IDLE,
615 };
616 chromeos::LoginState::Get()->SetLoggedInState(
617 chromeos::LoginState::LOGGED_IN_ACTIVE,
618 chromeos::LoginState::LOGGED_IN_USER_ARC_KIOSK_APP);
619 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
620 status_collector_->Simulate(test_states,
621 sizeof(test_states) / sizeof(ui::IdleState));
622 GetStatus();
623 EXPECT_EQ(5 * ActivePeriodMilliseconds(),
624 GetActiveMilliseconds(device_status_));
625 }
626
583 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { 627 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) {
584 ui::IdleState test_states[] = { 628 ui::IdleState test_states[] = {
585 ui::IDLE_STATE_ACTIVE, 629 ui::IDLE_STATE_ACTIVE,
586 ui::IDLE_STATE_IDLE, 630 ui::IDLE_STATE_IDLE,
587 ui::IDLE_STATE_ACTIVE,
588 ui::IDLE_STATE_ACTIVE,
589 ui::IDLE_STATE_IDLE,
590 ui::IDLE_STATE_IDLE
591 };
592 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
593 status_collector_->Simulate(test_states,
594 sizeof(test_states) / sizeof(ui::IdleState));
595
596 // Process the list a second time after restarting the collector. It should be
597 // able to count the active periods found by the original collector, because
598 // the results are stored in a pref.
599 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo),
600 base::Bind(&GetEmptyCPUStatistics),
601 base::Bind(&GetEmptyCPUTempInfo),
602 base::Bind(&GetEmptyAndroidStatus));
603 status_collector_->Simulate(test_states,
604 sizeof(test_states) / sizeof(ui::IdleState));
605
606 GetStatus();
607 EXPECT_EQ(6 * ActivePeriodMilliseconds(),
608 GetActiveMilliseconds(device_status_));
609 }
610
611 TEST_F(DeviceStatusCollectorTest, Times) {
Ivan Šandrk 2017/05/09 14:22:06 I removed this test as it's the same as MixedState
612 ui::IdleState test_states[] = {
613 ui::IDLE_STATE_ACTIVE,
614 ui::IDLE_STATE_IDLE,
615 ui::IDLE_STATE_ACTIVE, 631 ui::IDLE_STATE_ACTIVE,
616 ui::IDLE_STATE_ACTIVE, 632 ui::IDLE_STATE_ACTIVE,
617 ui::IDLE_STATE_IDLE, 633 ui::IDLE_STATE_IDLE,
618 ui::IDLE_STATE_IDLE 634 ui::IDLE_STATE_IDLE
619 }; 635 };
620 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); 636 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true);
621 status_collector_->Simulate(test_states, 637 status_collector_->Simulate(test_states,
622 sizeof(test_states) / sizeof(ui::IdleState)); 638 sizeof(test_states) / sizeof(ui::IdleState));
639
640 // Process the list a second time after restarting the collector. It should be
641 // able to count the active periods found by the original collector, because
642 // the results are stored in a pref.
643 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo),
644 base::Bind(&GetEmptyCPUStatistics),
645 base::Bind(&GetEmptyCPUTempInfo),
646 base::Bind(&GetEmptyAndroidStatus));
647 status_collector_->Simulate(test_states,
648 sizeof(test_states) / sizeof(ui::IdleState));
649
623 GetStatus(); 650 GetStatus();
624 EXPECT_EQ(3 * ActivePeriodMilliseconds(), 651 EXPECT_EQ(6 * ActivePeriodMilliseconds(),
625 GetActiveMilliseconds(device_status_)); 652 GetActiveMilliseconds(device_status_));
626 } 653 }
627 654
628 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { 655 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) {
629 ui::IdleState test_states[] = { 656 ui::IdleState test_states[] = {
630 ui::IDLE_STATE_ACTIVE, 657 ui::IDLE_STATE_ACTIVE,
631 ui::IDLE_STATE_IDLE 658 ui::IDLE_STATE_IDLE
632 }; 659 };
633 const int kMaxDays = 10; 660 const int kMaxDays = 10;
634 661
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 AccountId::FromUserEmail(kPublicAccountId)); 1630 AccountId::FromUserEmail(kPublicAccountId));
1604 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) 1631 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount())
1605 .WillRepeatedly(Return(true)); 1632 .WillRepeatedly(Return(true));
1606 1633
1607 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); 1634 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true);
1608 GetStatus(); 1635 GetStatus();
1609 VerifyNetworkReporting(); 1636 VerifyNetworkReporting();
1610 } 1637 }
1611 1638
1612 } // namespace policy 1639 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_status_collector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698