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

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_service_unittest.cc

Issue 2798343003: Merge "cros: Fix flaky owner detection" (Closed)
Patch Set: Created 3 years, 8 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/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
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 that DeviceSettingsService defers load operations until after
462 // OwnerSettingsService finishes loading the private key and invokes
463 // DeviceSettingsService::InitOwner to set the owner info.
464 // See http://crbug.com/706820 for more details.
465 TEST_F(DeviceSettingsServiceTest, LoadDeferredDuringOwnershipEstablishment) {
466 owner_key_util_->Clear();
467
468 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey());
469 EXPECT_FALSE(device_settings_service_.GetPublicKey().get());
470 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_UNKNOWN,
471 device_settings_service_.GetOwnershipStatus());
472
473 // Mark ownership establishment is running.
474 device_settings_service_.MarkWillEstablishConsumerOwnership();
475
476 const std::string& user_id = device_policy_.policy_data().username();
477 owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey());
478 InitOwner(AccountId::FromUserEmail(user_id), false);
479 OwnerSettingsServiceChromeOS* service =
480 OwnerSettingsServiceChromeOSFactory::GetForBrowserContext(profile_.get());
481 ASSERT_TRUE(service);
482 service->IsOwnerAsync(base::Bind(&DeviceSettingsServiceTest::OnIsOwner,
483 base::Unretained(this)));
484 ReloadDeviceSettings();
485
486 // No load operation should happen until OwnerSettingsService loads the
487 // private key.
488 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey());
489 ASSERT_FALSE(device_settings_service_.GetPublicKey().get());
490 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_UNKNOWN,
491 device_settings_service_.GetOwnershipStatus());
492 EXPECT_FALSE(is_owner_set_);
493
494 // Load the private key and trigger a reload. Load operations should finish.
495 owner_key_util_->SetPrivateKey(device_policy_.GetSigningKey());
496 service->OnTPMTokenReady(true /* is ready */);
497 FlushDeviceSettings();
498
499 // Verify owner key is loaded and ownership status is updated.
500 EXPECT_TRUE(device_settings_service_.HasPrivateOwnerKey());
501 ASSERT_TRUE(device_settings_service_.GetPublicKey().get());
502 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded());
503 EXPECT_EQ(device_policy_.GetPublicSigningKeyAsString(),
504 device_settings_service_.GetPublicKey()->as_string());
505 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_TAKEN,
506 device_settings_service_.GetOwnershipStatus());
507 EXPECT_TRUE(is_owner_set_);
508 EXPECT_TRUE(is_owner_);
509 }
510
461 } // namespace chromeos 511 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/settings/device_settings_service.cc ('k') | components/user_manager/user_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698