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

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

Issue 384423002: [Canceled] Extensions: Add install_flags parameter to ManagementPolicy::UserMayLoad (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update tests Created 6 years, 5 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
« no previous file with comments | « extensions/browser/management_policy.cc ('k') | extensions/browser/test_management_policy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/install_flag.h"
6 #include "extensions/browser/management_policy.h" 7 #include "extensions/browser/management_policy.h"
7 #include "extensions/browser/test_management_policy.h" 8 #include "extensions/browser/test_management_policy.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 typedef extensions::TestManagementPolicyProvider TestProvider; 11 typedef extensions::TestManagementPolicyProvider TestProvider;
11 using extensions::Extension; 12 using extensions::Extension;
12 13
14 const int kInstallFlags = extensions::kInstallFlagNone;
15
13 class ManagementPolicyTest : public testing::Test { 16 class ManagementPolicyTest : public testing::Test {
14 public: 17 public:
15 virtual void SetUp() { 18 virtual void SetUp() {
16 allow_all_.SetProhibitedActions(TestProvider::ALLOW_ALL); 19 allow_all_.SetProhibitedActions(TestProvider::ALLOW_ALL);
17 no_modify_status_.SetProhibitedActions( 20 no_modify_status_.SetProhibitedActions(
18 TestProvider::PROHIBIT_MODIFY_STATUS); 21 TestProvider::PROHIBIT_MODIFY_STATUS);
19 no_load_.SetProhibitedActions(TestProvider::PROHIBIT_LOAD); 22 no_load_.SetProhibitedActions(TestProvider::PROHIBIT_LOAD);
20 must_remain_enabled_.SetProhibitedActions( 23 must_remain_enabled_.SetProhibitedActions(
21 TestProvider::MUST_REMAIN_ENABLED); 24 TestProvider::MUST_REMAIN_ENABLED);
22 must_remain_disabled_.SetProhibitedActions( 25 must_remain_disabled_.SetProhibitedActions(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 EXPECT_EQ(2, policy_.GetNumProviders()); 62 EXPECT_EQ(2, policy_.GetNumProviders());
60 policy_.UnregisterAllProviders(); 63 policy_.UnregisterAllProviders();
61 EXPECT_EQ(0, policy_.GetNumProviders()); 64 EXPECT_EQ(0, policy_.GetNumProviders());
62 } 65 }
63 66
64 TEST_F(ManagementPolicyTest, UserMayLoad) { 67 TEST_F(ManagementPolicyTest, UserMayLoad) {
65 // No providers registered. 68 // No providers registered.
66 base::string16 error; 69 base::string16 error;
67 // The extension and location are irrelevant to the 70 // The extension and location are irrelevant to the
68 // TestManagementPolicyProviders. 71 // TestManagementPolicyProviders.
69 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 72 EXPECT_TRUE(policy_.UserMayLoad(NULL, kInstallFlags, &error));
70 EXPECT_TRUE(error.empty()); 73 EXPECT_TRUE(error.empty());
71 74
72 // One provider, no relevant restriction. 75 // One provider, no relevant restriction.
73 policy_.RegisterProvider(&no_modify_status_); 76 policy_.RegisterProvider(&no_modify_status_);
74 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 77 EXPECT_TRUE(policy_.UserMayLoad(NULL, kInstallFlags, &error));
75 EXPECT_TRUE(error.empty()); 78 EXPECT_TRUE(error.empty());
76 79
77 // Two providers, no relevant restrictions. 80 // Two providers, no relevant restrictions.
78 policy_.RegisterProvider(&must_remain_enabled_); 81 policy_.RegisterProvider(&must_remain_enabled_);
79 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 82 EXPECT_TRUE(policy_.UserMayLoad(NULL, kInstallFlags, &error));
80 EXPECT_TRUE(error.empty()); 83 EXPECT_TRUE(error.empty());
81 84
82 // Three providers, one with a relevant restriction. 85 // Three providers, one with a relevant restriction.
83 policy_.RegisterProvider(&no_load_); 86 policy_.RegisterProvider(&no_load_);
84 EXPECT_FALSE(policy_.UserMayLoad(NULL, &error)); 87 EXPECT_FALSE(policy_.UserMayLoad(NULL, kInstallFlags, &error));
85 EXPECT_FALSE(error.empty()); 88 EXPECT_FALSE(error.empty());
86 89
87 // Remove the restriction. 90 // Remove the restriction.
88 policy_.UnregisterProvider(&no_load_); 91 policy_.UnregisterProvider(&no_load_);
89 error.clear(); 92 error.clear();
90 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 93 EXPECT_TRUE(policy_.UserMayLoad(NULL, kInstallFlags, &error));
91 EXPECT_TRUE(error.empty()); 94 EXPECT_TRUE(error.empty());
92 } 95 }
93 TEST_F(ManagementPolicyTest, UserMayModifySettings) { 96 TEST_F(ManagementPolicyTest, UserMayModifySettings) {
94 // No providers registered. 97 // No providers registered.
95 base::string16 error; 98 base::string16 error;
96 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); 99 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error));
97 EXPECT_TRUE(error.empty()); 100 EXPECT_TRUE(error.empty());
98 101
99 // One provider, no relevant restriction. 102 // One provider, no relevant restriction.
100 policy_.RegisterProvider(&allow_all_); 103 policy_.RegisterProvider(&allow_all_);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
179 // Tests error handling in the ManagementPolicy. 182 // Tests error handling in the ManagementPolicy.
180 TEST_F(ManagementPolicyTest, ErrorHandling) { 183 TEST_F(ManagementPolicyTest, ErrorHandling) {
181 // The error parameter should be unchanged if no restriction was found. 184 // The error parameter should be unchanged if no restriction was found.
182 std::string original_error = "Ceci est en effet une erreur."; 185 std::string original_error = "Ceci est en effet une erreur.";
183 base::string16 original_error16 = base::UTF8ToUTF16(original_error); 186 base::string16 original_error16 = base::UTF8ToUTF16(original_error);
184 base::string16 error = original_error16; 187 base::string16 error = original_error16;
185 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 188 EXPECT_TRUE(policy_.UserMayLoad(NULL, kInstallFlags, &error));
186 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); 189 EXPECT_EQ(original_error, base::UTF16ToUTF8(error));
187 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); 190 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error));
188 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); 191 EXPECT_EQ(original_error, base::UTF16ToUTF8(error));
189 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error)); 192 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error));
190 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); 193 EXPECT_EQ(original_error, base::UTF16ToUTF8(error));
191 194
192 // Ensure no crashes if no error message was requested. 195 // Ensure no crashes if no error message was requested.
193 EXPECT_TRUE(policy_.UserMayLoad(NULL, NULL)); 196 EXPECT_TRUE(policy_.UserMayLoad(NULL, kInstallFlags, NULL));
194 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, NULL)); 197 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, NULL));
195 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, NULL)); 198 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, NULL));
196 policy_.RegisterProvider(&restrict_all_); 199 policy_.RegisterProvider(&restrict_all_);
197 EXPECT_FALSE(policy_.UserMayLoad(NULL, NULL)); 200 EXPECT_FALSE(policy_.UserMayLoad(NULL, kInstallFlags, NULL));
198 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, NULL)); 201 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, NULL));
199 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, NULL)); 202 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, NULL));
200 203
201 // Make sure returned error is correct. 204 // Make sure returned error is correct.
202 error = original_error16; 205 error = original_error16;
203 EXPECT_FALSE(policy_.UserMayLoad(NULL, &error)); 206 EXPECT_FALSE(policy_.UserMayLoad(NULL, kInstallFlags, &error));
204 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); 207 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error);
205 error = original_error16; 208 error = original_error16;
206 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, &error)); 209 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, &error));
207 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); 210 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error);
208 error = original_error16; 211 error = original_error16;
209 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error)); 212 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error));
210 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); 213 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error);
211 } 214 }
OLDNEW
« no previous file with comments | « extensions/browser/management_policy.cc ('k') | extensions/browser/test_management_policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698