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

Side by Side Diff: chrome/common/extensions/permissions/permission_set_unittest.cc

Issue 51433002: Enable permission warnings from ManifestHandlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing. 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
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/json/json_file_value_serializer.h" 6 #include "base/json/json_file_value_serializer.h"
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/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 permissions = extension->GetActivePermissions(); 195 permissions = extension->GetActivePermissions();
196 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); 196 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/")));
197 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); 197 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/")));
198 EXPECT_TRUE( 198 EXPECT_TRUE(
199 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); 199 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com")));
200 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); 200 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
201 } 201 }
202 202
203 TEST(PermissionsTest, ExplicitAccessToOrigin) { 203 TEST(PermissionsTest, ExplicitAccessToOrigin) {
204 APIPermissionSet apis; 204 APIPermissionSet apis;
205 ManifestPermissionSet manifest_permissions;
205 URLPatternSet explicit_hosts; 206 URLPatternSet explicit_hosts;
206 URLPatternSet scriptable_hosts; 207 URLPatternSet scriptable_hosts;
207 208
208 AddPattern(&explicit_hosts, "http://*.google.com/*"); 209 AddPattern(&explicit_hosts, "http://*.google.com/*");
209 // The explicit host paths should get set to /*. 210 // The explicit host paths should get set to /*.
210 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*"); 211 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*");
211 212
212 scoped_refptr<PermissionSet> perm_set = new PermissionSet( 213 scoped_refptr<PermissionSet> perm_set = new PermissionSet(
213 apis, explicit_hosts, scriptable_hosts); 214 apis, manifest_permissions, explicit_hosts, scriptable_hosts);
214 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( 215 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
215 GURL("http://www.google.com/"))); 216 GURL("http://www.google.com/")));
216 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( 217 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
217 GURL("http://test.google.com/"))); 218 GURL("http://test.google.com/")));
218 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( 219 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
219 GURL("http://www.example.com"))); 220 GURL("http://www.example.com")));
220 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL( 221 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL(
221 GURL("http://www.example.com"))); 222 GURL("http://www.example.com")));
222 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin( 223 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin(
223 GURL("http://test.example.com"))); 224 GURL("http://test.example.com")));
224 } 225 }
225 226
226 TEST(PermissionsTest, CreateUnion) { 227 TEST(PermissionsTest, CreateUnion) {
227 APIPermission* permission = NULL; 228 APIPermission* permission = NULL;
228 229
230 ManifestPermissionSet manifest_permissions;
229 APIPermissionSet apis1; 231 APIPermissionSet apis1;
230 APIPermissionSet apis2; 232 APIPermissionSet apis2;
231 APIPermissionSet expected_apis; 233 APIPermissionSet expected_apis;
232 234
233 URLPatternSet explicit_hosts1; 235 URLPatternSet explicit_hosts1;
234 URLPatternSet explicit_hosts2; 236 URLPatternSet explicit_hosts2;
235 URLPatternSet expected_explicit_hosts; 237 URLPatternSet expected_explicit_hosts;
236 238
237 URLPatternSet scriptable_hosts1; 239 URLPatternSet scriptable_hosts1;
238 URLPatternSet scriptable_hosts2; 240 URLPatternSet scriptable_hosts2;
(...skipping 24 matching lines...) Expand all
263 apis1.insert(APIPermission::kBackground); 265 apis1.insert(APIPermission::kBackground);
264 apis1.insert(permission->Clone()); 266 apis1.insert(permission->Clone());
265 expected_apis.insert(APIPermission::kTab); 267 expected_apis.insert(APIPermission::kTab);
266 expected_apis.insert(APIPermission::kBackground); 268 expected_apis.insert(APIPermission::kBackground);
267 expected_apis.insert(permission); 269 expected_apis.insert(permission);
268 270
269 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 271 AddPattern(&explicit_hosts1, "http://*.google.com/*");
270 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); 272 AddPattern(&expected_explicit_hosts, "http://*.google.com/*");
271 AddPattern(&effective_hosts, "http://*.google.com/*"); 273 AddPattern(&effective_hosts, "http://*.google.com/*");
272 274
273 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); 275 set1 = new PermissionSet(apis1, manifest_permissions,
274 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 276 explicit_hosts1, scriptable_hosts1);
277 set2 = new PermissionSet(apis2, manifest_permissions,
278 explicit_hosts2, scriptable_hosts2);
275 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); 279 union_set = PermissionSet::CreateUnion(set1.get(), set2.get());
276 EXPECT_TRUE(set1->Contains(*set2.get())); 280 EXPECT_TRUE(set1->Contains(*set2.get()));
277 EXPECT_TRUE(set1->Contains(*union_set.get())); 281 EXPECT_TRUE(set1->Contains(*union_set.get()));
278 EXPECT_FALSE(set2->Contains(*set1.get())); 282 EXPECT_FALSE(set2->Contains(*set1.get()));
279 EXPECT_FALSE(set2->Contains(*union_set.get())); 283 EXPECT_FALSE(set2->Contains(*union_set.get()));
280 EXPECT_TRUE(union_set->Contains(*set1.get())); 284 EXPECT_TRUE(union_set->Contains(*set1.get()));
281 EXPECT_TRUE(union_set->Contains(*set2.get())); 285 EXPECT_TRUE(union_set->Contains(*set2.get()));
282 286
283 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); 287 EXPECT_FALSE(union_set->HasEffectiveFullAccess());
284 EXPECT_EQ(expected_apis, union_set->apis()); 288 EXPECT_EQ(expected_apis, union_set->apis());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 expected_apis.insert(permission); 329 expected_apis.insert(permission);
326 330
327 AddPattern(&explicit_hosts2, "http://*.example.com/*"); 331 AddPattern(&explicit_hosts2, "http://*.example.com/*");
328 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 332 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
329 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); 333 AddPattern(&expected_explicit_hosts, "http://*.example.com/*");
330 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); 334 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*");
331 335
332 URLPatternSet::CreateUnion( 336 URLPatternSet::CreateUnion(
333 explicit_hosts2, scriptable_hosts2, &effective_hosts); 337 explicit_hosts2, scriptable_hosts2, &effective_hosts);
334 338
335 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 339 set2 = new PermissionSet(apis2, manifest_permissions,
340 explicit_hosts2, scriptable_hosts2);
336 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); 341 union_set = PermissionSet::CreateUnion(set1.get(), set2.get());
337 342
338 EXPECT_FALSE(set1->Contains(*set2.get())); 343 EXPECT_FALSE(set1->Contains(*set2.get()));
339 EXPECT_FALSE(set1->Contains(*union_set.get())); 344 EXPECT_FALSE(set1->Contains(*union_set.get()));
340 EXPECT_FALSE(set2->Contains(*set1.get())); 345 EXPECT_FALSE(set2->Contains(*set1.get()));
341 EXPECT_FALSE(set2->Contains(*union_set.get())); 346 EXPECT_FALSE(set2->Contains(*union_set.get()));
342 EXPECT_TRUE(union_set->Contains(*set1.get())); 347 EXPECT_TRUE(union_set->Contains(*set1.get()));
343 EXPECT_TRUE(union_set->Contains(*set2.get())); 348 EXPECT_TRUE(union_set->Contains(*set2.get()));
344 349
345 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); 350 EXPECT_TRUE(union_set->HasEffectiveFullAccess());
346 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); 351 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts());
347 EXPECT_EQ(expected_apis, union_set->apis()); 352 EXPECT_EQ(expected_apis, union_set->apis());
348 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); 353 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
349 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); 354 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
350 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); 355 EXPECT_EQ(effective_hosts, union_set->effective_hosts());
351 } 356 }
352 357
353 TEST(PermissionsTest, CreateIntersection) { 358 TEST(PermissionsTest, CreateIntersection) {
354 APIPermission* permission = NULL; 359 APIPermission* permission = NULL;
355 360
361 ManifestPermissionSet manifest_permissions;
356 APIPermissionSet apis1; 362 APIPermissionSet apis1;
357 APIPermissionSet apis2; 363 APIPermissionSet apis2;
358 APIPermissionSet expected_apis; 364 APIPermissionSet expected_apis;
359 365
360 URLPatternSet explicit_hosts1; 366 URLPatternSet explicit_hosts1;
361 URLPatternSet explicit_hosts2; 367 URLPatternSet explicit_hosts2;
362 URLPatternSet expected_explicit_hosts; 368 URLPatternSet expected_explicit_hosts;
363 369
364 URLPatternSet scriptable_hosts1; 370 URLPatternSet scriptable_hosts1;
365 URLPatternSet scriptable_hosts2; 371 URLPatternSet scriptable_hosts2;
(...skipping 20 matching lines...) Expand all
386 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); 392 value->Append(base::Value::CreateStringValue("udp-send-to::8888"));
387 if (!permission->FromValue(value.get())) { 393 if (!permission->FromValue(value.get())) {
388 NOTREACHED(); 394 NOTREACHED();
389 } 395 }
390 } 396 }
391 apis1.insert(permission); 397 apis1.insert(permission);
392 398
393 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 399 AddPattern(&explicit_hosts1, "http://*.google.com/*");
394 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); 400 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*");
395 401
396 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); 402 set1 = new PermissionSet(apis1, manifest_permissions,
397 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 403 explicit_hosts1, scriptable_hosts1);
404 set2 = new PermissionSet(apis2, manifest_permissions,
405 explicit_hosts2, scriptable_hosts2);
398 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); 406 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get());
399 EXPECT_TRUE(set1->Contains(*new_set.get())); 407 EXPECT_TRUE(set1->Contains(*new_set.get()));
400 EXPECT_TRUE(set2->Contains(*new_set.get())); 408 EXPECT_TRUE(set2->Contains(*new_set.get()));
401 EXPECT_TRUE(set1->Contains(*set2.get())); 409 EXPECT_TRUE(set1->Contains(*set2.get()));
402 EXPECT_FALSE(set2->Contains(*set1.get())); 410 EXPECT_FALSE(set2->Contains(*set1.get()));
403 EXPECT_FALSE(new_set->Contains(*set1.get())); 411 EXPECT_FALSE(new_set->Contains(*set1.get()));
404 EXPECT_TRUE(new_set->Contains(*set2.get())); 412 EXPECT_TRUE(new_set->Contains(*set2.get()));
405 413
406 EXPECT_TRUE(new_set->IsEmpty()); 414 EXPECT_TRUE(new_set->IsEmpty());
407 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); 415 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 expected_apis.insert(permission); 448 expected_apis.insert(permission);
441 449
442 AddPattern(&explicit_hosts2, "http://*.example.com/*"); 450 AddPattern(&explicit_hosts2, "http://*.example.com/*");
443 AddPattern(&explicit_hosts2, "http://*.google.com/*"); 451 AddPattern(&explicit_hosts2, "http://*.google.com/*");
444 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 452 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
445 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); 453 AddPattern(&expected_explicit_hosts, "http://*.google.com/*");
446 454
447 effective_hosts.ClearPatterns(); 455 effective_hosts.ClearPatterns();
448 AddPattern(&effective_hosts, "http://*.google.com/*"); 456 AddPattern(&effective_hosts, "http://*.google.com/*");
449 457
450 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 458 set2 = new PermissionSet(apis2, manifest_permissions,
459 explicit_hosts2, scriptable_hosts2);
451 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); 460 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get());
452 461
453 EXPECT_TRUE(set1->Contains(*new_set.get())); 462 EXPECT_TRUE(set1->Contains(*new_set.get()));
454 EXPECT_TRUE(set2->Contains(*new_set.get())); 463 EXPECT_TRUE(set2->Contains(*new_set.get()));
455 EXPECT_FALSE(set1->Contains(*set2.get())); 464 EXPECT_FALSE(set1->Contains(*set2.get()));
456 EXPECT_FALSE(set2->Contains(*set1.get())); 465 EXPECT_FALSE(set2->Contains(*set1.get()));
457 EXPECT_FALSE(new_set->Contains(*set1.get())); 466 EXPECT_FALSE(new_set->Contains(*set1.get()));
458 EXPECT_FALSE(new_set->Contains(*set2.get())); 467 EXPECT_FALSE(new_set->Contains(*set2.get()));
459 468
460 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); 469 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
461 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); 470 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts());
462 EXPECT_EQ(expected_apis, new_set->apis()); 471 EXPECT_EQ(expected_apis, new_set->apis());
463 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); 472 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
464 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); 473 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
465 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); 474 EXPECT_EQ(effective_hosts, new_set->effective_hosts());
466 } 475 }
467 476
468 TEST(PermissionsTest, CreateDifference) { 477 TEST(PermissionsTest, CreateDifference) {
469 APIPermission* permission = NULL; 478 APIPermission* permission = NULL;
470 479
480 ManifestPermissionSet manifest_permissions;
471 APIPermissionSet apis1; 481 APIPermissionSet apis1;
472 APIPermissionSet apis2; 482 APIPermissionSet apis2;
473 APIPermissionSet expected_apis; 483 APIPermissionSet expected_apis;
474 484
475 URLPatternSet explicit_hosts1; 485 URLPatternSet explicit_hosts1;
476 URLPatternSet explicit_hosts2; 486 URLPatternSet explicit_hosts2;
477 URLPatternSet expected_explicit_hosts; 487 URLPatternSet expected_explicit_hosts;
478 488
479 URLPatternSet scriptable_hosts1; 489 URLPatternSet scriptable_hosts1;
480 URLPatternSet scriptable_hosts2; 490 URLPatternSet scriptable_hosts2;
(...skipping 20 matching lines...) Expand all
501 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); 511 value->Append(base::Value::CreateStringValue("udp-send-to::8888"));
502 if (!permission->FromValue(value.get())) { 512 if (!permission->FromValue(value.get())) {
503 NOTREACHED(); 513 NOTREACHED();
504 } 514 }
505 } 515 }
506 apis1.insert(permission); 516 apis1.insert(permission);
507 517
508 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 518 AddPattern(&explicit_hosts1, "http://*.google.com/*");
509 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); 519 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*");
510 520
511 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); 521 set1 = new PermissionSet(apis1, manifest_permissions,
512 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 522 explicit_hosts1, scriptable_hosts1);
523 set2 = new PermissionSet(apis2, manifest_permissions,
524 explicit_hosts2, scriptable_hosts2);
513 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); 525 new_set = PermissionSet::CreateDifference(set1.get(), set2.get());
514 EXPECT_EQ(*set1.get(), *new_set.get()); 526 EXPECT_EQ(*set1.get(), *new_set.get());
515 527
516 // Now use a real second set. 528 // Now use a real second set.
517 apis2.insert(APIPermission::kTab); 529 apis2.insert(APIPermission::kTab);
518 apis2.insert(APIPermission::kProxy); 530 apis2.insert(APIPermission::kProxy);
519 apis2.insert(APIPermission::kClipboardWrite); 531 apis2.insert(APIPermission::kClipboardWrite);
520 apis2.insert(APIPermission::kPlugin); 532 apis2.insert(APIPermission::kPlugin);
521 permission = permission_info->CreateAPIPermission(); 533 permission = permission_info->CreateAPIPermission();
522 { 534 {
(...skipping 20 matching lines...) Expand all
543 expected_apis.insert(permission); 555 expected_apis.insert(permission);
544 556
545 AddPattern(&explicit_hosts2, "http://*.example.com/*"); 557 AddPattern(&explicit_hosts2, "http://*.example.com/*");
546 AddPattern(&explicit_hosts2, "http://*.google.com/*"); 558 AddPattern(&explicit_hosts2, "http://*.google.com/*");
547 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 559 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
548 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); 560 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*");
549 561
550 effective_hosts.ClearPatterns(); 562 effective_hosts.ClearPatterns();
551 AddPattern(&effective_hosts, "http://www.reddit.com/*"); 563 AddPattern(&effective_hosts, "http://www.reddit.com/*");
552 564
553 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 565 set2 = new PermissionSet(apis2, manifest_permissions,
566 explicit_hosts2, scriptable_hosts2);
554 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); 567 new_set = PermissionSet::CreateDifference(set1.get(), set2.get());
555 568
556 EXPECT_TRUE(set1->Contains(*new_set.get())); 569 EXPECT_TRUE(set1->Contains(*new_set.get()));
557 EXPECT_FALSE(set2->Contains(*new_set.get())); 570 EXPECT_FALSE(set2->Contains(*new_set.get()));
558 571
559 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); 572 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
560 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); 573 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts());
561 EXPECT_EQ(expected_apis, new_set->apis()); 574 EXPECT_EQ(expected_apis, new_set->apis());
562 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); 575 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
563 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); 576 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 << "missing message_id for " << permission_info->name(); 778 << "missing message_id for " << permission_info->name();
766 } 779 }
767 } 780 }
768 } 781 }
769 782
770 TEST(PermissionsTest, FileSystemPermissionMessages) { 783 TEST(PermissionsTest, FileSystemPermissionMessages) {
771 APIPermissionSet api_permissions; 784 APIPermissionSet api_permissions;
772 api_permissions.insert(APIPermission::kFileSystemWrite); 785 api_permissions.insert(APIPermission::kFileSystemWrite);
773 api_permissions.insert(APIPermission::kFileSystemDirectory); 786 api_permissions.insert(APIPermission::kFileSystemDirectory);
774 scoped_refptr<PermissionSet> permissions( 787 scoped_refptr<PermissionSet> permissions(
775 new PermissionSet(api_permissions, URLPatternSet(), URLPatternSet())); 788 new PermissionSet(api_permissions, ManifestPermissionSet(),
789 URLPatternSet(), URLPatternSet()));
776 PermissionMessages messages = 790 PermissionMessages messages =
777 PermissionMessageProvider::Get()->GetPermissionMessages( 791 PermissionMessageProvider::Get()->GetPermissionMessages(
778 permissions, Manifest::TYPE_PLATFORM_APP); 792 permissions, Manifest::TYPE_PLATFORM_APP);
779 ASSERT_EQ(2u, messages.size()); 793 ASSERT_EQ(2u, messages.size());
780 std::sort(messages.begin(), messages.end()); 794 std::sort(messages.begin(), messages.end());
781 std::set<PermissionMessage::ID> ids; 795 std::set<PermissionMessage::ID> ids;
782 for (PermissionMessages::const_iterator it = messages.begin(); 796 for (PermissionMessages::const_iterator it = messages.begin();
783 it != messages.end(); ++it) { 797 it != messages.end(); ++it) {
784 ids.insert(it->id()); 798 ids.insert(it->id());
785 } 799 }
786 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemDirectory)); 800 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemDirectory));
787 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemWrite)); 801 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemWrite));
788 } 802 }
789 803
790 TEST(PermissionsTest, HiddenFileSystemPermissionMessages) { 804 TEST(PermissionsTest, HiddenFileSystemPermissionMessages) {
791 APIPermissionSet api_permissions; 805 APIPermissionSet api_permissions;
792 api_permissions.insert(APIPermission::kFileSystemWrite); 806 api_permissions.insert(APIPermission::kFileSystemWrite);
793 api_permissions.insert(APIPermission::kFileSystemDirectory); 807 api_permissions.insert(APIPermission::kFileSystemDirectory);
794 api_permissions.insert(APIPermission::kFileSystemWriteDirectory); 808 api_permissions.insert(APIPermission::kFileSystemWriteDirectory);
795 scoped_refptr<PermissionSet> permissions( 809 scoped_refptr<PermissionSet> permissions(
796 new PermissionSet(api_permissions, URLPatternSet(), URLPatternSet())); 810 new PermissionSet(api_permissions, ManifestPermissionSet(),
811 URLPatternSet(), URLPatternSet()));
797 PermissionMessages messages = 812 PermissionMessages messages =
798 PermissionMessageProvider::Get()->GetPermissionMessages( 813 PermissionMessageProvider::Get()->GetPermissionMessages(
799 permissions, Manifest::TYPE_PLATFORM_APP); 814 permissions, Manifest::TYPE_PLATFORM_APP);
800 ASSERT_EQ(1u, messages.size()); 815 ASSERT_EQ(1u, messages.size());
801 EXPECT_EQ(PermissionMessage::kFileSystemWriteDirectory, messages[0].id()); 816 EXPECT_EQ(PermissionMessage::kFileSystemWriteDirectory, messages[0].id());
802 } 817 }
803 818
804 TEST(PermissionsTest, MergedFileSystemPermissionComparison) { 819 TEST(PermissionsTest, MergedFileSystemPermissionComparison) {
805 APIPermissionSet write_api_permissions; 820 APIPermissionSet write_api_permissions;
806 write_api_permissions.insert(APIPermission::kFileSystemWrite); 821 write_api_permissions.insert(APIPermission::kFileSystemWrite);
807 scoped_refptr<PermissionSet> write_permissions(new PermissionSet( 822 scoped_refptr<PermissionSet> write_permissions(
808 write_api_permissions, URLPatternSet(), URLPatternSet())); 823 new PermissionSet(write_api_permissions, ManifestPermissionSet(),
824 URLPatternSet(), URLPatternSet()));
809 825
810 APIPermissionSet directory_api_permissions; 826 APIPermissionSet directory_api_permissions;
811 directory_api_permissions.insert(APIPermission::kFileSystemDirectory); 827 directory_api_permissions.insert(APIPermission::kFileSystemDirectory);
812 scoped_refptr<PermissionSet> directory_permissions(new PermissionSet( 828 scoped_refptr<PermissionSet> directory_permissions(
813 directory_api_permissions, URLPatternSet(), URLPatternSet())); 829 new PermissionSet(directory_api_permissions, ManifestPermissionSet(),
830 URLPatternSet(), URLPatternSet()));
814 831
815 APIPermissionSet write_directory_api_permissions; 832 APIPermissionSet write_directory_api_permissions;
816 write_directory_api_permissions.insert( 833 write_directory_api_permissions.insert(
817 APIPermission::kFileSystemWriteDirectory); 834 APIPermission::kFileSystemWriteDirectory);
818 scoped_refptr<PermissionSet> write_directory_permissions(new PermissionSet( 835 scoped_refptr<PermissionSet> write_directory_permissions(
819 write_directory_api_permissions, URLPatternSet(), URLPatternSet())); 836 new PermissionSet(write_directory_api_permissions,
837 ManifestPermissionSet(),
838 URLPatternSet(),
839 URLPatternSet()));
820 840
821 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); 841 const PermissionMessageProvider* provider = PermissionMessageProvider::Get();
822 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions, 842 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions,
823 write_permissions, 843 write_permissions,
824 Manifest::TYPE_PLATFORM_APP)); 844 Manifest::TYPE_PLATFORM_APP));
825 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions, 845 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions,
826 directory_permissions, 846 directory_permissions,
827 Manifest::TYPE_PLATFORM_APP)); 847 Manifest::TYPE_PLATFORM_APP));
828 EXPECT_TRUE(provider->IsPrivilegeIncrease(write_permissions, 848 EXPECT_TRUE(provider->IsPrivilegeIncrease(write_permissions,
829 directory_permissions, 849 directory_permissions,
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1173
1154 explicit_hosts.AddPattern( 1174 explicit_hosts.AddPattern(
1155 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); 1175 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*"));
1156 scriptable_hosts.AddPattern( 1176 scriptable_hosts.AddPattern(
1157 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*")); 1177 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*"));
1158 1178
1159 expected.insert("*.google.com"); 1179 expected.insert("*.google.com");
1160 expected.insert("*.example.com"); 1180 expected.insert("*.example.com");
1161 1181
1162 scoped_refptr<PermissionSet> perm_set(new PermissionSet( 1182 scoped_refptr<PermissionSet> perm_set(new PermissionSet(
1163 empty_perms, explicit_hosts, scriptable_hosts)); 1183 empty_perms, ManifestPermissionSet(),
1184 explicit_hosts, scriptable_hosts));
1164 EXPECT_EQ(expected, 1185 EXPECT_EQ(expected,
1165 permission_message_util::GetDistinctHosts( 1186 permission_message_util::GetDistinctHosts(
1166 perm_set->effective_hosts(), true, true)); 1187 perm_set->effective_hosts(), true, true));
1167 } 1188 }
1168 1189
1169 { 1190 {
1170 // We don't display warnings for file URLs because they are off by default. 1191 // We don't display warnings for file URLs because they are off by default.
1171 SCOPED_TRACE("file urls"); 1192 SCOPED_TRACE("file urls");
1172 1193
1173 explicit_hosts.ClearPatterns(); 1194 explicit_hosts.ClearPatterns();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 std::set<std::string> expected; 1281 std::set<std::string> expected;
1261 expected.insert("www.foo.ca"); 1282 expected.insert("www.foo.ca");
1262 EXPECT_EQ(expected, 1283 EXPECT_EQ(expected,
1263 permission_message_util::GetDistinctHosts( 1284 permission_message_util::GetDistinctHosts(
1264 explicit_hosts, true, true)); 1285 explicit_hosts, true, true));
1265 } 1286 }
1266 1287
1267 TEST(PermissionsTest, IsHostPrivilegeIncrease) { 1288 TEST(PermissionsTest, IsHostPrivilegeIncrease) {
1268 Manifest::Type type = Manifest::TYPE_EXTENSION; 1289 Manifest::Type type = Manifest::TYPE_EXTENSION;
1269 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); 1290 const PermissionMessageProvider* provider = PermissionMessageProvider::Get();
1291 ManifestPermissionSet empty_manifest_permissions;
1270 URLPatternSet elist1; 1292 URLPatternSet elist1;
1271 URLPatternSet elist2; 1293 URLPatternSet elist2;
1272 URLPatternSet slist1; 1294 URLPatternSet slist1;
1273 URLPatternSet slist2; 1295 URLPatternSet slist2;
1274 scoped_refptr<PermissionSet> set1; 1296 scoped_refptr<PermissionSet> set1;
1275 scoped_refptr<PermissionSet> set2; 1297 scoped_refptr<PermissionSet> set2;
1276 APIPermissionSet empty_perms; 1298 APIPermissionSet empty_perms;
1277 elist1.AddPattern( 1299 elist1.AddPattern(
1278 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); 1300 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path"));
1279 elist1.AddPattern( 1301 elist1.AddPattern(
1280 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); 1302 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
1281 1303
1282 // Test that the host order does not matter. 1304 // Test that the host order does not matter.
1283 elist2.AddPattern( 1305 elist2.AddPattern(
1284 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); 1306 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
1285 elist2.AddPattern( 1307 elist2.AddPattern(
1286 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); 1308 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path"));
1287 1309
1288 set1 = new PermissionSet(empty_perms, elist1, slist1); 1310 set1 = new PermissionSet(empty_perms, empty_manifest_permissions,
1289 set2 = new PermissionSet(empty_perms, elist2, slist2); 1311 elist1, slist1);
1312 set2 = new PermissionSet(empty_perms, empty_manifest_permissions,
1313 elist2, slist2);
1290 1314
1291 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); 1315 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type));
1292 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); 1316 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type));
1293 1317
1294 // Test that paths are ignored. 1318 // Test that paths are ignored.
1295 elist2.ClearPatterns(); 1319 elist2.ClearPatterns();
1296 elist2.AddPattern( 1320 elist2.AddPattern(
1297 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*")); 1321 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*"));
1298 set2 = new PermissionSet(empty_perms, elist2, slist2); 1322 set2 = new PermissionSet(empty_perms, empty_manifest_permissions,
1323 elist2, slist2);
1299 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); 1324 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type));
1300 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); 1325 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type));
1301 1326
1302 // Test that RCDs are ignored. 1327 // Test that RCDs are ignored.
1303 elist2.ClearPatterns(); 1328 elist2.ClearPatterns();
1304 elist2.AddPattern( 1329 elist2.AddPattern(
1305 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*")); 1330 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*"));
1306 set2 = new PermissionSet(empty_perms, elist2, slist2); 1331 set2 = new PermissionSet(empty_perms, empty_manifest_permissions,
1332 elist2, slist2);
1307 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); 1333 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type));
1308 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); 1334 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type));
1309 1335
1310 // Test that subdomain wildcards are handled properly. 1336 // Test that subdomain wildcards are handled properly.
1311 elist2.ClearPatterns(); 1337 elist2.ClearPatterns();
1312 elist2.AddPattern( 1338 elist2.AddPattern(
1313 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*")); 1339 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*"));
1314 set2 = new PermissionSet(empty_perms, elist2, slist2); 1340 set2 = new PermissionSet(empty_perms, empty_manifest_permissions,
1341 elist2, slist2);
1315 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); 1342 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type));
1316 // TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337 1343 // TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337
1317 // EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); 1344 // EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type));
1318 1345
1319 // Test that different domains count as different hosts. 1346 // Test that different domains count as different hosts.
1320 elist2.ClearPatterns(); 1347 elist2.ClearPatterns();
1321 elist2.AddPattern( 1348 elist2.AddPattern(
1322 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); 1349 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
1323 elist2.AddPattern( 1350 elist2.AddPattern(
1324 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path")); 1351 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path"));
1325 set2 = new PermissionSet(empty_perms, elist2, slist2); 1352 set2 = new PermissionSet(empty_perms, empty_manifest_permissions,
1353 elist2, slist2);
1326 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); 1354 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type));
1327 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); 1355 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type));
1328 1356
1329 // Test that different subdomains count as different hosts. 1357 // Test that different subdomains count as different hosts.
1330 elist2.ClearPatterns(); 1358 elist2.ClearPatterns();
1331 elist2.AddPattern( 1359 elist2.AddPattern(
1332 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); 1360 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*"));
1333 set2 = new PermissionSet(empty_perms, elist2, slist2); 1361 set2 = new PermissionSet(empty_perms, empty_manifest_permissions,
1362 elist2, slist2);
1334 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); 1363 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type));
1335 EXPECT_TRUE(provider->IsPrivilegeIncrease(set2, set1, type)); 1364 EXPECT_TRUE(provider->IsPrivilegeIncrease(set2, set1, type));
1336 1365
1337 // Test that platform apps do not have host permissions increases. 1366 // Test that platform apps do not have host permissions increases.
1338 type = Manifest::TYPE_PLATFORM_APP; 1367 type = Manifest::TYPE_PLATFORM_APP;
1339 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); 1368 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type));
1340 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); 1369 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type));
1341 } 1370 }
1342 1371
1343 TEST(PermissionsTest, GetAPIsAsStrings) { 1372 TEST(PermissionsTest, GetAPIsAsStrings) {
1344 APIPermissionSet apis; 1373 APIPermissionSet apis;
1345 URLPatternSet empty_set; 1374 URLPatternSet empty_set;
1346 1375
1347 apis.insert(APIPermission::kProxy); 1376 apis.insert(APIPermission::kProxy);
1348 apis.insert(APIPermission::kBackground); 1377 apis.insert(APIPermission::kBackground);
1349 apis.insert(APIPermission::kNotification); 1378 apis.insert(APIPermission::kNotification);
1350 apis.insert(APIPermission::kTab); 1379 apis.insert(APIPermission::kTab);
1351 1380
1352 scoped_refptr<PermissionSet> perm_set = new PermissionSet( 1381 scoped_refptr<PermissionSet> perm_set = new PermissionSet(
1353 apis, empty_set, empty_set); 1382 apis, ManifestPermissionSet(), empty_set, empty_set);
1354 std::set<std::string> api_names = perm_set->GetAPIsAsStrings(); 1383 std::set<std::string> api_names = perm_set->GetAPIsAsStrings();
1355 1384
1356 // The result is correct if it has the same number of elements 1385 // The result is correct if it has the same number of elements
1357 // and we can convert it back to the id set. 1386 // and we can convert it back to the id set.
1358 EXPECT_EQ(4u, api_names.size()); 1387 EXPECT_EQ(4u, api_names.size());
1359 EXPECT_EQ(apis, 1388 EXPECT_EQ(apis,
1360 PermissionsInfo::GetInstance()->GetAllByName(api_names)); 1389 PermissionsInfo::GetInstance()->GetAllByName(api_names));
1361 } 1390 }
1362 1391
1363 TEST(PermissionsTest, IsEmpty) { 1392 TEST(PermissionsTest, IsEmpty) {
1364 APIPermissionSet empty_apis; 1393 APIPermissionSet empty_apis;
1365 URLPatternSet empty_extent; 1394 URLPatternSet empty_extent;
1366 1395
1367 scoped_refptr<PermissionSet> empty = new PermissionSet(); 1396 scoped_refptr<PermissionSet> empty = new PermissionSet();
1368 EXPECT_TRUE(empty->IsEmpty()); 1397 EXPECT_TRUE(empty->IsEmpty());
1369 scoped_refptr<PermissionSet> perm_set; 1398 scoped_refptr<PermissionSet> perm_set;
1370 1399
1371 perm_set = new PermissionSet(empty_apis, empty_extent, empty_extent); 1400 perm_set = new PermissionSet(empty_apis, ManifestPermissionSet(),
1401 empty_extent, empty_extent);
1372 EXPECT_TRUE(perm_set->IsEmpty()); 1402 EXPECT_TRUE(perm_set->IsEmpty());
1373 1403
1374 APIPermissionSet non_empty_apis; 1404 APIPermissionSet non_empty_apis;
1375 non_empty_apis.insert(APIPermission::kBackground); 1405 non_empty_apis.insert(APIPermission::kBackground);
1376 perm_set = new PermissionSet( 1406 perm_set = new PermissionSet(non_empty_apis, ManifestPermissionSet(),
1377 non_empty_apis, empty_extent, empty_extent); 1407 empty_extent, empty_extent);
1378 EXPECT_FALSE(perm_set->IsEmpty()); 1408 EXPECT_FALSE(perm_set->IsEmpty());
1379 1409
1380 // Try non standard host 1410 // Try non standard host
1381 URLPatternSet non_empty_extent; 1411 URLPatternSet non_empty_extent;
1382 AddPattern(&non_empty_extent, "http://www.google.com/*"); 1412 AddPattern(&non_empty_extent, "http://www.google.com/*");
1383 1413
1384 perm_set = new PermissionSet( 1414 perm_set = new PermissionSet(empty_apis, ManifestPermissionSet(),
1385 empty_apis, non_empty_extent, empty_extent); 1415 non_empty_extent, empty_extent);
1386 EXPECT_FALSE(perm_set->IsEmpty()); 1416 EXPECT_FALSE(perm_set->IsEmpty());
1387 1417
1388 perm_set = new PermissionSet( 1418 perm_set = new PermissionSet(empty_apis, ManifestPermissionSet(),
1389 empty_apis, empty_extent, non_empty_extent); 1419 empty_extent, non_empty_extent);
1390 EXPECT_FALSE(perm_set->IsEmpty()); 1420 EXPECT_FALSE(perm_set->IsEmpty());
1391 } 1421 }
1392 1422
1393 TEST(PermissionsTest, ImpliedPermissions) { 1423 TEST(PermissionsTest, ImpliedPermissions) {
1394 URLPatternSet empty_extent; 1424 URLPatternSet empty_extent;
1395 APIPermissionSet apis; 1425 APIPermissionSet apis;
1396 apis.insert(APIPermission::kWebRequest); 1426 apis.insert(APIPermission::kWebRequest);
1397 apis.insert(APIPermission::kFileBrowserHandler); 1427 apis.insert(APIPermission::kFileBrowserHandler);
1398 EXPECT_EQ(2U, apis.size()); 1428 EXPECT_EQ(2U, apis.size());
1399 1429
1400 scoped_refptr<PermissionSet> perm_set; 1430 scoped_refptr<PermissionSet> perm_set;
1401 perm_set = new PermissionSet(apis, empty_extent, empty_extent); 1431 perm_set = new PermissionSet(apis, ManifestPermissionSet(),
1432 empty_extent, empty_extent);
1402 EXPECT_EQ(4U, perm_set->apis().size()); 1433 EXPECT_EQ(4U, perm_set->apis().size());
1403 } 1434 }
1404 1435
1405 TEST(PermissionsTest, SyncFileSystemPermission) { 1436 TEST(PermissionsTest, SyncFileSystemPermission) {
1406 scoped_refptr<Extension> extension = LoadManifest( 1437 scoped_refptr<Extension> extension = LoadManifest(
1407 "permissions", "sync_file_system.json"); 1438 "permissions", "sync_file_system.json");
1408 APIPermissionSet apis; 1439 APIPermissionSet apis;
1409 apis.insert(APIPermission::kSyncFileSystem); 1440 apis.insert(APIPermission::kSyncFileSystem);
1410 EXPECT_TRUE(extension->is_platform_app()); 1441 EXPECT_TRUE(extension->is_platform_app());
1411 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); 1442 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem));
1412 std::vector<string16> warnings = 1443 std::vector<string16> warnings =
1413 PermissionsData::GetPermissionMessageStrings(extension.get()); 1444 PermissionsData::GetPermissionMessageStrings(extension.get());
1414 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); 1445 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account"));
1415 ASSERT_EQ(1u, warnings.size()); 1446 ASSERT_EQ(1u, warnings.size());
1416 } 1447 }
1417 1448
1418 // Make sure that we don't crash when we're trying to show the permissions 1449 // Make sure that we don't crash when we're trying to show the permissions
1419 // even though chrome://thumb (and everything that's not chrome://favicon with 1450 // even though chrome://thumb (and everything that's not chrome://favicon with
1420 // a chrome:// scheme) is not a valid permission. 1451 // a chrome:// scheme) is not a valid permission.
1421 // More details here: crbug/246314. 1452 // More details here: crbug/246314.
1422 TEST(PermissionsTest, ChromeURLs) { 1453 TEST(PermissionsTest, ChromeURLs) {
1423 URLPatternSet allowed_hosts; 1454 URLPatternSet allowed_hosts;
1424 allowed_hosts.AddPattern( 1455 allowed_hosts.AddPattern(
1425 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/")); 1456 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/"));
1426 allowed_hosts.AddPattern( 1457 allowed_hosts.AddPattern(
1427 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); 1458 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/"));
1428 allowed_hosts.AddPattern( 1459 allowed_hosts.AddPattern(
1429 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); 1460 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/"));
1430 scoped_refptr<PermissionSet> permissions( 1461 scoped_refptr<PermissionSet> permissions(
1431 new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet())); 1462 new PermissionSet(APIPermissionSet(), ManifestPermissionSet(),
1463 allowed_hosts, URLPatternSet()));
1432 PermissionMessageProvider::Get()-> 1464 PermissionMessageProvider::Get()->
1433 GetPermissionMessages(permissions, Manifest::TYPE_EXTENSION); 1465 GetPermissionMessages(permissions, Manifest::TYPE_EXTENSION);
1434 } 1466 }
1435 1467
1436 TEST(PermissionsTest, IsPrivilegeIncrease_DeclarativeWebRequest) { 1468 TEST(PermissionsTest, IsPrivilegeIncrease_DeclarativeWebRequest) {
1437 scoped_refptr<Extension> extension( 1469 scoped_refptr<Extension> extension(
1438 LoadManifest("permissions", "permissions_all_urls.json")); 1470 LoadManifest("permissions", "permissions_all_urls.json"));
1439 scoped_refptr<const PermissionSet> permissions( 1471 scoped_refptr<const PermissionSet> permissions(
1440 extension->GetActivePermissions()); 1472 extension->GetActivePermissions());
1441 1473
1442 scoped_refptr<Extension> extension_dwr( 1474 scoped_refptr<Extension> extension_dwr(
1443 LoadManifest("permissions", "web_request_all_host_permissions.json")); 1475 LoadManifest("permissions", "web_request_all_host_permissions.json"));
1444 scoped_refptr<const PermissionSet> permissions_dwr( 1476 scoped_refptr<const PermissionSet> permissions_dwr(
1445 extension_dwr->GetActivePermissions()); 1477 extension_dwr->GetActivePermissions());
1446 1478
1447 EXPECT_FALSE(PermissionMessageProvider::Get()-> 1479 EXPECT_FALSE(PermissionMessageProvider::Get()->
1448 IsPrivilegeIncrease(permissions.get(), 1480 IsPrivilegeIncrease(permissions.get(),
1449 permissions_dwr.get(), 1481 permissions_dwr.get(),
1450 extension->GetType())); 1482 extension->GetType()));
1451 } 1483 }
1452 1484
1453 } // namespace extensions 1485 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698