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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 12 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" |
13 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | 13 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" |
14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 14 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
15 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 15 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 17 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
18 #include "policy/proto/device_management_backend.pb.h" | 18 #include "policy/proto/device_management_backend.pb.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 namespace em = enterprise_management; | 22 namespace em = enterprise_management; |
23 | 23 |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 TEST_F(DeviceSettingsServiceTest, OnTPMTokenReadyForNonOwner) { | 490 TEST_F(DeviceSettingsServiceTest, OnTPMTokenReadyForNonOwner) { |
491 owner_key_util_->Clear(); | 491 owner_key_util_->Clear(); |
492 | 492 |
493 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); | 493 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); |
494 EXPECT_FALSE(device_settings_service_.GetPublicKey().get()); | 494 EXPECT_FALSE(device_settings_service_.GetPublicKey().get()); |
495 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_UNKNOWN, | 495 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_UNKNOWN, |
496 device_settings_service_.GetOwnershipStatus()); | 496 device_settings_service_.GetOwnershipStatus()); |
497 | 497 |
498 const std::string& user_id = device_policy_.policy_data().username(); | 498 const std::string& user_id = device_policy_.policy_data().username(); |
499 InitOwner(user_id, false); | 499 InitOwner(user_id, false); |
500 OwnerSettingsServiceChromeOS* service = | 500 OwnerSettingsService* service = |
501 OwnerSettingsServiceChromeOSFactory::GetForProfile(profile_.get()); | 501 OwnerSettingsServiceFactory::GetForProfile(profile_.get()); |
502 ASSERT_TRUE(service); | 502 ASSERT_TRUE(service); |
503 service->IsOwnerAsync(base::Bind(&DeviceSettingsServiceTest::OnIsOwner, | 503 service->IsOwnerAsync(base::Bind(&DeviceSettingsServiceTest::OnIsOwner, |
504 base::Unretained(this))); | 504 base::Unretained(this))); |
505 | 505 |
506 owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); | 506 owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); |
507 ReloadDeviceSettings(); | 507 ReloadDeviceSettings(); |
508 | 508 |
509 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); | 509 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); |
510 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); | 510 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); |
511 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); | 511 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); |
(...skipping 23 matching lines...) Expand all Loading... |
535 owner_key_util_->Clear(); | 535 owner_key_util_->Clear(); |
536 | 536 |
537 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); | 537 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); |
538 EXPECT_FALSE(device_settings_service_.GetPublicKey().get()); | 538 EXPECT_FALSE(device_settings_service_.GetPublicKey().get()); |
539 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_UNKNOWN, | 539 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_UNKNOWN, |
540 device_settings_service_.GetOwnershipStatus()); | 540 device_settings_service_.GetOwnershipStatus()); |
541 | 541 |
542 const std::string& user_id = device_policy_.policy_data().username(); | 542 const std::string& user_id = device_policy_.policy_data().username(); |
543 owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); | 543 owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); |
544 InitOwner(user_id, false); | 544 InitOwner(user_id, false); |
545 OwnerSettingsServiceChromeOS* service = | 545 OwnerSettingsService* service = |
546 OwnerSettingsServiceChromeOSFactory::GetForProfile(profile_.get()); | 546 OwnerSettingsServiceFactory::GetForProfile(profile_.get()); |
547 ASSERT_TRUE(service); | 547 ASSERT_TRUE(service); |
548 service->IsOwnerAsync(base::Bind(&DeviceSettingsServiceTest::OnIsOwner, | 548 service->IsOwnerAsync(base::Bind(&DeviceSettingsServiceTest::OnIsOwner, |
549 base::Unretained(this))); | 549 base::Unretained(this))); |
550 ReloadDeviceSettings(); | 550 ReloadDeviceSettings(); |
551 | 551 |
552 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); | 552 EXPECT_FALSE(device_settings_service_.HasPrivateOwnerKey()); |
553 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); | 553 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); |
554 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); | 554 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); |
555 std::vector<uint8> key; | 555 std::vector<uint8> key; |
556 ASSERT_TRUE(device_policy_.GetSigningKey()->ExportPublicKey(&key)); | 556 ASSERT_TRUE(device_policy_.GetSigningKey()->ExportPublicKey(&key)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 EXPECT_TRUE(device_settings_service_.HasPrivateOwnerKey()); | 592 EXPECT_TRUE(device_settings_service_.HasPrivateOwnerKey()); |
593 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); | 593 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); |
594 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); | 594 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); |
595 std::vector<uint8> key; | 595 std::vector<uint8> key; |
596 ASSERT_TRUE(device_policy_.GetSigningKey()->ExportPublicKey(&key)); | 596 ASSERT_TRUE(device_policy_.GetSigningKey()->ExportPublicKey(&key)); |
597 EXPECT_EQ(device_settings_service_.GetPublicKey()->data(), key); | 597 EXPECT_EQ(device_settings_service_.GetPublicKey()->data(), key); |
598 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_TAKEN, | 598 EXPECT_EQ(DeviceSettingsService::OWNERSHIP_TAKEN, |
599 device_settings_service_.GetOwnershipStatus()); | 599 device_settings_service_.GetOwnershipStatus()); |
600 EXPECT_FALSE(is_owner_set_); | 600 EXPECT_FALSE(is_owner_set_); |
601 | 601 |
602 OwnerSettingsServiceChromeOS* service = | 602 OwnerSettingsService* service = |
603 OwnerSettingsServiceChromeOSFactory::GetForProfile(profile_.get()); | 603 OwnerSettingsServiceFactory::GetForProfile(profile_.get()); |
604 ASSERT_TRUE(service); | 604 ASSERT_TRUE(service); |
605 service->IsOwnerAsync(base::Bind(&DeviceSettingsServiceTest::OnIsOwner, | 605 service->IsOwnerAsync(base::Bind(&DeviceSettingsServiceTest::OnIsOwner, |
606 base::Unretained(this))); | 606 base::Unretained(this))); |
607 // The callback should be called immediately. | 607 // The callback should be called immediately. |
608 base::MessageLoop::current()->RunUntilIdle(); | 608 base::MessageLoop::current()->RunUntilIdle(); |
609 | 609 |
610 EXPECT_TRUE(device_settings_service_.HasPrivateOwnerKey()); | 610 EXPECT_TRUE(device_settings_service_.HasPrivateOwnerKey()); |
611 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); | 611 ASSERT_TRUE(device_settings_service_.GetPublicKey().get()); |
612 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); | 612 ASSERT_TRUE(device_settings_service_.GetPublicKey()->is_loaded()); |
613 ASSERT_TRUE(device_policy_.GetSigningKey()->ExportPublicKey(&key)); | 613 ASSERT_TRUE(device_policy_.GetSigningKey()->ExportPublicKey(&key)); |
(...skipping 30 matching lines...) Expand all Loading... |
644 EXPECT_CALL(observer_, OwnershipStatusChanged()).Times(0); | 644 EXPECT_CALL(observer_, OwnershipStatusChanged()).Times(0); |
645 EXPECT_CALL(observer_, DeviceSettingsUpdated()).Times(1); | 645 EXPECT_CALL(observer_, DeviceSettingsUpdated()).Times(1); |
646 device_settings_service_.PropertyChangeComplete(true); | 646 device_settings_service_.PropertyChangeComplete(true); |
647 FlushDeviceSettings(); | 647 FlushDeviceSettings(); |
648 Mock::VerifyAndClearExpectations(&observer_); | 648 Mock::VerifyAndClearExpectations(&observer_); |
649 | 649 |
650 device_settings_service_.RemoveObserver(&observer_); | 650 device_settings_service_.RemoveObserver(&observer_); |
651 } | 651 } |
652 | 652 |
653 } // namespace chromeos | 653 } // namespace chromeos |
OLD | NEW |