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

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

Issue 15836003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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) 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/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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 EXPECT_EQ(APIPermission::kUnlimitedStorage, 118 EXPECT_EQ(APIPermission::kUnlimitedStorage,
119 info->GetByName("unlimited_storage")->id()); 119 info->GetByName("unlimited_storage")->id());
120 } 120 }
121 121
122 TEST(PermissionsTest, EffectiveHostPermissions) { 122 TEST(PermissionsTest, EffectiveHostPermissions) {
123 scoped_refptr<Extension> extension; 123 scoped_refptr<Extension> extension;
124 scoped_refptr<const PermissionSet> permissions; 124 scoped_refptr<const PermissionSet> permissions;
125 125
126 extension = LoadManifest("effective_host_permissions", "empty.json"); 126 extension = LoadManifest("effective_host_permissions", "empty.json");
127 permissions = extension->GetActivePermissions(); 127 permissions = extension->GetActivePermissions();
128 EXPECT_EQ( 128 EXPECT_EQ(0u,
129 0u, 129 PermissionsData::GetEffectiveHostPermissions(extension.get())
130 PermissionsData::GetEffectiveHostPermissions( 130 .patterns().size());
131 extension).patterns().size()); 131 EXPECT_FALSE(
132 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( 132 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com")));
133 GURL("http://www.google.com")));
134 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 133 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
135 134
136 extension = LoadManifest("effective_host_permissions", "one_host.json"); 135 extension = LoadManifest("effective_host_permissions", "one_host.json");
137 permissions = extension->GetActivePermissions(); 136 permissions = extension->GetActivePermissions();
138 EXPECT_TRUE(permissions->HasEffectiveAccessToURL( 137 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(
139 GURL("http://www.google.com"))); 138 GURL("http://www.google.com")));
140 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( 139 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(
141 GURL("https://www.google.com"))); 140 GURL("https://www.google.com")));
142 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 141 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
143 142
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 expected_apis.insert(APIPermission::kBackground); 262 expected_apis.insert(APIPermission::kBackground);
264 expected_apis.insert(permission); 263 expected_apis.insert(permission);
265 264
266 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 265 AddPattern(&explicit_hosts1, "http://*.google.com/*");
267 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); 266 AddPattern(&expected_explicit_hosts, "http://*.google.com/*");
268 AddPattern(&effective_hosts, "http://*.google.com/*"); 267 AddPattern(&effective_hosts, "http://*.google.com/*");
269 268
270 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); 269 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1);
271 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 270 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
272 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); 271 union_set = PermissionSet::CreateUnion(set1.get(), set2.get());
273 EXPECT_TRUE(set1->Contains(*set2)); 272 EXPECT_TRUE(set1->Contains(*set2.get()));
274 EXPECT_TRUE(set1->Contains(*union_set)); 273 EXPECT_TRUE(set1->Contains(*union_set.get()));
275 EXPECT_FALSE(set2->Contains(*set1)); 274 EXPECT_FALSE(set2->Contains(*set1.get()));
276 EXPECT_FALSE(set2->Contains(*union_set)); 275 EXPECT_FALSE(set2->Contains(*union_set.get()));
277 EXPECT_TRUE(union_set->Contains(*set1)); 276 EXPECT_TRUE(union_set->Contains(*set1.get()));
278 EXPECT_TRUE(union_set->Contains(*set2)); 277 EXPECT_TRUE(union_set->Contains(*set2.get()));
279 278
280 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); 279 EXPECT_FALSE(union_set->HasEffectiveFullAccess());
281 EXPECT_EQ(expected_apis, union_set->apis()); 280 EXPECT_EQ(expected_apis, union_set->apis());
282 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); 281 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
283 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); 282 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
284 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts()); 283 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts());
285 284
286 // Now use a real second set. 285 // Now use a real second set.
287 apis2.insert(APIPermission::kTab); 286 apis2.insert(APIPermission::kTab);
288 apis2.insert(APIPermission::kProxy); 287 apis2.insert(APIPermission::kProxy);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 322 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
324 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); 323 AddPattern(&expected_explicit_hosts, "http://*.example.com/*");
325 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); 324 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*");
326 325
327 URLPatternSet::CreateUnion( 326 URLPatternSet::CreateUnion(
328 explicit_hosts2, scriptable_hosts2, &effective_hosts); 327 explicit_hosts2, scriptable_hosts2, &effective_hosts);
329 328
330 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 329 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
331 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); 330 union_set = PermissionSet::CreateUnion(set1.get(), set2.get());
332 331
333 EXPECT_FALSE(set1->Contains(*set2)); 332 EXPECT_FALSE(set1->Contains(*set2.get()));
334 EXPECT_FALSE(set1->Contains(*union_set)); 333 EXPECT_FALSE(set1->Contains(*union_set.get()));
335 EXPECT_FALSE(set2->Contains(*set1)); 334 EXPECT_FALSE(set2->Contains(*set1.get()));
336 EXPECT_FALSE(set2->Contains(*union_set)); 335 EXPECT_FALSE(set2->Contains(*union_set.get()));
337 EXPECT_TRUE(union_set->Contains(*set1)); 336 EXPECT_TRUE(union_set->Contains(*set1.get()));
338 EXPECT_TRUE(union_set->Contains(*set2)); 337 EXPECT_TRUE(union_set->Contains(*set2.get()));
339 338
340 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); 339 EXPECT_TRUE(union_set->HasEffectiveFullAccess());
341 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); 340 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts());
342 EXPECT_EQ(expected_apis, union_set->apis()); 341 EXPECT_EQ(expected_apis, union_set->apis());
343 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); 342 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
344 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); 343 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
345 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); 344 EXPECT_EQ(effective_hosts, union_set->effective_hosts());
346 } 345 }
347 346
348 TEST(PermissionsTest, CreateIntersection) { 347 TEST(PermissionsTest, CreateIntersection) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 382 }
384 } 383 }
385 apis1.insert(permission); 384 apis1.insert(permission);
386 385
387 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 386 AddPattern(&explicit_hosts1, "http://*.google.com/*");
388 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); 387 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*");
389 388
390 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); 389 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1);
391 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 390 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
392 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); 391 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get());
393 EXPECT_TRUE(set1->Contains(*new_set)); 392 EXPECT_TRUE(set1->Contains(*new_set.get()));
394 EXPECT_TRUE(set2->Contains(*new_set)); 393 EXPECT_TRUE(set2->Contains(*new_set.get()));
395 EXPECT_TRUE(set1->Contains(*set2)); 394 EXPECT_TRUE(set1->Contains(*set2.get()));
396 EXPECT_FALSE(set2->Contains(*set1)); 395 EXPECT_FALSE(set2->Contains(*set1.get()));
397 EXPECT_FALSE(new_set->Contains(*set1)); 396 EXPECT_FALSE(new_set->Contains(*set1.get()));
398 EXPECT_TRUE(new_set->Contains(*set2)); 397 EXPECT_TRUE(new_set->Contains(*set2.get()));
399 398
400 EXPECT_TRUE(new_set->IsEmpty()); 399 EXPECT_TRUE(new_set->IsEmpty());
401 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); 400 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
402 EXPECT_EQ(expected_apis, new_set->apis()); 401 EXPECT_EQ(expected_apis, new_set->apis());
403 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); 402 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
404 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); 403 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
405 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts()); 404 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts());
406 405
407 // Now use a real second set. 406 // Now use a real second set.
408 apis2.insert(APIPermission::kTab); 407 apis2.insert(APIPermission::kTab);
(...skipping 28 matching lines...) Expand all
437 AddPattern(&explicit_hosts2, "http://*.google.com/*"); 436 AddPattern(&explicit_hosts2, "http://*.google.com/*");
438 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 437 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
439 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); 438 AddPattern(&expected_explicit_hosts, "http://*.google.com/*");
440 439
441 effective_hosts.ClearPatterns(); 440 effective_hosts.ClearPatterns();
442 AddPattern(&effective_hosts, "http://*.google.com/*"); 441 AddPattern(&effective_hosts, "http://*.google.com/*");
443 442
444 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 443 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
445 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); 444 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get());
446 445
447 EXPECT_TRUE(set1->Contains(*new_set)); 446 EXPECT_TRUE(set1->Contains(*new_set.get()));
448 EXPECT_TRUE(set2->Contains(*new_set)); 447 EXPECT_TRUE(set2->Contains(*new_set.get()));
449 EXPECT_FALSE(set1->Contains(*set2)); 448 EXPECT_FALSE(set1->Contains(*set2.get()));
450 EXPECT_FALSE(set2->Contains(*set1)); 449 EXPECT_FALSE(set2->Contains(*set1.get()));
451 EXPECT_FALSE(new_set->Contains(*set1)); 450 EXPECT_FALSE(new_set->Contains(*set1.get()));
452 EXPECT_FALSE(new_set->Contains(*set2)); 451 EXPECT_FALSE(new_set->Contains(*set2.get()));
453 452
454 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); 453 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
455 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); 454 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts());
456 EXPECT_EQ(expected_apis, new_set->apis()); 455 EXPECT_EQ(expected_apis, new_set->apis());
457 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); 456 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
458 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); 457 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
459 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); 458 EXPECT_EQ(effective_hosts, new_set->effective_hosts());
460 } 459 }
461 460
462 TEST(PermissionsTest, CreateDifference) { 461 TEST(PermissionsTest, CreateDifference) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 496 }
498 } 497 }
499 apis1.insert(permission); 498 apis1.insert(permission);
500 499
501 AddPattern(&explicit_hosts1, "http://*.google.com/*"); 500 AddPattern(&explicit_hosts1, "http://*.google.com/*");
502 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); 501 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*");
503 502
504 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); 503 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1);
505 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 504 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
506 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); 505 new_set = PermissionSet::CreateDifference(set1.get(), set2.get());
507 EXPECT_EQ(*set1, *new_set); 506 EXPECT_EQ(*set1.get(), *new_set.get());
508 507
509 // Now use a real second set. 508 // Now use a real second set.
510 apis2.insert(APIPermission::kTab); 509 apis2.insert(APIPermission::kTab);
511 apis2.insert(APIPermission::kProxy); 510 apis2.insert(APIPermission::kProxy);
512 apis2.insert(APIPermission::kClipboardWrite); 511 apis2.insert(APIPermission::kClipboardWrite);
513 apis2.insert(APIPermission::kPlugin); 512 apis2.insert(APIPermission::kPlugin);
514 permission = permission_info->CreateAPIPermission(); 513 permission = permission_info->CreateAPIPermission();
515 { 514 {
516 scoped_ptr<ListValue> value(new ListValue()); 515 scoped_ptr<ListValue> value(new ListValue());
517 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); 516 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80"));
(...skipping 20 matching lines...) Expand all
538 AddPattern(&explicit_hosts2, "http://*.google.com/*"); 537 AddPattern(&explicit_hosts2, "http://*.google.com/*");
539 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); 538 AddPattern(&scriptable_hosts2, "http://*.google.com/*");
540 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); 539 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*");
541 540
542 effective_hosts.ClearPatterns(); 541 effective_hosts.ClearPatterns();
543 AddPattern(&effective_hosts, "http://www.reddit.com/*"); 542 AddPattern(&effective_hosts, "http://www.reddit.com/*");
544 543
545 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); 544 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2);
546 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); 545 new_set = PermissionSet::CreateDifference(set1.get(), set2.get());
547 546
548 EXPECT_TRUE(set1->Contains(*new_set)); 547 EXPECT_TRUE(set1->Contains(*new_set.get()));
549 EXPECT_FALSE(set2->Contains(*new_set)); 548 EXPECT_FALSE(set2->Contains(*new_set.get()));
550 549
551 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); 550 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
552 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); 551 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts());
553 EXPECT_EQ(expected_apis, new_set->apis()); 552 EXPECT_EQ(expected_apis, new_set->apis());
554 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); 553 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
555 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); 554 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
556 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); 555 EXPECT_EQ(effective_hosts, new_set->effective_hosts());
557 556
558 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set 557 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set
559 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get()); 558 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json"; 599 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json";
601 if (!new_extension.get()) 600 if (!new_extension.get())
602 continue; 601 continue;
603 602
604 scoped_refptr<const PermissionSet> old_p( 603 scoped_refptr<const PermissionSet> old_p(
605 old_extension->GetActivePermissions()); 604 old_extension->GetActivePermissions());
606 scoped_refptr<const PermissionSet> new_p( 605 scoped_refptr<const PermissionSet> new_p(
607 new_extension->GetActivePermissions()); 606 new_extension->GetActivePermissions());
608 607
609 EXPECT_EQ(kTests[i].expect_increase, 608 EXPECT_EQ(kTests[i].expect_increase,
610 old_p->HasLessPrivilegesThan(new_p)) << kTests[i].base_name; 609 old_p->HasLessPrivilegesThan(new_p.get())) << kTests[i].base_name;
611 } 610 }
612 } 611 }
613 612
614 TEST(PermissionsTest, PermissionMessages) { 613 TEST(PermissionsTest, PermissionMessages) {
615 // Ensure that all permissions that needs to show install UI actually have 614 // Ensure that all permissions that needs to show install UI actually have
616 // strings associated with them. 615 // strings associated with them.
617 APIPermissionSet skip; 616 APIPermissionSet skip;
618 617
619 // These are considered "nuisance" or "trivial" permissions that don't need 618 // These are considered "nuisance" or "trivial" permissions that don't need
620 // a prompt. 619 // a prompt.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 EXPECT_EQ(kTests[i].expect_success, 806 EXPECT_EQ(kTests[i].expect_success,
808 empty->HasAnyAccessToAPI(kTests[i].api_name)); 807 empty->HasAnyAccessToAPI(kTests[i].api_name));
809 } 808 }
810 } 809 }
811 810
812 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { 811 TEST(PermissionsTest, GetWarningMessages_ManyHosts) {
813 scoped_refptr<Extension> extension; 812 scoped_refptr<Extension> extension;
814 813
815 extension = LoadManifest("permissions", "many-hosts.json"); 814 extension = LoadManifest("permissions", "many-hosts.json");
816 std::vector<string16> warnings = 815 std::vector<string16> warnings =
817 PermissionsData::GetPermissionMessageStrings(extension); 816 PermissionsData::GetPermissionMessageStrings(extension.get());
818 ASSERT_EQ(1u, warnings.size()); 817 ASSERT_EQ(1u, warnings.size());
819 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 818 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com",
820 UTF16ToUTF8(warnings[0])); 819 UTF16ToUTF8(warnings[0]));
821 } 820 }
822 821
823 TEST(PermissionsTest, GetWarningMessages_Plugins) { 822 TEST(PermissionsTest, GetWarningMessages_Plugins) {
824 scoped_refptr<Extension> extension; 823 scoped_refptr<Extension> extension;
825 scoped_refptr<PermissionSet> permissions; 824 scoped_refptr<PermissionSet> permissions;
826 825
827 extension = LoadManifest("permissions", "plugins.json"); 826 extension = LoadManifest("permissions", "plugins.json");
828 std::vector<string16> warnings = 827 std::vector<string16> warnings =
829 PermissionsData::GetPermissionMessageStrings(extension); 828 PermissionsData::GetPermissionMessageStrings(extension.get());
830 // We don't parse the plugins key on Chrome OS, so it should not ask for any 829 // We don't parse the plugins key on Chrome OS, so it should not ask for any
831 // permissions. 830 // permissions.
832 #if defined(OS_CHROMEOS) 831 #if defined(OS_CHROMEOS)
833 ASSERT_EQ(0u, warnings.size()); 832 ASSERT_EQ(0u, warnings.size());
834 #else 833 #else
835 ASSERT_EQ(1u, warnings.size()); 834 ASSERT_EQ(1u, warnings.size());
836 EXPECT_EQ("Access all data on your computer and the websites you visit", 835 EXPECT_EQ("Access all data on your computer and the websites you visit",
837 UTF16ToUTF8(warnings[0])); 836 UTF16ToUTF8(warnings[0]));
838 #endif 837 #endif
839 } 838 }
840 839
(...skipping 30 matching lines...) Expand all
871 EXPECT_TRUE(Contains(warnings, "Use your camera")); 870 EXPECT_TRUE(Contains(warnings, "Use your camera"));
872 } 871 }
873 872
874 TEST(PermissionsTest, GetWarningMessages_Serial) { 873 TEST(PermissionsTest, GetWarningMessages_Serial) {
875 scoped_refptr<Extension> extension = 874 scoped_refptr<Extension> extension =
876 LoadManifest("permissions", "serial.json"); 875 LoadManifest("permissions", "serial.json");
877 876
878 EXPECT_TRUE(extension->is_platform_app()); 877 EXPECT_TRUE(extension->is_platform_app());
879 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); 878 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial));
880 std::vector<string16> warnings = 879 std::vector<string16> warnings =
881 PermissionsData::GetPermissionMessageStrings(extension); 880 PermissionsData::GetPermissionMessageStrings(extension.get());
882 EXPECT_TRUE(Contains(warnings, 881 EXPECT_TRUE(
883 "Use serial devices attached to your computer")); 882 Contains(warnings, "Use serial devices attached to your computer"));
884 ASSERT_EQ(1u, warnings.size()); 883 ASSERT_EQ(1u, warnings.size());
885 } 884 }
886 885
887 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { 886 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) {
888 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 887 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
889 888
890 scoped_refptr<Extension> extension = 889 scoped_refptr<Extension> extension =
891 LoadManifest("permissions", "socket_any_host.json"); 890 LoadManifest("permissions", "socket_any_host.json");
892 EXPECT_TRUE(extension->is_platform_app()); 891 EXPECT_TRUE(extension->is_platform_app());
893 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 892 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
894 std::vector<string16> warnings = 893 std::vector<string16> warnings =
895 PermissionsData::GetPermissionMessageStrings(extension); 894 PermissionsData::GetPermissionMessageStrings(extension.get());
896 EXPECT_EQ(1u, warnings.size()); 895 EXPECT_EQ(1u, warnings.size());
897 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " 896 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer "
898 "on the local network or internet")); 897 "on the local network or internet"));
899 } 898 }
900 899
901 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { 900 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) {
902 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 901 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
903 902
904 scoped_refptr<Extension> extension = 903 scoped_refptr<Extension> extension =
905 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); 904 LoadManifest("permissions", "socket_one_domain_two_hostnames.json");
906 EXPECT_TRUE(extension->is_platform_app()); 905 EXPECT_TRUE(extension->is_platform_app());
907 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 906 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
908 std::vector<string16> warnings = 907 std::vector<string16> warnings =
909 PermissionsData::GetPermissionMessageStrings(extension); 908 PermissionsData::GetPermissionMessageStrings(extension.get());
910 909
911 // Verify the warnings, including support for unicode characters, the fact 910 // Verify the warnings, including support for unicode characters, the fact
912 // that domain host warnings come before specific host warnings, and the fact 911 // that domain host warnings come before specific host warnings, and the fact
913 // that domains and hostnames are in alphabetical order regardless of the 912 // that domains and hostnames are in alphabetical order regardless of the
914 // order in the manifest file. 913 // order in the manifest file.
915 EXPECT_EQ(2u, warnings.size()); 914 EXPECT_EQ(2u, warnings.size());
916 if (warnings.size() > 0) 915 if (warnings.size() > 0)
917 EXPECT_EQ(warnings[0], 916 EXPECT_EQ(warnings[0],
918 UTF8ToUTF16("Exchange data with any computer in the domain " 917 UTF8ToUTF16("Exchange data with any computer in the domain "
919 "example.org")); 918 "example.org"));
920 if (warnings.size() > 1) 919 if (warnings.size() > 1)
921 EXPECT_EQ(warnings[1], 920 EXPECT_EQ(warnings[1],
922 UTF8ToUTF16("Exchange data with the computers named: " 921 UTF8ToUTF16("Exchange data with the computers named: "
923 "b\xC3\xA5r.example.com foo.example.com")); 922 "b\xC3\xA5r.example.com foo.example.com"));
924 // "\xC3\xA5" = UTF-8 for lowercase A with ring above 923 // "\xC3\xA5" = UTF-8 for lowercase A with ring above
925 } 924 }
926 925
927 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { 926 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) {
928 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); 927 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
929 928
930 scoped_refptr<Extension> extension = 929 scoped_refptr<Extension> extension =
931 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); 930 LoadManifest("permissions", "socket_two_domains_one_hostname.json");
932 EXPECT_TRUE(extension->is_platform_app()); 931 EXPECT_TRUE(extension->is_platform_app());
933 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 932 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
934 std::vector<string16> warnings = 933 std::vector<string16> warnings =
935 PermissionsData::GetPermissionMessageStrings(extension); 934 PermissionsData::GetPermissionMessageStrings(extension.get());
936 935
937 // Verify the warnings, including the fact that domain host warnings come 936 // Verify the warnings, including the fact that domain host warnings come
938 // before specific host warnings and the fact that domains and hostnames are 937 // before specific host warnings and the fact that domains and hostnames are
939 // in alphabetical order regardless of the order in the manifest file. 938 // in alphabetical order regardless of the order in the manifest file.
940 EXPECT_EQ(2u, warnings.size()); 939 EXPECT_EQ(2u, warnings.size());
941 if (warnings.size() > 0) 940 if (warnings.size() > 0)
942 EXPECT_EQ(warnings[0], 941 EXPECT_EQ(warnings[0],
943 UTF8ToUTF16("Exchange data with any computer in the domains: " 942 UTF8ToUTF16("Exchange data with any computer in the domains: "
944 "example.com foo.example.org")); 943 "example.com foo.example.org"));
945 if (warnings.size() > 1) 944 if (warnings.size() > 1)
946 EXPECT_EQ(warnings[1], 945 EXPECT_EQ(warnings[1],
947 UTF8ToUTF16("Exchange data with the computer named " 946 UTF8ToUTF16("Exchange data with the computer named "
948 "bar.example.org")); 947 "bar.example.org"));
949 } 948 }
950 949
951 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { 950 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) {
952 scoped_refptr<Extension> extension; 951 scoped_refptr<Extension> extension;
953 952
954 extension = LoadManifest("permissions", "platform_app_hosts.json"); 953 extension = LoadManifest("permissions", "platform_app_hosts.json");
955 EXPECT_TRUE(extension->is_platform_app()); 954 EXPECT_TRUE(extension->is_platform_app());
956 std::vector<string16> warnings = 955 std::vector<string16> warnings =
957 PermissionsData::GetPermissionMessageStrings(extension); 956 PermissionsData::GetPermissionMessageStrings(extension.get());
958 ASSERT_EQ(0u, warnings.size()); 957 ASSERT_EQ(0u, warnings.size());
959 958
960 extension = LoadManifest("permissions", "platform_app_all_urls.json"); 959 extension = LoadManifest("permissions", "platform_app_all_urls.json");
961 EXPECT_TRUE(extension->is_platform_app()); 960 EXPECT_TRUE(extension->is_platform_app());
962 warnings = PermissionsData::GetPermissionMessageStrings(extension); 961 warnings = PermissionsData::GetPermissionMessageStrings(extension.get());
963 ASSERT_EQ(0u, warnings.size()); 962 ASSERT_EQ(0u, warnings.size());
964 } 963 }
965 964
966 TEST(PermissionsTest, GetDistinctHostsForDisplay) { 965 TEST(PermissionsTest, GetDistinctHostsForDisplay) {
967 scoped_refptr<PermissionSet> perm_set; 966 scoped_refptr<PermissionSet> perm_set;
968 APIPermissionSet empty_perms; 967 APIPermissionSet empty_perms;
969 std::set<std::string> expected; 968 std::set<std::string> expected;
970 expected.insert("www.foo.com"); 969 expected.insert("www.foo.com");
971 expected.insert("www.bar.com"); 970 expected.insert("www.bar.com");
972 expected.insert("www.baz.com"); 971 expected.insert("www.baz.com");
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 } 1346 }
1348 1347
1349 TEST(PermissionsTest, SyncFileSystemPermission) { 1348 TEST(PermissionsTest, SyncFileSystemPermission) {
1350 scoped_refptr<Extension> extension = LoadManifest( 1349 scoped_refptr<Extension> extension = LoadManifest(
1351 "permissions", "sync_file_system.json"); 1350 "permissions", "sync_file_system.json");
1352 APIPermissionSet apis; 1351 APIPermissionSet apis;
1353 apis.insert(APIPermission::kSyncFileSystem); 1352 apis.insert(APIPermission::kSyncFileSystem);
1354 EXPECT_TRUE(extension->is_platform_app()); 1353 EXPECT_TRUE(extension->is_platform_app());
1355 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); 1354 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem));
1356 std::vector<string16> warnings = 1355 std::vector<string16> warnings =
1357 PermissionsData::GetPermissionMessageStrings(extension); 1356 PermissionsData::GetPermissionMessageStrings(extension.get());
1358 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); 1357 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account"));
1359 ASSERT_EQ(1u, warnings.size()); 1358 ASSERT_EQ(1u, warnings.size());
1360 } 1359 }
1361 1360
1362 } // namespace extensions 1361 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/permissions/permission_set.cc ('k') | chrome/common/extensions/permissions/permissions_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698