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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc
diff --git a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc
index e08fc5f0469c223822c35b27940d597445e97a9a..c46d00a8a02d8cc0c6540b4ab468ba561ec78bbe 100644
--- a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc
+++ b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc
@@ -18,6 +18,7 @@
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
+#include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/device_local_account.h"
#include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
@@ -268,13 +269,15 @@ class DeviceStatusCollectorTest : public testing::Test {
// Remove the real DeviceSettingsProvider and replace it with a stub.
cros_settings_ = chromeos::CrosSettings::Get();
device_settings_provider_ =
- cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo);
+ cros_settings_->GetProvider(chromeos::kReportDeviceActivityTimes);
EXPECT_TRUE(device_settings_provider_ != NULL);
EXPECT_TRUE(
cros_settings_->RemoveSettingsProvider(device_settings_provider_));
cros_settings_->AddSettingsProvider(&stub_settings_provider_);
+ owner_settings_service_.reset(
+ new chromeos::FakeOwnerSettingsService(nullptr));
- RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo));
+ RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo));
}
void AddMountPoint(const std::string& mount_point) {
@@ -361,7 +364,7 @@ class DeviceStatusCollectorTest : public testing::Test {
void MockRunningKioskApp(const DeviceLocalAccount& account) {
std::vector<DeviceLocalAccount> accounts;
accounts.push_back(account);
- SetDeviceLocalAccounts(cros_settings_, accounts);
+ SetDeviceLocalAccounts(owner_settings_service_.get(), accounts);
user_manager_->CreateKioskAppUser(account.user_id);
EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly(
Return(true));
@@ -390,6 +393,7 @@ class DeviceStatusCollectorTest : public testing::Test {
chromeos::CrosSettings* cros_settings_;
chromeos::CrosSettingsProvider* device_settings_provider_;
chromeos::StubCrosSettingsProvider stub_settings_provider_;
+ scoped_ptr<chromeos::FakeOwnerSettingsService> owner_settings_service_;
chromeos::MockUserManager* user_manager_;
chromeos::ScopedUserManagerEnabler user_manager_enabler_;
em::DeviceStatusReportRequest status_;
@@ -403,7 +407,8 @@ TEST_F(DeviceStatusCollectorTest, AllIdle) {
ui::IDLE_STATE_IDLE,
ui::IDLE_STATE_IDLE
};
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ true);
// Test reporting with no data.
GetStatus();
@@ -430,7 +435,8 @@ TEST_F(DeviceStatusCollectorTest, AllActive) {
ui::IDLE_STATE_ACTIVE,
ui::IDLE_STATE_ACTIVE
};
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ true);
// Test a single active sample.
status_collector_->Simulate(test_states, 1);
@@ -457,7 +463,8 @@ TEST_F(DeviceStatusCollectorTest, MixedStates) {
ui::IDLE_STATE_IDLE,
ui::IDLE_STATE_ACTIVE
};
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ true);
status_collector_->Simulate(test_states,
sizeof(test_states) / sizeof(ui::IdleState));
GetStatus();
@@ -473,7 +480,8 @@ TEST_F(DeviceStatusCollectorTest, StateKeptInPref) {
ui::IDLE_STATE_IDLE,
ui::IDLE_STATE_IDLE
};
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ true);
status_collector_->Simulate(test_states,
sizeof(test_states) / sizeof(ui::IdleState));
@@ -497,7 +505,8 @@ TEST_F(DeviceStatusCollectorTest, Times) {
ui::IDLE_STATE_IDLE,
ui::IDLE_STATE_IDLE
};
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ true);
status_collector_->Simulate(test_states,
sizeof(test_states) / sizeof(ui::IdleState));
GetStatus();
@@ -511,7 +520,8 @@ TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) {
};
const int kMaxDays = 10;
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ true);
status_collector_->set_max_stored_past_activity_days(kMaxDays - 1);
status_collector_->set_max_stored_future_activity_days(1);
Time baseline = Time::Now().LocalMidnight();
@@ -566,7 +576,8 @@ TEST_F(DeviceStatusCollectorTest, ActivityTimesEnabledByDefault) {
TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) {
// Device activity times should not be reported if explicitly disabled.
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ false);
ui::IdleState test_states[] = {
ui::IDLE_STATE_ACTIVE,
@@ -584,7 +595,8 @@ TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) {
ui::IdleState test_states[] = {
ui::IDLE_STATE_ACTIVE
};
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ true);
// Set the baseline time to 10 seconds after midnight.
status_collector_->SetBaselineTime(
@@ -616,7 +628,8 @@ TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) {
ui::IDLE_STATE_ACTIVE,
ui::IDLE_STATE_ACTIVE,
};
- cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceActivityTimes,
+ true);
status_collector_->Simulate(test_states, 2);
GetStatus();
@@ -644,14 +657,14 @@ TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) {
EXPECT_EQ("Verified", status_.boot_mode());
// Test that boot mode data is not reported if the pref turned off.
- cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceBootMode, false);
GetStatus();
EXPECT_FALSE(status_.has_boot_mode());
// Turn the pref on, and check that the status is reported iff the
// statistics provider returns valid data.
- cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceBootMode, true);
fake_statistics_provider_.SetMachineStatistic(
chromeos::system::kDevSwitchBootKey, "(error)");
@@ -685,13 +698,14 @@ TEST_F(DeviceStatusCollectorTest, VersionInfo) {
// When the pref to collect this data is not enabled, expect that none of
// the fields are present in the protobuf.
- cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceVersionInfo,
+ false);
GetStatus();
EXPECT_FALSE(status_.has_browser_version());
EXPECT_FALSE(status_.has_os_version());
EXPECT_FALSE(status_.has_firmware_version());
- cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceVersionInfo, true);
GetStatus();
EXPECT_TRUE(status_.has_browser_version());
EXPECT_TRUE(status_.has_os_version());
@@ -723,7 +737,7 @@ TEST_F(DeviceStatusCollectorTest, Location) {
// Check that when device location reporting is enabled and a valid fix is
// available, the location is reported and is stored in local state.
SetMockPositionToReturnNext(valid_fix);
- cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceLocation, true);
EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty());
CheckThatAValidLocationIsReported();
@@ -737,7 +751,7 @@ TEST_F(DeviceStatusCollectorTest, Location) {
// Check that after disabling location reporting again, the last known
// location has been cleared from local state and is no longer reported.
SetMockPositionToReturnNext(valid_fix);
- cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceLocation, false);
// Allow the new pref to propagate to the status collector.
message_loop_.RunUntilIdle();
EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty());
@@ -746,7 +760,7 @@ TEST_F(DeviceStatusCollectorTest, Location) {
// Check that after enabling location reporting again, an error is reported
// if no valid fix is available.
SetMockPositionToReturnNext(invalid_fix);
- cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceLocation, true);
// Allow the new pref to propagate to the status collector.
message_loop_.RunUntilIdle();
CheckThatALocationErrorIsReported();
@@ -766,7 +780,7 @@ TEST_F(DeviceStatusCollectorTest, ReportUsers) {
EXPECT_EQ(6, status_.user_size());
// Verify that users are reported after enabling the setting.
- cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceUsers, true);
GetStatus();
EXPECT_EQ(6, status_.user_size());
EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type());
@@ -783,7 +797,7 @@ TEST_F(DeviceStatusCollectorTest, ReportUsers) {
EXPECT_EQ("user5@managed.com", status_.user(5).email());
// Verify that users are no longer reported if setting is disabled.
- cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceUsers, false);
GetStatus();
EXPECT_EQ(0, status_.user_size());
}
@@ -828,7 +842,8 @@ TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) {
}
// Now turn off hardware status reporting - should have no data.
- cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceHardwareStatus,
+ false);
GetStatus();
EXPECT_EQ(0, status_.volume_info_size());
}
@@ -864,21 +879,24 @@ TEST_F(DeviceStatusCollectorTest, TestCPUSamples) {
EXPECT_EQ(idle_cpu_usage, utilization);
// Turning off hardware reporting should not report CPU utilization.
- cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceHardwareStatus,
+ false);
GetStatus();
EXPECT_EQ(0, status_.cpu_utilization_pct().size());
}
TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) {
// Should not report session status if we don't have an active kiosk app.
- cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceSessionStatus,
+ true);
em::SessionStatusReportRequest session_status;
EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status));
}
TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) {
// Should not report session status if session status reporting is disabled.
- cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceSessionStatus,
+ false);
status_collector_->set_kiosk_account(make_scoped_ptr(
new policy::DeviceLocalAccount(fake_device_local_account_)).Pass());
// Set up a device-local account for single-app kiosk mode.
@@ -889,7 +907,8 @@ TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) {
}
TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) {
- cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceSessionStatus,
+ true);
status_collector_->set_kiosk_account(make_scoped_ptr(
new policy::DeviceLocalAccount(fake_device_local_account_)).Pass());
@@ -1122,13 +1141,15 @@ TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) {
EXPECT_LT(0, status_.network_state_size());
// No interfaces should be reported if the policy is off.
- cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces,
+ false);
GetStatus();
EXPECT_EQ(0, status_.network_interface_size());
EXPECT_EQ(0, status_.network_state_size());
// Switch the policy on and verify the interface list is present.
- cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true);
+ owner_settings_service_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces,
+ true);
GetStatus();
int count = 0;

Powered by Google App Engine
This is Rietveld 408576698