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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "extensions/browser/management_policy.h" | 6 #include "extensions/browser/management_policy.h" |
7 #include "extensions/browser/test_management_policy.h" | 7 #include "extensions/browser/test_management_policy.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 typedef extensions::TestManagementPolicyProvider TestProvider; | 10 typedef extensions::TestManagementPolicyProvider TestProvider; |
11 using extensions::Extension; | 11 using extensions::Extension; |
12 | 12 |
13 class ManagementPolicyTest : public testing::Test { | 13 class ManagementPolicyTest : public testing::Test { |
14 public: | 14 public: |
15 virtual void SetUp() { | 15 virtual void SetUp() { |
16 allow_all_.SetProhibitedActions(TestProvider::ALLOW_ALL); | 16 allow_all_.SetProhibitedActions(TestProvider::ALLOW_ALL); |
17 no_modify_status_.SetProhibitedActions( | 17 no_modify_status_.SetProhibitedActions( |
18 TestProvider::PROHIBIT_MODIFY_STATUS); | 18 TestProvider::PROHIBIT_MODIFY_STATUS); |
19 no_load_.SetProhibitedActions(TestProvider::PROHIBIT_LOAD); | 19 no_load_.SetProhibitedActions(TestProvider::PROHIBIT_LOAD); |
20 must_remain_enabled_.SetProhibitedActions( | 20 must_remain_enabled_.SetProhibitedActions( |
21 TestProvider::MUST_REMAIN_ENABLED); | 21 TestProvider::MUST_REMAIN_ENABLED); |
22 must_remain_disabled_.SetProhibitedActions( | 22 must_remain_disabled_.SetProhibitedActions( |
23 TestProvider::MUST_REMAIN_DISABLED); | 23 TestProvider::MUST_REMAIN_DISABLED); |
24 must_remain_disabled_.SetDisableReason(Extension::DISABLE_SIDELOAD_WIPEOUT); | 24 must_remain_disabled_.SetDisableReason(Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 25 must_remain_installed_.SetProhibitedActions( |
| 26 TestProvider::MUST_REMAIN_INSTALLED); |
25 restrict_all_.SetProhibitedActions(TestProvider::PROHIBIT_MODIFY_STATUS | | 27 restrict_all_.SetProhibitedActions(TestProvider::PROHIBIT_MODIFY_STATUS | |
26 TestProvider::PROHIBIT_LOAD | | 28 TestProvider::PROHIBIT_LOAD | |
27 TestProvider::MUST_REMAIN_ENABLED); | 29 TestProvider::MUST_REMAIN_ENABLED); |
28 } | 30 } |
29 | 31 |
30 protected: | 32 protected: |
31 extensions::ManagementPolicy policy_; | 33 extensions::ManagementPolicy policy_; |
32 | 34 |
33 TestProvider allow_all_; | 35 TestProvider allow_all_; |
34 TestProvider no_modify_status_; | 36 TestProvider no_modify_status_; |
35 TestProvider no_load_; | 37 TestProvider no_load_; |
36 TestProvider must_remain_enabled_; | 38 TestProvider must_remain_enabled_; |
37 TestProvider must_remain_disabled_; | 39 TestProvider must_remain_disabled_; |
| 40 TestProvider must_remain_installed_; |
38 TestProvider restrict_all_; | 41 TestProvider restrict_all_; |
39 }; | 42 }; |
40 | 43 |
41 TEST_F(ManagementPolicyTest, RegisterAndUnregister) { | 44 TEST_F(ManagementPolicyTest, RegisterAndUnregister) { |
42 EXPECT_EQ(0, policy_.GetNumProviders()); | 45 EXPECT_EQ(0, policy_.GetNumProviders()); |
43 policy_.RegisterProvider(&allow_all_); | 46 policy_.RegisterProvider(&allow_all_); |
44 EXPECT_EQ(1, policy_.GetNumProviders()); | 47 EXPECT_EQ(1, policy_.GetNumProviders()); |
45 policy_.RegisterProvider(&allow_all_); | 48 policy_.RegisterProvider(&allow_all_); |
46 EXPECT_EQ(1, policy_.GetNumProviders()); | 49 EXPECT_EQ(1, policy_.GetNumProviders()); |
47 | 50 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 EXPECT_FALSE(error.empty()); | 172 EXPECT_FALSE(error.empty()); |
170 EXPECT_EQ(Extension::DISABLE_SIDELOAD_WIPEOUT, reason); | 173 EXPECT_EQ(Extension::DISABLE_SIDELOAD_WIPEOUT, reason); |
171 | 174 |
172 // Remove the restriction. | 175 // Remove the restriction. |
173 policy_.UnregisterProvider(&must_remain_disabled_); | 176 policy_.UnregisterProvider(&must_remain_disabled_); |
174 error.clear(); | 177 error.clear(); |
175 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error)); | 178 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error)); |
176 EXPECT_TRUE(error.empty()); | 179 EXPECT_TRUE(error.empty()); |
177 } | 180 } |
178 | 181 |
| 182 TEST_F(ManagementPolicyTest, MustRemainInstalled) { |
| 183 // No providers registered. |
| 184 base::string16 error; |
| 185 EXPECT_FALSE(policy_.MustRemainInstalled(NULL, &error)); |
| 186 EXPECT_TRUE(error.empty()); |
| 187 |
| 188 // One provider, no relevant restriction. |
| 189 policy_.RegisterProvider(&allow_all_); |
| 190 EXPECT_FALSE(policy_.MustRemainInstalled(NULL, &error)); |
| 191 EXPECT_TRUE(error.empty()); |
| 192 |
| 193 // Two providers, no relevant restrictions. |
| 194 policy_.RegisterProvider(&no_modify_status_); |
| 195 EXPECT_FALSE(policy_.MustRemainInstalled(NULL, &error)); |
| 196 EXPECT_TRUE(error.empty()); |
| 197 |
| 198 // Three providers, one with a relevant restriction. |
| 199 policy_.RegisterProvider(&must_remain_installed_); |
| 200 EXPECT_TRUE(policy_.MustRemainInstalled(NULL, &error)); |
| 201 EXPECT_FALSE(error.empty()); |
| 202 |
| 203 // Remove the restriction. |
| 204 policy_.UnregisterProvider(&must_remain_installed_); |
| 205 error.clear(); |
| 206 EXPECT_FALSE(policy_.MustRemainInstalled(NULL, &error)); |
| 207 EXPECT_TRUE(error.empty()); |
| 208 } |
| 209 |
179 // Tests error handling in the ManagementPolicy. | 210 // Tests error handling in the ManagementPolicy. |
180 TEST_F(ManagementPolicyTest, ErrorHandling) { | 211 TEST_F(ManagementPolicyTest, ErrorHandling) { |
181 // The error parameter should be unchanged if no restriction was found. | 212 // The error parameter should be unchanged if no restriction was found. |
182 std::string original_error = "Ceci est en effet une erreur."; | 213 std::string original_error = "Ceci est en effet une erreur."; |
183 base::string16 original_error16 = base::UTF8ToUTF16(original_error); | 214 base::string16 original_error16 = base::UTF8ToUTF16(original_error); |
184 base::string16 error = original_error16; | 215 base::string16 error = original_error16; |
185 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); | 216 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); |
186 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); | 217 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); |
187 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); | 218 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); |
188 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); | 219 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); |
(...skipping 13 matching lines...) Expand all Loading... |
202 error = original_error16; | 233 error = original_error16; |
203 EXPECT_FALSE(policy_.UserMayLoad(NULL, &error)); | 234 EXPECT_FALSE(policy_.UserMayLoad(NULL, &error)); |
204 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); | 235 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); |
205 error = original_error16; | 236 error = original_error16; |
206 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, &error)); | 237 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, &error)); |
207 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); | 238 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); |
208 error = original_error16; | 239 error = original_error16; |
209 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error)); | 240 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error)); |
210 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); | 241 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); |
211 } | 242 } |
OLD | NEW |