OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/settings/device_settings_provider.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | 234 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); |
235 | 235 |
236 // Verify the change has been applied. | 236 // Verify the change has been applied. |
237 const base::Value* saved_value = provider_->Get(kReleaseChannel); | 237 const base::Value* saved_value = provider_->Get(kReleaseChannel); |
238 ASSERT_TRUE(saved_value); | 238 ASSERT_TRUE(saved_value); |
239 EXPECT_TRUE(saved_value->GetAsString(&string_value)); | 239 EXPECT_TRUE(saved_value->GetAsString(&string_value)); |
240 ASSERT_EQ("stable-channel", string_value); | 240 ASSERT_EQ("stable-channel", string_value); |
241 } | 241 } |
242 | 242 |
243 TEST_F(DeviceSettingsProviderTest, SetPrefFailed) { | 243 TEST_F(DeviceSettingsProviderTest, SetPrefFailed) { |
244 // Initialize pref. | |
245 provider_->SetPrefForTesting(kStatsReportingPref, false); | |
Mattias Nissler (ping if slow)
2015/10/28 09:51:15
This seems fishy - what failure do you get if you
gayane -on leave until 09-2017
2015/10/28 15:00:07
The problem I had was that the test will fail at l
Mattias Nissler (ping if slow)
2015/10/29 10:06:14
OK, I get it now. The previous code would set kSta
| |
246 | |
244 // If we are not the owner no sets should work. | 247 // If we are not the owner no sets should work. |
245 base::FundamentalValue value(true); | 248 base::FundamentalValue value(true); |
246 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); | 249 EXPECT_CALL(*this, SettingChanged(kStatsReportingPref)).Times(1); |
247 provider_->Set(kStatsReportingPref, value); | 250 provider_->Set(kStatsReportingPref, value); |
248 Mock::VerifyAndClearExpectations(this); | 251 Mock::VerifyAndClearExpectations(this); |
249 | 252 |
250 // This shouldn't trigger a write. | 253 // This shouldn't trigger a write. |
251 device_settings_test_helper_.set_policy_blob(std::string()); | 254 device_settings_test_helper_.set_policy_blob(std::string()); |
252 FlushDeviceSettings(); | 255 FlushDeviceSettings(); |
253 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | 256 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 | 360 |
358 EXPECT_EQ(CrosSettingsProvider::TEMPORARILY_UNTRUSTED, | 361 EXPECT_EQ(CrosSettingsProvider::TEMPORARILY_UNTRUSTED, |
359 provider_->PrepareTrustedValues( | 362 provider_->PrepareTrustedValues( |
360 base::Bind(&DeviceSettingsProviderTest::GetTrustedCallback, | 363 base::Bind(&DeviceSettingsProviderTest::GetTrustedCallback, |
361 base::Unretained(this)))); | 364 base::Unretained(this)))); |
362 | 365 |
363 ReloadDeviceSettings(); | 366 ReloadDeviceSettings(); |
364 Mock::VerifyAndClearExpectations(this); | 367 Mock::VerifyAndClearExpectations(this); |
365 } | 368 } |
366 | 369 |
367 TEST_F(DeviceSettingsProviderTest, StatsReportingMigration) { | |
368 // Create the legacy consent file. | |
369 base::FilePath consent_file; | |
370 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &consent_file)); | |
371 consent_file = consent_file.AppendASCII("Consent To Send Stats"); | |
372 ASSERT_EQ(1, base::WriteFile(consent_file, "0", 1)); | |
373 | |
374 // This should trigger migration because the metrics policy isn't in the blob. | |
375 device_settings_test_helper_.set_policy_blob(std::string()); | |
376 FlushDeviceSettings(); | |
377 EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob()); | |
378 | |
379 // Verify that migration has kicked in. | |
380 const base::Value* saved_value = provider_->Get(kStatsReportingPref); | |
381 ASSERT_TRUE(saved_value); | |
382 bool bool_value; | |
383 EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value)); | |
384 EXPECT_FALSE(bool_value); | |
385 } | |
386 | |
387 TEST_F(DeviceSettingsProviderTest, LegacyDeviceLocalAccounts) { | 370 TEST_F(DeviceSettingsProviderTest, LegacyDeviceLocalAccounts) { |
388 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); | 371 EXPECT_CALL(*this, SettingChanged(_)).Times(AnyNumber()); |
389 em::DeviceLocalAccountInfoProto* account = | 372 em::DeviceLocalAccountInfoProto* account = |
390 device_policy_.payload().mutable_device_local_accounts()->add_account(); | 373 device_policy_.payload().mutable_device_local_accounts()->add_account(); |
391 account->set_deprecated_public_session_id( | 374 account->set_deprecated_public_session_id( |
392 policy::PolicyBuilder::kFakeUsername); | 375 policy::PolicyBuilder::kFakeUsername); |
393 device_policy_.Build(); | 376 device_policy_.Build(); |
394 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 377 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
395 ReloadDeviceSettings(); | 378 ReloadDeviceSettings(); |
396 Mock::VerifyAndClearExpectations(this); | 379 Mock::VerifyAndClearExpectations(this); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 } | 482 } |
500 | 483 |
501 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { | 484 TEST_F(DeviceSettingsProviderTest, DecodeLogUploadSettings) { |
502 SetLogUploadSettings(true); | 485 SetLogUploadSettings(true); |
503 VerifyLogUploadSettings(true); | 486 VerifyLogUploadSettings(true); |
504 | 487 |
505 SetLogUploadSettings(false); | 488 SetLogUploadSettings(false); |
506 VerifyLogUploadSettings(false); | 489 VerifyLogUploadSettings(false); |
507 } | 490 } |
508 } // namespace chromeos | 491 } // namespace chromeos |
OLD | NEW |