Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | |
| 6 | |
| 7 #include <string> | |
|
bartfab (slow)
2014/08/04 18:44:53
Nit: Already included by header.
davidyu
2014/08/05 07:26:59
Done.
| |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/bind_helpers.h" | |
| 11 #include "base/prefs/pref_registry_simple.h" | |
| 12 #include "base/prefs/testing_pref_service.h" | |
| 13 #include "chrome/common/pref_names.h" | |
| 14 #include "chrome/test/base/scoped_testing_local_state.h" | |
| 15 #include "chrome/test/base/testing_browser_process.h" | |
| 16 #include "chromeos/dbus/cryptohome/rpc.pb.h" | |
| 17 #include "chromeos/dbus/cryptohome_client.h" | |
| 18 #include "chromeos/dbus/dbus_method_call_status.h" | |
|
bartfab (slow)
2014/08/04 18:44:53
Nit: Already included by header.
davidyu
2014/08/05 07:26:59
Done.
| |
| 19 #include "chromeos/dbus/mock_cryptohome_client.h" | |
| 20 #include "testing/gmock/include/gmock/gmock.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 using testing::Invoke; | |
| 24 using testing::NiceMock; | |
| 25 using testing::_; | |
| 26 | |
| 27 namespace policy { | |
| 28 namespace { | |
|
bartfab (slow)
2014/08/04 18:44:55
Nit: No need to wrap the entire test in an anonymo
davidyu
2014/08/05 07:27:00
Done.
| |
| 29 | |
| 30 class ConsumerManagementServiceTest : public testing::Test { | |
| 31 public: | |
| 32 ConsumerManagementServiceTest() : | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit: Per style guide, move the : to the next line.
davidyu
2014/08/05 07:27:00
Done.
| |
| 33 testing_local_state_(TestingBrowserProcess::GetGlobal()), | |
| 34 service_(new ConsumerManagementService(&mock_cryptohome_client_)) { | |
| 35 ON_CALL(mock_cryptohome_client_, GetBootAttribute(_, _)) | |
| 36 .WillByDefault( | |
| 37 Invoke(this, &ConsumerManagementServiceTest::MockGetBootAttribute)); | |
| 38 ON_CALL(mock_cryptohome_client_, SetBootAttribute(_, _)) | |
| 39 .WillByDefault( | |
| 40 Invoke(this, &ConsumerManagementServiceTest::MockSetBootAttribute)); | |
| 41 ON_CALL(mock_cryptohome_client_, FlushAndSignBootAttributes(_, _)) | |
| 42 .WillByDefault( | |
| 43 Invoke(this, | |
| 44 &ConsumerManagementServiceTest:: | |
| 45 MockFlushAndSignBootAttributes)); | |
| 46 } | |
| 47 | |
| 48 void MockGetBootAttribute( | |
| 49 const cryptohome::GetBootAttributeRequest& request, | |
| 50 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) { | |
| 51 get_boot_attribute_request_ = request; | |
| 52 callback.Run(cryptohome_status_, cryptohome_result_, cryptohome_reply_); | |
| 53 } | |
| 54 | |
| 55 void MockSetBootAttribute( | |
| 56 const cryptohome::SetBootAttributeRequest& request, | |
| 57 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) { | |
| 58 set_boot_attribute_request_ = request; | |
| 59 callback.Run(cryptohome_status_, cryptohome_result_, cryptohome_reply_); | |
| 60 } | |
| 61 | |
| 62 void MockFlushAndSignBootAttributes( | |
| 63 const cryptohome::FlushAndSignBootAttributesRequest& request, | |
| 64 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) { | |
| 65 callback.Run(cryptohome_status_, cryptohome_result_, cryptohome_reply_); | |
| 66 } | |
| 67 | |
| 68 void OnGetOwnerDone(const std::string& owner) { | |
| 69 owner_ = owner; | |
| 70 } | |
| 71 | |
| 72 void OnSetOwnerDone(bool status) { | |
| 73 set_owner_status_ = status; | |
| 74 } | |
| 75 | |
| 76 ScopedTestingLocalState testing_local_state_; | |
| 77 NiceMock<chromeos::MockCryptohomeClient> mock_cryptohome_client_; | |
| 78 scoped_ptr<ConsumerManagementService> service_; | |
| 79 | |
| 80 chromeos::DBusMethodCallStatus cryptohome_status_; | |
| 81 bool cryptohome_result_; | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit: Initialize this in the constructor to guarant
davidyu
2014/08/05 07:27:00
Done.
| |
| 82 cryptohome::BaseReply cryptohome_reply_; | |
| 83 cryptohome::GetBootAttributeRequest get_boot_attribute_request_; | |
| 84 cryptohome::SetBootAttributeRequest set_boot_attribute_request_; | |
| 85 | |
| 86 std::string owner_; | |
| 87 bool set_owner_status_; | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit: Initialize this in the constructor to guarant
davidyu
2014/08/05 07:26:59
Done.
| |
| 88 }; | |
| 89 | |
| 90 TEST_F(ConsumerManagementServiceTest, CanGetEnrollState) { | |
|
bartfab (slow)
2014/08/04 18:44:55
Nit: s/Enroll/Enrollment/
davidyu
2014/08/05 07:27:00
Done.
| |
| 91 testing_local_state_.Get()->SetInteger( | |
| 92 prefs::kConsumerManagementEnrollState, | |
| 93 ConsumerManagementService::ENROLL_ENROLLING); | |
| 94 | |
| 95 EXPECT_EQ(ConsumerManagementService::ENROLL_ENROLLING, | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit: Check first that before the set call, GetEnro
davidyu
2014/08/05 07:26:59
Done.
| |
| 96 service_->GetEnrollState()); | |
| 97 } | |
| 98 | |
| 99 TEST_F(ConsumerManagementServiceTest, CanSetEnrollState) { | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit: s/Enroll/Enrollment/
davidyu
2014/08/05 07:26:59
Done.
| |
| 100 service_->SetEnrollState(ConsumerManagementService::ENROLL_ENROLLING); | |
| 101 | |
| 102 EXPECT_EQ(ConsumerManagementService::ENROLL_ENROLLING, | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit: Check first that before the set call, GetInte
davidyu
2014/08/05 07:27:00
Done.
| |
| 103 testing_local_state_.Get()->GetInteger( | |
| 104 prefs::kConsumerManagementEnrollState)); | |
| 105 } | |
| 106 | |
| 107 TEST_F(ConsumerManagementServiceTest, CanGetOwner) { | |
| 108 cryptohome_status_ = chromeos::DBUS_METHOD_CALL_SUCCESS; | |
| 109 cryptohome_result_ = true; | |
| 110 cryptohome_reply_.MutableExtension(cryptohome::GetBootAttributeReply::reply) | |
| 111 ->set_value("test@chromium.org"); | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit 1: Move the -> operator to the previous line.
davidyu
2014/08/05 07:26:59
Done.
| |
| 112 | |
| 113 service_->GetOwner(base::Bind(&ConsumerManagementServiceTest::OnGetOwnerDone, | |
| 114 base::Unretained(this))); | |
| 115 | |
| 116 EXPECT_EQ("consumer_management.owner", get_boot_attribute_request_.name()); | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit: Extract "consumer_management.owner" to a cons
davidyu
2014/08/05 07:26:59
Done.
| |
| 117 EXPECT_EQ("test@chromium.org", owner_); | |
| 118 } | |
| 119 | |
| 120 TEST_F(ConsumerManagementServiceTest, GetOwnerReturnsAnEmptyStringWhenFails) { | |
|
bartfab (slow)
2014/08/04 18:44:53
Nit: s/When/WhenIt/
davidyu
2014/08/05 07:26:59
Done.
| |
| 121 cryptohome_status_ = chromeos::DBUS_METHOD_CALL_FAILURE; | |
| 122 cryptohome_result_ = false; | |
| 123 cryptohome_reply_.MutableExtension(cryptohome::GetBootAttributeReply::reply) | |
| 124 ->set_value("test@chromium.org"); | |
|
bartfab (slow)
2014/08/04 18:44:55
Nit: Move the -> operator to the previous line.
davidyu
2014/08/05 07:27:00
Done.
| |
| 125 | |
| 126 service_->GetOwner(base::Bind(&ConsumerManagementServiceTest::OnGetOwnerDone, | |
| 127 base::Unretained(this))); | |
| 128 | |
| 129 EXPECT_EQ("", owner_); | |
| 130 } | |
| 131 | |
| 132 TEST_F(ConsumerManagementServiceTest, CanSetOwner) { | |
| 133 cryptohome_status_ = chromeos::DBUS_METHOD_CALL_SUCCESS; | |
| 134 cryptohome_result_ = true; | |
| 135 | |
| 136 service_->SetOwner("test@chromium.org", | |
| 137 base::Bind(&ConsumerManagementServiceTest::OnSetOwnerDone, | |
| 138 base::Unretained(this))); | |
| 139 | |
| 140 EXPECT_EQ("consumer_management.owner", set_boot_attribute_request_.name()); | |
| 141 EXPECT_EQ("test@chromium.org", set_boot_attribute_request_.value()); | |
| 142 EXPECT_TRUE(set_owner_status_); | |
| 143 } | |
| 144 | |
| 145 TEST_F(ConsumerManagementServiceTest, SetOwnerReturnsFalseWhenFails) { | |
|
bartfab (slow)
2014/08/04 18:44:54
Nit: s/When/WhenIt/
davidyu
2014/08/05 07:27:00
Done.
| |
| 146 cryptohome_status_ = chromeos::DBUS_METHOD_CALL_FAILURE; | |
| 147 cryptohome_result_ = false; | |
| 148 | |
| 149 service_->SetOwner("test@chromium.org", | |
| 150 base::Bind(&ConsumerManagementServiceTest::OnSetOwnerDone, | |
| 151 base::Unretained(this))); | |
| 152 | |
| 153 EXPECT_FALSE(set_owner_status_); | |
| 154 } | |
| 155 | |
| 156 } // namespace | |
| 157 } // namespace policy | |
| OLD | NEW |