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

Side by Side Diff: chrome/browser/policy/enterprise_install_attributes_unittest.cc

Issue 9403010: Add support for kiosk mode on the client. Make sure the settings are written in the lockbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only check and set enrollment_type for device registrations. Created 8 years, 10 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 | Annotate | Revision Log
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/policy/enterprise_install_attributes.h" 5 #include "chrome/browser/policy/enterprise_install_attributes.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 8 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace em = enterprise_management;
12
11 namespace policy { 13 namespace policy {
12 14
13 static const char kTestUser[] = "test@example.com"; 15 static const char kTestUser[] = "test@example.com";
16 static const char kTestDomain[] = "example.com";
17 static const char kTestDeviceId[] = "133750519";
18
19 static const char kAttrEnterpriseOwned[] = "enterprise.owned";
20 static const char kAttrEnterpriseUser[] = "enterprise.user";
14 21
15 class EnterpriseInstallAttributesTest : public testing::Test { 22 class EnterpriseInstallAttributesTest : public testing::Test {
16 protected: 23 protected:
17 EnterpriseInstallAttributesTest() 24 EnterpriseInstallAttributesTest()
18 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)), 25 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)),
19 install_attributes_(cryptohome_.get()) {} 26 install_attributes_(cryptohome_.get()) {}
20 27
21 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; 28 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_;
22 EnterpriseInstallAttributes install_attributes_; 29 EnterpriseInstallAttributes install_attributes_;
23 }; 30 };
24 31
25 TEST_F(EnterpriseInstallAttributesTest, Lock) { 32 TEST_F(EnterpriseInstallAttributesTest, Lock) {
26 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, 33 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
27 install_attributes_.LockDevice(kTestUser)); 34 install_attributes_.LockDevice(
35 kTestUser,
36 CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE,
37 kTestDeviceId));
28 38
29 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, 39 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
30 install_attributes_.LockDevice(kTestUser)); 40 install_attributes_.LockDevice(
41 kTestUser,
42 CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE,
43 kTestDeviceId));
31 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_WRONG_USER, 44 EXPECT_EQ(EnterpriseInstallAttributes::LOCK_WRONG_USER,
32 install_attributes_.LockDevice("test1@example.com")); 45 install_attributes_.LockDevice(
46 "test1@example.com",
47 CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE,
48 kTestDeviceId));
33 } 49 }
34 50
35 TEST_F(EnterpriseInstallAttributesTest, IsEnterpriseDevice) { 51 TEST_F(EnterpriseInstallAttributesTest, IsEnterpriseDevice) {
36 EXPECT_FALSE(install_attributes_.IsEnterpriseDevice()); 52 EXPECT_FALSE(install_attributes_.IsEnterpriseDevice());
37 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, 53 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
38 install_attributes_.LockDevice(kTestUser)); 54 install_attributes_.LockDevice(
55 kTestUser,
56 CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE,
57 kTestDeviceId));
39 EXPECT_TRUE(install_attributes_.IsEnterpriseDevice()); 58 EXPECT_TRUE(install_attributes_.IsEnterpriseDevice());
40 } 59 }
41 60
42 TEST_F(EnterpriseInstallAttributesTest, GetDomain) { 61 TEST_F(EnterpriseInstallAttributesTest, GetDomain) {
43 EXPECT_EQ(std::string(), install_attributes_.GetDomain()); 62 EXPECT_EQ(std::string(), install_attributes_.GetDomain());
44 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, 63 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
45 install_attributes_.LockDevice(kTestUser)); 64 install_attributes_.LockDevice(
46 EXPECT_EQ("example.com", install_attributes_.GetDomain()); 65 kTestUser,
66 CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE,
67 kTestDeviceId));
68 EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
47 } 69 }
48 70
49 TEST_F(EnterpriseInstallAttributesTest, GetRegistrationUser) { 71 TEST_F(EnterpriseInstallAttributesTest, GetRegistrationUser) {
50 EXPECT_EQ(std::string(), install_attributes_.GetRegistrationUser()); 72 EXPECT_EQ(std::string(), install_attributes_.GetRegistrationUser());
51 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, 73 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
52 install_attributes_.LockDevice(kTestUser)); 74 install_attributes_.LockDevice(
75 kTestUser,
76 CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE,
77 kTestDeviceId));
53 EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser()); 78 EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
54 } 79 }
55 80
81 TEST_F(EnterpriseInstallAttributesTest, GetDeviceId) {
82 EXPECT_EQ(std::string(), install_attributes_.GetDeviceId());
83 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
84 install_attributes_.LockDevice(
85 kTestUser,
86 CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE,
87 kTestDeviceId));
88 EXPECT_EQ(kTestDeviceId, install_attributes_.GetDeviceId());
89 }
90
91 TEST_F(EnterpriseInstallAttributesTest, GetMode) {
92 EXPECT_EQ(CloudPolicyDataStore::DEVICE_MODE_UNKNOWN,
93 install_attributes_.GetMode());
94 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
95 install_attributes_.LockDevice(
96 kTestUser,
97 CloudPolicyDataStore::DEVICE_MODE_KIOSK,
98 kTestDeviceId));
99 EXPECT_EQ(CloudPolicyDataStore::DEVICE_MODE_KIOSK,
100 install_attributes_.GetMode());
101 }
102
103 TEST_F(EnterpriseInstallAttributesTest, ConsumerDevice) {
104 EXPECT_EQ(CloudPolicyDataStore::DEVICE_MODE_UNKNOWN,
105 install_attributes_.GetMode());
106 // Lock the attributes empty.
107 ASSERT_TRUE(cryptohome_->InstallAttributesFinalize());
108 ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall());
109 EXPECT_EQ(CloudPolicyDataStore::DEVICE_MODE_CONSUMER,
110 install_attributes_.GetMode());
111 }
112
113 TEST_F(EnterpriseInstallAttributesTest, DeviceLockedFromOlderVersion) {
114 EXPECT_EQ(CloudPolicyDataStore::DEVICE_MODE_UNKNOWN,
115 install_attributes_.GetMode());
116 // Lock the attributes as if it was done from older Chrome version.
117 ASSERT_TRUE(cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true"));
118 ASSERT_TRUE(cryptohome_->InstallAttributesSet(kAttrEnterpriseUser,
119 kTestUser));
120 ASSERT_TRUE(cryptohome_->InstallAttributesFinalize());
121 ASSERT_FALSE(cryptohome_->InstallAttributesIsFirstInstall());
122 EXPECT_EQ(CloudPolicyDataStore::DEVICE_MODE_ENTERPRISE,
123 install_attributes_.GetMode());
124 EXPECT_EQ(kTestDomain, install_attributes_.GetDomain());
125 EXPECT_EQ(kTestUser, install_attributes_.GetRegistrationUser());
126 EXPECT_EQ("", install_attributes_.GetDeviceId());
127 }
128
56 } // namespace policy 129 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698