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

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

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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/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;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 EXPECT_EQ(2, policy_.GetNumProviders()); 59 EXPECT_EQ(2, policy_.GetNumProviders());
60 policy_.UnregisterAllProviders(); 60 policy_.UnregisterAllProviders();
61 EXPECT_EQ(0, policy_.GetNumProviders()); 61 EXPECT_EQ(0, policy_.GetNumProviders());
62 } 62 }
63 63
64 TEST_F(ManagementPolicyTest, UserMayLoad) { 64 TEST_F(ManagementPolicyTest, UserMayLoad) {
65 // No providers registered. 65 // No providers registered.
66 base::string16 error; 66 base::string16 error;
67 // The extension and location are irrelevant to the 67 // The extension and location are irrelevant to the
68 // TestManagementPolicyProviders. 68 // TestManagementPolicyProviders.
69 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 69 EXPECT_TRUE(policy_.UserMayLoad(nullptr, &error));
70 EXPECT_TRUE(error.empty()); 70 EXPECT_TRUE(error.empty());
71 71
72 // One provider, no relevant restriction. 72 // One provider, no relevant restriction.
73 policy_.RegisterProvider(&no_modify_status_); 73 policy_.RegisterProvider(&no_modify_status_);
74 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 74 EXPECT_TRUE(policy_.UserMayLoad(nullptr, &error));
75 EXPECT_TRUE(error.empty()); 75 EXPECT_TRUE(error.empty());
76 76
77 // Two providers, no relevant restrictions. 77 // Two providers, no relevant restrictions.
78 policy_.RegisterProvider(&must_remain_enabled_); 78 policy_.RegisterProvider(&must_remain_enabled_);
79 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 79 EXPECT_TRUE(policy_.UserMayLoad(nullptr, &error));
80 EXPECT_TRUE(error.empty()); 80 EXPECT_TRUE(error.empty());
81 81
82 // Three providers, one with a relevant restriction. 82 // Three providers, one with a relevant restriction.
83 policy_.RegisterProvider(&no_load_); 83 policy_.RegisterProvider(&no_load_);
84 EXPECT_FALSE(policy_.UserMayLoad(NULL, &error)); 84 EXPECT_FALSE(policy_.UserMayLoad(nullptr, &error));
85 EXPECT_FALSE(error.empty()); 85 EXPECT_FALSE(error.empty());
86 86
87 // Remove the restriction. 87 // Remove the restriction.
88 policy_.UnregisterProvider(&no_load_); 88 policy_.UnregisterProvider(&no_load_);
89 error.clear(); 89 error.clear();
90 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 90 EXPECT_TRUE(policy_.UserMayLoad(nullptr, &error));
91 EXPECT_TRUE(error.empty()); 91 EXPECT_TRUE(error.empty());
92 } 92 }
93 TEST_F(ManagementPolicyTest, UserMayModifySettings) { 93 TEST_F(ManagementPolicyTest, UserMayModifySettings) {
94 // No providers registered. 94 // No providers registered.
95 base::string16 error; 95 base::string16 error;
96 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); 96 EXPECT_TRUE(policy_.UserMayModifySettings(nullptr, &error));
97 EXPECT_TRUE(error.empty()); 97 EXPECT_TRUE(error.empty());
98 98
99 // One provider, no relevant restriction. 99 // One provider, no relevant restriction.
100 policy_.RegisterProvider(&allow_all_); 100 policy_.RegisterProvider(&allow_all_);
101 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); 101 EXPECT_TRUE(policy_.UserMayModifySettings(nullptr, &error));
102 EXPECT_TRUE(error.empty()); 102 EXPECT_TRUE(error.empty());
103 103
104 // Two providers, no relevant restrictions. 104 // Two providers, no relevant restrictions.
105 policy_.RegisterProvider(&no_load_); 105 policy_.RegisterProvider(&no_load_);
106 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); 106 EXPECT_TRUE(policy_.UserMayModifySettings(nullptr, &error));
107 EXPECT_TRUE(error.empty()); 107 EXPECT_TRUE(error.empty());
108 108
109 // Three providers, one with a relevant restriction. 109 // Three providers, one with a relevant restriction.
110 policy_.RegisterProvider(&no_modify_status_); 110 policy_.RegisterProvider(&no_modify_status_);
111 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, &error)); 111 EXPECT_FALSE(policy_.UserMayModifySettings(nullptr, &error));
112 EXPECT_FALSE(error.empty()); 112 EXPECT_FALSE(error.empty());
113 113
114 // Remove the restriction. 114 // Remove the restriction.
115 policy_.UnregisterProvider(&no_modify_status_); 115 policy_.UnregisterProvider(&no_modify_status_);
116 error.clear(); 116 error.clear();
117 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); 117 EXPECT_TRUE(policy_.UserMayModifySettings(nullptr, &error));
118 EXPECT_TRUE(error.empty()); 118 EXPECT_TRUE(error.empty());
119 } 119 }
120 120
121 TEST_F(ManagementPolicyTest, MustRemainEnabled) { 121 TEST_F(ManagementPolicyTest, MustRemainEnabled) {
122 // No providers registered. 122 // No providers registered.
123 base::string16 error; 123 base::string16 error;
124 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error)); 124 EXPECT_FALSE(policy_.MustRemainEnabled(nullptr, &error));
125 EXPECT_TRUE(error.empty()); 125 EXPECT_TRUE(error.empty());
126 126
127 // One provider, no relevant restriction. 127 // One provider, no relevant restriction.
128 policy_.RegisterProvider(&allow_all_); 128 policy_.RegisterProvider(&allow_all_);
129 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error)); 129 EXPECT_FALSE(policy_.MustRemainEnabled(nullptr, &error));
130 EXPECT_TRUE(error.empty()); 130 EXPECT_TRUE(error.empty());
131 131
132 // Two providers, no relevant restrictions. 132 // Two providers, no relevant restrictions.
133 policy_.RegisterProvider(&no_modify_status_); 133 policy_.RegisterProvider(&no_modify_status_);
134 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error)); 134 EXPECT_FALSE(policy_.MustRemainEnabled(nullptr, &error));
135 EXPECT_TRUE(error.empty()); 135 EXPECT_TRUE(error.empty());
136 136
137 // Three providers, one with a relevant restriction. 137 // Three providers, one with a relevant restriction.
138 policy_.RegisterProvider(&must_remain_enabled_); 138 policy_.RegisterProvider(&must_remain_enabled_);
139 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error)); 139 EXPECT_TRUE(policy_.MustRemainEnabled(nullptr, &error));
140 EXPECT_FALSE(error.empty()); 140 EXPECT_FALSE(error.empty());
141 141
142 // Remove the restriction. 142 // Remove the restriction.
143 policy_.UnregisterProvider(&must_remain_enabled_); 143 policy_.UnregisterProvider(&must_remain_enabled_);
144 error.clear(); 144 error.clear();
145 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error)); 145 EXPECT_FALSE(policy_.MustRemainEnabled(nullptr, &error));
146 EXPECT_TRUE(error.empty()); 146 EXPECT_TRUE(error.empty());
147 } 147 }
148 148
149 TEST_F(ManagementPolicyTest, MustRemainDisabled) { 149 TEST_F(ManagementPolicyTest, MustRemainDisabled) {
150 // No providers registered. 150 // No providers registered.
151 base::string16 error; 151 base::string16 error;
152 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error)); 152 EXPECT_FALSE(policy_.MustRemainDisabled(nullptr, NULL, &error));
153 EXPECT_TRUE(error.empty()); 153 EXPECT_TRUE(error.empty());
154 154
155 // One provider, no relevant restriction. 155 // One provider, no relevant restriction.
156 policy_.RegisterProvider(&allow_all_); 156 policy_.RegisterProvider(&allow_all_);
157 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error)); 157 EXPECT_FALSE(policy_.MustRemainDisabled(nullptr, NULL, &error));
158 EXPECT_TRUE(error.empty()); 158 EXPECT_TRUE(error.empty());
159 159
160 // Two providers, no relevant restrictions. 160 // Two providers, no relevant restrictions.
161 policy_.RegisterProvider(&no_modify_status_); 161 policy_.RegisterProvider(&no_modify_status_);
162 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error)); 162 EXPECT_FALSE(policy_.MustRemainDisabled(nullptr, NULL, &error));
163 EXPECT_TRUE(error.empty()); 163 EXPECT_TRUE(error.empty());
164 164
165 // Three providers, one with a relevant restriction. 165 // Three providers, one with a relevant restriction.
166 Extension::DisableReason reason = Extension::DISABLE_NONE; 166 Extension::DisableReason reason = Extension::DISABLE_NONE;
167 policy_.RegisterProvider(&must_remain_disabled_); 167 policy_.RegisterProvider(&must_remain_disabled_);
168 EXPECT_TRUE(policy_.MustRemainDisabled(NULL, &reason, &error)); 168 EXPECT_TRUE(policy_.MustRemainDisabled(nullptr, &reason, &error));
169 EXPECT_FALSE(error.empty()); 169 EXPECT_FALSE(error.empty());
170 EXPECT_EQ(Extension::DISABLE_SIDELOAD_WIPEOUT, reason); 170 EXPECT_EQ(Extension::DISABLE_SIDELOAD_WIPEOUT, reason);
171 171
172 // Remove the restriction. 172 // Remove the restriction.
173 policy_.UnregisterProvider(&must_remain_disabled_); 173 policy_.UnregisterProvider(&must_remain_disabled_);
174 error.clear(); 174 error.clear();
175 EXPECT_FALSE(policy_.MustRemainDisabled(NULL, NULL, &error)); 175 EXPECT_FALSE(policy_.MustRemainDisabled(nullptr, NULL, &error));
176 EXPECT_TRUE(error.empty()); 176 EXPECT_TRUE(error.empty());
177 } 177 }
178 178
179 // Tests error handling in the ManagementPolicy. 179 // Tests error handling in the ManagementPolicy.
180 TEST_F(ManagementPolicyTest, ErrorHandling) { 180 TEST_F(ManagementPolicyTest, ErrorHandling) {
181 // The error parameter should be unchanged if no restriction was found. 181 // The error parameter should be unchanged if no restriction was found.
182 std::string original_error = "Ceci est en effet une erreur."; 182 std::string original_error = "Ceci est en effet une erreur.";
183 base::string16 original_error16 = base::UTF8ToUTF16(original_error); 183 base::string16 original_error16 = base::UTF8ToUTF16(original_error);
184 base::string16 error = original_error16; 184 base::string16 error = original_error16;
185 EXPECT_TRUE(policy_.UserMayLoad(NULL, &error)); 185 EXPECT_TRUE(policy_.UserMayLoad(nullptr, &error));
186 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); 186 EXPECT_EQ(original_error, base::UTF16ToUTF8(error));
187 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, &error)); 187 EXPECT_TRUE(policy_.UserMayModifySettings(nullptr, &error));
188 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); 188 EXPECT_EQ(original_error, base::UTF16ToUTF8(error));
189 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error)); 189 EXPECT_FALSE(policy_.MustRemainEnabled(nullptr, &error));
190 EXPECT_EQ(original_error, base::UTF16ToUTF8(error)); 190 EXPECT_EQ(original_error, base::UTF16ToUTF8(error));
191 191
192 // Ensure no crashes if no error message was requested. 192 // Ensure no crashes if no error message was requested.
193 EXPECT_TRUE(policy_.UserMayLoad(NULL, NULL)); 193 EXPECT_TRUE(policy_.UserMayLoad(nullptr, NULL));
194 EXPECT_TRUE(policy_.UserMayModifySettings(NULL, NULL)); 194 EXPECT_TRUE(policy_.UserMayModifySettings(nullptr, NULL));
195 EXPECT_FALSE(policy_.MustRemainEnabled(NULL, NULL)); 195 EXPECT_FALSE(policy_.MustRemainEnabled(nullptr, NULL));
196 policy_.RegisterProvider(&restrict_all_); 196 policy_.RegisterProvider(&restrict_all_);
197 EXPECT_FALSE(policy_.UserMayLoad(NULL, NULL)); 197 EXPECT_FALSE(policy_.UserMayLoad(nullptr, NULL));
198 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, NULL)); 198 EXPECT_FALSE(policy_.UserMayModifySettings(nullptr, NULL));
199 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, NULL)); 199 EXPECT_TRUE(policy_.MustRemainEnabled(nullptr, NULL));
200 200
201 // Make sure returned error is correct. 201 // Make sure returned error is correct.
202 error = original_error16; 202 error = original_error16;
203 EXPECT_FALSE(policy_.UserMayLoad(NULL, &error)); 203 EXPECT_FALSE(policy_.UserMayLoad(nullptr, &error));
204 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); 204 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error);
205 error = original_error16; 205 error = original_error16;
206 EXPECT_FALSE(policy_.UserMayModifySettings(NULL, &error)); 206 EXPECT_FALSE(policy_.UserMayModifySettings(nullptr, &error));
207 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); 207 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error);
208 error = original_error16; 208 error = original_error16;
209 EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error)); 209 EXPECT_TRUE(policy_.MustRemainEnabled(nullptr, &error));
210 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error); 210 EXPECT_EQ(base::UTF8ToUTF16(TestProvider::expected_error()), error);
211 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698