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

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

Issue 12253022: Manifest handler for all keys background-related. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/background_info.h"
12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_manifest_constants.h" 14 #include "chrome/common/extensions/extension_manifest_constants.h"
14 #include "chrome/common/extensions/features/feature.h" 15 #include "chrome/common/extensions/features/feature.h"
15 #include "chrome/common/extensions/permissions/permission_set.h" 16 #include "chrome/common/extensions/permissions/permission_set.h"
16 #include "chrome/common/extensions/permissions/permissions_info.h" 17 #include "chrome/common/extensions/permissions/permissions_info.h"
17 #include "chrome/common/extensions/permissions/socket_permission.h" 18 #include "chrome/common/extensions/permissions/socket_permission.h"
18 #include "extensions/common/error_utils.h" 19 #include "extensions/common/error_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 using extensions::Extension; 22 using extensions::Extension;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 75
75 bool Contains(const std::vector<string16>& warnings, 76 bool Contains(const std::vector<string16>& warnings,
76 const std::string& warning) { 77 const std::string& warning) {
77 return IndexOf(warnings, warning) != warnings.size(); 78 return IndexOf(warnings, warning) != warnings.size();
78 } 79 }
79 80
80 } // namespace 81 } // namespace
81 82
82 83
83 class PermissionsTest : public testing::Test { 84 class PermissionsTest : public testing::Test {
85 virtual void SetUp() OVERRIDE {
86 std::vector<std::string> background_keys(BackgroundManifestHandler::keys());
87 linked_ptr<BackgroundManifestHandler> background_handler(
88 new BackgroundManifestHandler);
89 for (size_t i = 0; i < background_keys.size(); ++i)
90 ManifestHandler::Register(background_keys[i], background_handler);
91 }
84 }; 92 };
85 93
86 // Tests GetByID. 94 // Tests GetByID.
87 TEST(PermissionsTest, GetByID) { 95 TEST_F(PermissionsTest, GetByID) {
88 PermissionsInfo* info = PermissionsInfo::GetInstance(); 96 PermissionsInfo* info = PermissionsInfo::GetInstance();
89 APIPermissionSet apis = info->GetAll(); 97 APIPermissionSet apis = info->GetAll();
90 for (APIPermissionSet::const_iterator i = apis.begin(); 98 for (APIPermissionSet::const_iterator i = apis.begin();
91 i != apis.end(); ++i) { 99 i != apis.end(); ++i) {
92 EXPECT_EQ(i->id(), i->info()->id()); 100 EXPECT_EQ(i->id(), i->info()->id());
93 } 101 }
94 } 102 }
95 103
96 // Tests that GetByName works with normal permission names and aliases. 104 // Tests that GetByName works with normal permission names and aliases.
97 TEST(PermissionsTest, GetByName) { 105 TEST_F(PermissionsTest, GetByName) {
98 PermissionsInfo* info = PermissionsInfo::GetInstance(); 106 PermissionsInfo* info = PermissionsInfo::GetInstance();
99 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id()); 107 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id());
100 EXPECT_EQ(APIPermission::kManagement, 108 EXPECT_EQ(APIPermission::kManagement,
101 info->GetByName("management")->id()); 109 info->GetByName("management")->id());
102 EXPECT_FALSE(info->GetByName("alsdkfjasldkfj")); 110 EXPECT_FALSE(info->GetByName("alsdkfjasldkfj"));
103 } 111 }
104 112
105 TEST(PermissionsTest, GetAll) { 113 TEST_F(PermissionsTest, GetAll) {
106 size_t count = 0; 114 size_t count = 0;
107 PermissionsInfo* info = PermissionsInfo::GetInstance(); 115 PermissionsInfo* info = PermissionsInfo::GetInstance();
108 APIPermissionSet apis = info->GetAll(); 116 APIPermissionSet apis = info->GetAll();
109 for (APIPermissionSet::const_iterator api = apis.begin(); 117 for (APIPermissionSet::const_iterator api = apis.begin();
110 api != apis.end(); ++api) { 118 api != apis.end(); ++api) {
111 // Make sure only the valid permission IDs get returned. 119 // Make sure only the valid permission IDs get returned.
112 EXPECT_NE(APIPermission::kInvalid, api->id()); 120 EXPECT_NE(APIPermission::kInvalid, api->id());
113 EXPECT_NE(APIPermission::kUnknown, api->id()); 121 EXPECT_NE(APIPermission::kUnknown, api->id());
114 count++; 122 count++;
115 } 123 }
116 EXPECT_EQ(count, info->get_permission_count()); 124 EXPECT_EQ(count, info->get_permission_count());
117 } 125 }
118 126
119 TEST(PermissionsTest, GetAllByName) { 127 TEST_F(PermissionsTest, GetAllByName) {
120 std::set<std::string> names; 128 std::set<std::string> names;
121 names.insert("background"); 129 names.insert("background");
122 names.insert("management"); 130 names.insert("management");
123 131
124 // This is an alias of kTab 132 // This is an alias of kTab
125 names.insert("windows"); 133 names.insert("windows");
126 134
127 // This unknown name should get dropped. 135 // This unknown name should get dropped.
128 names.insert("sdlkfjasdlkfj"); 136 names.insert("sdlkfjasdlkfj");
129 137
130 APIPermissionSet expected; 138 APIPermissionSet expected;
131 expected.insert(APIPermission::kBackground); 139 expected.insert(APIPermission::kBackground);
132 expected.insert(APIPermission::kManagement); 140 expected.insert(APIPermission::kManagement);
133 expected.insert(APIPermission::kTab); 141 expected.insert(APIPermission::kTab);
134 142
135 EXPECT_EQ(expected, 143 EXPECT_EQ(expected,
136 PermissionsInfo::GetInstance()->GetAllByName(names)); 144 PermissionsInfo::GetInstance()->GetAllByName(names));
137 } 145 }
138 146
139 // Tests that the aliases are properly mapped. 147 // Tests that the aliases are properly mapped.
140 TEST(PermissionsTest, Aliases) { 148 TEST_F(PermissionsTest, Aliases) {
141 PermissionsInfo* info = PermissionsInfo::GetInstance(); 149 PermissionsInfo* info = PermissionsInfo::GetInstance();
142 // tabs: tabs, windows 150 // tabs: tabs, windows
143 std::string tabs_name = "tabs"; 151 std::string tabs_name = "tabs";
144 EXPECT_EQ(tabs_name, info->GetByID(APIPermission::kTab)->name()); 152 EXPECT_EQ(tabs_name, info->GetByID(APIPermission::kTab)->name());
145 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id()); 153 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id());
146 EXPECT_EQ(APIPermission::kTab, info->GetByName("windows")->id()); 154 EXPECT_EQ(APIPermission::kTab, info->GetByName("windows")->id());
147 155
148 // unlimitedStorage: unlimitedStorage, unlimited_storage 156 // unlimitedStorage: unlimitedStorage, unlimited_storage
149 std::string storage_name = "unlimitedStorage"; 157 std::string storage_name = "unlimitedStorage";
150 EXPECT_EQ(storage_name, info->GetByID( 158 EXPECT_EQ(storage_name, info->GetByID(
151 APIPermission::kUnlimitedStorage)->name()); 159 APIPermission::kUnlimitedStorage)->name());
152 EXPECT_EQ(APIPermission::kUnlimitedStorage, 160 EXPECT_EQ(APIPermission::kUnlimitedStorage,
153 info->GetByName("unlimitedStorage")->id()); 161 info->GetByName("unlimitedStorage")->id());
154 EXPECT_EQ(APIPermission::kUnlimitedStorage, 162 EXPECT_EQ(APIPermission::kUnlimitedStorage,
155 info->GetByName("unlimited_storage")->id()); 163 info->GetByName("unlimited_storage")->id());
156 } 164 }
157 165
158 TEST(PermissionsTest, EffectiveHostPermissions) { 166 TEST_F(PermissionsTest, EffectiveHostPermissions) {
159 scoped_refptr<Extension> extension; 167 scoped_refptr<Extension> extension;
160 scoped_refptr<const PermissionSet> permissions; 168 scoped_refptr<const PermissionSet> permissions;
161 169
162 extension = LoadManifest("effective_host_permissions", "empty.json"); 170 extension = LoadManifest("effective_host_permissions", "empty.json");
163 permissions = extension->GetActivePermissions(); 171 permissions = extension->GetActivePermissions();
164 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); 172 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size());
165 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( 173 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(
166 GURL("http://www.google.com"))); 174 GURL("http://www.google.com")));
167 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); 175 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts());
168 176
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 232
225 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); 233 extension = LoadManifest("effective_host_permissions", "all_hosts3.json");
226 permissions = extension->GetActivePermissions(); 234 permissions = extension->GetActivePermissions();
227 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); 235 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/")));
228 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); 236 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/")));
229 EXPECT_TRUE( 237 EXPECT_TRUE(
230 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); 238 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com")));
231 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); 239 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
232 } 240 }
233 241
234 TEST(PermissionsTest, ExplicitAccessToOrigin) { 242 TEST_F(PermissionsTest, ExplicitAccessToOrigin) {
235 APIPermissionSet apis; 243 APIPermissionSet apis;
236 URLPatternSet explicit_hosts; 244 URLPatternSet explicit_hosts;
237 URLPatternSet scriptable_hosts; 245 URLPatternSet scriptable_hosts;
238 246
239 AddPattern(&explicit_hosts, "http://*.google.com/*"); 247 AddPattern(&explicit_hosts, "http://*.google.com/*");
240 // The explicit host paths should get set to /*. 248 // The explicit host paths should get set to /*.
241 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*"); 249 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*");
242 250
243 scoped_refptr<PermissionSet> perm_set = new PermissionSet( 251 scoped_refptr<PermissionSet> perm_set = new PermissionSet(
244 apis, explicit_hosts, scriptable_hosts); 252 apis, explicit_hosts, scriptable_hosts);
245 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( 253 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
246 GURL("http://www.google.com/"))); 254 GURL("http://www.google.com/")));
247 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( 255 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
248 GURL("http://test.google.com/"))); 256 GURL("http://test.google.com/")));
249 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( 257 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin(
250 GURL("http://www.example.com"))); 258 GURL("http://www.example.com")));
251 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL( 259 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL(
252 GURL("http://www.example.com"))); 260 GURL("http://www.example.com")));
253 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin( 261 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin(
254 GURL("http://test.example.com"))); 262 GURL("http://test.example.com")));
255 } 263 }
256 264
257 TEST(PermissionsTest, CreateUnion) { 265 TEST_F(PermissionsTest, CreateUnion) {
258 APIPermission* permission = NULL; 266 APIPermission* permission = NULL;
259 267
260 APIPermissionSet apis1; 268 APIPermissionSet apis1;
261 APIPermissionSet apis2; 269 APIPermissionSet apis2;
262 APIPermissionSet expected_apis; 270 APIPermissionSet expected_apis;
263 271
264 URLPatternSet explicit_hosts1; 272 URLPatternSet explicit_hosts1;
265 URLPatternSet explicit_hosts2; 273 URLPatternSet explicit_hosts2;
266 URLPatternSet expected_explicit_hosts; 274 URLPatternSet expected_explicit_hosts;
267 275
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 EXPECT_TRUE(union_set->Contains(*set2)); 379 EXPECT_TRUE(union_set->Contains(*set2));
372 380
373 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); 381 EXPECT_TRUE(union_set->HasEffectiveFullAccess());
374 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); 382 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts());
375 EXPECT_EQ(expected_apis, union_set->apis()); 383 EXPECT_EQ(expected_apis, union_set->apis());
376 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); 384 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts());
377 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); 385 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts());
378 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); 386 EXPECT_EQ(effective_hosts, union_set->effective_hosts());
379 } 387 }
380 388
381 TEST(PermissionsTest, CreateIntersection) { 389 TEST_F(PermissionsTest, CreateIntersection) {
382 APIPermission* permission = NULL; 390 APIPermission* permission = NULL;
383 391
384 APIPermissionSet apis1; 392 APIPermissionSet apis1;
385 APIPermissionSet apis2; 393 APIPermissionSet apis2;
386 APIPermissionSet expected_apis; 394 APIPermissionSet expected_apis;
387 395
388 URLPatternSet explicit_hosts1; 396 URLPatternSet explicit_hosts1;
389 URLPatternSet explicit_hosts2; 397 URLPatternSet explicit_hosts2;
390 URLPatternSet expected_explicit_hosts; 398 URLPatternSet expected_explicit_hosts;
391 399
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 EXPECT_FALSE(new_set->Contains(*set2)); 493 EXPECT_FALSE(new_set->Contains(*set2));
486 494
487 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); 495 EXPECT_FALSE(new_set->HasEffectiveFullAccess());
488 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); 496 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts());
489 EXPECT_EQ(expected_apis, new_set->apis()); 497 EXPECT_EQ(expected_apis, new_set->apis());
490 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); 498 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
491 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); 499 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
492 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); 500 EXPECT_EQ(effective_hosts, new_set->effective_hosts());
493 } 501 }
494 502
495 TEST(PermissionsTest, CreateDifference) { 503 TEST_F(PermissionsTest, CreateDifference) {
496 APIPermission* permission = NULL; 504 APIPermission* permission = NULL;
497 505
498 APIPermissionSet apis1; 506 APIPermissionSet apis1;
499 APIPermissionSet apis2; 507 APIPermissionSet apis2;
500 APIPermissionSet expected_apis; 508 APIPermissionSet expected_apis;
501 509
502 URLPatternSet explicit_hosts1; 510 URLPatternSet explicit_hosts1;
503 URLPatternSet explicit_hosts2; 511 URLPatternSet explicit_hosts2;
504 URLPatternSet expected_explicit_hosts; 512 URLPatternSet expected_explicit_hosts;
505 513
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 EXPECT_EQ(expected_apis, new_set->apis()); 594 EXPECT_EQ(expected_apis, new_set->apis());
587 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); 595 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts());
588 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); 596 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts());
589 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); 597 EXPECT_EQ(effective_hosts, new_set->effective_hosts());
590 598
591 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set 599 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set
592 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get()); 600 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get());
593 EXPECT_TRUE(set1->IsEmpty()); 601 EXPECT_TRUE(set1->IsEmpty());
594 } 602 }
595 603
596 TEST(PermissionsTest, HasLessPrivilegesThan) { 604 TEST_F(PermissionsTest, HasLessPrivilegesThan) {
597 const struct { 605 const struct {
598 const char* base_name; 606 const char* base_name;
599 bool expect_increase; 607 bool expect_increase;
600 } kTests[] = { 608 } kTests[] = {
601 { "allhosts1", false }, // all -> all 609 { "allhosts1", false }, // all -> all
602 { "allhosts2", false }, // all -> one 610 { "allhosts2", false }, // all -> one
603 { "allhosts3", true }, // one -> all 611 { "allhosts3", true }, // one -> all
604 { "hosts1", false }, // http://a,http://b -> http://a,http://b 612 { "hosts1", false }, // http://a,http://b -> http://a,http://b
605 { "hosts2", true }, // http://a,http://b -> https://a,http://*.b 613 { "hosts2", true }, // http://a,http://b -> https://a,http://*.b
606 { "hosts3", false }, // http://a,http://b -> http://a 614 { "hosts3", false }, // http://a,http://b -> http://a
(...skipping 30 matching lines...) Expand all
637 scoped_refptr<const PermissionSet> old_p( 645 scoped_refptr<const PermissionSet> old_p(
638 old_extension->GetActivePermissions()); 646 old_extension->GetActivePermissions());
639 scoped_refptr<const PermissionSet> new_p( 647 scoped_refptr<const PermissionSet> new_p(
640 new_extension->GetActivePermissions()); 648 new_extension->GetActivePermissions());
641 649
642 EXPECT_EQ(kTests[i].expect_increase, 650 EXPECT_EQ(kTests[i].expect_increase,
643 old_p->HasLessPrivilegesThan(new_p)) << kTests[i].base_name; 651 old_p->HasLessPrivilegesThan(new_p)) << kTests[i].base_name;
644 } 652 }
645 } 653 }
646 654
647 TEST(PermissionsTest, PermissionMessages) { 655 TEST_F(PermissionsTest, PermissionMessages) {
648 // Ensure that all permissions that needs to show install UI actually have 656 // Ensure that all permissions that needs to show install UI actually have
649 // strings associated with them. 657 // strings associated with them.
650 APIPermissionSet skip; 658 APIPermissionSet skip;
651 659
652 // These are considered "nuisance" or "trivial" permissions that don't need 660 // These are considered "nuisance" or "trivial" permissions that don't need
653 // a prompt. 661 // a prompt.
654 skip.insert(APIPermission::kActiveTab); 662 skip.insert(APIPermission::kActiveTab);
655 skip.insert(APIPermission::kAlarms); 663 skip.insert(APIPermission::kAlarms);
656 skip.insert(APIPermission::kAppCurrentWindowInternal); 664 skip.insert(APIPermission::kAppCurrentWindowInternal);
657 skip.insert(APIPermission::kAppNotifications); 665 skip.insert(APIPermission::kAppNotifications);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 EXPECT_EQ(PermissionMessage::kNone, permission_info->message_id()) 764 EXPECT_EQ(PermissionMessage::kNone, permission_info->message_id())
757 << "unexpected message_id for " << permission_info->name(); 765 << "unexpected message_id for " << permission_info->name();
758 } else { 766 } else {
759 EXPECT_NE(PermissionMessage::kNone, permission_info->message_id()) 767 EXPECT_NE(PermissionMessage::kNone, permission_info->message_id())
760 << "missing message_id for " << permission_info->name(); 768 << "missing message_id for " << permission_info->name();
761 } 769 }
762 } 770 }
763 } 771 }
764 772
765 // Tests the default permissions (empty API permission set). 773 // Tests the default permissions (empty API permission set).
766 TEST(PermissionsTest, DefaultFunctionAccess) { 774 TEST_F(PermissionsTest, DefaultFunctionAccess) {
767 const struct { 775 const struct {
768 const char* permission_name; 776 const char* permission_name;
769 bool expect_success; 777 bool expect_success;
770 } kTests[] = { 778 } kTests[] = {
771 // Negative test. 779 // Negative test.
772 { "non_existing_permission", false }, 780 { "non_existing_permission", false },
773 // Test default module/package permission. 781 // Test default module/package permission.
774 { "browserAction", true }, 782 { "browserAction", true },
775 { "devtools", true }, 783 { "devtools", true },
776 { "extension", true }, 784 { "extension", true },
(...skipping 18 matching lines...) Expand all
795 803
796 scoped_refptr<PermissionSet> empty = new PermissionSet(); 804 scoped_refptr<PermissionSet> empty = new PermissionSet();
797 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 805 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
798 EXPECT_EQ(kTests[i].expect_success, 806 EXPECT_EQ(kTests[i].expect_success,
799 empty->HasAccessToFunction(kTests[i].permission_name, true)) 807 empty->HasAccessToFunction(kTests[i].permission_name, true))
800 << "Permission being tested: " << kTests[i].permission_name; 808 << "Permission being tested: " << kTests[i].permission_name;
801 } 809 }
802 } 810 }
803 811
804 // Tests the default permissions (empty API permission set). 812 // Tests the default permissions (empty API permission set).
805 TEST(PermissionsTest, DefaultAnyAPIAccess) { 813 TEST_F(PermissionsTest, DefaultAnyAPIAccess) {
806 const struct { 814 const struct {
807 const char* api_name; 815 const char* api_name;
808 bool expect_success; 816 bool expect_success;
809 } kTests[] = { 817 } kTests[] = {
810 // Negative test. 818 // Negative test.
811 { "non_existing_permission", false }, 819 { "non_existing_permission", false },
812 // Test default module/package permission. 820 // Test default module/package permission.
813 { "browserAction", true }, 821 { "browserAction", true },
814 { "devtools", true }, 822 { "devtools", true },
815 { "extension", true }, 823 { "extension", true },
(...skipping 10 matching lines...) Expand all
826 { "tabs", true}, 834 { "tabs", true},
827 }; 835 };
828 836
829 scoped_refptr<PermissionSet> empty = new PermissionSet(); 837 scoped_refptr<PermissionSet> empty = new PermissionSet();
830 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 838 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
831 EXPECT_EQ(kTests[i].expect_success, 839 EXPECT_EQ(kTests[i].expect_success,
832 empty->HasAnyAccessToAPI(kTests[i].api_name)); 840 empty->HasAnyAccessToAPI(kTests[i].api_name));
833 } 841 }
834 } 842 }
835 843
836 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { 844 TEST_F(PermissionsTest, GetWarningMessages_ManyHosts) {
837 scoped_refptr<Extension> extension; 845 scoped_refptr<Extension> extension;
838 846
839 extension = LoadManifest("permissions", "many-hosts.json"); 847 extension = LoadManifest("permissions", "many-hosts.json");
840 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 848 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
841 ASSERT_EQ(1u, warnings.size()); 849 ASSERT_EQ(1u, warnings.size());
842 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", 850 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com",
843 UTF16ToUTF8(warnings[0])); 851 UTF16ToUTF8(warnings[0]));
844 } 852 }
845 853
846 TEST(PermissionsTest, GetWarningMessages_Plugins) { 854 TEST_F(PermissionsTest, GetWarningMessages_Plugins) {
847 scoped_refptr<Extension> extension; 855 scoped_refptr<Extension> extension;
848 scoped_refptr<PermissionSet> permissions; 856 scoped_refptr<PermissionSet> permissions;
849 857
850 extension = LoadManifest("permissions", "plugins.json"); 858 extension = LoadManifest("permissions", "plugins.json");
851 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 859 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
852 // We don't parse the plugins key on Chrome OS, so it should not ask for any 860 // We don't parse the plugins key on Chrome OS, so it should not ask for any
853 // permissions. 861 // permissions.
854 #if defined(OS_CHROMEOS) 862 #if defined(OS_CHROMEOS)
855 ASSERT_EQ(0u, warnings.size()); 863 ASSERT_EQ(0u, warnings.size());
856 #else 864 #else
857 ASSERT_EQ(1u, warnings.size()); 865 ASSERT_EQ(1u, warnings.size());
858 EXPECT_EQ("Access all data on your computer and the websites you visit", 866 EXPECT_EQ("Access all data on your computer and the websites you visit",
859 UTF16ToUTF8(warnings[0])); 867 UTF16ToUTF8(warnings[0]));
860 #endif 868 #endif
861 } 869 }
862 870
863 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { 871 TEST_F(PermissionsTest, GetWarningMessages_AudioVideo) {
864 // Both audio and video present. 872 // Both audio and video present.
865 scoped_refptr<Extension> extension = 873 scoped_refptr<Extension> extension =
866 LoadManifest("permissions", "audio-video.json"); 874 LoadManifest("permissions", "audio-video.json");
867 PermissionSet* set = 875 PermissionSet* set =
868 const_cast<PermissionSet*>( 876 const_cast<PermissionSet*>(
869 extension->GetActivePermissions().get()); 877 extension->GetActivePermissions().get());
870 std::vector<string16> warnings = 878 std::vector<string16> warnings =
871 set->GetWarningMessages(extension->GetType()); 879 set->GetWarningMessages(extension->GetType());
872 EXPECT_FALSE(Contains(warnings, "Use your microphone")); 880 EXPECT_FALSE(Contains(warnings, "Use your microphone"));
873 EXPECT_FALSE(Contains(warnings, "Use your camera")); 881 EXPECT_FALSE(Contains(warnings, "Use your camera"));
(...skipping 12 matching lines...) Expand all
886 // Just video present. 894 // Just video present.
887 set->apis_.erase(APIPermission::kAudioCapture); 895 set->apis_.erase(APIPermission::kAudioCapture);
888 set->apis_.insert(APIPermission::kVideoCapture); 896 set->apis_.insert(APIPermission::kVideoCapture);
889 warnings = set->GetWarningMessages(extension->GetType()); 897 warnings = set->GetWarningMessages(extension->GetType());
890 EXPECT_EQ(combined_size, warnings.size()); 898 EXPECT_EQ(combined_size, warnings.size());
891 EXPECT_FALSE(Contains(warnings, "Use your microphone")); 899 EXPECT_FALSE(Contains(warnings, "Use your microphone"));
892 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); 900 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera"));
893 EXPECT_TRUE(Contains(warnings, "Use your camera")); 901 EXPECT_TRUE(Contains(warnings, "Use your camera"));
894 } 902 }
895 903
896 TEST(PermissionsTest, GetWarningMessages_Serial) { 904 TEST_F(PermissionsTest, GetWarningMessages_Serial) {
897 scoped_refptr<Extension> extension = 905 scoped_refptr<Extension> extension =
898 LoadManifest("permissions", "serial.json"); 906 LoadManifest("permissions", "serial.json");
899 907
900 EXPECT_TRUE(extension->is_platform_app()); 908 EXPECT_TRUE(extension->is_platform_app());
901 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); 909 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial));
902 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 910 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
903 EXPECT_TRUE(Contains(warnings, 911 EXPECT_TRUE(Contains(warnings,
904 "Use serial devices attached to your computer")); 912 "Use serial devices attached to your computer"));
905 ASSERT_EQ(1u, warnings.size()); 913 ASSERT_EQ(1u, warnings.size());
906 } 914 }
907 915
908 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { 916 TEST_F(PermissionsTest, GetWarningMessages_Socket_AnyHost) {
909 extensions::Feature::ScopedCurrentChannel channel( 917 extensions::Feature::ScopedCurrentChannel channel(
910 chrome::VersionInfo::CHANNEL_DEV); 918 chrome::VersionInfo::CHANNEL_DEV);
911 919
912 scoped_refptr<Extension> extension = 920 scoped_refptr<Extension> extension =
913 LoadManifest("permissions", "socket_any_host.json"); 921 LoadManifest("permissions", "socket_any_host.json");
914 EXPECT_TRUE(extension->is_platform_app()); 922 EXPECT_TRUE(extension->is_platform_app());
915 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 923 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
916 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 924 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
917 EXPECT_EQ(1u, warnings.size()); 925 EXPECT_EQ(1u, warnings.size());
918 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " 926 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer "
919 "on the local network or internet")); 927 "on the local network or internet"));
920 } 928 }
921 929
922 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { 930 TEST_F(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) {
923 extensions::Feature::ScopedCurrentChannel channel( 931 extensions::Feature::ScopedCurrentChannel channel(
924 chrome::VersionInfo::CHANNEL_DEV); 932 chrome::VersionInfo::CHANNEL_DEV);
925 933
926 scoped_refptr<Extension> extension = 934 scoped_refptr<Extension> extension =
927 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); 935 LoadManifest("permissions", "socket_one_domain_two_hostnames.json");
928 EXPECT_TRUE(extension->is_platform_app()); 936 EXPECT_TRUE(extension->is_platform_app());
929 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 937 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
930 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 938 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
931 939
932 // Verify the warnings, including support for unicode characters, the fact 940 // Verify the warnings, including support for unicode characters, the fact
933 // that domain host warnings come before specific host warnings, and the fact 941 // that domain host warnings come before specific host warnings, and the fact
934 // that domains and hostnames are in alphabetical order regardless of the 942 // that domains and hostnames are in alphabetical order regardless of the
935 // order in the manifest file. 943 // order in the manifest file.
936 EXPECT_EQ(2u, warnings.size()); 944 EXPECT_EQ(2u, warnings.size());
937 if (warnings.size() > 0) 945 if (warnings.size() > 0)
938 EXPECT_EQ(warnings[0], 946 EXPECT_EQ(warnings[0],
939 UTF8ToUTF16("Exchange data with any computer in the domain " 947 UTF8ToUTF16("Exchange data with any computer in the domain "
940 "example.org")); 948 "example.org"));
941 if (warnings.size() > 1) 949 if (warnings.size() > 1)
942 EXPECT_EQ(warnings[1], 950 EXPECT_EQ(warnings[1],
943 UTF8ToUTF16("Exchange data with the computers named: " 951 UTF8ToUTF16("Exchange data with the computers named: "
944 "b\xC3\xA5r.example.com foo.example.com")); 952 "b\xC3\xA5r.example.com foo.example.com"));
945 // "\xC3\xA5" = UTF-8 for lowercase A with ring above 953 // "\xC3\xA5" = UTF-8 for lowercase A with ring above
946 } 954 }
947 955
948 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { 956 TEST_F(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) {
949 extensions::Feature::ScopedCurrentChannel channel( 957 extensions::Feature::ScopedCurrentChannel channel(
950 chrome::VersionInfo::CHANNEL_DEV); 958 chrome::VersionInfo::CHANNEL_DEV);
951 959
952 scoped_refptr<Extension> extension = 960 scoped_refptr<Extension> extension =
953 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); 961 LoadManifest("permissions", "socket_two_domains_one_hostname.json");
954 EXPECT_TRUE(extension->is_platform_app()); 962 EXPECT_TRUE(extension->is_platform_app());
955 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); 963 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket));
956 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 964 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
957 965
958 // Verify the warnings, including the fact that domain host warnings come 966 // Verify the warnings, including the fact that domain host warnings come
959 // before specific host warnings and the fact that domains and hostnames are 967 // before specific host warnings and the fact that domains and hostnames are
960 // in alphabetical order regardless of the order in the manifest file. 968 // in alphabetical order regardless of the order in the manifest file.
961 EXPECT_EQ(2u, warnings.size()); 969 EXPECT_EQ(2u, warnings.size());
962 if (warnings.size() > 0) 970 if (warnings.size() > 0)
963 EXPECT_EQ(warnings[0], 971 EXPECT_EQ(warnings[0],
964 UTF8ToUTF16("Exchange data with any computer in the domains: " 972 UTF8ToUTF16("Exchange data with any computer in the domains: "
965 "example.com foo.example.org")); 973 "example.com foo.example.org"));
966 if (warnings.size() > 1) 974 if (warnings.size() > 1)
967 EXPECT_EQ(warnings[1], 975 EXPECT_EQ(warnings[1],
968 UTF8ToUTF16("Exchange data with the computer named " 976 UTF8ToUTF16("Exchange data with the computer named "
969 "bar.example.org")); 977 "bar.example.org"));
970 } 978 }
971 979
972 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { 980 TEST_F(PermissionsTest, GetWarningMessages_PlatformApppHosts) {
973 scoped_refptr<Extension> extension; 981 scoped_refptr<Extension> extension;
974 982
975 extension = LoadManifest("permissions", "platform_app_hosts.json"); 983 extension = LoadManifest("permissions", "platform_app_hosts.json");
976 EXPECT_TRUE(extension->is_platform_app()); 984 EXPECT_TRUE(extension->is_platform_app());
977 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); 985 std::vector<string16> warnings = extension->GetPermissionMessageStrings();
978 ASSERT_EQ(0u, warnings.size()); 986 ASSERT_EQ(0u, warnings.size());
979 987
980 extension = LoadManifest("permissions", "platform_app_all_urls.json"); 988 extension = LoadManifest("permissions", "platform_app_all_urls.json");
981 EXPECT_TRUE(extension->is_platform_app()); 989 EXPECT_TRUE(extension->is_platform_app());
982 warnings = extension->GetPermissionMessageStrings(); 990 warnings = extension->GetPermissionMessageStrings();
983 ASSERT_EQ(0u, warnings.size()); 991 ASSERT_EQ(0u, warnings.size());
984 } 992 }
985 993
986 TEST(PermissionsTest, GetDistinctHostsForDisplay) { 994 TEST_F(PermissionsTest, GetDistinctHostsForDisplay) {
987 scoped_refptr<PermissionSet> perm_set; 995 scoped_refptr<PermissionSet> perm_set;
988 APIPermissionSet empty_perms; 996 APIPermissionSet empty_perms;
989 std::set<std::string> expected; 997 std::set<std::string> expected;
990 expected.insert("www.foo.com"); 998 expected.insert("www.foo.com");
991 expected.insert("www.bar.com"); 999 expected.insert("www.bar.com");
992 expected.insert("www.baz.com"); 1000 expected.insert("www.baz.com");
993 URLPatternSet explicit_hosts; 1001 URLPatternSet explicit_hosts;
994 URLPatternSet scriptable_hosts; 1002 URLPatternSet scriptable_hosts;
995 1003
996 { 1004 {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 1140
1133 explicit_hosts.AddPattern( 1141 explicit_hosts.AddPattern(
1134 URLPattern(URLPattern::SCHEME_FILE, "file:///*")); 1142 URLPattern(URLPattern::SCHEME_FILE, "file:///*"));
1135 1143
1136 perm_set = new PermissionSet( 1144 perm_set = new PermissionSet(
1137 empty_perms, explicit_hosts, scriptable_hosts); 1145 empty_perms, explicit_hosts, scriptable_hosts);
1138 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 1146 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
1139 } 1147 }
1140 } 1148 }
1141 1149
1142 TEST(PermissionsTest, GetDistinctHostsForDisplay_ComIsBestRcd) { 1150 TEST_F(PermissionsTest, GetDistinctHostsForDisplay_ComIsBestRcd) {
1143 scoped_refptr<PermissionSet> perm_set; 1151 scoped_refptr<PermissionSet> perm_set;
1144 APIPermissionSet empty_perms; 1152 APIPermissionSet empty_perms;
1145 URLPatternSet explicit_hosts; 1153 URLPatternSet explicit_hosts;
1146 URLPatternSet scriptable_hosts; 1154 URLPatternSet scriptable_hosts;
1147 explicit_hosts.AddPattern( 1155 explicit_hosts.AddPattern(
1148 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 1156 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
1149 explicit_hosts.AddPattern( 1157 explicit_hosts.AddPattern(
1150 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 1158 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
1151 explicit_hosts.AddPattern( 1159 explicit_hosts.AddPattern(
1152 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 1160 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
1153 explicit_hosts.AddPattern( 1161 explicit_hosts.AddPattern(
1154 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); 1162 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
1155 explicit_hosts.AddPattern( 1163 explicit_hosts.AddPattern(
1156 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 1164 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
1157 explicit_hosts.AddPattern( 1165 explicit_hosts.AddPattern(
1158 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); 1166 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
1159 1167
1160 std::set<std::string> expected; 1168 std::set<std::string> expected;
1161 expected.insert("www.foo.com"); 1169 expected.insert("www.foo.com");
1162 perm_set = new PermissionSet( 1170 perm_set = new PermissionSet(
1163 empty_perms, explicit_hosts, scriptable_hosts); 1171 empty_perms, explicit_hosts, scriptable_hosts);
1164 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 1172 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
1165 } 1173 }
1166 1174
1167 TEST(PermissionsTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) { 1175 TEST_F(PermissionsTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) {
1168 scoped_refptr<PermissionSet> perm_set; 1176 scoped_refptr<PermissionSet> perm_set;
1169 APIPermissionSet empty_perms; 1177 APIPermissionSet empty_perms;
1170 URLPatternSet explicit_hosts; 1178 URLPatternSet explicit_hosts;
1171 URLPatternSet scriptable_hosts; 1179 URLPatternSet scriptable_hosts;
1172 explicit_hosts.AddPattern( 1180 explicit_hosts.AddPattern(
1173 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 1181 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
1174 explicit_hosts.AddPattern( 1182 explicit_hosts.AddPattern(
1175 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 1183 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
1176 explicit_hosts.AddPattern( 1184 explicit_hosts.AddPattern(
1177 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 1185 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
1178 explicit_hosts.AddPattern( 1186 explicit_hosts.AddPattern(
1179 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); 1187 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
1180 explicit_hosts.AddPattern( 1188 explicit_hosts.AddPattern(
1181 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 1189 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
1182 // No http://www.foo.com/path 1190 // No http://www.foo.com/path
1183 1191
1184 std::set<std::string> expected; 1192 std::set<std::string> expected;
1185 expected.insert("www.foo.net"); 1193 expected.insert("www.foo.net");
1186 perm_set = new PermissionSet( 1194 perm_set = new PermissionSet(
1187 empty_perms, explicit_hosts, scriptable_hosts); 1195 empty_perms, explicit_hosts, scriptable_hosts);
1188 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 1196 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
1189 } 1197 }
1190 1198
1191 TEST(PermissionsTest, 1199 TEST_F(PermissionsTest,
1192 GetDistinctHostsForDisplay_OrgIs3rdBestRcd) { 1200 GetDistinctHostsForDisplay_OrgIs3rdBestRcd) {
1193 scoped_refptr<PermissionSet> perm_set; 1201 scoped_refptr<PermissionSet> perm_set;
1194 APIPermissionSet empty_perms; 1202 APIPermissionSet empty_perms;
1195 URLPatternSet explicit_hosts; 1203 URLPatternSet explicit_hosts;
1196 URLPatternSet scriptable_hosts; 1204 URLPatternSet scriptable_hosts;
1197 explicit_hosts.AddPattern( 1205 explicit_hosts.AddPattern(
1198 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 1206 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
1199 explicit_hosts.AddPattern( 1207 explicit_hosts.AddPattern(
1200 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); 1208 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
1201 explicit_hosts.AddPattern( 1209 explicit_hosts.AddPattern(
1202 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 1210 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
1203 // No http://www.foo.net/path 1211 // No http://www.foo.net/path
1204 explicit_hosts.AddPattern( 1212 explicit_hosts.AddPattern(
1205 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 1213 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
1206 // No http://www.foo.com/path 1214 // No http://www.foo.com/path
1207 1215
1208 std::set<std::string> expected; 1216 std::set<std::string> expected;
1209 expected.insert("www.foo.org"); 1217 expected.insert("www.foo.org");
1210 perm_set = new PermissionSet( 1218 perm_set = new PermissionSet(
1211 empty_perms, explicit_hosts, scriptable_hosts); 1219 empty_perms, explicit_hosts, scriptable_hosts);
1212 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 1220 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
1213 } 1221 }
1214 1222
1215 TEST(PermissionsTest, 1223 TEST_F(PermissionsTest,
1216 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) { 1224 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) {
1217 scoped_refptr<PermissionSet> perm_set; 1225 scoped_refptr<PermissionSet> perm_set;
1218 APIPermissionSet empty_perms; 1226 APIPermissionSet empty_perms;
1219 URLPatternSet explicit_hosts; 1227 URLPatternSet explicit_hosts;
1220 URLPatternSet scriptable_hosts; 1228 URLPatternSet scriptable_hosts;
1221 explicit_hosts.AddPattern( 1229 explicit_hosts.AddPattern(
1222 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); 1230 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
1223 // No http://www.foo.org/path 1231 // No http://www.foo.org/path
1224 explicit_hosts.AddPattern( 1232 explicit_hosts.AddPattern(
1225 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); 1233 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
1226 // No http://www.foo.net/path 1234 // No http://www.foo.net/path
1227 explicit_hosts.AddPattern( 1235 explicit_hosts.AddPattern(
1228 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); 1236 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
1229 // No http://www.foo.com/path 1237 // No http://www.foo.com/path
1230 1238
1231 std::set<std::string> expected; 1239 std::set<std::string> expected;
1232 expected.insert("www.foo.ca"); 1240 expected.insert("www.foo.ca");
1233 perm_set = new PermissionSet( 1241 perm_set = new PermissionSet(
1234 empty_perms, explicit_hosts, scriptable_hosts); 1242 empty_perms, explicit_hosts, scriptable_hosts);
1235 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); 1243 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay());
1236 } 1244 }
1237 1245
1238 TEST(PermissionsTest, HasLessHostPrivilegesThan) { 1246 TEST_F(PermissionsTest, HasLessHostPrivilegesThan) {
1239 URLPatternSet elist1; 1247 URLPatternSet elist1;
1240 URLPatternSet elist2; 1248 URLPatternSet elist2;
1241 URLPatternSet slist1; 1249 URLPatternSet slist1;
1242 URLPatternSet slist2; 1250 URLPatternSet slist2;
1243 scoped_refptr<PermissionSet> set1; 1251 scoped_refptr<PermissionSet> set1;
1244 scoped_refptr<PermissionSet> set2; 1252 scoped_refptr<PermissionSet> set2;
1245 APIPermissionSet empty_perms; 1253 APIPermissionSet empty_perms;
1246 elist1.AddPattern( 1254 elist1.AddPattern(
1247 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); 1255 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path"));
1248 elist1.AddPattern( 1256 elist1.AddPattern(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 1305
1298 // Test that different subdomains count as different hosts. 1306 // Test that different subdomains count as different hosts.
1299 elist2.ClearPatterns(); 1307 elist2.ClearPatterns();
1300 elist2.AddPattern( 1308 elist2.AddPattern(
1301 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); 1309 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*"));
1302 set2 = new PermissionSet(empty_perms, elist2, slist2); 1310 set2 = new PermissionSet(empty_perms, elist2, slist2);
1303 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get())); 1311 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get()));
1304 EXPECT_TRUE(set2->HasLessHostPrivilegesThan(set1.get())); 1312 EXPECT_TRUE(set2->HasLessHostPrivilegesThan(set1.get()));
1305 } 1313 }
1306 1314
1307 TEST(PermissionsTest, GetAPIsAsStrings) { 1315 TEST_F(PermissionsTest, GetAPIsAsStrings) {
1308 APIPermissionSet apis; 1316 APIPermissionSet apis;
1309 URLPatternSet empty_set; 1317 URLPatternSet empty_set;
1310 1318
1311 apis.insert(APIPermission::kProxy); 1319 apis.insert(APIPermission::kProxy);
1312 apis.insert(APIPermission::kBackground); 1320 apis.insert(APIPermission::kBackground);
1313 apis.insert(APIPermission::kNotification); 1321 apis.insert(APIPermission::kNotification);
1314 apis.insert(APIPermission::kTab); 1322 apis.insert(APIPermission::kTab);
1315 1323
1316 scoped_refptr<PermissionSet> perm_set = new PermissionSet( 1324 scoped_refptr<PermissionSet> perm_set = new PermissionSet(
1317 apis, empty_set, empty_set); 1325 apis, empty_set, empty_set);
1318 std::set<std::string> api_names = perm_set->GetAPIsAsStrings(); 1326 std::set<std::string> api_names = perm_set->GetAPIsAsStrings();
1319 1327
1320 // The result is correct if it has the same number of elements 1328 // The result is correct if it has the same number of elements
1321 // and we can convert it back to the id set. 1329 // and we can convert it back to the id set.
1322 EXPECT_EQ(4u, api_names.size()); 1330 EXPECT_EQ(4u, api_names.size());
1323 EXPECT_EQ(apis, 1331 EXPECT_EQ(apis,
1324 PermissionsInfo::GetInstance()->GetAllByName(api_names)); 1332 PermissionsInfo::GetInstance()->GetAllByName(api_names));
1325 } 1333 }
1326 1334
1327 TEST(PermissionsTest, IsEmpty) { 1335 TEST_F(PermissionsTest, IsEmpty) {
1328 APIPermissionSet empty_apis; 1336 APIPermissionSet empty_apis;
1329 URLPatternSet empty_extent; 1337 URLPatternSet empty_extent;
1330 1338
1331 scoped_refptr<PermissionSet> empty = new PermissionSet(); 1339 scoped_refptr<PermissionSet> empty = new PermissionSet();
1332 EXPECT_TRUE(empty->IsEmpty()); 1340 EXPECT_TRUE(empty->IsEmpty());
1333 scoped_refptr<PermissionSet> perm_set; 1341 scoped_refptr<PermissionSet> perm_set;
1334 1342
1335 perm_set = new PermissionSet(empty_apis, empty_extent, empty_extent); 1343 perm_set = new PermissionSet(empty_apis, empty_extent, empty_extent);
1336 EXPECT_TRUE(perm_set->IsEmpty()); 1344 EXPECT_TRUE(perm_set->IsEmpty());
1337 1345
1338 APIPermissionSet non_empty_apis; 1346 APIPermissionSet non_empty_apis;
1339 non_empty_apis.insert(APIPermission::kBackground); 1347 non_empty_apis.insert(APIPermission::kBackground);
1340 perm_set = new PermissionSet( 1348 perm_set = new PermissionSet(
1341 non_empty_apis, empty_extent, empty_extent); 1349 non_empty_apis, empty_extent, empty_extent);
1342 EXPECT_FALSE(perm_set->IsEmpty()); 1350 EXPECT_FALSE(perm_set->IsEmpty());
1343 1351
1344 // Try non standard host 1352 // Try non standard host
1345 URLPatternSet non_empty_extent; 1353 URLPatternSet non_empty_extent;
1346 AddPattern(&non_empty_extent, "http://www.google.com/*"); 1354 AddPattern(&non_empty_extent, "http://www.google.com/*");
1347 1355
1348 perm_set = new PermissionSet( 1356 perm_set = new PermissionSet(
1349 empty_apis, non_empty_extent, empty_extent); 1357 empty_apis, non_empty_extent, empty_extent);
1350 EXPECT_FALSE(perm_set->IsEmpty()); 1358 EXPECT_FALSE(perm_set->IsEmpty());
1351 1359
1352 perm_set = new PermissionSet( 1360 perm_set = new PermissionSet(
1353 empty_apis, empty_extent, non_empty_extent); 1361 empty_apis, empty_extent, non_empty_extent);
1354 EXPECT_FALSE(perm_set->IsEmpty()); 1362 EXPECT_FALSE(perm_set->IsEmpty());
1355 } 1363 }
1356 1364
1357 TEST(PermissionsTest, ImpliedPermissions) { 1365 TEST_F(PermissionsTest, ImpliedPermissions) {
1358 URLPatternSet empty_extent; 1366 URLPatternSet empty_extent;
1359 APIPermissionSet apis; 1367 APIPermissionSet apis;
1360 apis.insert(APIPermission::kWebRequest); 1368 apis.insert(APIPermission::kWebRequest);
1361 apis.insert(APIPermission::kFileBrowserHandler); 1369 apis.insert(APIPermission::kFileBrowserHandler);
1362 EXPECT_EQ(2U, apis.size()); 1370 EXPECT_EQ(2U, apis.size());
1363 1371
1364 scoped_refptr<PermissionSet> perm_set; 1372 scoped_refptr<PermissionSet> perm_set;
1365 perm_set = new PermissionSet(apis, empty_extent, empty_extent); 1373 perm_set = new PermissionSet(apis, empty_extent, empty_extent);
1366 EXPECT_EQ(4U, perm_set->apis().size()); 1374 EXPECT_EQ(4U, perm_set->apis().size());
1367 } 1375 }
1368 1376
1369 } // namespace extensions 1377 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698