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

Side by Side Diff: chrome/common/extensions/extension_permission_set_unittest.cc

Issue 7432006: Add an experimental permissions API for extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang Created 9 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/extensions/extension_permission_set.h" 5 #include "chrome/common/extensions/extension_permission_set.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 hosted_perms.insert(ExtensionAPIPermission::kBackground); 145 hosted_perms.insert(ExtensionAPIPermission::kBackground);
146 hosted_perms.insert(ExtensionAPIPermission::kClipboardRead); 146 hosted_perms.insert(ExtensionAPIPermission::kClipboardRead);
147 hosted_perms.insert(ExtensionAPIPermission::kClipboardWrite); 147 hosted_perms.insert(ExtensionAPIPermission::kClipboardWrite);
148 hosted_perms.insert(ExtensionAPIPermission::kChromeAuthPrivate); 148 hosted_perms.insert(ExtensionAPIPermission::kChromeAuthPrivate);
149 hosted_perms.insert(ExtensionAPIPermission::kChromePrivate); 149 hosted_perms.insert(ExtensionAPIPermission::kChromePrivate);
150 hosted_perms.insert(ExtensionAPIPermission::kExperimental); 150 hosted_perms.insert(ExtensionAPIPermission::kExperimental);
151 hosted_perms.insert(ExtensionAPIPermission::kGeolocation); 151 hosted_perms.insert(ExtensionAPIPermission::kGeolocation);
152 hosted_perms.insert(ExtensionAPIPermission::kNotification); 152 hosted_perms.insert(ExtensionAPIPermission::kNotification);
153 hosted_perms.insert(ExtensionAPIPermission::kUnlimitedStorage); 153 hosted_perms.insert(ExtensionAPIPermission::kUnlimitedStorage);
154 hosted_perms.insert(ExtensionAPIPermission::kWebstorePrivate); 154 hosted_perms.insert(ExtensionAPIPermission::kWebstorePrivate);
155 hosted_perms.insert(ExtensionAPIPermission::kPermissions);
155 156
156 ExtensionAPIPermissionSet perms = info->GetAll(); 157 ExtensionAPIPermissionSet perms = info->GetAll();
157 size_t count = 0; 158 size_t count = 0;
158 for (ExtensionAPIPermissionSet::iterator i = perms.begin(); 159 for (ExtensionAPIPermissionSet::iterator i = perms.begin();
159 i != perms.end(); ++i) { 160 i != perms.end(); ++i) {
160 count += hosted_perms.count(*i); 161 count += hosted_perms.count(*i);
161 EXPECT_EQ(hosted_perms.count(*i) > 0, info->GetByID(*i)->is_hosted_app()); 162 EXPECT_EQ(hosted_perms.count(*i) > 0, info->GetByID(*i)->is_hosted_app());
162 } 163 }
163 164
164 EXPECT_EQ(10u, count); 165 EXPECT_EQ(hosted_perms.size(), count);
165 EXPECT_EQ(10u, info->get_hosted_app_permission_count()); 166 EXPECT_EQ(hosted_perms.size(), info->get_hosted_app_permission_count());
166 } 167 }
167 168
168 TEST(ExtensionAPIPermissionTest, ComponentOnlyPermissions) { 169 TEST(ExtensionAPIPermissionTest, ComponentOnlyPermissions) {
169 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); 170 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance();
170 ExtensionAPIPermissionSet private_perms; 171 ExtensionAPIPermissionSet private_perms;
171 private_perms.insert(ExtensionAPIPermission::kChromeAuthPrivate); 172 private_perms.insert(ExtensionAPIPermission::kChromeAuthPrivate);
172 private_perms.insert(ExtensionAPIPermission::kChromeosInfoPrivate); 173 private_perms.insert(ExtensionAPIPermission::kChromeosInfoPrivate);
173 private_perms.insert(ExtensionAPIPermission::kFileBrowserPrivate); 174 private_perms.insert(ExtensionAPIPermission::kFileBrowserPrivate);
174 private_perms.insert(ExtensionAPIPermission::kMediaPlayerPrivate); 175 private_perms.insert(ExtensionAPIPermission::kMediaPlayerPrivate);
175 private_perms.insert(ExtensionAPIPermission::kWebstorePrivate); 176 private_perms.insert(ExtensionAPIPermission::kWebstorePrivate);
176 177
177 ExtensionAPIPermissionSet perms = info->GetAll(); 178 ExtensionAPIPermissionSet perms = info->GetAll();
178 int count = 0; 179 int count = 0;
179 for (ExtensionAPIPermissionSet::iterator i = perms.begin(); 180 for (ExtensionAPIPermissionSet::iterator i = perms.begin();
180 i != perms.end(); ++i) { 181 i != perms.end(); ++i) {
181 count += private_perms.count(*i); 182 count += private_perms.count(*i);
182 EXPECT_EQ(private_perms.count(*i) > 0, 183 EXPECT_EQ(private_perms.count(*i) > 0,
183 info->GetByID(*i)->is_component_only()); 184 info->GetByID(*i)->is_component_only());
184 } 185 }
185 186
186 EXPECT_EQ(5, count); 187 EXPECT_EQ(5, count);
187 } 188 }
188 189
189 TEST(ExtensionPermissionSetTest, EffectiveHostPermissions) { 190 TEST(ExtensionPermissionSetTest, EffectiveHostPermissions) {
190 scoped_refptr<Extension> extension; 191 scoped_refptr<Extension> extension;
191 const ExtensionPermissionSet* permissions = NULL; 192 scoped_refptr<const ExtensionPermissionSet> permissions;
192 193
193 extension = LoadManifest("effective_host_permissions", "empty.json"); 194 extension = LoadManifest("effective_host_permissions", "empty.json");
194 permissions = extension->permission_set(); 195 permissions = extension->GetActivePermissions();
195 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); 196 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size());
196 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( 197 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(
197 GURL("http://www.google.com"))); 198 GURL("http://www.google.com")));
198 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 199 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
199 200
200 extension = LoadManifest("effective_host_permissions", "one_host.json"); 201 extension = LoadManifest("effective_host_permissions", "one_host.json");
201 permissions = extension->permission_set(); 202 permissions = extension->GetActivePermissions();
202 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( 203 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(
203 GURL("http://www.google.com"))); 204 GURL("http://www.google.com")));
204 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( 205 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(
205 GURL("https://www.google.com"))); 206 GURL("https://www.google.com")));
206 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 207 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
207 208
208 extension = LoadManifest("effective_host_permissions", 209 extension = LoadManifest("effective_host_permissions",
209 "one_host_wildcard.json"); 210 "one_host_wildcard.json");
210 permissions = extension->permission_set(); 211 permissions = extension->GetActivePermissions();
211 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); 212 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com")));
212 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( 213 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(
213 GURL("http://foo.google.com"))); 214 GURL("http://foo.google.com")));
214 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 215 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
215 216
216 extension = LoadManifest("effective_host_permissions", "two_hosts.json"); 217 extension = LoadManifest("effective_host_permissions", "two_hosts.json");
217 permissions = extension->permission_set(); 218 permissions = extension->GetActivePermissions();
218 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( 219 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(
219 GURL("http://www.google.com"))); 220 GURL("http://www.google.com")));
220 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( 221 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(
221 GURL("http://www.reddit.com"))); 222 GURL("http://www.reddit.com")));
222 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 223 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
223 224
224 extension = LoadManifest("effective_host_permissions", 225 extension = LoadManifest("effective_host_permissions",
225 "https_not_considered.json"); 226 "https_not_considered.json");
226 permissions = extension->permission_set(); 227 permissions = extension->GetActivePermissions();
227 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); 228 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com")));
228 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://google.com"))); 229 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://google.com")));
229 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 230 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
230 231
231 extension = LoadManifest("effective_host_permissions", 232 extension = LoadManifest("effective_host_permissions",
232 "two_content_scripts.json"); 233 "two_content_scripts.json");
233 permissions = extension->permission_set(); 234 permissions = extension->GetActivePermissions();
234 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com"))); 235 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://google.com")));
235 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( 236 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(
236 GURL("http://www.reddit.com"))); 237 GURL("http://www.reddit.com")));
237 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( 238 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(
238 GURL("http://news.ycombinator.com"))); 239 GURL("http://news.ycombinator.com")));
239 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 240 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
240 241
241 extension = LoadManifest("effective_host_permissions", "all_hosts.json"); 242 extension = LoadManifest("effective_host_permissions", "all_hosts.json");
242 permissions = extension->permission_set(); 243 permissions = extension->GetActivePermissions();
243 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); 244 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://test/")));
244 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); 245 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("https://test/")));
245 EXPECT_TRUE( 246 EXPECT_TRUE(
246 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); 247 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com")));
247 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); 248 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
248 249
249 extension = LoadManifest("effective_host_permissions", "all_hosts2.json"); 250 extension = LoadManifest("effective_host_permissions", "all_hosts2.json");
250 permissions = extension->permission_set(); 251 permissions = extension->GetActivePermissions();
251 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); 252 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("http://test/")));
252 EXPECT_TRUE( 253 EXPECT_TRUE(
253 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); 254 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com")));
254 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); 255 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
255 256
256 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); 257 extension = LoadManifest("effective_host_permissions", "all_hosts3.json");
257 permissions = extension->permission_set(); 258 permissions = extension->GetActivePermissions();
258 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); 259 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/")));
259 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); 260 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/")));
260 EXPECT_TRUE( 261 EXPECT_TRUE(
261 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); 262 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com")));
262 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); 263 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
263 } 264 }
264 265
265 TEST(ExtensionPermissionSetTest, ExplicitAccessToOrigin) { 266 TEST(ExtensionPermissionSetTest, ExplicitAccessToOrigin) {
266 ExtensionAPIPermissionSet apis; 267 ExtensionAPIPermissionSet apis;
267 URLPatternSet explicit_hosts; 268 URLPatternSet explicit_hosts;
268 URLPatternSet scriptable_hosts; 269 URLPatternSet scriptable_hosts;
269 270
270 AddPattern(&explicit_hosts, "http://*.google.com/*"); 271 AddPattern(&explicit_hosts, "http://*.google.com/*");
271 // The explicit host paths should get set to /*. 272 // The explicit host paths should get set to /*.
272 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*"); 273 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*");
273 274
274 ExtensionPermissionSet perm_set(apis, explicit_hosts, scriptable_hosts); 275 scoped_refptr<ExtensionPermissionSet> perm_set = new ExtensionPermissionSet(
275 ASSERT_TRUE(perm_set.HasExplicitAccessToOrigin( 276 apis, explicit_hosts, scriptable_hosts);
277 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
276 GURL("http://www.google.com/"))); 278 GURL("http://www.google.com/")));
277 ASSERT_TRUE(perm_set.HasExplicitAccessToOrigin( 279 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
278 GURL("http://test.google.com/"))); 280 GURL("http://test.google.com/")));
279 ASSERT_TRUE(perm_set.HasExplicitAccessToOrigin( 281 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
280 GURL("http://www.example.com"))); 282 GURL("http://www.example.com")));
281 ASSERT_TRUE(perm_set.HasEffectiveAccessToURL( 283 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL(
282 GURL("http://www.example.com"))); 284 GURL("http://www.example.com")));
283 ASSERT_FALSE(perm_set.HasExplicitAccessToOrigin( 285 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin(
284 GURL("http://test.example.com"))); 286 GURL("http://test.example.com")));
285 } 287 }
286 288
287 TEST(ExtensionPermissionSetTest, CreateUnion) { 289 TEST(ExtensionPermissionSetTest, CreateUnion) {
288 ExtensionAPIPermissionSet apis1; 290 ExtensionAPIPermissionSet apis1;
289 ExtensionAPIPermissionSet apis2; 291 ExtensionAPIPermissionSet apis2;
290 ExtensionAPIPermissionSet expected_apis; 292 ExtensionAPIPermissionSet expected_apis;
291 293
292 URLPatternSet explicit_hosts1; 294 URLPatternSet explicit_hosts1;
293 URLPatternSet explicit_hosts2; 295 URLPatternSet explicit_hosts2;
294 URLPatternSet expected_explicit_hosts; 296 URLPatternSet expected_explicit_hosts;
295 297
296 URLPatternSet scriptable_hosts1; 298 URLPatternSet scriptable_hosts1;
297 URLPatternSet scriptable_hosts2; 299 URLPatternSet scriptable_hosts2;
298 URLPatternSet expected_scriptable_hosts; 300 URLPatternSet expected_scriptable_hosts;
299 301
300 URLPatternSet effective_hosts; 302 URLPatternSet effective_hosts;
301 303
302 scoped_ptr<ExtensionPermissionSet> set1; 304 scoped_refptr<ExtensionPermissionSet> set1;
303 scoped_ptr<ExtensionPermissionSet> set2; 305 scoped_refptr<ExtensionPermissionSet> set2;
304 scoped_ptr<ExtensionPermissionSet> union_set; 306 scoped_refptr<ExtensionPermissionSet> union_set;
305 307
306 // Union with an empty set. 308 // Union with an empty set.
307 apis1.insert(ExtensionAPIPermission::kTab); 309 apis1.insert(ExtensionAPIPermission::kTab);
308 apis1.insert(ExtensionAPIPermission::kBackground); 310 apis1.insert(ExtensionAPIPermission::kBackground);
309 expected_apis.insert(ExtensionAPIPermission::kTab); 311 expected_apis.insert(ExtensionAPIPermission::kTab);
310 expected_apis.insert(ExtensionAPIPermission::kBackground); 312 expected_apis.insert(ExtensionAPIPermission::kBackground);
311 313
312 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 314 AddPattern(&explicit_hosts1, "http://*.google.com/*");
313 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); 315 AddPattern(&expected_explicit_hosts, "http://*.google.com/*");
314 AddPattern(&effective_hosts, "http://*.google.com/*"); 316 AddPattern(&effective_hosts, "http://*.google.com/*");
315 317
316 set1.reset(new ExtensionPermissionSet( 318 set1 = new ExtensionPermissionSet(apis1, explicit_hosts1, scriptable_hosts1);
317 apis1, explicit_hosts1, scriptable_hosts1)); 319 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
318 set2.reset(new ExtensionPermissionSet( 320 union_set = ExtensionPermissionSet::CreateUnion(set1.get(), set2.get());
319 apis2, explicit_hosts2, scriptable_hosts2)); 321 EXPECT_TRUE(set1->Contains(*set2));
320 union_set.reset(ExtensionPermissionSet::CreateUnion(set1.get(), set2.get())); 322 EXPECT_TRUE(set1->Contains(*union_set));
323 EXPECT_FALSE(set2->Contains(*set1));
324 EXPECT_FALSE(set2->Contains(*union_set));
325 EXPECT_TRUE(union_set->Contains(*set1));
326 EXPECT_TRUE(union_set->Contains(*set2));
321 327
322 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); 328 EXPECT_FALSE(union_set->HasEffectiveFullAccess());
323 EXPECT_EQ(expected_apis, union_set->apis()); 329 EXPECT_EQ(expected_apis, union_set->apis());
324 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); 330 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
325 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); 331 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
326 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts()); 332 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts());
327 333
328 // Now use a real second set. 334 // Now use a real second set.
329 apis2.insert(ExtensionAPIPermission::kTab); 335 apis2.insert(ExtensionAPIPermission::kTab);
330 apis2.insert(ExtensionAPIPermission::kProxy); 336 apis2.insert(ExtensionAPIPermission::kProxy);
331 apis2.insert(ExtensionAPIPermission::kClipboardWrite); 337 apis2.insert(ExtensionAPIPermission::kClipboardWrite);
332 apis2.insert(ExtensionAPIPermission::kPlugin); 338 apis2.insert(ExtensionAPIPermission::kPlugin);
333 expected_apis.insert(ExtensionAPIPermission::kTab); 339 expected_apis.insert(ExtensionAPIPermission::kTab);
334 expected_apis.insert(ExtensionAPIPermission::kProxy); 340 expected_apis.insert(ExtensionAPIPermission::kProxy);
335 expected_apis.insert(ExtensionAPIPermission::kClipboardWrite); 341 expected_apis.insert(ExtensionAPIPermission::kClipboardWrite);
336 expected_apis.insert(ExtensionAPIPermission::kPlugin); 342 expected_apis.insert(ExtensionAPIPermission::kPlugin);
337 343
338 AddPattern(&explicit_hosts2, "http://*.example.com/*"); 344 AddPattern(&explicit_hosts2, "http://*.example.com/*");
339 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 345 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
340 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); 346 AddPattern(&expected_explicit_hosts, "http://*.example.com/*");
341 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); 347 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*");
342 348
343 effective_hosts.ClearPatterns(); 349 effective_hosts.ClearPatterns();
344 AddPattern(&effective_hosts, "<all_urls>"); 350 AddPattern(&effective_hosts, "<all_urls>");
345 351
346 set2.reset(new ExtensionPermissionSet( 352 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
347 apis2, explicit_hosts2, scriptable_hosts2)); 353 union_set = ExtensionPermissionSet::CreateUnion(set1.get(), set2.get());
348 union_set.reset(ExtensionPermissionSet::CreateUnion(set1.get(), set2.get())); 354
355 EXPECT_FALSE(set1->Contains(*set2));
356 EXPECT_FALSE(set1->Contains(*union_set));
357 EXPECT_FALSE(set2->Contains(*set1));
358 EXPECT_FALSE(set2->Contains(*union_set));
359 EXPECT_TRUE(union_set->Contains(*set1));
360 EXPECT_TRUE(union_set->Contains(*set2));
361
349 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); 362 EXPECT_TRUE(union_set->HasEffectiveFullAccess());
350 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); 363 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts());
351 EXPECT_EQ(expected_apis, union_set->apis()); 364 EXPECT_EQ(expected_apis, union_set->apis());
352 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); 365 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
353 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); 366 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
354 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); 367 EXPECT_EQ(effective_hosts, union_set->effective_hosts());
355 } 368 }
356 369
370 TEST(ExtensionPermissionSetTest, CreateIntersection) {
371 ExtensionAPIPermissionSet apis1;
372 ExtensionAPIPermissionSet apis2;
373 ExtensionAPIPermissionSet expected_apis;
374
375 URLPatternSet explicit_hosts1;
376 URLPatternSet explicit_hosts2;
377 URLPatternSet expected_explicit_hosts;
378
379 URLPatternSet scriptable_hosts1;
380 URLPatternSet scriptable_hosts2;
381 URLPatternSet expected_scriptable_hosts;
382
383 URLPatternSet effective_hosts;
384
385 scoped_refptr<ExtensionPermissionSet> set1;
386 scoped_refptr<ExtensionPermissionSet> set2;
387 scoped_refptr<ExtensionPermissionSet> new_set;
388
389 // Intersection with an empty set.
390 apis1.insert(ExtensionAPIPermission::kTab);
391 apis1.insert(ExtensionAPIPermission::kBackground);
392
393 AddPattern(&explicit_hosts1, "http://*.google.com/*");
394 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*");
395
396 set1 = new ExtensionPermissionSet(apis1, explicit_hosts1, scriptable_hosts1);
397 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
398 new_set = ExtensionPermissionSet::CreateIntersection(set1.get(), set2.get());
399 EXPECT_TRUE(set1->Contains(*new_set));
400 EXPECT_TRUE(set2->Contains(*new_set));
401 EXPECT_TRUE(set1->Contains(*set2));
402 EXPECT_FALSE(set2->Contains(*set1));
403 EXPECT_FALSE(new_set->Contains(*set1));
404 EXPECT_TRUE(new_set->Contains(*set2));
405
406 EXPECT_TRUE(new_set->IsEmpty());
407 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
408 EXPECT_EQ(expected_apis, new_set->apis());
409 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
410 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
411 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts());
412
413 // Now use a real second set.
414 apis2.insert(ExtensionAPIPermission::kTab);
415 apis2.insert(ExtensionAPIPermission::kProxy);
416 apis2.insert(ExtensionAPIPermission::kClipboardWrite);
417 apis2.insert(ExtensionAPIPermission::kPlugin);
418 expected_apis.insert(ExtensionAPIPermission::kTab);
419
420 AddPattern(&explicit_hosts2, "http://*.example.com/*");
421 AddPattern(&explicit_hosts2, "http://*.google.com/*");
422 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
423 AddPattern(&expected_explicit_hosts, "http://*.google.com/*");
424
425 effective_hosts.ClearPatterns();
426 AddPattern(&effective_hosts, "http://*.google.com/*");
427
428 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
429 new_set = ExtensionPermissionSet::CreateIntersection(set1.get(), set2.get());
430
431 EXPECT_TRUE(set1->Contains(*new_set));
432 EXPECT_TRUE(set2->Contains(*new_set));
433 EXPECT_FALSE(set1->Contains(*set2));
434 EXPECT_FALSE(set2->Contains(*set1));
435 EXPECT_FALSE(new_set->Contains(*set1));
436 EXPECT_FALSE(new_set->Contains(*set2));
437
438 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
439 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts());
440 EXPECT_EQ(expected_apis, new_set->apis());
441 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
442 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
443 EXPECT_EQ(effective_hosts, new_set->effective_hosts());
444 }
445
446 TEST(ExtensionPermissionSetTest, CreateDifference) {
447 ExtensionAPIPermissionSet apis1;
448 ExtensionAPIPermissionSet apis2;
449 ExtensionAPIPermissionSet expected_apis;
450
451 URLPatternSet explicit_hosts1;
452 URLPatternSet explicit_hosts2;
453 URLPatternSet expected_explicit_hosts;
454
455 URLPatternSet scriptable_hosts1;
456 URLPatternSet scriptable_hosts2;
457 URLPatternSet expected_scriptable_hosts;
458
459 URLPatternSet effective_hosts;
460
461 scoped_refptr<ExtensionPermissionSet> set1;
462 scoped_refptr<ExtensionPermissionSet> set2;
463 scoped_refptr<ExtensionPermissionSet> new_set;
464
465 // Difference with an empty set.
466 apis1.insert(ExtensionAPIPermission::kTab);
467 apis1.insert(ExtensionAPIPermission::kBackground);
468
469 AddPattern(&explicit_hosts1, "http://*.google.com/*");
470 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*");
471
472 set1 = new ExtensionPermissionSet(apis1, explicit_hosts1, scriptable_hosts1);
473 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
474 new_set = ExtensionPermissionSet::CreateDifference(set1.get(), set2.get());
475 EXPECT_EQ(*set1, *new_set);
476
477 // Now use a real second set.
478 apis2.insert(ExtensionAPIPermission::kTab);
479 apis2.insert(ExtensionAPIPermission::kProxy);
480 apis2.insert(ExtensionAPIPermission::kClipboardWrite);
481 apis2.insert(ExtensionAPIPermission::kPlugin);
482 expected_apis.insert(ExtensionAPIPermission::kBackground);
483
484 AddPattern(&explicit_hosts2, "http://*.example.com/*");
485 AddPattern(&explicit_hosts2, "http://*.google.com/*");
486 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
487 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*");
488
489 effective_hosts.ClearPatterns();
490 AddPattern(&effective_hosts, "http://www.reddit.com/*");
491
492 set2 = new ExtensionPermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
493 new_set = ExtensionPermissionSet::CreateDifference(set1.get(), set2.get());
494
495 EXPECT_TRUE(set1->Contains(*new_set));
496 EXPECT_FALSE(set2->Contains(*new_set));
497
498 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
499 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts());
500 EXPECT_EQ(expected_apis, new_set->apis());
501 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
502 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
503 EXPECT_EQ(effective_hosts, new_set->effective_hosts());
504
505 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set
506 set1 = ExtensionPermissionSet::CreateIntersection(new_set.get(), set2.get());
507 EXPECT_TRUE(set1->IsEmpty());
508 }
509
357 TEST(ExtensionPermissionSetTest, HasLessPrivilegesThan) { 510 TEST(ExtensionPermissionSetTest, HasLessPrivilegesThan) {
358 const struct { 511 const struct {
359 const char* base_name; 512 const char* base_name;
360 // Increase these sizes if you have more than 10. 513 // Increase these sizes if you have more than 10.
361 const char* granted_apis[10]; 514 const char* granted_apis[10];
362 const char* granted_hosts[10]; 515 const char* granted_hosts[10];
363 bool full_access; 516 bool full_access;
364 bool expect_increase; 517 bool expect_increase;
365 } kTests[] = { 518 } kTests[] = {
366 { "allhosts1", {NULL}, {"http://*/", NULL}, false, 519 { "allhosts1", {NULL}, {"http://*/", NULL}, false,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } 581 }
429 582
430 URLPatternSet granted_hosts; 583 URLPatternSet granted_hosts;
431 for (size_t j = 0; kTests[i].granted_hosts[j] != NULL; ++j) 584 for (size_t j = 0; kTests[i].granted_hosts[j] != NULL; ++j)
432 AddPattern(&granted_hosts, kTests[i].granted_hosts[j]); 585 AddPattern(&granted_hosts, kTests[i].granted_hosts[j]);
433 586
434 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json"; 587 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json";
435 if (!new_extension.get()) 588 if (!new_extension.get())
436 continue; 589 continue;
437 590
438 const ExtensionPermissionSet* old_p = old_extension->permission_set(); 591 scoped_refptr<const ExtensionPermissionSet> old_p(
439 const ExtensionPermissionSet* new_p = new_extension->permission_set(); 592 old_extension->GetActivePermissions());
593 scoped_refptr<const ExtensionPermissionSet> new_p(
594 new_extension->GetActivePermissions());
440 595
441 EXPECT_EQ(kTests[i].expect_increase, old_p->HasLessPrivilegesThan(new_p)) 596 EXPECT_EQ(kTests[i].expect_increase,
442 << kTests[i].base_name; 597 old_p->HasLessPrivilegesThan(new_p)) << kTests[i].base_name;
443 } 598 }
444 } 599 }
445 600
446 TEST(ExtensionPermissionSetTest, PermissionMessages) { 601 TEST(ExtensionPermissionSetTest, PermissionMessages) {
447 // Ensure that all permissions that needs to show install UI actually have 602 // Ensure that all permissions that needs to show install UI actually have
448 // strings associated with them. 603 // strings associated with them.
449 ExtensionAPIPermissionSet skip; 604 ExtensionAPIPermissionSet skip;
450 605
451 skip.insert(ExtensionAPIPermission::kDefault); 606 skip.insert(ExtensionAPIPermission::kDefault);
452 607
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 skip.insert(ExtensionAPIPermission::kFileBrowserPrivate); 639 skip.insert(ExtensionAPIPermission::kFileBrowserPrivate);
485 skip.insert(ExtensionAPIPermission::kMediaPlayerPrivate); 640 skip.insert(ExtensionAPIPermission::kMediaPlayerPrivate);
486 skip.insert(ExtensionAPIPermission::kChromeAuthPrivate); 641 skip.insert(ExtensionAPIPermission::kChromeAuthPrivate);
487 skip.insert(ExtensionAPIPermission::kChromePrivate); 642 skip.insert(ExtensionAPIPermission::kChromePrivate);
488 skip.insert(ExtensionAPIPermission::kChromeosInfoPrivate); 643 skip.insert(ExtensionAPIPermission::kChromeosInfoPrivate);
489 skip.insert(ExtensionAPIPermission::kWebSocketProxyPrivate); 644 skip.insert(ExtensionAPIPermission::kWebSocketProxyPrivate);
490 skip.insert(ExtensionAPIPermission::kInputMethodPrivate); 645 skip.insert(ExtensionAPIPermission::kInputMethodPrivate);
491 646
492 // Warned as part of host permissions. 647 // Warned as part of host permissions.
493 skip.insert(ExtensionAPIPermission::kDevtools); 648 skip.insert(ExtensionAPIPermission::kDevtools);
649
650 // This will warn users later, when they request new permissions.
651 skip.insert(ExtensionAPIPermission::kPermissions);
652
494 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); 653 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance();
495 ExtensionAPIPermissionSet permissions = info->GetAll(); 654 ExtensionAPIPermissionSet permissions = info->GetAll();
496 for (ExtensionAPIPermissionSet::const_iterator i = permissions.begin(); 655 for (ExtensionAPIPermissionSet::const_iterator i = permissions.begin();
497 i != permissions.end(); ++i) { 656 i != permissions.end(); ++i) {
498 ExtensionAPIPermission* permission = info->GetByID(*i); 657 ExtensionAPIPermission* permission = info->GetByID(*i);
499 EXPECT_TRUE(permission); 658 EXPECT_TRUE(permission);
500 if (skip.count(*i)) { 659 if (skip.count(*i)) {
501 EXPECT_EQ(ExtensionPermissionMessage::kNone, permission->message_id()) 660 EXPECT_EQ(ExtensionPermissionMessage::kNone, permission->message_id())
502 << "unexpected message_id for " << permission->name(); 661 << "unexpected message_id for " << permission->name();
503 } else { 662 } else {
(...skipping 27 matching lines...) Expand all
531 { "tabs.onUpdated", false }, 690 { "tabs.onUpdated", false },
532 // Make sure we find the module name after stripping '.' and '/'. 691 // Make sure we find the module name after stripping '.' and '/'.
533 { "browserAction/abcd/onClick", true }, 692 { "browserAction/abcd/onClick", true },
534 { "browserAction.abcd.onClick", true }, 693 { "browserAction.abcd.onClick", true },
535 // Test Tabs functions. 694 // Test Tabs functions.
536 { "tabs.create", true}, 695 { "tabs.create", true},
537 { "tabs.update", true}, 696 { "tabs.update", true},
538 { "tabs.getSelected", false}, 697 { "tabs.getSelected", false},
539 }; 698 };
540 699
541 ExtensionPermissionSet permissions; 700 scoped_refptr<ExtensionPermissionSet> empty = new ExtensionPermissionSet();
542 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 701 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
543 EXPECT_EQ(kTests[i].expect_success, 702 EXPECT_EQ(kTests[i].expect_success,
544 permissions.HasAccessToFunction(kTests[i].permission_name)); 703 empty->HasAccessToFunction(kTests[i].permission_name));
545 } 704 }
546 } 705 }
547 706
548 TEST(ExtensionPermissionSetTest, GetWarningMessages_ManyHosts) { 707 TEST(ExtensionPermissionSetTest, GetWarningMessages_ManyHosts) {
549 scoped_refptr<Extension> extension; 708 scoped_refptr<Extension> extension;
550 709
551 extension = LoadManifest("permissions", "many-hosts.json"); 710 extension = LoadManifest("permissions", "many-hosts.json");
552 std::vector<string16> warnings = 711 std::vector<string16> warnings =
553 extension->permission_set()->GetWarningMessages(); 712 extension->GetActivePermissions()->GetWarningMessages();
554 ASSERT_EQ(1u, warnings.size()); 713 ASSERT_EQ(1u, warnings.size());
555 EXPECT_EQ("Your data on encrypted.google.com and www.google.com", 714 EXPECT_EQ("Your data on encrypted.google.com and www.google.com",
556 UTF16ToUTF8(warnings[0])); 715 UTF16ToUTF8(warnings[0]));
557 } 716 }
558 717
559 TEST(ExtensionPermissionSetTest, GetWarningMessages_Plugins) { 718 TEST(ExtensionPermissionSetTest, GetWarningMessages_Plugins) {
560 scoped_refptr<Extension> extension; 719 scoped_refptr<Extension> extension;
561 scoped_ptr<ExtensionPermissionSet> permissions; 720 scoped_refptr<ExtensionPermissionSet> permissions;
562 721
563 extension = LoadManifest("permissions", "plugins.json"); 722 extension = LoadManifest("permissions", "plugins.json");
564 std::vector<string16> warnings = 723 std::vector<string16> warnings =
565 extension->permission_set()->GetWarningMessages(); 724 extension->GetActivePermissions()->GetWarningMessages();
566 // We don't parse the plugins key on Chrome OS, so it should not ask for any 725 // We don't parse the plugins key on Chrome OS, so it should not ask for any
567 // permissions. 726 // permissions.
568 #if defined(OS_CHROMEOS) 727 #if defined(OS_CHROMEOS)
569 ASSERT_EQ(0u, warnings.size()); 728 ASSERT_EQ(0u, warnings.size());
570 #else 729 #else
571 ASSERT_EQ(1u, warnings.size()); 730 ASSERT_EQ(1u, warnings.size());
572 EXPECT_EQ("All data on your computer and the websites you visit", 731 EXPECT_EQ("All data on your computer and the websites you visit",
573 UTF16ToUTF8(warnings[0])); 732 UTF16ToUTF8(warnings[0]));
574 #endif 733 #endif
575 } 734 }
576 735
577 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) { 736 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay) {
578 scoped_ptr<ExtensionPermissionSet> perm_set; 737 scoped_refptr<ExtensionPermissionSet> perm_set;
579 ExtensionAPIPermissionSet empty_perms; 738 ExtensionAPIPermissionSet empty_perms;
580 std::set<std::string> expected; 739 std::set<std::string> expected;
581 expected.insert("www.foo.com"); 740 expected.insert("www.foo.com");
582 expected.insert("www.bar.com"); 741 expected.insert("www.bar.com");
583 expected.insert("www.baz.com"); 742 expected.insert("www.baz.com");
584 URLPatternSet explicit_hosts; 743 URLPatternSet explicit_hosts;
585 URLPatternSet scriptable_hosts; 744 URLPatternSet scriptable_hosts;
586 745
587 { 746 {
588 SCOPED_TRACE("no dupes"); 747 SCOPED_TRACE("no dupes");
589 748
590 // Simple list with no dupes. 749 // Simple list with no dupes.
591 explicit_hosts.AddPattern( 750 explicit_hosts.AddPattern(
592 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 751 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
593 explicit_hosts.AddPattern( 752 explicit_hosts.AddPattern(
594 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path")); 753 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path"));
595 explicit_hosts.AddPattern( 754 explicit_hosts.AddPattern(
596 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); 755 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
597 perm_set.reset(new ExtensionPermissionSet( 756 perm_set = new ExtensionPermissionSet(
598 empty_perms, explicit_hosts, scriptable_hosts)); 757 empty_perms, explicit_hosts, scriptable_hosts);
599 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 758 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
600 } 759 }
601 760
602 { 761 {
603 SCOPED_TRACE("two dupes"); 762 SCOPED_TRACE("two dupes");
604 763
605 // Add some dupes. 764 // Add some dupes.
606 explicit_hosts.AddPattern( 765 explicit_hosts.AddPattern(
607 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 766 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
608 explicit_hosts.AddPattern( 767 explicit_hosts.AddPattern(
609 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path")); 768 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
610 perm_set.reset(new ExtensionPermissionSet( 769 perm_set = new ExtensionPermissionSet(
611 empty_perms, explicit_hosts, scriptable_hosts)); 770 empty_perms, explicit_hosts, scriptable_hosts);
612 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 771 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
613 } 772 }
614 773
615 { 774 {
616 SCOPED_TRACE("schemes differ"); 775 SCOPED_TRACE("schemes differ");
617 776
618 // Add a pattern that differs only by scheme. This should be filtered out. 777 // Add a pattern that differs only by scheme. This should be filtered out.
619 explicit_hosts.AddPattern( 778 explicit_hosts.AddPattern(
620 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path")); 779 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path"));
621 perm_set.reset(new ExtensionPermissionSet( 780 perm_set = new ExtensionPermissionSet(
622 empty_perms, explicit_hosts, scriptable_hosts)); 781 empty_perms, explicit_hosts, scriptable_hosts);
623 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 782 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
624 } 783 }
625 784
626 { 785 {
627 SCOPED_TRACE("paths differ"); 786 SCOPED_TRACE("paths differ");
628 787
629 // Add some dupes by path. 788 // Add some dupes by path.
630 explicit_hosts.AddPattern( 789 explicit_hosts.AddPattern(
631 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath")); 790 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath"));
632 perm_set.reset(new ExtensionPermissionSet( 791 perm_set = new ExtensionPermissionSet(
633 empty_perms, explicit_hosts, scriptable_hosts)); 792 empty_perms, explicit_hosts, scriptable_hosts);
634 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 793 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
635 } 794 }
636 795
637 { 796 {
638 SCOPED_TRACE("subdomains differ"); 797 SCOPED_TRACE("subdomains differ");
639 798
640 // We don't do anything special for subdomains. 799 // We don't do anything special for subdomains.
641 explicit_hosts.AddPattern( 800 explicit_hosts.AddPattern(
642 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path")); 801 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path"));
643 explicit_hosts.AddPattern( 802 explicit_hosts.AddPattern(
644 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path")); 803 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path"));
645 804
646 expected.insert("monkey.www.bar.com"); 805 expected.insert("monkey.www.bar.com");
647 expected.insert("bar.com"); 806 expected.insert("bar.com");
648 807
649 perm_set.reset(new ExtensionPermissionSet( 808 perm_set = new ExtensionPermissionSet(
650 empty_perms, explicit_hosts, scriptable_hosts)); 809 empty_perms, explicit_hosts, scriptable_hosts);
651 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 810 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
652 } 811 }
653 812
654 { 813 {
655 SCOPED_TRACE("RCDs differ"); 814 SCOPED_TRACE("RCDs differ");
656 815
657 // Now test for RCD uniquing. 816 // Now test for RCD uniquing.
658 explicit_hosts.AddPattern( 817 explicit_hosts.AddPattern(
659 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 818 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
660 explicit_hosts.AddPattern( 819 explicit_hosts.AddPattern(
661 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 820 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
662 explicit_hosts.AddPattern( 821 explicit_hosts.AddPattern(
663 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path")); 822 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path"));
664 explicit_hosts.AddPattern( 823 explicit_hosts.AddPattern(
665 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path")); 824 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path"));
666 explicit_hosts.AddPattern( 825 explicit_hosts.AddPattern(
667 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); 826 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
668 explicit_hosts.AddPattern( 827 explicit_hosts.AddPattern(
669 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path")); 828 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path"));
670 829
671 // This is an unknown RCD, which shouldn't be uniqued out. 830 // This is an unknown RCD, which shouldn't be uniqued out.
672 explicit_hosts.AddPattern( 831 explicit_hosts.AddPattern(
673 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); 832 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path"));
674 // But it should only occur once. 833 // But it should only occur once.
675 explicit_hosts.AddPattern( 834 explicit_hosts.AddPattern(
676 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path")); 835 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path"));
677 836
678 expected.insert("www.foo.xyzzy"); 837 expected.insert("www.foo.xyzzy");
679 838
680 perm_set.reset(new ExtensionPermissionSet( 839 perm_set = new ExtensionPermissionSet(
681 empty_perms, explicit_hosts, scriptable_hosts)); 840 empty_perms, explicit_hosts, scriptable_hosts);
682 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 841 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
683 } 842 }
684 843
685 { 844 {
686 SCOPED_TRACE("wildcards"); 845 SCOPED_TRACE("wildcards");
687 846
688 explicit_hosts.AddPattern( 847 explicit_hosts.AddPattern(
689 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); 848 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*"));
690 849
691 expected.insert("*.google.com"); 850 expected.insert("*.google.com");
692 851
693 perm_set.reset(new ExtensionPermissionSet( 852 perm_set = new ExtensionPermissionSet(
694 empty_perms, explicit_hosts, scriptable_hosts)); 853 empty_perms, explicit_hosts, scriptable_hosts);
695 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 854 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
696 } 855 }
697 856
698 { 857 {
699 SCOPED_TRACE("scriptable hosts"); 858 SCOPED_TRACE("scriptable hosts");
700 explicit_hosts.ClearPatterns(); 859 explicit_hosts.ClearPatterns();
701 scriptable_hosts.ClearPatterns(); 860 scriptable_hosts.ClearPatterns();
702 expected.clear(); 861 expected.clear();
703 862
704 explicit_hosts.AddPattern( 863 explicit_hosts.AddPattern(
705 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); 864 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*"));
706 scriptable_hosts.AddPattern( 865 scriptable_hosts.AddPattern(
707 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*")); 866 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*"));
708 867
709 expected.insert("*.google.com"); 868 expected.insert("*.google.com");
710 expected.insert("*.example.com"); 869 expected.insert("*.example.com");
711 870
712 perm_set.reset(new ExtensionPermissionSet( 871 perm_set = new ExtensionPermissionSet(
713 empty_perms, explicit_hosts, scriptable_hosts)); 872 empty_perms, explicit_hosts, scriptable_hosts);
714 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 873 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
715 } 874 }
716 } 875 }
717 876
718 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_ComIsBestRcd) { 877 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_ComIsBestRcd) {
719 scoped_ptr<ExtensionPermissionSet> perm_set; 878 scoped_refptr<ExtensionPermissionSet> perm_set;
720 ExtensionAPIPermissionSet empty_perms; 879 ExtensionAPIPermissionSet empty_perms;
721 URLPatternSet explicit_hosts; 880 URLPatternSet explicit_hosts;
722 URLPatternSet scriptable_hosts; 881 URLPatternSet scriptable_hosts;
723 explicit_hosts.AddPattern( 882 explicit_hosts.AddPattern(
724 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 883 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
725 explicit_hosts.AddPattern( 884 explicit_hosts.AddPattern(
726 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 885 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
727 explicit_hosts.AddPattern( 886 explicit_hosts.AddPattern(
728 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 887 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
729 explicit_hosts.AddPattern( 888 explicit_hosts.AddPattern(
730 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); 889 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
731 explicit_hosts.AddPattern( 890 explicit_hosts.AddPattern(
732 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 891 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
733 explicit_hosts.AddPattern( 892 explicit_hosts.AddPattern(
734 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 893 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
735 894
736 std::set<std::string> expected; 895 std::set<std::string> expected;
737 expected.insert("www.foo.com"); 896 expected.insert("www.foo.com");
738 perm_set.reset(new ExtensionPermissionSet( 897 perm_set = new ExtensionPermissionSet(
739 empty_perms, explicit_hosts, scriptable_hosts)); 898 empty_perms, explicit_hosts, scriptable_hosts);
740 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 899 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
741 } 900 }
742 901
743 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) { 902 TEST(ExtensionPermissionSetTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) {
744 scoped_ptr<ExtensionPermissionSet> perm_set; 903 scoped_refptr<ExtensionPermissionSet> perm_set;
745 ExtensionAPIPermissionSet empty_perms; 904 ExtensionAPIPermissionSet empty_perms;
746 URLPatternSet explicit_hosts; 905 URLPatternSet explicit_hosts;
747 URLPatternSet scriptable_hosts; 906 URLPatternSet scriptable_hosts;
748 explicit_hosts.AddPattern( 907 explicit_hosts.AddPattern(
749 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 908 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
750 explicit_hosts.AddPattern( 909 explicit_hosts.AddPattern(
751 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 910 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
752 explicit_hosts.AddPattern( 911 explicit_hosts.AddPattern(
753 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 912 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
754 explicit_hosts.AddPattern( 913 explicit_hosts.AddPattern(
755 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); 914 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
756 explicit_hosts.AddPattern( 915 explicit_hosts.AddPattern(
757 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 916 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
758 // No http://www.foo.com/path 917 // No http://www.foo.com/path
759 918
760 std::set<std::string> expected; 919 std::set<std::string> expected;
761 expected.insert("www.foo.net"); 920 expected.insert("www.foo.net");
762 perm_set.reset(new ExtensionPermissionSet( 921 perm_set = new ExtensionPermissionSet(
763 empty_perms, explicit_hosts, scriptable_hosts)); 922 empty_perms, explicit_hosts, scriptable_hosts);
764 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 923 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
765 } 924 }
766 925
767 TEST(ExtensionPermissionSetTest, 926 TEST(ExtensionPermissionSetTest,
768 GetDistinctHostsForDisplay_OrgIs3rdBestRcd) { 927 GetDistinctHostsForDisplay_OrgIs3rdBestRcd) {
769 scoped_ptr<ExtensionPermissionSet> perm_set; 928 scoped_refptr<ExtensionPermissionSet> perm_set;
770 ExtensionAPIPermissionSet empty_perms; 929 ExtensionAPIPermissionSet empty_perms;
771 URLPatternSet explicit_hosts; 930 URLPatternSet explicit_hosts;
772 URLPatternSet scriptable_hosts; 931 URLPatternSet scriptable_hosts;
773 explicit_hosts.AddPattern( 932 explicit_hosts.AddPattern(
774 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 933 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
775 explicit_hosts.AddPattern( 934 explicit_hosts.AddPattern(
776 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 935 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
777 explicit_hosts.AddPattern( 936 explicit_hosts.AddPattern(
778 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 937 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
779 // No http://www.foo.net/path 938 // No http://www.foo.net/path
780 explicit_hosts.AddPattern( 939 explicit_hosts.AddPattern(
781 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 940 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
782 // No http://www.foo.com/path 941 // No http://www.foo.com/path
783 942
784 std::set<std::string> expected; 943 std::set<std::string> expected;
785 expected.insert("www.foo.org"); 944 expected.insert("www.foo.org");
786 perm_set.reset(new ExtensionPermissionSet( 945 perm_set = new ExtensionPermissionSet(
787 empty_perms, explicit_hosts, scriptable_hosts)); 946 empty_perms, explicit_hosts, scriptable_hosts);
788 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 947 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
789 } 948 }
790 949
791 TEST(ExtensionPermissionSetTest, 950 TEST(ExtensionPermissionSetTest,
792 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) { 951 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) {
793 scoped_ptr<ExtensionPermissionSet> perm_set; 952 scoped_refptr<ExtensionPermissionSet> perm_set;
794 ExtensionAPIPermissionSet empty_perms; 953 ExtensionAPIPermissionSet empty_perms;
795 URLPatternSet explicit_hosts; 954 URLPatternSet explicit_hosts;
796 URLPatternSet scriptable_hosts; 955 URLPatternSet scriptable_hosts;
797 explicit_hosts.AddPattern( 956 explicit_hosts.AddPattern(
798 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 957 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
799 // No http://www.foo.org/path 958 // No http://www.foo.org/path
800 explicit_hosts.AddPattern( 959 explicit_hosts.AddPattern(
801 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 960 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
802 // No http://www.foo.net/path 961 // No http://www.foo.net/path
803 explicit_hosts.AddPattern( 962 explicit_hosts.AddPattern(
804 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 963 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
805 // No http://www.foo.com/path 964 // No http://www.foo.com/path
806 965
807 std::set<std::string> expected; 966 std::set<std::string> expected;
808 expected.insert("www.foo.ca"); 967 expected.insert("www.foo.ca");
809 perm_set.reset(new ExtensionPermissionSet( 968 perm_set = new ExtensionPermissionSet(
810 empty_perms, explicit_hosts, scriptable_hosts)); 969 empty_perms, explicit_hosts, scriptable_hosts);
811 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 970 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
812 } 971 }
813 972
814 TEST(ExtensionPermissionSetTest, HasLessHostPrivilegesThan) { 973 TEST(ExtensionPermissionSetTest, HasLessHostPrivilegesThan) {
815 URLPatternSet elist1; 974 URLPatternSet elist1;
816 URLPatternSet elist2; 975 URLPatternSet elist2;
817 URLPatternSet slist1; 976 URLPatternSet slist1;
818 URLPatternSet slist2; 977 URLPatternSet slist2;
819 scoped_ptr<ExtensionPermissionSet> set1; 978 scoped_refptr<ExtensionPermissionSet> set1;
820 scoped_ptr<ExtensionPermissionSet> set2; 979 scoped_refptr<ExtensionPermissionSet> set2;
821 ExtensionAPIPermissionSet empty_perms; 980 ExtensionAPIPermissionSet empty_perms;
822 elist1.AddPattern( 981 elist1.AddPattern(
823 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); 982 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path"));
824 elist1.AddPattern( 983 elist1.AddPattern(
825 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); 984 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
826 985
827 // Test that the host order does not matter. 986 // Test that the host order does not matter.
828 elist2.AddPattern( 987 elist2.AddPattern(
829 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); 988 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
830 elist2.AddPattern( 989 elist2.AddPattern(
831 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); 990 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path"));
832 991
833 set1.reset(new ExtensionPermissionSet(empty_perms, elist1, slist1)); 992 set1 = new ExtensionPermissionSet(empty_perms, elist1, slist1);
834 set2.reset(new ExtensionPermissionSet(empty_perms, elist2, slist2)); 993 set2 = new ExtensionPermissionSet(empty_perms, elist2, slist2);
835 994
836 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get())); 995 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get()));
837 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get())); 996 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get()));
838 997
839 // Test that paths are ignored. 998 // Test that paths are ignored.
840 elist2.ClearPatterns(); 999 elist2.ClearPatterns();
841 elist2.AddPattern( 1000 elist2.AddPattern(
842 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*")); 1001 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*"));
843 set2.reset(new ExtensionPermissionSet(empty_perms, elist2, slist2)); 1002 set2 = new ExtensionPermissionSet(empty_perms, elist2, slist2);
844 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get())); 1003 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get()));
845 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get())); 1004 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get()));
846 1005
847 // Test that RCDs are ignored. 1006 // Test that RCDs are ignored.
848 elist2.ClearPatterns(); 1007 elist2.ClearPatterns();
849 elist2.AddPattern( 1008 elist2.AddPattern(
850 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*")); 1009 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*"));
851 set2.reset(new ExtensionPermissionSet(empty_perms, elist2, slist2)); 1010 set2 = new ExtensionPermissionSet(empty_perms, elist2, slist2);
852 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get())); 1011 EXPECT_FALSE(set1->HasLessHostPrivilegesThan(set2.get()));
853 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get())); 1012 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get()));
854 1013
855 // Test that subdomain wildcards are handled properly. 1014 // Test that subdomain wildcards are handled properly.
856 elist2.ClearPatterns(); 1015 elist2.ClearPatterns();
857 elist2.AddPattern( 1016 elist2.AddPattern(
858 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*")); 1017 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*"));
859 set2.reset(new ExtensionPermissionSet(empty_perms, elist2, slist2)); 1018 set2 = new ExtensionPermissionSet(empty_perms, elist2, slist2);
860 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get())); 1019 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get()));
861 //TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337 1020 //TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337
862 //EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get())); 1021 //EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get()));
863 1022
864 // Test that different domains count as different hosts. 1023 // Test that different domains count as different hosts.
865 elist2.ClearPatterns(); 1024 elist2.ClearPatterns();
866 elist2.AddPattern( 1025 elist2.AddPattern(
867 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); 1026 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
868 elist2.AddPattern( 1027 elist2.AddPattern(
869 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path")); 1028 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path"));
870 set2.reset(new ExtensionPermissionSet(empty_perms, elist2, slist2)); 1029 set2 = new ExtensionPermissionSet(empty_perms, elist2, slist2);
871 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get())); 1030 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get()));
872 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get())); 1031 EXPECT_FALSE(set2->HasLessHostPrivilegesThan(set1.get()));
873 1032
874 // Test that different subdomains count as different hosts. 1033 // Test that different subdomains count as different hosts.
875 elist2.ClearPatterns(); 1034 elist2.ClearPatterns();
876 elist2.AddPattern( 1035 elist2.AddPattern(
877 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); 1036 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*"));
878 set2.reset(new ExtensionPermissionSet(empty_perms, elist2, slist2)); 1037 set2 = new ExtensionPermissionSet(empty_perms, elist2, slist2);
879 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get())); 1038 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get()));
880 EXPECT_TRUE(set2->HasLessHostPrivilegesThan(set1.get())); 1039 EXPECT_TRUE(set2->HasLessHostPrivilegesThan(set1.get()));
881 } 1040 }
882 1041
883 TEST(ExtensionPermissionSetTest, GetAPIsAsStrings) { 1042 TEST(ExtensionPermissionSetTest, GetAPIsAsStrings) {
884 ExtensionAPIPermissionSet apis; 1043 ExtensionAPIPermissionSet apis;
885 URLPatternSet empty_set; 1044 URLPatternSet empty_set;
886 1045
887 apis.insert(ExtensionAPIPermission::kProxy); 1046 apis.insert(ExtensionAPIPermission::kProxy);
888 apis.insert(ExtensionAPIPermission::kBackground); 1047 apis.insert(ExtensionAPIPermission::kBackground);
889 apis.insert(ExtensionAPIPermission::kNotification); 1048 apis.insert(ExtensionAPIPermission::kNotification);
890 apis.insert(ExtensionAPIPermission::kTab); 1049 apis.insert(ExtensionAPIPermission::kTab);
891 1050
892 ExtensionPermissionSet perm_set(apis, empty_set, empty_set); 1051 scoped_refptr<ExtensionPermissionSet> perm_set = new ExtensionPermissionSet(
893 std::set<std::string> api_names = perm_set.GetAPIsAsStrings(); 1052 apis, empty_set, empty_set);
1053 std::set<std::string> api_names = perm_set->GetAPIsAsStrings();
894 1054
895 // The result is correct if it has the same number of elements 1055 // The result is correct if it has the same number of elements
896 // and we can convert it back to the id set. 1056 // and we can convert it back to the id set.
897 EXPECT_EQ(4u, api_names.size()); 1057 EXPECT_EQ(4u, api_names.size());
898 EXPECT_EQ(apis, 1058 EXPECT_EQ(apis,
899 ExtensionPermissionsInfo::GetInstance()->GetAllByName(api_names)); 1059 ExtensionPermissionsInfo::GetInstance()->GetAllByName(api_names));
900 } 1060 }
901 1061
902 TEST(ExtensionPermissionSetTest, IsEmpty) { 1062 TEST(ExtensionPermissionSetTest, IsEmpty) {
903 ExtensionAPIPermissionSet empty_apis; 1063 ExtensionAPIPermissionSet empty_apis;
904 URLPatternSet empty_extent; 1064 URLPatternSet empty_extent;
905 1065
906 ExtensionPermissionSet perm_set; 1066 scoped_refptr<ExtensionPermissionSet> empty = new ExtensionPermissionSet();
907 EXPECT_TRUE(perm_set.IsEmpty()); 1067 EXPECT_TRUE(empty->IsEmpty());
1068 scoped_refptr<ExtensionPermissionSet> perm_set;
908 1069
909 perm_set = ExtensionPermissionSet(empty_apis, empty_extent, empty_extent); 1070 perm_set = new ExtensionPermissionSet(empty_apis, empty_extent, empty_extent);
910 EXPECT_TRUE(perm_set.IsEmpty()); 1071 EXPECT_TRUE(perm_set->IsEmpty());
911 1072
912 ExtensionAPIPermissionSet non_empty_apis; 1073 ExtensionAPIPermissionSet non_empty_apis;
913 non_empty_apis.insert(ExtensionAPIPermission::kBackground); 1074 non_empty_apis.insert(ExtensionAPIPermission::kBackground);
914 perm_set = ExtensionPermissionSet( 1075 perm_set = new ExtensionPermissionSet(
915 non_empty_apis, empty_extent, empty_extent); 1076 non_empty_apis, empty_extent, empty_extent);
916 EXPECT_FALSE(perm_set.IsEmpty()); 1077 EXPECT_FALSE(perm_set->IsEmpty());
917 1078
918 // Try non standard host 1079 // Try non standard host
919 URLPatternSet non_empty_extent; 1080 URLPatternSet non_empty_extent;
920 AddPattern(&non_empty_extent, "http://www.google.com/*"); 1081 AddPattern(&non_empty_extent, "http://www.google.com/*");
921 1082
922 perm_set = ExtensionPermissionSet( 1083 perm_set = new ExtensionPermissionSet(
923 empty_apis, non_empty_extent, empty_extent); 1084 empty_apis, non_empty_extent, empty_extent);
924 EXPECT_FALSE(perm_set.IsEmpty()); 1085 EXPECT_FALSE(perm_set->IsEmpty());
925 1086
926 perm_set = ExtensionPermissionSet( 1087 perm_set = new ExtensionPermissionSet(
927 empty_apis, empty_extent, non_empty_extent); 1088 empty_apis, empty_extent, non_empty_extent);
928 EXPECT_FALSE(perm_set.IsEmpty()); 1089 EXPECT_FALSE(perm_set->IsEmpty());
929 } 1090 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_permission_set.cc ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698