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.
5 #include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"
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"
14 namespace extensions
{
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
{
23 ChromePermissionMessageProviderUnittest()
24 : message_provider_(new ChromePermissionMessageProvider()) {}
25 ~ChromePermissionMessageProviderUnittest() override
{}
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
);
36 scoped_ptr
<ChromePermissionMessageProvider
> message_provider_
;
38 DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageProviderUnittest
);
41 // Checks that if an app has a superset and a subset permission, only the
42 // superset permission message is displayed if thye are both present.
43 TEST_F(ChromePermissionMessageProviderUnittest
,
44 SupersetOverridesSubsetPermission
) {
45 APIPermissionSet permissions
;
46 std::vector
<base::string16
> messages
;
49 permissions
.insert(APIPermission::kTab
);
50 messages
= GetMessages(permissions
, Manifest::TYPE_PLATFORM_APP
);
51 ASSERT_EQ(1U, messages
.size());
53 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ
),
57 permissions
.insert(APIPermission::kTopSites
);
58 messages
= GetMessages(permissions
, Manifest::TYPE_PLATFORM_APP
);
59 ASSERT_EQ(1U, messages
.size());
60 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_TOPSITES
),
64 permissions
.insert(APIPermission::kTab
);
65 permissions
.insert(APIPermission::kTopSites
);
66 messages
= GetMessages(permissions
, Manifest::TYPE_PLATFORM_APP
);
67 ASSERT_EQ(1U, messages
.size());
69 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ
),
73 } // namespace extensions