OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/extensions/permissions/chrome_permission_message_provide
r.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "extensions/common/permissions/permissions_data.h" |
| 10 #include "extensions/strings/grit/extensions_strings.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/base/l10n/l10n_util.h" |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 // Tests that ChromePermissionMessageProvider provides correct permission |
| 17 // messages for given permissions. |
| 18 // NOTE: No extensions are created as part of these tests. Integration tests |
| 19 // that test the messages are generated properly for extensions can be found in |
| 20 // chrome/browser/extensions/permission_messages_unittest.cc. |
| 21 class ChromePermissionMessageProviderUnittest : public testing::Test { |
| 22 public: |
| 23 ChromePermissionMessageProviderUnittest() |
| 24 : message_provider_(new ChromePermissionMessageProvider()) {} |
| 25 virtual ~ChromePermissionMessageProviderUnittest() {} |
| 26 |
| 27 protected: |
| 28 std::vector<base::string16> GetMessages(APIPermissionSet& permissions, |
| 29 Manifest::Type type) { |
| 30 scoped_refptr<const PermissionSet> permission_set = new PermissionSet( |
| 31 permissions, ManifestPermissionSet(), URLPatternSet(), URLPatternSet()); |
| 32 return message_provider_->GetWarningMessages(permission_set.get(), type); |
| 33 } |
| 34 |
| 35 private: |
| 36 scoped_ptr<ChromePermissionMessageProvider> message_provider_; |
| 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageProviderUnittest); |
| 39 }; |
| 40 |
| 41 // Checks that two related permissions display individual messages when they are |
| 42 // the only permission, but combine into one message when they are both present. |
| 43 TEST_F(ChromePermissionMessageProviderUnittest, RelatedPermissionsCoalesce) { |
| 44 APIPermissionSet permissions; |
| 45 std::vector<base::string16> messages; |
| 46 |
| 47 permissions.clear(); |
| 48 permissions.insert(APIPermission::kUsb); |
| 49 messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); |
| 50 ASSERT_EQ(1U, messages.size()); |
| 51 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_USB), |
| 52 messages[0]); |
| 53 |
| 54 permissions.clear(); |
| 55 permissions.insert(APIPermission::kSerial); |
| 56 messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); |
| 57 ASSERT_EQ(1U, messages.size()); |
| 58 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_SERIAL), |
| 59 messages[0]); |
| 60 |
| 61 permissions.clear(); |
| 62 permissions.insert(APIPermission::kSerial); |
| 63 permissions.insert(APIPermission::kUsb); |
| 64 messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); |
| 65 ASSERT_EQ(1U, messages.size()); |
| 66 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_USB_SERIAL), |
| 67 messages[0]); |
| 68 } |
| 69 |
| 70 // Checks that if an app has a superset and a subset permission, only the |
| 71 // superset permission message is displayed if thye are both present. |
| 72 TEST_F(ChromePermissionMessageProviderUnittest, |
| 73 SupersetOverridesSubsetPermission) { |
| 74 APIPermissionSet permissions; |
| 75 std::vector<base::string16> messages; |
| 76 |
| 77 permissions.clear(); |
| 78 permissions.insert(APIPermission::kTab); |
| 79 messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); |
| 80 ASSERT_EQ(1U, messages.size()); |
| 81 EXPECT_EQ( |
| 82 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), |
| 83 messages[0]); |
| 84 |
| 85 permissions.clear(); |
| 86 permissions.insert(APIPermission::kTopSites); |
| 87 messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); |
| 88 ASSERT_EQ(1U, messages.size()); |
| 89 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_TOPSITES), |
| 90 messages[0]); |
| 91 |
| 92 permissions.clear(); |
| 93 permissions.insert(APIPermission::kTab); |
| 94 permissions.insert(APIPermission::kTopSites); |
| 95 messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); |
| 96 ASSERT_EQ(1U, messages.size()); |
| 97 EXPECT_EQ( |
| 98 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), |
| 99 messages[0]); |
| 100 } |
| 101 |
| 102 } // namespace extensions |
OLD | NEW |