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

Side by Side Diff: chrome/browser/extensions/management_policy_unittest.cc

Issue 54903011: Add management policy function allowing extensions to be disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/extensions/management_policy.h" 6 #include "chrome/browser/extensions/management_policy.h"
7 #include "chrome/browser/extensions/test_management_policy.h" 7 #include "chrome/browser/extensions/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(
23 TestProvider::MUST_REMAIN_DISABLED);
24 must_remain_disabled_.SetDisableReason(Extension::DISABLE_SIDELOAD_WIPEOUT);
22 restrict_all_.SetProhibitedActions(TestProvider::PROHIBIT_MODIFY_STATUS | 25 restrict_all_.SetProhibitedActions(TestProvider::PROHIBIT_MODIFY_STATUS |
23 TestProvider::PROHIBIT_LOAD | 26 TestProvider::PROHIBIT_LOAD |
24 TestProvider::MUST_REMAIN_ENABLED); 27 TestProvider::MUST_REMAIN_ENABLED);
25 } 28 }
26 29
27 protected: 30 protected:
28 extensions::ManagementPolicy policy_; 31 extensions::ManagementPolicy policy_;
29 32
30 TestProvider allow_all_; 33 TestProvider allow_all_;
31 TestProvider no_modify_status_; 34 TestProvider no_modify_status_;
32 TestProvider no_load_; 35 TestProvider no_load_;
33 TestProvider must_remain_enabled_; 36 TestProvider must_remain_enabled_;
37 TestProvider must_remain_disabled_;
34 TestProvider restrict_all_; 38 TestProvider restrict_all_;
35 }; 39 };
36 40
37 TEST_F(ManagementPolicyTest, RegisterAndUnregister) { 41 TEST_F(ManagementPolicyTest, RegisterAndUnregister) {
38 EXPECT_EQ(0, policy_.GetNumProviders()); 42 EXPECT_EQ(0, policy_.GetNumProviders());
39 policy_.RegisterProvider(&allow_all_); 43 policy_.RegisterProvider(&allow_all_);
40 EXPECT_EQ(1, policy_.GetNumProviders()); 44 EXPECT_EQ(1, policy_.GetNumProviders());
41 policy_.RegisterProvider(&allow_all_); 45 policy_.RegisterProvider(&allow_all_);
42 EXPECT_EQ(1, policy_.GetNumProviders()); 46 EXPECT_EQ(1, policy_.GetNumProviders());
43 47
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error)); 139 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error));
136 EXPECT_FALSE(error.empty()); 140 EXPECT_FALSE(error.empty());
137 141
138 // Remove the restriction. 142 // Remove the restriction.
139 policy_.UnregisterProvider(&must_remain_enabled_); 143 policy_.UnregisterProvider(&must_remain_enabled_);
140 error.clear(); 144 error.clear();
141 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error)); 145 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error));
142 EXPECT_TRUE(error.empty()); 146 EXPECT_TRUE(error.empty());
143 } 147 }
144 148
149 TEST_F(ManagementPolicyTest, MustRemainDisabled) {
150 // No providers registered.
151 string16 error;
152 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error));
153 EXPECT_TRUE(error.empty());
154
155 // One provider, no relevant restriction.
156 policy_.RegisterProvider(&allow_all_);
157 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error));
158 EXPECT_TRUE(error.empty());
159
160 // Two providers, no relevant restrictions.
161 policy_.RegisterProvider(&no_modify_status_);
162 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error));
163 EXPECT_TRUE(error.empty());
164
165 // Three providers, one with a relevant restriction.
166 Extension::DisableReason reason = Extension::DISABLE_NONE;
167 policy_.RegisterProvider(&must_remain_disabled_);
168 EXPECT_TRUE(policy_.MustRemainDisabled(NULL, &reason, &error));
169 EXPECT_FALSE(error.empty());
170 EXPECT_EQ(Extension::DISABLE_SIDELOAD_WIPEOUT, reason);
171
172 // Remove the restriction.
173 policy_.UnregisterProvider(&must_remain_disabled_);
174 error.clear();
175 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error));
176 EXPECT_TRUE(error.empty());
177 }
178
145 // Tests error handling in the ManagementPolicy. 179 // Tests error handling in the ManagementPolicy.
146 TEST_F(ManagementPolicyTest, ErrorHandling) { 180 TEST_F(ManagementPolicyTest, ErrorHandling) {
147 // The error parameter should be unchanged if no restriction was found. 181 // The error parameter should be unchanged if no restriction was found.
148 std::string original_error = "Ceci est en effet une erreur."; 182 std::string original_error = "Ceci est en effet une erreur.";
149 string16 original_error16 = UTF8ToUTF16(original_error); 183 string16 original_error16 = UTF8ToUTF16(original_error);
150 string16 error = original_error16; 184 string16 error = original_error16;
151 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 185 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error));
152 EXPECT_EQ(original_error, UTF16ToUTF8(error)); 186 EXPECT_EQ(original_error, UTF16ToUTF8(error));
153 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); 187 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error));
154 EXPECT_EQ(original_error, UTF16ToUTF8(error)); 188 EXPECT_EQ(original_error, UTF16ToUTF8(error));
(...skipping 13 matching lines...) Expand all
168 error = original_error16; 202 error = original_error16;
169 EXPECT_FALSE(policy_.UserMayLoad(NULL, &error)); 203 EXPECT_FALSE(policy_.UserMayLoad(NULL, &error));
170 EXPECT_EQ(UTF8ToUTF16(TestProvider::expected_error()), error); 204 EXPECT_EQ(UTF8ToUTF16(TestProvider::expected_error()), error);
171 error = original_error16; 205 error = original_error16;
172 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, &error)); 206 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, &error));
173 EXPECT_EQ(UTF8ToUTF16(TestProvider::expected_error()), error); 207 EXPECT_EQ(UTF8ToUTF16(TestProvider::expected_error()), error);
174 error = original_error16; 208 error = original_error16;
175 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error)); 209 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error));
176 EXPECT_EQ(UTF8ToUTF16(TestProvider::expected_error()), error); 210 EXPECT_EQ(UTF8ToUTF16(TestProvider::expected_error()), error);
177 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698