Chromium Code Reviews| 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_service.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 | 451 |
| 452 EXPECT_CALL(observer_, OwnershipStatusChanged()).Times(0); | 452 EXPECT_CALL(observer_, OwnershipStatusChanged()).Times(0); |
| 453 EXPECT_CALL(observer_, DeviceSettingsUpdated()).Times(1); | 453 EXPECT_CALL(observer_, DeviceSettingsUpdated()).Times(1); |
| 454 device_settings_service_.PropertyChangeComplete(true); | 454 device_settings_service_.PropertyChangeComplete(true); |
| 455 FlushDeviceSettings(); | 455 FlushDeviceSettings(); |
| 456 Mock::VerifyAndClearExpectations(&observer_); | 456 Mock::VerifyAndClearExpectations(&observer_); |
| 457 | 457 |
| 458 device_settings_service_.RemoveObserver(&observer_); | 458 device_settings_service_.RemoveObserver(&observer_); |
| 459 } | 459 } |
| 460 | 460 |
| 461 TEST_F(DeviceSettingsServiceTest, LoadDeferredDuringOwnershipEastablishment) { | |
|
achuithb
2017/04/04 19:38:34
Please add a comment explaining what this test is
xiyuan
2017/04/04 20:17:50
Done and done.
| |
| 462 owner_key_util_->Clear(); | |
| 463 | |
| 464 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); | |
| 465 EXPECT_FALSE(device_settings_service_.GetPublicKey().get()); | |
| 466 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_UNKNOWN, | |
| 467 device_settings_service_.GetOwnershipStatus()); | |
| 468 | |
| 469 // Mark ownership establishment is running. | |
| 470 device_settings_service_.MarkWillEstablishConsumerOwnership(); | |
| 471 | |
| 472 const std::string& user_id = device_policy_.policy_data().username(); | |
| 473 owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); | |
| 474 InitOwner(AccountId::FromUserEmail(user_id), false); | |
| 475 OwnerSettingsServiceChromeOS* service = | |
| 476 OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile_.get()); | |
| 477 ASSERT_TRUE(service); | |
| 478 service->IsOwnerAsync(base::Bind(&DeviceSettingsServiceTest::OnIsOwner, | |
| 479 base::Unretained(this))); | |
| 480 ReloadDeviceSettings(); | |
| 481 | |
| 482 // No load operation should happen until OwnerSettingsService loads the | |
| 483 // private key. | |
| 484 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); | |
| 485 ASSERT_FALSE(device_settings_service_.GetPublicKey().get()); | |
| 486 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_UNKNOWN, | |
| 487 device_settings_service_.GetOwnershipStatus()); | |
| 488 EXPECT_FALSE(is_owner_set_); | |
| 489 | |
| 490 // Load the private key and trigger a reload. Load operations should finish. | |
| 491 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey()); | |
| 492 service->OnTPMTokenReady(true /* is ready */); | |
| 493 FlushDeviceSettings(); | |
| 494 | |
| 495 // Verify owner key is loaded and ownership status is updated. | |
| 496 EXPECT_TRUE(device_settings_service_.HasPrivateOwnerKey()); | |
| 497 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); | |
| 498 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); | |
| 499 EXPECT_EQ(device_policy_.GetPublicSigningKeyAsString(), | |
| 500 device_settings_service_.GetPublicKey()->as_string()); | |
| 501 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_TAKEN, | |
| 502 device_settings_service_.GetOwnershipStatus()); | |
| 503 EXPECT_TRUE(is_owner_set_); | |
| 504 EXPECT_TRUE(is_owner_); | |
| 505 } | |
| 506 | |
| 461 } // namespace chromeos | 507 } // namespace chromeos |
| OLD | NEW |