OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/device_local_account_management_pol
icy_provider.h" | 5 #include "chrome/browser/chromeos/extensions/device_local_account_management_pol
icy_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "extensions/common/manifest.h" | 13 #include "extensions/common/manifest.h" |
14 #include "extensions/common/manifest_constants.h" | 14 #include "extensions/common/manifest_constants.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch"; | 21 const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch"; |
22 | 22 |
23 scoped_refptr<const extensions::Extension> CreateExtensionFromValues( | 23 scoped_refptr<const extensions::Extension> CreateExtensionFromValues( |
24 const std::string& id, | 24 const std::string& id, |
| 25 extensions::Manifest::Location location, |
25 base::DictionaryValue* values) { | 26 base::DictionaryValue* values) { |
26 values->SetString(extensions::manifest_keys::kName, "test"); | 27 values->SetString(extensions::manifest_keys::kName, "test"); |
27 values->SetString(extensions::manifest_keys::kVersion, "0.1"); | 28 values->SetString(extensions::manifest_keys::kVersion, "0.1"); |
28 std::string error; | 29 std::string error; |
29 return extensions::Extension::Create(base::FilePath(), | 30 return extensions::Extension::Create(base::FilePath(), |
30 extensions::Manifest::INTERNAL, | 31 location, |
31 *values, | 32 *values, |
32 extensions::Extension::NO_FLAGS, | 33 extensions::Extension::NO_FLAGS, |
33 id, | 34 id, |
34 &error); | 35 &error); |
35 } | 36 } |
36 | 37 |
37 scoped_refptr<const extensions::Extension> CreateExtension( | 38 scoped_refptr<const extensions::Extension> CreateRegularExtension( |
38 const std::string& id) { | 39 const std::string& id) { |
39 base::DictionaryValue values; | 40 base::DictionaryValue values; |
40 return CreateExtensionFromValues(id, &values); | 41 return CreateExtensionFromValues(id, extensions::Manifest::INTERNAL, &values); |
| 42 } |
| 43 |
| 44 scoped_refptr<const extensions::Extension> CreateExternalComponentExtension() { |
| 45 base::DictionaryValue values; |
| 46 return CreateExtensionFromValues(std::string(), |
| 47 extensions::Manifest::EXTERNAL_COMPONENT, |
| 48 &values); |
41 } | 49 } |
42 | 50 |
43 scoped_refptr<const extensions::Extension> CreateHostedApp() { | 51 scoped_refptr<const extensions::Extension> CreateHostedApp() { |
44 base::DictionaryValue values; | 52 base::DictionaryValue values; |
45 values.Set(extensions::manifest_keys::kApp, new base::DictionaryValue); | 53 values.Set(extensions::manifest_keys::kApp, new base::DictionaryValue); |
46 values.Set(extensions::manifest_keys::kWebURLs, new base::ListValue); | 54 values.Set(extensions::manifest_keys::kWebURLs, new base::ListValue); |
47 return CreateExtensionFromValues(std::string(), &values); | 55 return CreateExtensionFromValues(std::string(), |
| 56 extensions::Manifest::INTERNAL, |
| 57 &values); |
48 } | 58 } |
49 | 59 |
50 scoped_refptr<const extensions::Extension> CreatePlatformApp() { | 60 scoped_refptr<const extensions::Extension> CreatePlatformApp() { |
51 base::DictionaryValue values; | 61 base::DictionaryValue values; |
52 values.Set(extensions::manifest_keys::kApp, new base::DictionaryValue); | 62 values.Set(extensions::manifest_keys::kApp, new base::DictionaryValue); |
53 values.Set(extensions::manifest_keys::kPlatformAppBackground, | 63 values.Set(extensions::manifest_keys::kPlatformAppBackground, |
54 new base::DictionaryValue); | 64 new base::DictionaryValue); |
55 values.Set(extensions::manifest_keys::kPlatformAppBackgroundPage, | 65 values.Set(extensions::manifest_keys::kPlatformAppBackgroundPage, |
56 new base::StringValue("background.html")); | 66 new base::StringValue("background.html")); |
57 return CreateExtensionFromValues(std::string(), &values); | 67 return CreateExtensionFromValues(std::string(), |
| 68 extensions::Manifest::INTERNAL, |
| 69 &values); |
58 } | 70 } |
59 | 71 |
60 } // namespace | 72 } // namespace |
61 | 73 |
62 TEST(DeviceLocalAccountManagementPolicyProviderTest, PublicSession) { | 74 TEST(DeviceLocalAccountManagementPolicyProviderTest, PublicSession) { |
63 DeviceLocalAccountManagementPolicyProvider | 75 DeviceLocalAccountManagementPolicyProvider |
64 provider(policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION); | 76 provider(policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION); |
65 | 77 |
| 78 // Verify that if an extension's location has been whitelisted for use in |
| 79 // public sessions, the extension can be installed. |
| 80 scoped_refptr<const extensions::Extension> extension = |
| 81 CreateExternalComponentExtension(); |
| 82 ASSERT_TRUE(extension); |
| 83 base::string16 error; |
| 84 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error)); |
| 85 EXPECT_EQ(base::string16(), error); |
| 86 error.clear(); |
| 87 |
66 // Verify that if an extension's type has been whitelisted for use in | 88 // Verify that if an extension's type has been whitelisted for use in |
67 // device-local accounts, the extension can be installed. | 89 // device-local accounts, the extension can be installed. |
68 scoped_refptr<const extensions::Extension> extension = CreateHostedApp(); | 90 extension = CreateHostedApp(); |
69 ASSERT_TRUE(extension); | 91 ASSERT_TRUE(extension); |
70 string16 error; | |
71 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error)); | 92 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error)); |
72 EXPECT_EQ(string16(), error); | 93 EXPECT_EQ(string16(), error); |
73 error.clear(); | 94 error.clear(); |
74 | 95 |
75 // Verify that if an extension's ID has been explicitly whitelisted for use in | 96 // Verify that if an extension's ID has been explicitly whitelisted for use in |
76 // device-local accounts, the extension can be installed. | 97 // device-local accounts, the extension can be installed. |
77 extension = CreateExtension(kWhitelistedId); | 98 extension = CreateRegularExtension(kWhitelistedId); |
78 ASSERT_TRUE(extension); | 99 ASSERT_TRUE(extension); |
79 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error)); | 100 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error)); |
80 EXPECT_EQ(string16(), error); | 101 EXPECT_EQ(string16(), error); |
81 error.clear(); | 102 error.clear(); |
82 | 103 |
83 // Verify that if neither the type nor the ID of an extension have been | 104 // Verify that if neither the location, type nor the ID of an extension have |
84 // whitelisted for use in device-local accounts, the extension cannot be | 105 // been whitelisted for use in public sessions, the extension cannot be |
85 // installed. | 106 // installed. |
86 extension = CreateExtension(std::string()); | 107 extension = CreateRegularExtension(std::string()); |
87 ASSERT_TRUE(extension); | 108 ASSERT_TRUE(extension); |
88 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error)); | 109 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error)); |
89 EXPECT_NE(string16(), error); | 110 EXPECT_NE(string16(), error); |
90 error.clear(); | 111 error.clear(); |
91 } | 112 } |
92 | 113 |
93 TEST(DeviceLocalAccountManagementPolicyProviderTest, KioskAppSession) { | 114 TEST(DeviceLocalAccountManagementPolicyProviderTest, KioskAppSession) { |
94 DeviceLocalAccountManagementPolicyProvider | 115 DeviceLocalAccountManagementPolicyProvider |
95 provider(policy::DeviceLocalAccount::TYPE_KIOSK_APP); | 116 provider(policy::DeviceLocalAccount::TYPE_KIOSK_APP); |
96 | 117 |
97 // Verify that a platform app can be installed. | 118 // Verify that a platform app can be installed. |
98 scoped_refptr<const extensions::Extension> extension = CreatePlatformApp(); | 119 scoped_refptr<const extensions::Extension> extension = CreatePlatformApp(); |
99 ASSERT_TRUE(extension); | 120 ASSERT_TRUE(extension); |
100 string16 error; | 121 string16 error; |
101 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error)); | 122 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error)); |
102 EXPECT_EQ(string16(), error); | 123 EXPECT_EQ(string16(), error); |
103 error.clear(); | 124 error.clear(); |
104 | 125 |
| 126 // Verify that an extension whose location has been whitelisted for use in |
| 127 // other types of device-local accounts cannot be installed in a single-app |
| 128 // kiosk session. |
| 129 extension = CreateExternalComponentExtension(); |
| 130 ASSERT_TRUE(extension); |
| 131 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error)); |
| 132 EXPECT_NE(base::string16(), error); |
| 133 error.clear(); |
| 134 |
105 // Verify that an extension whose type has been whitelisted for use in other | 135 // Verify that an extension whose type has been whitelisted for use in other |
106 // types of device-local accounts cannot be installed in a single-app kiosk | 136 // types of device-local accounts cannot be installed in a single-app kiosk |
107 // session. | 137 // session. |
108 extension = CreateHostedApp(); | 138 extension = CreateHostedApp(); |
109 ASSERT_TRUE(extension); | 139 ASSERT_TRUE(extension); |
110 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error)); | 140 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error)); |
111 EXPECT_NE(string16(), error); | 141 EXPECT_NE(string16(), error); |
112 error.clear(); | 142 error.clear(); |
113 | 143 |
114 // Verify that an extension whose ID has been whitelisted for use in other | 144 // Verify that an extension whose ID has been whitelisted for use in other |
115 // types of device-local accounts cannot be installed in a single-app kiosk | 145 // types of device-local accounts cannot be installed in a single-app kiosk |
116 // session. | 146 // session. |
117 extension = CreateExtension(kWhitelistedId); | 147 extension = CreateRegularExtension(kWhitelistedId); |
118 ASSERT_TRUE(extension); | 148 ASSERT_TRUE(extension); |
119 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error)); | 149 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error)); |
120 EXPECT_NE(string16(), error); | 150 EXPECT_NE(string16(), error); |
121 error.clear(); | 151 error.clear(); |
122 } | 152 } |
123 | 153 |
124 } // namespace chromeos | 154 } // namespace chromeos |
OLD | NEW |