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 "chrome/common/extensions/extension_permission_set.h" | 5 #include "chrome/common/extensions/extension_permission_set.h" |
6 | 6 |
7 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 TEST(ExtensionPermissionsTest, DefaultFunctionAccess) { | 637 TEST(ExtensionPermissionsTest, DefaultFunctionAccess) { |
638 const struct { | 638 const struct { |
639 const char* permission_name; | 639 const char* permission_name; |
640 bool expect_success; | 640 bool expect_success; |
641 } kTests[] = { | 641 } kTests[] = { |
642 // Negative test. | 642 // Negative test. |
643 { "non_existing_permission", false }, | 643 { "non_existing_permission", false }, |
644 // Test default module/package permission. | 644 // Test default module/package permission. |
645 { "browserAction", true }, | 645 { "browserAction", true }, |
646 { "devtools", true }, | 646 { "devtools", true }, |
647 { "extension", true }, | |
648 { "i18n", true }, | 647 { "i18n", true }, |
649 { "pageAction", true }, | 648 { "pageAction", true }, |
650 { "pageActions", true }, | 649 { "pageActions", true }, |
651 { "test", true }, | 650 { "test", true }, |
652 // Some negative tests. | 651 // Some negative tests. |
653 { "bookmarks", false }, | 652 { "bookmarks", false }, |
654 { "cookies", false }, | 653 { "cookies", false }, |
655 { "history", false }, | 654 { "history", false }, |
656 { "tabs.onUpdated", false }, | |
657 // Make sure we find the module name after stripping '.' and '/'. | 655 // Make sure we find the module name after stripping '.' and '/'. |
658 { "browserAction/abcd/onClick", true }, | 656 { "browserAction/abcd/onClick", true }, |
659 { "browserAction.abcd.onClick", true }, | 657 { "browserAction.abcd.onClick", true }, |
660 // Test Tabs functions. | |
661 { "tabs.create", true}, | |
662 { "tabs.update", true}, | |
663 { "tabs.getSelected", false}, | |
664 }; | 658 }; |
665 | 659 |
666 scoped_refptr<ExtensionPermissionSet> empty = new ExtensionPermissionSet(); | 660 scoped_refptr<ExtensionPermissionSet> empty = new ExtensionPermissionSet(); |
667 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { | 661 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
668 EXPECT_EQ(kTests[i].expect_success, | 662 EXPECT_EQ(kTests[i].expect_success, |
669 empty->HasAccessToFunction(kTests[i].permission_name)); | 663 empty->HasAccessToFunction(kTests[i].permission_name)); |
670 } | 664 } |
671 } | 665 } |
672 | 666 |
673 // Tests the default permissions (empty API permission set). | 667 // Tests the default permissions (empty API permission set). |
674 TEST(ExtensionPermissionSetTest, DefaultAnyAPIAccess) { | 668 TEST(ExtensionPermissionSetTest, DefaultAnyAPIAccess) { |
675 const struct { | 669 const struct { |
676 const char* api_name; | 670 const char* api_name; |
677 bool expect_success; | 671 bool expect_success; |
678 } kTests[] = { | 672 } kTests[] = { |
679 // Negative test. | 673 // Negative test. |
680 { "non_existing_permission", false }, | 674 { "non_existing_permission", false }, |
681 // Test default module/package permission. | 675 // Test default module/package permission. |
682 { "browserAction", true }, | 676 { "browserAction", true }, |
683 { "devtools", true }, | 677 { "devtools", true }, |
684 { "extension", true }, | |
685 { "i18n", true }, | 678 { "i18n", true }, |
686 { "pageAction", true }, | 679 { "pageAction", true }, |
687 { "pageActions", true }, | 680 { "pageActions", true }, |
688 { "test", true }, | 681 { "test", true }, |
689 // Some negative tests. | 682 // Some negative tests. |
690 { "bookmarks", false }, | 683 { "bookmarks", false }, |
691 { "cookies", false }, | 684 { "cookies", false }, |
692 { "history", false }, | 685 { "history", false }, |
693 // Negative APIs that have positive individual functions. | 686 // Negative APIs that have positive individual functions. |
694 { "management", true}, | 687 { "management", true}, |
695 { "tabs", true}, | |
696 }; | 688 }; |
697 | 689 |
698 scoped_refptr<ExtensionPermissionSet> empty = new ExtensionPermissionSet(); | 690 scoped_refptr<ExtensionPermissionSet> empty = new ExtensionPermissionSet(); |
699 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { | 691 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { |
700 EXPECT_EQ(kTests[i].expect_success, | 692 EXPECT_EQ(kTests[i].expect_success, |
701 empty->HasAnyAccessToAPI(kTests[i].api_name)); | 693 empty->HasAnyAccessToAPI(kTests[i].api_name)); |
702 } | 694 } |
703 } | 695 } |
704 | 696 |
705 TEST(ExtensionPermissionsTest, GetWarningMessages_ManyHosts) { | 697 TEST(ExtensionPermissionsTest, GetWarningMessages_ManyHosts) { |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 AddPattern(&non_empty_extent, "http://www.google.com/*"); | 1086 AddPattern(&non_empty_extent, "http://www.google.com/*"); |
1095 | 1087 |
1096 perm_set = new ExtensionPermissionSet( | 1088 perm_set = new ExtensionPermissionSet( |
1097 empty_apis, non_empty_extent, empty_extent); | 1089 empty_apis, non_empty_extent, empty_extent); |
1098 EXPECT_FALSE(perm_set->IsEmpty()); | 1090 EXPECT_FALSE(perm_set->IsEmpty()); |
1099 | 1091 |
1100 perm_set = new ExtensionPermissionSet( | 1092 perm_set = new ExtensionPermissionSet( |
1101 empty_apis, empty_extent, non_empty_extent); | 1093 empty_apis, empty_extent, non_empty_extent); |
1102 EXPECT_FALSE(perm_set->IsEmpty()); | 1094 EXPECT_FALSE(perm_set->IsEmpty()); |
1103 } | 1095 } |
OLD | NEW |