| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/permissions/chrome_permission_message_provide
r.h" | 5 #include "chrome/common/extensions/permissions/chrome_permission_message_provide
r.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "extensions/common/permissions/permission_set.h" | 14 #include "extensions/common/permissions/permission_set.h" |
| 15 #include "extensions/common/permissions/permissions_info.h" | 15 #include "extensions/common/permissions/permissions_info.h" |
| 16 #include "extensions/common/permissions/settings_override_permission.h" | 16 #include "extensions/common/permissions/settings_override_permission.h" |
| 17 #include "extensions/common/permissions/usb_device_permission.h" | 17 #include "extensions/common/permissions/usb_device_permission.h" |
| 18 #include "extensions/common/url_pattern_set.h" | 18 #include "extensions/common/url_pattern_set.h" |
| 19 #include "extensions/strings/grit/extensions_strings.h" | 19 #include "extensions/strings/grit/extensions_strings.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 const APIPermissionSet& new_permissions) { | 47 const APIPermissionSet& new_permissions) { |
| 48 return message_provider_->IsPrivilegeIncrease( | 48 return message_provider_->IsPrivilegeIncrease( |
| 49 PermissionSet(old_permissions, ManifestPermissionSet(), URLPatternSet(), | 49 PermissionSet(old_permissions, ManifestPermissionSet(), URLPatternSet(), |
| 50 URLPatternSet()), | 50 URLPatternSet()), |
| 51 PermissionSet(new_permissions, ManifestPermissionSet(), URLPatternSet(), | 51 PermissionSet(new_permissions, ManifestPermissionSet(), URLPatternSet(), |
| 52 URLPatternSet()), | 52 URLPatternSet()), |
| 53 Manifest::TYPE_EXTENSION); | 53 Manifest::TYPE_EXTENSION); |
| 54 } | 54 } |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 scoped_ptr<ChromePermissionMessageProvider> message_provider_; | 57 std::unique_ptr<ChromePermissionMessageProvider> message_provider_; |
| 58 | 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageProviderUnittest); | 59 DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageProviderUnittest); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 // Checks that if an app has a superset and a subset permission, only the | 62 // Checks that if an app has a superset and a subset permission, only the |
| 63 // superset permission message is displayed if they are both present. | 63 // superset permission message is displayed if they are both present. |
| 64 TEST_F(ChromePermissionMessageProviderUnittest, | 64 TEST_F(ChromePermissionMessageProviderUnittest, |
| 65 SupersetOverridesSubsetPermission) { | 65 SupersetOverridesSubsetPermission) { |
| 66 { | 66 { |
| 67 APIPermissionSet permissions; | 67 APIPermissionSet permissions; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 97 | 97 |
| 98 // Checks that when permissions are merged into a single message, their details | 98 // Checks that when permissions are merged into a single message, their details |
| 99 // are merged as well. | 99 // are merged as well. |
| 100 TEST_F(ChromePermissionMessageProviderUnittest, | 100 TEST_F(ChromePermissionMessageProviderUnittest, |
| 101 WarningsAndDetailsCoalesceTogether) { | 101 WarningsAndDetailsCoalesceTogether) { |
| 102 // kTab and kTopSites should be merged into a single message. | 102 // kTab and kTopSites should be merged into a single message. |
| 103 APIPermissionSet permissions; | 103 APIPermissionSet permissions; |
| 104 permissions.insert(APIPermission::kTab); | 104 permissions.insert(APIPermission::kTab); |
| 105 permissions.insert(APIPermission::kTopSites); | 105 permissions.insert(APIPermission::kTopSites); |
| 106 // The USB device permission message has a non-empty details string. | 106 // The USB device permission message has a non-empty details string. |
| 107 scoped_ptr<UsbDevicePermission> usb(new UsbDevicePermission( | 107 std::unique_ptr<UsbDevicePermission> usb(new UsbDevicePermission( |
| 108 PermissionsInfo::GetInstance()->GetByID(APIPermission::kUsbDevice))); | 108 PermissionsInfo::GetInstance()->GetByID(APIPermission::kUsbDevice))); |
| 109 scoped_ptr<base::ListValue> devices_list(new base::ListValue()); | 109 std::unique_ptr<base::ListValue> devices_list(new base::ListValue()); |
| 110 devices_list->Append( | 110 devices_list->Append( |
| 111 UsbDevicePermissionData(0x02ad, 0x138c, -1).ToValue().release()); | 111 UsbDevicePermissionData(0x02ad, 0x138c, -1).ToValue().release()); |
| 112 devices_list->Append( | 112 devices_list->Append( |
| 113 UsbDevicePermissionData(0x02ad, 0x138d, -1).ToValue().release()); | 113 UsbDevicePermissionData(0x02ad, 0x138d, -1).ToValue().release()); |
| 114 ASSERT_TRUE(usb->FromValue(devices_list.get(), nullptr, nullptr)); | 114 ASSERT_TRUE(usb->FromValue(devices_list.get(), nullptr, nullptr)); |
| 115 permissions.insert(usb.release()); | 115 permissions.insert(usb.release()); |
| 116 | 116 |
| 117 PermissionMessages messages = | 117 PermissionMessages messages = |
| 118 GetMessages(permissions, Manifest::TYPE_EXTENSION); | 118 GetMessages(permissions, Manifest::TYPE_EXTENSION); |
| 119 | 119 |
| 120 ASSERT_EQ(2U, messages.size()); | 120 ASSERT_EQ(2U, messages.size()); |
| 121 auto it = messages.begin(); | 121 auto it = messages.begin(); |
| 122 const PermissionMessage& message0 = *it++; | 122 const PermissionMessage& message0 = *it++; |
| 123 EXPECT_EQ( | 123 EXPECT_EQ( |
| 124 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), | 124 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), |
| 125 message0.message()); | 125 message0.message()); |
| 126 EXPECT_TRUE(message0.submessages().empty()); | 126 EXPECT_TRUE(message0.submessages().empty()); |
| 127 const PermissionMessage& message1 = *it++; | 127 const PermissionMessage& message1 = *it++; |
| 128 EXPECT_EQ( | 128 EXPECT_EQ( |
| 129 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST), | 129 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST), |
| 130 message1.message()); | 130 message1.message()); |
| 131 EXPECT_FALSE(message1.submessages().empty()); | 131 EXPECT_FALSE(message1.submessages().empty()); |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace extensions | 134 } // namespace extensions |
| OLD | NEW |