| OLD | NEW |
| 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/api/plugins/plugins_handler.h" | |
| 13 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_test_util.h" | 13 #include "chrome/common/extensions/extension_test_util.h" |
| 15 #include "chrome/common/extensions/extension_unittest.h" | |
| 16 #include "chrome/common/extensions/features/feature.h" | 14 #include "chrome/common/extensions/features/feature.h" |
| 17 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" | |
| 18 #include "chrome/common/extensions/permissions/permission_set.h" | 15 #include "chrome/common/extensions/permissions/permission_set.h" |
| 19 #include "chrome/common/extensions/permissions/permissions_info.h" | 16 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 20 #include "chrome/common/extensions/permissions/socket_permission.h" | 17 #include "chrome/common/extensions/permissions/socket_permission.h" |
| 21 #include "extensions/common/error_utils.h" | 18 #include "extensions/common/error_utils.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 20 |
| 24 using extension_test_util::LoadManifest; | 21 using extension_test_util::LoadManifest; |
| 25 | 22 |
| 26 namespace extensions { | 23 namespace extensions { |
| 27 | 24 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 42 return warnings.size(); | 39 return warnings.size(); |
| 43 } | 40 } |
| 44 | 41 |
| 45 bool Contains(const std::vector<string16>& warnings, | 42 bool Contains(const std::vector<string16>& warnings, |
| 46 const std::string& warning) { | 43 const std::string& warning) { |
| 47 return IndexOf(warnings, warning) != warnings.size(); | 44 return IndexOf(warnings, warning) != warnings.size(); |
| 48 } | 45 } |
| 49 | 46 |
| 50 } // namespace | 47 } // namespace |
| 51 | 48 |
| 52 class PermissionsTest : public ExtensionTest { | |
| 53 protected: | |
| 54 virtual void SetUp() OVERRIDE { | |
| 55 ExtensionTest::SetUp(); | |
| 56 (new ContentScriptsHandler)->Register(); | |
| 57 (new PluginsHandler)->Register(); | |
| 58 } | |
| 59 | |
| 60 virtual void TearDown() OVERRIDE { | |
| 61 ExtensionTest::TearDown(); | |
| 62 } | |
| 63 }; | |
| 64 | |
| 65 // Tests GetByID. | 49 // Tests GetByID. |
| 66 TEST_F(PermissionsTest, GetByID) { | 50 TEST(PermissionsTest, GetByID) { |
| 67 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 51 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 68 APIPermissionSet apis = info->GetAll(); | 52 APIPermissionSet apis = info->GetAll(); |
| 69 for (APIPermissionSet::const_iterator i = apis.begin(); | 53 for (APIPermissionSet::const_iterator i = apis.begin(); |
| 70 i != apis.end(); ++i) { | 54 i != apis.end(); ++i) { |
| 71 EXPECT_EQ(i->id(), i->info()->id()); | 55 EXPECT_EQ(i->id(), i->info()->id()); |
| 72 } | 56 } |
| 73 } | 57 } |
| 74 | 58 |
| 75 // Tests that GetByName works with normal permission names and aliases. | 59 // Tests that GetByName works with normal permission names and aliases. |
| 76 TEST_F(PermissionsTest, GetByName) { | 60 TEST(PermissionsTest, GetByName) { |
| 77 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 61 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 78 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id()); | 62 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id()); |
| 79 EXPECT_EQ(APIPermission::kManagement, | 63 EXPECT_EQ(APIPermission::kManagement, |
| 80 info->GetByName("management")->id()); | 64 info->GetByName("management")->id()); |
| 81 EXPECT_FALSE(info->GetByName("alsdkfjasldkfj")); | 65 EXPECT_FALSE(info->GetByName("alsdkfjasldkfj")); |
| 82 } | 66 } |
| 83 | 67 |
| 84 TEST_F(PermissionsTest, GetAll) { | 68 TEST(PermissionsTest, GetAll) { |
| 85 size_t count = 0; | 69 size_t count = 0; |
| 86 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 70 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 87 APIPermissionSet apis = info->GetAll(); | 71 APIPermissionSet apis = info->GetAll(); |
| 88 for (APIPermissionSet::const_iterator api = apis.begin(); | 72 for (APIPermissionSet::const_iterator api = apis.begin(); |
| 89 api != apis.end(); ++api) { | 73 api != apis.end(); ++api) { |
| 90 // Make sure only the valid permission IDs get returned. | 74 // Make sure only the valid permission IDs get returned. |
| 91 EXPECT_NE(APIPermission::kInvalid, api->id()); | 75 EXPECT_NE(APIPermission::kInvalid, api->id()); |
| 92 EXPECT_NE(APIPermission::kUnknown, api->id()); | 76 EXPECT_NE(APIPermission::kUnknown, api->id()); |
| 93 count++; | 77 count++; |
| 94 } | 78 } |
| 95 EXPECT_EQ(count, info->get_permission_count()); | 79 EXPECT_EQ(count, info->get_permission_count()); |
| 96 } | 80 } |
| 97 | 81 |
| 98 TEST_F(PermissionsTest, GetAllByName) { | 82 TEST(PermissionsTest, GetAllByName) { |
| 99 std::set<std::string> names; | 83 std::set<std::string> names; |
| 100 names.insert("background"); | 84 names.insert("background"); |
| 101 names.insert("management"); | 85 names.insert("management"); |
| 102 | 86 |
| 103 // This is an alias of kTab | 87 // This is an alias of kTab |
| 104 names.insert("windows"); | 88 names.insert("windows"); |
| 105 | 89 |
| 106 // This unknown name should get dropped. | 90 // This unknown name should get dropped. |
| 107 names.insert("sdlkfjasdlkfj"); | 91 names.insert("sdlkfjasdlkfj"); |
| 108 | 92 |
| 109 APIPermissionSet expected; | 93 APIPermissionSet expected; |
| 110 expected.insert(APIPermission::kBackground); | 94 expected.insert(APIPermission::kBackground); |
| 111 expected.insert(APIPermission::kManagement); | 95 expected.insert(APIPermission::kManagement); |
| 112 expected.insert(APIPermission::kTab); | 96 expected.insert(APIPermission::kTab); |
| 113 | 97 |
| 114 EXPECT_EQ(expected, | 98 EXPECT_EQ(expected, |
| 115 PermissionsInfo::GetInstance()->GetAllByName(names)); | 99 PermissionsInfo::GetInstance()->GetAllByName(names)); |
| 116 } | 100 } |
| 117 | 101 |
| 118 // Tests that the aliases are properly mapped. | 102 // Tests that the aliases are properly mapped. |
| 119 TEST_F(PermissionsTest, Aliases) { | 103 TEST(PermissionsTest, Aliases) { |
| 120 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 104 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 121 // tabs: tabs, windows | 105 // tabs: tabs, windows |
| 122 std::string tabs_name = "tabs"; | 106 std::string tabs_name = "tabs"; |
| 123 EXPECT_EQ(tabs_name, info->GetByID(APIPermission::kTab)->name()); | 107 EXPECT_EQ(tabs_name, info->GetByID(APIPermission::kTab)->name()); |
| 124 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id()); | 108 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id()); |
| 125 EXPECT_EQ(APIPermission::kTab, info->GetByName("windows")->id()); | 109 EXPECT_EQ(APIPermission::kTab, info->GetByName("windows")->id()); |
| 126 | 110 |
| 127 // unlimitedStorage: unlimitedStorage, unlimited_storage | 111 // unlimitedStorage: unlimitedStorage, unlimited_storage |
| 128 std::string storage_name = "unlimitedStorage"; | 112 std::string storage_name = "unlimitedStorage"; |
| 129 EXPECT_EQ(storage_name, info->GetByID( | 113 EXPECT_EQ(storage_name, info->GetByID( |
| 130 APIPermission::kUnlimitedStorage)->name()); | 114 APIPermission::kUnlimitedStorage)->name()); |
| 131 EXPECT_EQ(APIPermission::kUnlimitedStorage, | 115 EXPECT_EQ(APIPermission::kUnlimitedStorage, |
| 132 info->GetByName("unlimitedStorage")->id()); | 116 info->GetByName("unlimitedStorage")->id()); |
| 133 EXPECT_EQ(APIPermission::kUnlimitedStorage, | 117 EXPECT_EQ(APIPermission::kUnlimitedStorage, |
| 134 info->GetByName("unlimited_storage")->id()); | 118 info->GetByName("unlimited_storage")->id()); |
| 135 } | 119 } |
| 136 | 120 |
| 137 TEST_F(PermissionsTest, EffectiveHostPermissions) { | 121 TEST(PermissionsTest, EffectiveHostPermissions) { |
| 138 scoped_refptr<Extension> extension; | 122 scoped_refptr<Extension> extension; |
| 139 scoped_refptr<const PermissionSet> permissions; | 123 scoped_refptr<const PermissionSet> permissions; |
| 140 | 124 |
| 141 extension = LoadManifest("effective_host_permissions", "empty.json"); | 125 extension = LoadManifest("effective_host_permissions", "empty.json"); |
| 142 permissions = extension->GetActivePermissions(); | 126 permissions = extension->GetActivePermissions(); |
| 143 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); | 127 EXPECT_EQ(0u, extension->GetEffectiveHostPermissions().patterns().size()); |
| 144 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( | 128 EXPECT_FALSE(permissions->HasEffectiveAccessToURL( |
| 145 GURL("http://www.google.com"))); | 129 GURL("http://www.google.com"))); |
| 146 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); | 130 EXPECT_FALSE(permissions->HasEffectiveAccessToAllHosts()); |
| 147 | 131 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 187 |
| 204 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); | 188 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); |
| 205 permissions = extension->GetActivePermissions(); | 189 permissions = extension->GetActivePermissions(); |
| 206 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); | 190 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); |
| 207 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); | 191 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); |
| 208 EXPECT_TRUE( | 192 EXPECT_TRUE( |
| 209 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); | 193 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); |
| 210 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); | 194 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
| 211 } | 195 } |
| 212 | 196 |
| 213 TEST_F(PermissionsTest, ExplicitAccessToOrigin) { | 197 TEST(PermissionsTest, ExplicitAccessToOrigin) { |
| 214 APIPermissionSet apis; | 198 APIPermissionSet apis; |
| 215 URLPatternSet explicit_hosts; | 199 URLPatternSet explicit_hosts; |
| 216 URLPatternSet scriptable_hosts; | 200 URLPatternSet scriptable_hosts; |
| 217 | 201 |
| 218 AddPattern(&explicit_hosts, "http://*.google.com/*"); | 202 AddPattern(&explicit_hosts, "http://*.google.com/*"); |
| 219 // The explicit host paths should get set to /*. | 203 // The explicit host paths should get set to /*. |
| 220 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*"); | 204 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*"); |
| 221 | 205 |
| 222 scoped_refptr<PermissionSet> perm_set = new PermissionSet( | 206 scoped_refptr<PermissionSet> perm_set = new PermissionSet( |
| 223 apis, explicit_hosts, scriptable_hosts); | 207 apis, explicit_hosts, scriptable_hosts); |
| 224 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( | 208 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( |
| 225 GURL("http://www.google.com/"))); | 209 GURL("http://www.google.com/"))); |
| 226 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( | 210 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( |
| 227 GURL("http://test.google.com/"))); | 211 GURL("http://test.google.com/"))); |
| 228 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( | 212 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( |
| 229 GURL("http://www.example.com"))); | 213 GURL("http://www.example.com"))); |
| 230 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL( | 214 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL( |
| 231 GURL("http://www.example.com"))); | 215 GURL("http://www.example.com"))); |
| 232 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin( | 216 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin( |
| 233 GURL("http://test.example.com"))); | 217 GURL("http://test.example.com"))); |
| 234 } | 218 } |
| 235 | 219 |
| 236 TEST_F(PermissionsTest, CreateUnion) { | 220 TEST(PermissionsTest, CreateUnion) { |
| 237 APIPermission* permission = NULL; | 221 APIPermission* permission = NULL; |
| 238 | 222 |
| 239 APIPermissionSet apis1; | 223 APIPermissionSet apis1; |
| 240 APIPermissionSet apis2; | 224 APIPermissionSet apis2; |
| 241 APIPermissionSet expected_apis; | 225 APIPermissionSet expected_apis; |
| 242 | 226 |
| 243 URLPatternSet explicit_hosts1; | 227 URLPatternSet explicit_hosts1; |
| 244 URLPatternSet explicit_hosts2; | 228 URLPatternSet explicit_hosts2; |
| 245 URLPatternSet expected_explicit_hosts; | 229 URLPatternSet expected_explicit_hosts; |
| 246 | 230 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 EXPECT_TRUE(union_set->Contains(*set2)); | 334 EXPECT_TRUE(union_set->Contains(*set2)); |
| 351 | 335 |
| 352 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); | 336 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); |
| 353 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); | 337 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); |
| 354 EXPECT_EQ(expected_apis, union_set->apis()); | 338 EXPECT_EQ(expected_apis, union_set->apis()); |
| 355 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); | 339 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); |
| 356 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); | 340 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); |
| 357 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); | 341 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); |
| 358 } | 342 } |
| 359 | 343 |
| 360 TEST_F(PermissionsTest, CreateIntersection) { | 344 TEST(PermissionsTest, CreateIntersection) { |
| 361 APIPermission* permission = NULL; | 345 APIPermission* permission = NULL; |
| 362 | 346 |
| 363 APIPermissionSet apis1; | 347 APIPermissionSet apis1; |
| 364 APIPermissionSet apis2; | 348 APIPermissionSet apis2; |
| 365 APIPermissionSet expected_apis; | 349 APIPermissionSet expected_apis; |
| 366 | 350 |
| 367 URLPatternSet explicit_hosts1; | 351 URLPatternSet explicit_hosts1; |
| 368 URLPatternSet explicit_hosts2; | 352 URLPatternSet explicit_hosts2; |
| 369 URLPatternSet expected_explicit_hosts; | 353 URLPatternSet expected_explicit_hosts; |
| 370 | 354 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 EXPECT_FALSE(new_set->Contains(*set2)); | 448 EXPECT_FALSE(new_set->Contains(*set2)); |
| 465 | 449 |
| 466 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 450 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
| 467 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); | 451 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); |
| 468 EXPECT_EQ(expected_apis, new_set->apis()); | 452 EXPECT_EQ(expected_apis, new_set->apis()); |
| 469 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 453 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
| 470 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 454 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
| 471 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); | 455 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); |
| 472 } | 456 } |
| 473 | 457 |
| 474 TEST_F(PermissionsTest, CreateDifference) { | 458 TEST(PermissionsTest, CreateDifference) { |
| 475 APIPermission* permission = NULL; | 459 APIPermission* permission = NULL; |
| 476 | 460 |
| 477 APIPermissionSet apis1; | 461 APIPermissionSet apis1; |
| 478 APIPermissionSet apis2; | 462 APIPermissionSet apis2; |
| 479 APIPermissionSet expected_apis; | 463 APIPermissionSet expected_apis; |
| 480 | 464 |
| 481 URLPatternSet explicit_hosts1; | 465 URLPatternSet explicit_hosts1; |
| 482 URLPatternSet explicit_hosts2; | 466 URLPatternSet explicit_hosts2; |
| 483 URLPatternSet expected_explicit_hosts; | 467 URLPatternSet expected_explicit_hosts; |
| 484 | 468 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 EXPECT_EQ(expected_apis, new_set->apis()); | 549 EXPECT_EQ(expected_apis, new_set->apis()); |
| 566 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 550 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
| 567 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 551 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
| 568 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); | 552 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); |
| 569 | 553 |
| 570 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set | 554 // |set3| = |set1| - |set2| --> |set3| intersect |set2| == empty_set |
| 571 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get()); | 555 set1 = PermissionSet::CreateIntersection(new_set.get(), set2.get()); |
| 572 EXPECT_TRUE(set1->IsEmpty()); | 556 EXPECT_TRUE(set1->IsEmpty()); |
| 573 } | 557 } |
| 574 | 558 |
| 575 TEST_F(PermissionsTest, HasLessPrivilegesThan) { | 559 TEST(PermissionsTest, HasLessPrivilegesThan) { |
| 576 const struct { | 560 const struct { |
| 577 const char* base_name; | 561 const char* base_name; |
| 578 bool expect_increase; | 562 bool expect_increase; |
| 579 } kTests[] = { | 563 } kTests[] = { |
| 580 { "allhosts1", false }, // all -> all | 564 { "allhosts1", false }, // all -> all |
| 581 { "allhosts2", false }, // all -> one | 565 { "allhosts2", false }, // all -> one |
| 582 { "allhosts3", true }, // one -> all | 566 { "allhosts3", true }, // one -> all |
| 583 { "hosts1", false }, // http://a,http://b -> http://a,http://b | 567 { "hosts1", false }, // http://a,http://b -> http://a,http://b |
| 584 { "hosts2", true }, // http://a,http://b -> https://a,http://*.b | 568 { "hosts2", true }, // http://a,http://b -> https://a,http://*.b |
| 585 { "hosts3", false }, // http://a,http://b -> http://a | 569 { "hosts3", false }, // http://a,http://b -> http://a |
| (...skipping 30 matching lines...) Expand all Loading... |
| 616 scoped_refptr<const PermissionSet> old_p( | 600 scoped_refptr<const PermissionSet> old_p( |
| 617 old_extension->GetActivePermissions()); | 601 old_extension->GetActivePermissions()); |
| 618 scoped_refptr<const PermissionSet> new_p( | 602 scoped_refptr<const PermissionSet> new_p( |
| 619 new_extension->GetActivePermissions()); | 603 new_extension->GetActivePermissions()); |
| 620 | 604 |
| 621 EXPECT_EQ(kTests[i].expect_increase, | 605 EXPECT_EQ(kTests[i].expect_increase, |
| 622 old_p->HasLessPrivilegesThan(new_p)) << kTests[i].base_name; | 606 old_p->HasLessPrivilegesThan(new_p)) << kTests[i].base_name; |
| 623 } | 607 } |
| 624 } | 608 } |
| 625 | 609 |
| 626 TEST_F(PermissionsTest, PermissionMessages) { | 610 TEST(PermissionsTest, PermissionMessages) { |
| 627 // Ensure that all permissions that needs to show install UI actually have | 611 // Ensure that all permissions that needs to show install UI actually have |
| 628 // strings associated with them. | 612 // strings associated with them. |
| 629 APIPermissionSet skip; | 613 APIPermissionSet skip; |
| 630 | 614 |
| 631 // These are considered "nuisance" or "trivial" permissions that don't need | 615 // These are considered "nuisance" or "trivial" permissions that don't need |
| 632 // a prompt. | 616 // a prompt. |
| 633 skip.insert(APIPermission::kActiveTab); | 617 skip.insert(APIPermission::kActiveTab); |
| 634 skip.insert(APIPermission::kAdView); | 618 skip.insert(APIPermission::kAdView); |
| 635 skip.insert(APIPermission::kAlarms); | 619 skip.insert(APIPermission::kAlarms); |
| 636 skip.insert(APIPermission::kAppCurrentWindowInternal); | 620 skip.insert(APIPermission::kAppCurrentWindowInternal); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 EXPECT_EQ(PermissionMessage::kNone, permission_info->message_id()) | 722 EXPECT_EQ(PermissionMessage::kNone, permission_info->message_id()) |
| 739 << "unexpected message_id for " << permission_info->name(); | 723 << "unexpected message_id for " << permission_info->name(); |
| 740 } else { | 724 } else { |
| 741 EXPECT_NE(PermissionMessage::kNone, permission_info->message_id()) | 725 EXPECT_NE(PermissionMessage::kNone, permission_info->message_id()) |
| 742 << "missing message_id for " << permission_info->name(); | 726 << "missing message_id for " << permission_info->name(); |
| 743 } | 727 } |
| 744 } | 728 } |
| 745 } | 729 } |
| 746 | 730 |
| 747 // Tests the default permissions (empty API permission set). | 731 // Tests the default permissions (empty API permission set). |
| 748 TEST_F(PermissionsTest, DefaultFunctionAccess) { | 732 TEST(PermissionsTest, DefaultFunctionAccess) { |
| 749 const struct { | 733 const struct { |
| 750 const char* permission_name; | 734 const char* permission_name; |
| 751 bool expect_success; | 735 bool expect_success; |
| 752 } kTests[] = { | 736 } kTests[] = { |
| 753 // Negative test. | 737 // Negative test. |
| 754 { "non_existing_permission", false }, | 738 { "non_existing_permission", false }, |
| 755 // Test default module/package permission. | 739 // Test default module/package permission. |
| 756 { "browserAction", true }, | 740 { "browserAction", true }, |
| 757 { "devtools", true }, | 741 { "devtools", true }, |
| 758 { "extension", true }, | 742 { "extension", true }, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 777 | 761 |
| 778 scoped_refptr<PermissionSet> empty = new PermissionSet(); | 762 scoped_refptr<PermissionSet> empty = new PermissionSet(); |
| 779 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { | 763 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
| 780 EXPECT_EQ(kTests[i].expect_success, | 764 EXPECT_EQ(kTests[i].expect_success, |
| 781 empty->HasAccessToFunction(kTests[i].permission_name, true)) | 765 empty->HasAccessToFunction(kTests[i].permission_name, true)) |
| 782 << "Permission being tested: " << kTests[i].permission_name; | 766 << "Permission being tested: " << kTests[i].permission_name; |
| 783 } | 767 } |
| 784 } | 768 } |
| 785 | 769 |
| 786 // Tests the default permissions (empty API permission set). | 770 // Tests the default permissions (empty API permission set). |
| 787 TEST_F(PermissionsTest, DefaultAnyAPIAccess) { | 771 TEST(PermissionsTest, DefaultAnyAPIAccess) { |
| 788 const struct { | 772 const struct { |
| 789 const char* api_name; | 773 const char* api_name; |
| 790 bool expect_success; | 774 bool expect_success; |
| 791 } kTests[] = { | 775 } kTests[] = { |
| 792 // Negative test. | 776 // Negative test. |
| 793 { "non_existing_permission", false }, | 777 { "non_existing_permission", false }, |
| 794 // Test default module/package permission. | 778 // Test default module/package permission. |
| 795 { "browserAction", true }, | 779 { "browserAction", true }, |
| 796 { "devtools", true }, | 780 { "devtools", true }, |
| 797 { "extension", true }, | 781 { "extension", true }, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 808 { "tabs", true}, | 792 { "tabs", true}, |
| 809 }; | 793 }; |
| 810 | 794 |
| 811 scoped_refptr<PermissionSet> empty = new PermissionSet(); | 795 scoped_refptr<PermissionSet> empty = new PermissionSet(); |
| 812 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { | 796 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
| 813 EXPECT_EQ(kTests[i].expect_success, | 797 EXPECT_EQ(kTests[i].expect_success, |
| 814 empty->HasAnyAccessToAPI(kTests[i].api_name)); | 798 empty->HasAnyAccessToAPI(kTests[i].api_name)); |
| 815 } | 799 } |
| 816 } | 800 } |
| 817 | 801 |
| 818 TEST_F(PermissionsTest, GetWarningMessages_ManyHosts) { | 802 TEST(PermissionsTest, GetWarningMessages_ManyHosts) { |
| 819 scoped_refptr<Extension> extension; | 803 scoped_refptr<Extension> extension; |
| 820 | 804 |
| 821 extension = LoadManifest("permissions", "many-hosts.json"); | 805 extension = LoadManifest("permissions", "many-hosts.json"); |
| 822 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); | 806 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 823 ASSERT_EQ(1u, warnings.size()); | 807 ASSERT_EQ(1u, warnings.size()); |
| 824 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", | 808 EXPECT_EQ("Access your data on encrypted.google.com and www.google.com", |
| 825 UTF16ToUTF8(warnings[0])); | 809 UTF16ToUTF8(warnings[0])); |
| 826 } | 810 } |
| 827 | 811 |
| 828 TEST_F(PermissionsTest, GetWarningMessages_Plugins) { | 812 TEST(PermissionsTest, GetWarningMessages_Plugins) { |
| 829 scoped_refptr<Extension> extension; | 813 scoped_refptr<Extension> extension; |
| 830 scoped_refptr<PermissionSet> permissions; | 814 scoped_refptr<PermissionSet> permissions; |
| 831 | 815 |
| 832 extension = LoadManifest("permissions", "plugins.json"); | 816 extension = LoadManifest("permissions", "plugins.json"); |
| 833 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); | 817 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 834 // We don't parse the plugins key on Chrome OS, so it should not ask for any | 818 // We don't parse the plugins key on Chrome OS, so it should not ask for any |
| 835 // permissions. | 819 // permissions. |
| 836 #if defined(OS_CHROMEOS) | 820 #if defined(OS_CHROMEOS) |
| 837 ASSERT_EQ(0u, warnings.size()); | 821 ASSERT_EQ(0u, warnings.size()); |
| 838 #else | 822 #else |
| 839 ASSERT_EQ(1u, warnings.size()); | 823 ASSERT_EQ(1u, warnings.size()); |
| 840 EXPECT_EQ("Access all data on your computer and the websites you visit", | 824 EXPECT_EQ("Access all data on your computer and the websites you visit", |
| 841 UTF16ToUTF8(warnings[0])); | 825 UTF16ToUTF8(warnings[0])); |
| 842 #endif | 826 #endif |
| 843 } | 827 } |
| 844 | 828 |
| 845 TEST_F(PermissionsTest, GetWarningMessages_AudioVideo) { | 829 TEST(PermissionsTest, GetWarningMessages_AudioVideo) { |
| 846 // Both audio and video present. | 830 // Both audio and video present. |
| 847 scoped_refptr<Extension> extension = | 831 scoped_refptr<Extension> extension = |
| 848 LoadManifest("permissions", "audio-video.json"); | 832 LoadManifest("permissions", "audio-video.json"); |
| 849 PermissionSet* set = | 833 PermissionSet* set = |
| 850 const_cast<PermissionSet*>( | 834 const_cast<PermissionSet*>( |
| 851 extension->GetActivePermissions().get()); | 835 extension->GetActivePermissions().get()); |
| 852 std::vector<string16> warnings = | 836 std::vector<string16> warnings = |
| 853 set->GetWarningMessages(extension->GetType()); | 837 set->GetWarningMessages(extension->GetType()); |
| 854 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 838 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
| 855 EXPECT_FALSE(Contains(warnings, "Use your camera")); | 839 EXPECT_FALSE(Contains(warnings, "Use your camera")); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 868 // Just video present. | 852 // Just video present. |
| 869 set->apis_.erase(APIPermission::kAudioCapture); | 853 set->apis_.erase(APIPermission::kAudioCapture); |
| 870 set->apis_.insert(APIPermission::kVideoCapture); | 854 set->apis_.insert(APIPermission::kVideoCapture); |
| 871 warnings = set->GetWarningMessages(extension->GetType()); | 855 warnings = set->GetWarningMessages(extension->GetType()); |
| 872 EXPECT_EQ(combined_size, warnings.size()); | 856 EXPECT_EQ(combined_size, warnings.size()); |
| 873 EXPECT_FALSE(Contains(warnings, "Use your microphone")); | 857 EXPECT_FALSE(Contains(warnings, "Use your microphone")); |
| 874 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); | 858 EXPECT_FALSE(Contains(warnings, "Use your microphone and camera")); |
| 875 EXPECT_TRUE(Contains(warnings, "Use your camera")); | 859 EXPECT_TRUE(Contains(warnings, "Use your camera")); |
| 876 } | 860 } |
| 877 | 861 |
| 878 TEST_F(PermissionsTest, GetWarningMessages_Serial) { | 862 TEST(PermissionsTest, GetWarningMessages_Serial) { |
| 879 scoped_refptr<Extension> extension = | 863 scoped_refptr<Extension> extension = |
| 880 LoadManifest("permissions", "serial.json"); | 864 LoadManifest("permissions", "serial.json"); |
| 881 | 865 |
| 882 EXPECT_TRUE(extension->is_platform_app()); | 866 EXPECT_TRUE(extension->is_platform_app()); |
| 883 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); | 867 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSerial)); |
| 884 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); | 868 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 885 EXPECT_TRUE(Contains(warnings, | 869 EXPECT_TRUE(Contains(warnings, |
| 886 "Use serial devices attached to your computer")); | 870 "Use serial devices attached to your computer")); |
| 887 ASSERT_EQ(1u, warnings.size()); | 871 ASSERT_EQ(1u, warnings.size()); |
| 888 } | 872 } |
| 889 | 873 |
| 890 TEST_F(PermissionsTest, GetWarningMessages_Socket_AnyHost) { | 874 TEST(PermissionsTest, GetWarningMessages_Socket_AnyHost) { |
| 891 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); | 875 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); |
| 892 | 876 |
| 893 scoped_refptr<Extension> extension = | 877 scoped_refptr<Extension> extension = |
| 894 LoadManifest("permissions", "socket_any_host.json"); | 878 LoadManifest("permissions", "socket_any_host.json"); |
| 895 EXPECT_TRUE(extension->is_platform_app()); | 879 EXPECT_TRUE(extension->is_platform_app()); |
| 896 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); | 880 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); |
| 897 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); | 881 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 898 EXPECT_EQ(1u, warnings.size()); | 882 EXPECT_EQ(1u, warnings.size()); |
| 899 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " | 883 EXPECT_TRUE(Contains(warnings, "Exchange data with any computer " |
| 900 "on the local network or internet")); | 884 "on the local network or internet")); |
| 901 } | 885 } |
| 902 | 886 |
| 903 TEST_F(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { | 887 TEST(PermissionsTest, GetWarningMessages_Socket_OneDomainTwoHostnames) { |
| 904 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); | 888 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); |
| 905 | 889 |
| 906 scoped_refptr<Extension> extension = | 890 scoped_refptr<Extension> extension = |
| 907 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); | 891 LoadManifest("permissions", "socket_one_domain_two_hostnames.json"); |
| 908 EXPECT_TRUE(extension->is_platform_app()); | 892 EXPECT_TRUE(extension->is_platform_app()); |
| 909 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); | 893 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); |
| 910 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); | 894 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 911 | 895 |
| 912 // Verify the warnings, including support for unicode characters, the fact | 896 // Verify the warnings, including support for unicode characters, the fact |
| 913 // that domain host warnings come before specific host warnings, and the fact | 897 // that domain host warnings come before specific host warnings, and the fact |
| 914 // that domains and hostnames are in alphabetical order regardless of the | 898 // that domains and hostnames are in alphabetical order regardless of the |
| 915 // order in the manifest file. | 899 // order in the manifest file. |
| 916 EXPECT_EQ(2u, warnings.size()); | 900 EXPECT_EQ(2u, warnings.size()); |
| 917 if (warnings.size() > 0) | 901 if (warnings.size() > 0) |
| 918 EXPECT_EQ(warnings[0], | 902 EXPECT_EQ(warnings[0], |
| 919 UTF8ToUTF16("Exchange data with any computer in the domain " | 903 UTF8ToUTF16("Exchange data with any computer in the domain " |
| 920 "example.org")); | 904 "example.org")); |
| 921 if (warnings.size() > 1) | 905 if (warnings.size() > 1) |
| 922 EXPECT_EQ(warnings[1], | 906 EXPECT_EQ(warnings[1], |
| 923 UTF8ToUTF16("Exchange data with the computers named: " | 907 UTF8ToUTF16("Exchange data with the computers named: " |
| 924 "b\xC3\xA5r.example.com foo.example.com")); | 908 "b\xC3\xA5r.example.com foo.example.com")); |
| 925 // "\xC3\xA5" = UTF-8 for lowercase A with ring above | 909 // "\xC3\xA5" = UTF-8 for lowercase A with ring above |
| 926 } | 910 } |
| 927 | 911 |
| 928 TEST_F(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { | 912 TEST(PermissionsTest, GetWarningMessages_Socket_TwoDomainsOneHostname) { |
| 929 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); | 913 Feature::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); |
| 930 | 914 |
| 931 scoped_refptr<Extension> extension = | 915 scoped_refptr<Extension> extension = |
| 932 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); | 916 LoadManifest("permissions", "socket_two_domains_one_hostname.json"); |
| 933 EXPECT_TRUE(extension->is_platform_app()); | 917 EXPECT_TRUE(extension->is_platform_app()); |
| 934 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); | 918 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSocket)); |
| 935 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); | 919 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 936 | 920 |
| 937 // Verify the warnings, including the fact that domain host warnings come | 921 // Verify the warnings, including the fact that domain host warnings come |
| 938 // before specific host warnings and the fact that domains and hostnames are | 922 // before specific host warnings and the fact that domains and hostnames are |
| 939 // in alphabetical order regardless of the order in the manifest file. | 923 // in alphabetical order regardless of the order in the manifest file. |
| 940 EXPECT_EQ(2u, warnings.size()); | 924 EXPECT_EQ(2u, warnings.size()); |
| 941 if (warnings.size() > 0) | 925 if (warnings.size() > 0) |
| 942 EXPECT_EQ(warnings[0], | 926 EXPECT_EQ(warnings[0], |
| 943 UTF8ToUTF16("Exchange data with any computer in the domains: " | 927 UTF8ToUTF16("Exchange data with any computer in the domains: " |
| 944 "example.com foo.example.org")); | 928 "example.com foo.example.org")); |
| 945 if (warnings.size() > 1) | 929 if (warnings.size() > 1) |
| 946 EXPECT_EQ(warnings[1], | 930 EXPECT_EQ(warnings[1], |
| 947 UTF8ToUTF16("Exchange data with the computer named " | 931 UTF8ToUTF16("Exchange data with the computer named " |
| 948 "bar.example.org")); | 932 "bar.example.org")); |
| 949 } | 933 } |
| 950 | 934 |
| 951 TEST_F(PermissionsTest, GetWarningMessages_PlatformApppHosts) { | 935 TEST(PermissionsTest, GetWarningMessages_PlatformApppHosts) { |
| 952 scoped_refptr<Extension> extension; | 936 scoped_refptr<Extension> extension; |
| 953 | 937 |
| 954 extension = LoadManifest("permissions", "platform_app_hosts.json"); | 938 extension = LoadManifest("permissions", "platform_app_hosts.json"); |
| 955 EXPECT_TRUE(extension->is_platform_app()); | 939 EXPECT_TRUE(extension->is_platform_app()); |
| 956 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); | 940 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 957 ASSERT_EQ(0u, warnings.size()); | 941 ASSERT_EQ(0u, warnings.size()); |
| 958 | 942 |
| 959 extension = LoadManifest("permissions", "platform_app_all_urls.json"); | 943 extension = LoadManifest("permissions", "platform_app_all_urls.json"); |
| 960 EXPECT_TRUE(extension->is_platform_app()); | 944 EXPECT_TRUE(extension->is_platform_app()); |
| 961 warnings = extension->GetPermissionMessageStrings(); | 945 warnings = extension->GetPermissionMessageStrings(); |
| 962 ASSERT_EQ(0u, warnings.size()); | 946 ASSERT_EQ(0u, warnings.size()); |
| 963 } | 947 } |
| 964 | 948 |
| 965 TEST_F(PermissionsTest, GetDistinctHostsForDisplay) { | 949 TEST(PermissionsTest, GetDistinctHostsForDisplay) { |
| 966 scoped_refptr<PermissionSet> perm_set; | 950 scoped_refptr<PermissionSet> perm_set; |
| 967 APIPermissionSet empty_perms; | 951 APIPermissionSet empty_perms; |
| 968 std::set<std::string> expected; | 952 std::set<std::string> expected; |
| 969 expected.insert("www.foo.com"); | 953 expected.insert("www.foo.com"); |
| 970 expected.insert("www.bar.com"); | 954 expected.insert("www.bar.com"); |
| 971 expected.insert("www.baz.com"); | 955 expected.insert("www.baz.com"); |
| 972 URLPatternSet explicit_hosts; | 956 URLPatternSet explicit_hosts; |
| 973 URLPatternSet scriptable_hosts; | 957 URLPatternSet scriptable_hosts; |
| 974 | 958 |
| 975 { | 959 { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 | 1095 |
| 1112 explicit_hosts.AddPattern( | 1096 explicit_hosts.AddPattern( |
| 1113 URLPattern(URLPattern::SCHEME_FILE, "file:///*")); | 1097 URLPattern(URLPattern::SCHEME_FILE, "file:///*")); |
| 1114 | 1098 |
| 1115 perm_set = new PermissionSet( | 1099 perm_set = new PermissionSet( |
| 1116 empty_perms, explicit_hosts, scriptable_hosts); | 1100 empty_perms, explicit_hosts, scriptable_hosts); |
| 1117 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); | 1101 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); |
| 1118 } | 1102 } |
| 1119 } | 1103 } |
| 1120 | 1104 |
| 1121 TEST_F(PermissionsTest, GetDistinctHostsForDisplay_ComIsBestRcd) { | 1105 TEST(PermissionsTest, GetDistinctHostsForDisplay_ComIsBestRcd) { |
| 1122 scoped_refptr<PermissionSet> perm_set; | 1106 scoped_refptr<PermissionSet> perm_set; |
| 1123 APIPermissionSet empty_perms; | 1107 APIPermissionSet empty_perms; |
| 1124 URLPatternSet explicit_hosts; | 1108 URLPatternSet explicit_hosts; |
| 1125 URLPatternSet scriptable_hosts; | 1109 URLPatternSet scriptable_hosts; |
| 1126 explicit_hosts.AddPattern( | 1110 explicit_hosts.AddPattern( |
| 1127 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); | 1111 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); |
| 1128 explicit_hosts.AddPattern( | 1112 explicit_hosts.AddPattern( |
| 1129 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); | 1113 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); |
| 1130 explicit_hosts.AddPattern( | 1114 explicit_hosts.AddPattern( |
| 1131 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1115 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
| 1132 explicit_hosts.AddPattern( | 1116 explicit_hosts.AddPattern( |
| 1133 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); | 1117 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); |
| 1134 explicit_hosts.AddPattern( | 1118 explicit_hosts.AddPattern( |
| 1135 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); | 1119 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); |
| 1136 explicit_hosts.AddPattern( | 1120 explicit_hosts.AddPattern( |
| 1137 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); | 1121 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path")); |
| 1138 | 1122 |
| 1139 std::set<std::string> expected; | 1123 std::set<std::string> expected; |
| 1140 expected.insert("www.foo.com"); | 1124 expected.insert("www.foo.com"); |
| 1141 perm_set = new PermissionSet( | 1125 perm_set = new PermissionSet( |
| 1142 empty_perms, explicit_hosts, scriptable_hosts); | 1126 empty_perms, explicit_hosts, scriptable_hosts); |
| 1143 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); | 1127 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); |
| 1144 } | 1128 } |
| 1145 | 1129 |
| 1146 TEST_F(PermissionsTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) { | 1130 TEST(PermissionsTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) { |
| 1147 scoped_refptr<PermissionSet> perm_set; | 1131 scoped_refptr<PermissionSet> perm_set; |
| 1148 APIPermissionSet empty_perms; | 1132 APIPermissionSet empty_perms; |
| 1149 URLPatternSet explicit_hosts; | 1133 URLPatternSet explicit_hosts; |
| 1150 URLPatternSet scriptable_hosts; | 1134 URLPatternSet scriptable_hosts; |
| 1151 explicit_hosts.AddPattern( | 1135 explicit_hosts.AddPattern( |
| 1152 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); | 1136 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); |
| 1153 explicit_hosts.AddPattern( | 1137 explicit_hosts.AddPattern( |
| 1154 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); | 1138 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); |
| 1155 explicit_hosts.AddPattern( | 1139 explicit_hosts.AddPattern( |
| 1156 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1140 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
| 1157 explicit_hosts.AddPattern( | 1141 explicit_hosts.AddPattern( |
| 1158 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); | 1142 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path")); |
| 1159 explicit_hosts.AddPattern( | 1143 explicit_hosts.AddPattern( |
| 1160 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); | 1144 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); |
| 1161 // No http://www.foo.com/path | 1145 // No http://www.foo.com/path |
| 1162 | 1146 |
| 1163 std::set<std::string> expected; | 1147 std::set<std::string> expected; |
| 1164 expected.insert("www.foo.net"); | 1148 expected.insert("www.foo.net"); |
| 1165 perm_set = new PermissionSet( | 1149 perm_set = new PermissionSet( |
| 1166 empty_perms, explicit_hosts, scriptable_hosts); | 1150 empty_perms, explicit_hosts, scriptable_hosts); |
| 1167 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); | 1151 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); |
| 1168 } | 1152 } |
| 1169 | 1153 |
| 1170 TEST_F(PermissionsTest, | 1154 TEST(PermissionsTest, |
| 1171 GetDistinctHostsForDisplay_OrgIs3rdBestRcd) { | 1155 GetDistinctHostsForDisplay_OrgIs3rdBestRcd) { |
| 1172 scoped_refptr<PermissionSet> perm_set; | 1156 scoped_refptr<PermissionSet> perm_set; |
| 1173 APIPermissionSet empty_perms; | 1157 APIPermissionSet empty_perms; |
| 1174 URLPatternSet explicit_hosts; | 1158 URLPatternSet explicit_hosts; |
| 1175 URLPatternSet scriptable_hosts; | 1159 URLPatternSet scriptable_hosts; |
| 1176 explicit_hosts.AddPattern( | 1160 explicit_hosts.AddPattern( |
| 1177 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); | 1161 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); |
| 1178 explicit_hosts.AddPattern( | 1162 explicit_hosts.AddPattern( |
| 1179 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); | 1163 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path")); |
| 1180 explicit_hosts.AddPattern( | 1164 explicit_hosts.AddPattern( |
| 1181 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1165 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
| 1182 // No http://www.foo.net/path | 1166 // No http://www.foo.net/path |
| 1183 explicit_hosts.AddPattern( | 1167 explicit_hosts.AddPattern( |
| 1184 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); | 1168 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); |
| 1185 // No http://www.foo.com/path | 1169 // No http://www.foo.com/path |
| 1186 | 1170 |
| 1187 std::set<std::string> expected; | 1171 std::set<std::string> expected; |
| 1188 expected.insert("www.foo.org"); | 1172 expected.insert("www.foo.org"); |
| 1189 perm_set = new PermissionSet( | 1173 perm_set = new PermissionSet( |
| 1190 empty_perms, explicit_hosts, scriptable_hosts); | 1174 empty_perms, explicit_hosts, scriptable_hosts); |
| 1191 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); | 1175 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); |
| 1192 } | 1176 } |
| 1193 | 1177 |
| 1194 TEST_F(PermissionsTest, | 1178 TEST(PermissionsTest, |
| 1195 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) { | 1179 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) { |
| 1196 scoped_refptr<PermissionSet> perm_set; | 1180 scoped_refptr<PermissionSet> perm_set; |
| 1197 APIPermissionSet empty_perms; | 1181 APIPermissionSet empty_perms; |
| 1198 URLPatternSet explicit_hosts; | 1182 URLPatternSet explicit_hosts; |
| 1199 URLPatternSet scriptable_hosts; | 1183 URLPatternSet scriptable_hosts; |
| 1200 explicit_hosts.AddPattern( | 1184 explicit_hosts.AddPattern( |
| 1201 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); | 1185 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path")); |
| 1202 // No http://www.foo.org/path | 1186 // No http://www.foo.org/path |
| 1203 explicit_hosts.AddPattern( | 1187 explicit_hosts.AddPattern( |
| 1204 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); | 1188 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path")); |
| 1205 // No http://www.foo.net/path | 1189 // No http://www.foo.net/path |
| 1206 explicit_hosts.AddPattern( | 1190 explicit_hosts.AddPattern( |
| 1207 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); | 1191 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path")); |
| 1208 // No http://www.foo.com/path | 1192 // No http://www.foo.com/path |
| 1209 | 1193 |
| 1210 std::set<std::string> expected; | 1194 std::set<std::string> expected; |
| 1211 expected.insert("www.foo.ca"); | 1195 expected.insert("www.foo.ca"); |
| 1212 perm_set = new PermissionSet( | 1196 perm_set = new PermissionSet( |
| 1213 empty_perms, explicit_hosts, scriptable_hosts); | 1197 empty_perms, explicit_hosts, scriptable_hosts); |
| 1214 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); | 1198 EXPECT_EQ(expected, perm_set->GetDistinctHostsForDisplay()); |
| 1215 } | 1199 } |
| 1216 | 1200 |
| 1217 TEST_F(PermissionsTest, HasLessHostPrivilegesThan) { | 1201 TEST(PermissionsTest, HasLessHostPrivilegesThan) { |
| 1218 URLPatternSet elist1; | 1202 URLPatternSet elist1; |
| 1219 URLPatternSet elist2; | 1203 URLPatternSet elist2; |
| 1220 URLPatternSet slist1; | 1204 URLPatternSet slist1; |
| 1221 URLPatternSet slist2; | 1205 URLPatternSet slist2; |
| 1222 scoped_refptr<PermissionSet> set1; | 1206 scoped_refptr<PermissionSet> set1; |
| 1223 scoped_refptr<PermissionSet> set2; | 1207 scoped_refptr<PermissionSet> set2; |
| 1224 APIPermissionSet empty_perms; | 1208 APIPermissionSet empty_perms; |
| 1225 elist1.AddPattern( | 1209 elist1.AddPattern( |
| 1226 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); | 1210 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); |
| 1227 elist1.AddPattern( | 1211 elist1.AddPattern( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 | 1260 |
| 1277 // Test that different subdomains count as different hosts. | 1261 // Test that different subdomains count as different hosts. |
| 1278 elist2.ClearPatterns(); | 1262 elist2.ClearPatterns(); |
| 1279 elist2.AddPattern( | 1263 elist2.AddPattern( |
| 1280 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); | 1264 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); |
| 1281 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1265 set2 = new PermissionSet(empty_perms, elist2, slist2); |
| 1282 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get())); | 1266 EXPECT_TRUE(set1->HasLessHostPrivilegesThan(set2.get())); |
| 1283 EXPECT_TRUE(set2->HasLessHostPrivilegesThan(set1.get())); | 1267 EXPECT_TRUE(set2->HasLessHostPrivilegesThan(set1.get())); |
| 1284 } | 1268 } |
| 1285 | 1269 |
| 1286 TEST_F(PermissionsTest, GetAPIsAsStrings) { | 1270 TEST(PermissionsTest, GetAPIsAsStrings) { |
| 1287 APIPermissionSet apis; | 1271 APIPermissionSet apis; |
| 1288 URLPatternSet empty_set; | 1272 URLPatternSet empty_set; |
| 1289 | 1273 |
| 1290 apis.insert(APIPermission::kProxy); | 1274 apis.insert(APIPermission::kProxy); |
| 1291 apis.insert(APIPermission::kBackground); | 1275 apis.insert(APIPermission::kBackground); |
| 1292 apis.insert(APIPermission::kNotification); | 1276 apis.insert(APIPermission::kNotification); |
| 1293 apis.insert(APIPermission::kTab); | 1277 apis.insert(APIPermission::kTab); |
| 1294 | 1278 |
| 1295 scoped_refptr<PermissionSet> perm_set = new PermissionSet( | 1279 scoped_refptr<PermissionSet> perm_set = new PermissionSet( |
| 1296 apis, empty_set, empty_set); | 1280 apis, empty_set, empty_set); |
| 1297 std::set<std::string> api_names = perm_set->GetAPIsAsStrings(); | 1281 std::set<std::string> api_names = perm_set->GetAPIsAsStrings(); |
| 1298 | 1282 |
| 1299 // The result is correct if it has the same number of elements | 1283 // The result is correct if it has the same number of elements |
| 1300 // and we can convert it back to the id set. | 1284 // and we can convert it back to the id set. |
| 1301 EXPECT_EQ(4u, api_names.size()); | 1285 EXPECT_EQ(4u, api_names.size()); |
| 1302 EXPECT_EQ(apis, | 1286 EXPECT_EQ(apis, |
| 1303 PermissionsInfo::GetInstance()->GetAllByName(api_names)); | 1287 PermissionsInfo::GetInstance()->GetAllByName(api_names)); |
| 1304 } | 1288 } |
| 1305 | 1289 |
| 1306 TEST_F(PermissionsTest, IsEmpty) { | 1290 TEST(PermissionsTest, IsEmpty) { |
| 1307 APIPermissionSet empty_apis; | 1291 APIPermissionSet empty_apis; |
| 1308 URLPatternSet empty_extent; | 1292 URLPatternSet empty_extent; |
| 1309 | 1293 |
| 1310 scoped_refptr<PermissionSet> empty = new PermissionSet(); | 1294 scoped_refptr<PermissionSet> empty = new PermissionSet(); |
| 1311 EXPECT_TRUE(empty->IsEmpty()); | 1295 EXPECT_TRUE(empty->IsEmpty()); |
| 1312 scoped_refptr<PermissionSet> perm_set; | 1296 scoped_refptr<PermissionSet> perm_set; |
| 1313 | 1297 |
| 1314 perm_set = new PermissionSet(empty_apis, empty_extent, empty_extent); | 1298 perm_set = new PermissionSet(empty_apis, empty_extent, empty_extent); |
| 1315 EXPECT_TRUE(perm_set->IsEmpty()); | 1299 EXPECT_TRUE(perm_set->IsEmpty()); |
| 1316 | 1300 |
| 1317 APIPermissionSet non_empty_apis; | 1301 APIPermissionSet non_empty_apis; |
| 1318 non_empty_apis.insert(APIPermission::kBackground); | 1302 non_empty_apis.insert(APIPermission::kBackground); |
| 1319 perm_set = new PermissionSet( | 1303 perm_set = new PermissionSet( |
| 1320 non_empty_apis, empty_extent, empty_extent); | 1304 non_empty_apis, empty_extent, empty_extent); |
| 1321 EXPECT_FALSE(perm_set->IsEmpty()); | 1305 EXPECT_FALSE(perm_set->IsEmpty()); |
| 1322 | 1306 |
| 1323 // Try non standard host | 1307 // Try non standard host |
| 1324 URLPatternSet non_empty_extent; | 1308 URLPatternSet non_empty_extent; |
| 1325 AddPattern(&non_empty_extent, "http://www.google.com/*"); | 1309 AddPattern(&non_empty_extent, "http://www.google.com/*"); |
| 1326 | 1310 |
| 1327 perm_set = new PermissionSet( | 1311 perm_set = new PermissionSet( |
| 1328 empty_apis, non_empty_extent, empty_extent); | 1312 empty_apis, non_empty_extent, empty_extent); |
| 1329 EXPECT_FALSE(perm_set->IsEmpty()); | 1313 EXPECT_FALSE(perm_set->IsEmpty()); |
| 1330 | 1314 |
| 1331 perm_set = new PermissionSet( | 1315 perm_set = new PermissionSet( |
| 1332 empty_apis, empty_extent, non_empty_extent); | 1316 empty_apis, empty_extent, non_empty_extent); |
| 1333 EXPECT_FALSE(perm_set->IsEmpty()); | 1317 EXPECT_FALSE(perm_set->IsEmpty()); |
| 1334 } | 1318 } |
| 1335 | 1319 |
| 1336 TEST_F(PermissionsTest, ImpliedPermissions) { | 1320 TEST(PermissionsTest, ImpliedPermissions) { |
| 1337 URLPatternSet empty_extent; | 1321 URLPatternSet empty_extent; |
| 1338 APIPermissionSet apis; | 1322 APIPermissionSet apis; |
| 1339 apis.insert(APIPermission::kWebRequest); | 1323 apis.insert(APIPermission::kWebRequest); |
| 1340 apis.insert(APIPermission::kFileBrowserHandler); | 1324 apis.insert(APIPermission::kFileBrowserHandler); |
| 1341 EXPECT_EQ(2U, apis.size()); | 1325 EXPECT_EQ(2U, apis.size()); |
| 1342 | 1326 |
| 1343 scoped_refptr<PermissionSet> perm_set; | 1327 scoped_refptr<PermissionSet> perm_set; |
| 1344 perm_set = new PermissionSet(apis, empty_extent, empty_extent); | 1328 perm_set = new PermissionSet(apis, empty_extent, empty_extent); |
| 1345 EXPECT_EQ(4U, perm_set->apis().size()); | 1329 EXPECT_EQ(4U, perm_set->apis().size()); |
| 1346 } | 1330 } |
| 1347 | 1331 |
| 1348 TEST_F(PermissionsTest, SyncFileSystemPermission) { | 1332 TEST(PermissionsTest, SyncFileSystemPermission) { |
| 1349 scoped_refptr<Extension> extension = LoadManifest( | 1333 scoped_refptr<Extension> extension = LoadManifest( |
| 1350 "permissions", "sync_file_system.json"); | 1334 "permissions", "sync_file_system.json"); |
| 1351 APIPermissionSet apis; | 1335 APIPermissionSet apis; |
| 1352 apis.insert(APIPermission::kSyncFileSystem); | 1336 apis.insert(APIPermission::kSyncFileSystem); |
| 1353 EXPECT_TRUE(extension->is_platform_app()); | 1337 EXPECT_TRUE(extension->is_platform_app()); |
| 1354 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); | 1338 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); |
| 1355 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); | 1339 std::vector<string16> warnings = extension->GetPermissionMessageStrings(); |
| 1356 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); | 1340 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); |
| 1357 ASSERT_EQ(1u, warnings.size()); | 1341 ASSERT_EQ(1u, warnings.size()); |
| 1358 } | 1342 } |
| 1359 | 1343 |
| 1360 } // namespace extensions | 1344 } // namespace extensions |
| OLD | NEW |