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 "base/command_line.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/test/values_test_util.h"
8 #include "chrome/browser/extensions/test_extension_environment.h"
9 #include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"
10 #include "extensions/common/extension.h"
11 #include "extensions/common/features/simple_feature.h"
12 #include "extensions/common/permissions/permission_message_test_util.h"
13 #include "extensions/common/permissions/permissions_data.h"
14 #include "extensions/common/switches.h"
15 #include "testing/gmock/include/gmock/gmock-matchers.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace extensions
{
20 const char kWhitelistedExtensionID
[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
22 // Tests that ChromePermissionMessageProvider produces the expected messages for
23 // various combinations of app/extension permissions.
24 class PermissionMessageCombinationsUnittest
: public testing::Test
{
26 PermissionMessageCombinationsUnittest()
27 : message_provider_(new ChromePermissionMessageProvider()),
28 whitelisted_extension_id_(kWhitelistedExtensionID
) {}
29 ~PermissionMessageCombinationsUnittest() override
{}
31 // Overridden from testing::Test:
32 void SetUp() override
{
33 testing::Test::SetUp();
37 // Create and install an app or extension with the given manifest JSON string.
38 // Single-quotes in the string will be replaced with double quotes.
39 void CreateAndInstall(const std::string
& json_manifest
) {
40 std::string json_manifest_with_double_quotes
= json_manifest
;
41 std::replace(json_manifest_with_double_quotes
.begin(),
42 json_manifest_with_double_quotes
.end(), '\'', '"');
43 app_
= env_
.MakeExtension(
44 *base::test::ParseJson(json_manifest_with_double_quotes
),
45 kWhitelistedExtensionID
);
48 // Checks whether the currently installed app or extension produces the given
49 // permission messages. Call this after installing an app with the expected
50 // permission messages. The messages are tested for existence in any order.
51 testing::AssertionResult
CheckManifestProducesPermissions() {
52 return VerifyNoPermissionMessages(app_
->permissions_data());
54 testing::AssertionResult
CheckManifestProducesPermissions(
55 const std::string
& expected_message_1
) {
56 return VerifyOnePermissionMessage(app_
->permissions_data(),
59 testing::AssertionResult
CheckManifestProducesPermissions(
60 const std::string
& expected_message_1
,
61 const std::string
& expected_message_2
) {
62 return VerifyTwoPermissionMessages(app_
->permissions_data(),
63 expected_message_1
, expected_message_2
,
66 testing::AssertionResult
CheckManifestProducesPermissions(
67 const std::string
& expected_message_1
,
68 const std::string
& expected_message_2
,
69 const std::string
& expected_message_3
) {
70 std::vector
<std::string
> expected_messages
;
71 expected_messages
.push_back(expected_message_1
);
72 expected_messages
.push_back(expected_message_2
);
73 expected_messages
.push_back(expected_message_3
);
74 return VerifyPermissionMessages(app_
->permissions_data(), expected_messages
,
77 testing::AssertionResult
CheckManifestProducesPermissions(
78 const std::string
& expected_message_1
,
79 const std::string
& expected_message_2
,
80 const std::string
& expected_message_3
,
81 const std::string
& expected_message_4
) {
82 std::vector
<std::string
> expected_messages
;
83 expected_messages
.push_back(expected_message_1
);
84 expected_messages
.push_back(expected_message_2
);
85 expected_messages
.push_back(expected_message_3
);
86 expected_messages
.push_back(expected_message_4
);
87 return VerifyPermissionMessages(app_
->permissions_data(), expected_messages
,
90 testing::AssertionResult
CheckManifestProducesPermissions(
91 const std::string
& expected_message_1
,
92 const std::string
& expected_message_2
,
93 const std::string
& expected_message_3
,
94 const std::string
& expected_message_4
,
95 const std::string
& expected_message_5
) {
96 std::vector
<std::string
> expected_messages
;
97 expected_messages
.push_back(expected_message_1
);
98 expected_messages
.push_back(expected_message_2
);
99 expected_messages
.push_back(expected_message_3
);
100 expected_messages
.push_back(expected_message_4
);
101 expected_messages
.push_back(expected_message_5
);
102 return VerifyPermissionMessages(app_
->permissions_data(), expected_messages
,
105 testing::AssertionResult
CheckManifestProducesPermissions(
106 const std::string
& expected_message_1
,
107 const std::vector
<std::string
>& expected_submessages_1
) {
108 return VerifyOnePermissionMessageWithSubmessages(
109 app_
->permissions_data(), expected_message_1
, expected_submessages_1
);
111 testing::AssertionResult
CheckManifestProducesPermissions(
112 const std::string
& expected_message_1
,
113 const std::vector
<std::string
>& expected_submessages_1
,
114 const std::string
& expected_message_2
,
115 const std::vector
<std::string
>& expected_submessages_2
) {
116 std::vector
<std::string
> expected_messages
;
117 expected_messages
.push_back(expected_message_1
);
118 expected_messages
.push_back(expected_message_2
);
119 std::vector
<std::vector
<std::string
>> expected_submessages
;
120 expected_submessages
.push_back(expected_submessages_1
);
121 expected_submessages
.push_back(expected_submessages_2
);
122 return VerifyPermissionMessagesWithSubmessages(app_
->permissions_data(),
124 expected_submessages
, false);
126 testing::AssertionResult
CheckManifestProducesPermissions(
127 const std::string
& expected_message_1
,
128 const std::vector
<std::string
>& expected_submessages_1
,
129 const std::string
& expected_message_2
,
130 const std::vector
<std::string
>& expected_submessages_2
,
131 const std::string
& expected_message_3
,
132 const std::vector
<std::string
>& expected_submessages_3
) {
133 std::vector
<std::string
> expected_messages
;
134 expected_messages
.push_back(expected_message_1
);
135 expected_messages
.push_back(expected_message_2
);
136 expected_messages
.push_back(expected_message_3
);
137 std::vector
<std::vector
<std::string
>> expected_submessages
;
138 expected_submessages
.push_back(expected_submessages_1
);
139 expected_submessages
.push_back(expected_submessages_2
);
140 expected_submessages
.push_back(expected_submessages_3
);
141 return VerifyPermissionMessagesWithSubmessages(app_
->permissions_data(),
143 expected_submessages
, false);
145 testing::AssertionResult
CheckManifestProducesPermissions(
146 const std::string
& expected_message_1
,
147 const std::vector
<std::string
>& expected_submessages_1
,
148 const std::string
& expected_message_2
,
149 const std::vector
<std::string
>& expected_submessages_2
,
150 const std::string
& expected_message_3
,
151 const std::vector
<std::string
>& expected_submessages_3
,
152 const std::string
& expected_message_4
,
153 const std::vector
<std::string
>& expected_submessages_4
) {
154 std::vector
<std::string
> expected_messages
;
155 expected_messages
.push_back(expected_message_1
);
156 expected_messages
.push_back(expected_message_2
);
157 expected_messages
.push_back(expected_message_3
);
158 expected_messages
.push_back(expected_message_4
);
159 std::vector
<std::vector
<std::string
>> expected_submessages
;
160 expected_submessages
.push_back(expected_submessages_1
);
161 expected_submessages
.push_back(expected_submessages_2
);
162 expected_submessages
.push_back(expected_submessages_3
);
163 expected_submessages
.push_back(expected_submessages_4
);
164 return VerifyPermissionMessagesWithSubmessages(app_
->permissions_data(),
166 expected_submessages
, false);
168 testing::AssertionResult
CheckManifestProducesPermissions(
169 const std::string
& expected_message_1
,
170 const std::vector
<std::string
>& expected_submessages_1
,
171 const std::string
& expected_message_2
,
172 const std::vector
<std::string
>& expected_submessages_2
,
173 const std::string
& expected_message_3
,
174 const std::vector
<std::string
>& expected_submessages_3
,
175 const std::string
& expected_message_4
,
176 const std::vector
<std::string
>& expected_submessages_4
,
177 const std::string
& expected_message_5
,
178 const std::vector
<std::string
>& expected_submessages_5
) {
179 std::vector
<std::string
> expected_messages
;
180 expected_messages
.push_back(expected_message_1
);
181 expected_messages
.push_back(expected_message_2
);
182 expected_messages
.push_back(expected_message_3
);
183 expected_messages
.push_back(expected_message_4
);
184 expected_messages
.push_back(expected_message_5
);
185 std::vector
<std::vector
<std::string
>> expected_submessages
;
186 expected_submessages
.push_back(expected_submessages_1
);
187 expected_submessages
.push_back(expected_submessages_2
);
188 expected_submessages
.push_back(expected_submessages_3
);
189 expected_submessages
.push_back(expected_submessages_4
);
190 expected_submessages
.push_back(expected_submessages_5
);
191 return VerifyPermissionMessagesWithSubmessages(app_
->permissions_data(),
193 expected_submessages
, false);
197 extensions::TestExtensionEnvironment env_
;
198 scoped_ptr
<ChromePermissionMessageProvider
> message_provider_
;
199 scoped_refptr
<const Extension
> app_
;
200 // Whitelist a known extension id so we can test all permissions. This ID
201 // will be used for each test app.
202 extensions::SimpleFeature::ScopedWhitelistForTest whitelisted_extension_id_
;
204 DISALLOW_COPY_AND_ASSIGN(PermissionMessageCombinationsUnittest
);
207 // Test that the USB, Bluetooth and Serial permissions do not coalesce on their
208 // own, but do coalesce when more than 1 is present.
209 TEST_F(PermissionMessageCombinationsUnittest
, USBSerialBluetoothCoalescing
) {
210 // Test that the USB permission does not coalesce on its own.
215 " 'scripts': ['background.js']"
219 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] }"
222 ASSERT_TRUE(CheckManifestProducesPermissions(
223 "Access USB devices from an unknown vendor"));
229 " 'scripts': ['background.js']"
233 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] }"
236 ASSERT_TRUE(CheckManifestProducesPermissions(
237 "Access USB devices from an unknown vendor"));
239 // Test that the serial permission does not coalesce on its own.
244 " 'scripts': ['background.js']"
251 ASSERT_TRUE(CheckManifestProducesPermissions("Access your serial devices"));
253 // Test that the bluetooth permission does not coalesce on its own.
258 " 'scripts': ['background.js']"
263 ASSERT_TRUE(CheckManifestProducesPermissions(
264 "Access information about Bluetooth devices paired with your system and "
265 "discover nearby Bluetooth devices."));
267 // Test that the bluetooth permission does not coalesce on its own, even
268 // when it specifies additional permissions.
273 " 'scripts': ['background.js']"
277 " 'uuids': ['1105', '1106']"
280 ASSERT_TRUE(CheckManifestProducesPermissions(
281 "Access information about Bluetooth devices paired with your system and "
282 "discover nearby Bluetooth devices."));
284 // Test that the USB and Serial permissions coalesce.
289 " 'scripts': ['background.js']"
293 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] },"
297 ASSERT_TRUE(CheckManifestProducesPermissions(
298 "Access USB devices from an unknown vendor",
299 "Access your serial devices"));
301 // Test that the USB, Serial and Bluetooth permissions coalesce.
306 " 'scripts': ['background.js']"
310 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] },"
315 ASSERT_TRUE(CheckManifestProducesPermissions(
316 "Access USB devices from an unknown vendor",
317 "Access your Bluetooth and Serial devices"));
319 // Test that the USB, Serial and Bluetooth permissions coalesce even when
320 // Bluetooth specifies multiple additional permissions.
325 " 'scripts': ['background.js']"
329 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] },"
333 " 'uuids': ['1105', '1106'],"
335 " 'low_energy': true"
338 ASSERT_TRUE(CheckManifestProducesPermissions(
339 "Access USB devices from an unknown vendor",
340 "Access your Bluetooth and Serial devices"));
343 // Test that the History permission takes precedence over the Tabs permission,
344 // and that the Sessions permission modifies this final message.
345 TEST_F(PermissionMessageCombinationsUnittest
, TabsHistorySessionsCoalescing
) {
352 ASSERT_TRUE(CheckManifestProducesPermissions("Read your browsing history"));
357 " 'tabs', 'sessions'"
360 ASSERT_TRUE(CheckManifestProducesPermissions(
361 "Read your browsing history on all your signed-in devices"));
369 ASSERT_TRUE(CheckManifestProducesPermissions(
370 "Read and change your browsing history"));
375 " 'tabs', 'history', 'sessions'"
378 ASSERT_TRUE(CheckManifestProducesPermissions(
379 "Read and change your browsing history on all your signed-in devices"));
382 // Test that the fileSystem permission produces no messages by itself, unless it
383 // has both the 'write' and 'directory' additional permissions, in which case it
384 // displays a message.
385 TEST_F(PermissionMessageCombinationsUnittest
, FileSystemReadWriteCoalescing
) {
390 " 'scripts': ['background.js']"
397 ASSERT_TRUE(CheckManifestProducesPermissions());
403 " 'scripts': ['background.js']"
407 " 'fileSystem', {'fileSystem': ['retainEntries', 'write']}"
410 ASSERT_TRUE(CheckManifestProducesPermissions());
416 " 'scripts': ['background.js']"
420 " 'fileSystem', {'fileSystem': ["
421 " 'retainEntries', 'write', 'directory'"
425 ASSERT_TRUE(CheckManifestProducesPermissions(
426 "Write to files and folders that you open in the application"));
429 // Check that host permission messages are generated correctly when URLs are
430 // entered as permissions.
431 TEST_F(PermissionMessageCombinationsUnittest
, HostsPermissionMessages
) {
435 " 'http://www.blogger.com/',"
438 ASSERT_TRUE(CheckManifestProducesPermissions(
439 "Read and change your data on www.blogger.com"));
444 " 'http://*.google.com/',"
447 ASSERT_TRUE(CheckManifestProducesPermissions(
448 "Read and change your data on all google.com sites"));
453 " 'http://www.blogger.com/',"
454 " 'http://*.google.com/',"
457 ASSERT_TRUE(CheckManifestProducesPermissions(
458 "Read and change your data on all google.com sites and "
464 " 'http://www.blogger.com/',"
465 " 'http://*.google.com/',"
466 " 'http://*.news.com/',"
469 ASSERT_TRUE(CheckManifestProducesPermissions(
470 "Read and change your data on all google.com sites, all news.com sites, "
471 "and www.blogger.com"));
476 " 'http://www.blogger.com/',"
477 " 'http://*.google.com/',"
478 " 'http://*.news.com/',"
479 " 'http://www.foobar.com/',"
482 std::vector
<std::string
> submessages
;
483 submessages
.push_back("All google.com sites");
484 submessages
.push_back("All news.com sites");
485 submessages
.push_back("www.blogger.com");
486 submessages
.push_back("www.foobar.com");
487 ASSERT_TRUE(CheckManifestProducesPermissions(
488 "Read and change your data on a number of websites", submessages
));
493 " 'http://www.blogger.com/',"
494 " 'http://*.google.com/',"
495 " 'http://*.news.com/',"
496 " 'http://www.foobar.com/',"
497 " 'http://*.go.com/',"
501 submessages
.push_back("All go.com sites");
502 submessages
.push_back("All google.com sites");
503 submessages
.push_back("All news.com sites");
504 submessages
.push_back("www.blogger.com");
505 submessages
.push_back("www.foobar.com");
506 ASSERT_TRUE(CheckManifestProducesPermissions(
507 "Read and change your data on a number of websites", submessages
));
512 " 'http://*.go.com/',"
513 " 'chrome://favicon/',"
516 ASSERT_TRUE(CheckManifestProducesPermissions(
517 "Read and change your data on all go.com sites",
518 "Read the icons of the websites you visit"));
520 // Having the 'all sites' permission doesn't change the permission message,
521 // since its pseudo-granted at runtime.
525 " 'http://*.go.com/',"
526 " 'chrome://favicon/',"
530 ASSERT_TRUE(CheckManifestProducesPermissions(
531 "Read and change your data on all go.com sites",
532 "Read the icons of the websites you visit"));
535 // Check that permission messages are generated correctly for
536 // SocketsManifestPermission, which has host-like permission messages.
537 TEST_F(PermissionMessageCombinationsUnittest
,
538 SocketsManifestPermissionMessages
) {
543 " 'scripts': ['background.js']"
547 " 'udp': {'send': '*'},"
550 ASSERT_TRUE(CheckManifestProducesPermissions(
551 "Exchange data with any device on the local network or internet"));
557 " 'scripts': ['background.js']"
561 " 'udp': {'send': ':99'},"
564 ASSERT_TRUE(CheckManifestProducesPermissions(
565 "Exchange data with any device on the local network or internet"));
571 " 'scripts': ['background.js']"
575 " 'tcp': {'connect': '127.0.0.1:80'},"
578 ASSERT_TRUE(CheckManifestProducesPermissions(
579 "Exchange data with the device named 127.0.0.1"));
585 " 'scripts': ['background.js']"
589 " 'tcp': {'connect': 'www.example.com:23'},"
592 ASSERT_TRUE(CheckManifestProducesPermissions(
593 "Exchange data with the device named www.example.com"));
599 " 'scripts': ['background.js']"
603 " 'tcpServer': {'listen': '127.0.0.1:80'}"
606 ASSERT_TRUE(CheckManifestProducesPermissions(
607 "Exchange data with the device named 127.0.0.1"));
613 " 'scripts': ['background.js']"
617 " 'tcpServer': {'listen': ':8080'}"
620 ASSERT_TRUE(CheckManifestProducesPermissions(
621 "Exchange data with any device on the local network or internet"));
627 " 'scripts': ['background.js']"
635 " 'www.example.com:*',"
636 " 'www.foo.com:200',"
642 ASSERT_TRUE(CheckManifestProducesPermissions(
643 "Exchange data with the devices named: 127.0.0.1 www.bar.com "
644 "www.example.com www.foo.com www.google.com"));
650 " 'scripts': ['background.js']"
657 " 'www.mywebsite.com:320',"
658 " 'www.freestuff.com',"
667 " 'www.example.com:*',"
668 " 'www.foo.com:200',"
673 ASSERT_TRUE(CheckManifestProducesPermissions(
674 "Exchange data with the devices named: 127.0.0.1 www.abc.com "
675 "www.example.com www.foo.com www.freestuff.com www.google.com "
676 "www.mywebsite.com www.test.com"));
682 " 'scripts': ['background.js']"
686 " 'tcp': {'send': '*:*'},"
687 " 'tcpServer': {'listen': '*:*'},"
690 ASSERT_TRUE(CheckManifestProducesPermissions(
691 "Exchange data with any device on the local network or internet"));
694 // Check that permission messages are generated correctly for
695 // MediaGalleriesPermission (an API permission with custom messages).
696 TEST_F(PermissionMessageCombinationsUnittest
,
697 MediaGalleriesPermissionMessages
) {
702 " 'scripts': ['background.js']"
706 " { 'mediaGalleries': ['read'] }"
709 ASSERT_TRUE(CheckManifestProducesPermissions());
715 " 'scripts': ['background.js']"
719 " { 'mediaGalleries': ['read', 'allAutoDetected'] }"
722 ASSERT_TRUE(CheckManifestProducesPermissions(
723 "Access photos, music, and other media from your computer"));
725 // TODO(sashab): Add a test for the
726 // IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_READ_WRITE message (generated
727 // with the 'read' and 'copyTo' permissions, but not the 'delete' permission),
728 // if it's possible to get this message. Otherwise, remove it from the code.
734 " 'scripts': ['background.js']"
738 " { 'mediaGalleries': ['read', 'delete', 'allAutoDetected'] }"
741 ASSERT_TRUE(CheckManifestProducesPermissions(
742 "Read and delete photos, music, and other media from your computer"));
748 " 'scripts': ['background.js']"
752 " { 'mediaGalleries':"
753 " [ 'read', 'delete', 'copyTo', 'allAutoDetected' ] }"
756 ASSERT_TRUE(CheckManifestProducesPermissions(
757 "Read, change and delete photos, music, and other media from your "
760 // Without the allAutoDetected permission, there should be no install-time
761 // permission messages.
766 " 'scripts': ['background.js']"
770 " { 'mediaGalleries': ['read', 'delete', 'copyTo'] }"
773 ASSERT_TRUE(CheckManifestProducesPermissions());
776 // TODO(sashab): Add tests for SettingsOverrideAPIPermission (an API permission
777 // with custom messages).
779 // Check that permission messages are generated correctly for SocketPermission
780 // (an API permission with custom messages).
781 TEST_F(PermissionMessageCombinationsUnittest
, SocketPermissionMessages
) {
786 " 'scripts': ['background.js']"
790 " { 'socket': ['tcp-connect:*:*'] }"
793 ASSERT_TRUE(CheckManifestProducesPermissions(
794 "Exchange data with any device on the local network or internet"));
800 " 'scripts': ['background.js']"
805 " 'tcp-connect:*:443',"
806 " 'tcp-connect:*:50032',"
807 " 'tcp-connect:*:23',"
811 ASSERT_TRUE(CheckManifestProducesPermissions(
812 "Exchange data with any device on the local network or internet"));
818 " 'scripts': ['background.js']"
822 " { 'socket': ['tcp-connect:foo.example.com:443'] }"
825 ASSERT_TRUE(CheckManifestProducesPermissions(
826 "Exchange data with the device named foo.example.com"));
832 " 'scripts': ['background.js']"
836 " { 'socket': ['tcp-connect:foo.example.com:443', 'udp-send-to'] }"
839 ASSERT_TRUE(CheckManifestProducesPermissions(
840 "Exchange data with any device on the local network or internet"));
846 " 'scripts': ['background.js']"
851 " 'tcp-connect:foo.example.com:443',"
852 " 'udp-send-to:test.ping.com:50032',"
856 ASSERT_TRUE(CheckManifestProducesPermissions(
857 "Exchange data with the devices named: foo.example.com test.ping.com"));
863 " 'scripts': ['background.js']"
868 " 'tcp-connect:foo.example.com:443',"
869 " 'udp-send-to:test.ping.com:50032',"
870 " 'udp-send-to:www.ping.com:50032',"
871 " 'udp-send-to:test2.ping.com:50032',"
872 " 'udp-bind:test.ping.com:50032',"
876 ASSERT_TRUE(CheckManifestProducesPermissions(
877 "Exchange data with the devices named: foo.example.com test.ping.com "
878 "test2.ping.com www.ping.com"));
884 " 'scripts': ['background.js']"
889 " 'tcp-connect:foo.example.com:443',"
890 " 'udp-send-to:test.ping.com:50032',"
891 " 'tcp-connect:*:23',"
895 ASSERT_TRUE(CheckManifestProducesPermissions(
896 "Exchange data with any device on the local network or internet"));
899 // Check that permission messages are generated correctly for
900 // USBDevicePermission (an API permission with custom messages).
901 TEST_F(PermissionMessageCombinationsUnittest
, USBDevicePermissionMessages
) {
906 " 'scripts': ['background.js']"
911 " { 'vendorId': 0, 'productId': 0 },"
915 ASSERT_TRUE(CheckManifestProducesPermissions(
916 "Access USB devices from an unknown vendor"));
922 " 'scripts': ['background.js']"
927 " { 'vendorId': 4179, 'productId': 529 },"
931 ASSERT_TRUE(CheckManifestProducesPermissions(
932 "Access USB devices from Immanuel Electronics Co., Ltd"));
938 " 'scripts': ['background.js']"
943 " { 'vendorId': 6353, 'productId': 8192 },"
948 CheckManifestProducesPermissions("Access USB devices from Google Inc."));
954 " 'scripts': ['background.js']"
959 " { 'vendorId': 4179, 'productId': 529 },"
960 " { 'vendorId': 6353, 'productId': 8192 },"
964 std::vector
<std::string
> submessages
;
965 submessages
.push_back("unknown devices from Immanuel Electronics Co., Ltd");
966 submessages
.push_back("unknown devices from Google Inc.");
967 ASSERT_TRUE(CheckManifestProducesPermissions(
968 "Access any of these USB devices", submessages
));
970 // TODO(sashab): Add a test with a valid product/vendor USB device.
973 // Test that hosted apps are not given any messages for host permissions.
974 TEST_F(PermissionMessageCombinationsUnittest
,
975 PackagedAppsHaveNoHostPermissions
) {
980 " 'scripts': ['background.js']"
984 " 'http://www.blogger.com/',"
985 " 'http://*.google.com/',"
988 ASSERT_TRUE(CheckManifestProducesPermissions());
994 " 'scripts': ['background.js']"
999 " 'http://www.blogger.com/',"
1000 " 'http://*.google.com/',"
1003 ASSERT_TRUE(CheckManifestProducesPermissions("Access your serial devices"));
1006 // Test various apps with lots of permissions, including those with no
1007 // permission messages, or those that only apply to apps or extensions even when
1008 // the given manifest is for a different type.
1009 TEST_F(PermissionMessageCombinationsUnittest
, PermissionMessageCombos
) {
1015 " 'http://www.blogger.com/',"
1016 " 'http://*.google.com/',"
1017 " 'unlimitedStorage',"
1020 ASSERT_TRUE(CheckManifestProducesPermissions(
1021 "Read and change your data on all google.com sites and www.blogger.com",
1022 "Read your browsing history", "Read and change your bookmarks"));
1030 " 'unlimitedStorage',"
1031 " 'syncFileSystem',"
1032 " 'http://www.blogger.com/',"
1033 " 'http://*.google.com/',"
1034 " 'http://*.news.com/',"
1035 " 'http://www.foobar.com/',"
1036 " 'http://*.go.com/',"
1039 std::vector
<std::string
> submessages
;
1040 submessages
.push_back("All go.com sites");
1041 submessages
.push_back("All google.com sites");
1042 submessages
.push_back("All news.com sites");
1043 submessages
.push_back("www.blogger.com");
1044 submessages
.push_back("www.foobar.com");
1045 ASSERT_TRUE(CheckManifestProducesPermissions(
1046 "Read your browsing history on all your signed-in devices",
1047 std::vector
<std::string
>(), "Read and change your bookmarks",
1048 std::vector
<std::string
>(),
1049 "Read and change your data on a number of websites", submessages
));
1057 " 'accessibilityFeatures.read',"
1058 " 'accessibilityFeatures.modify',"
1062 " 'desktopCapture',"
1066 " 'unlimitedStorage',"
1067 " 'syncFileSystem',"
1068 " 'http://www.blogger.com/',"
1069 " 'http://*.google.com/',"
1070 " 'http://*.news.com/',"
1071 " 'http://www.foobar.com/',"
1072 " 'http://*.go.com/',"
1076 submessages
.clear();
1077 submessages
.push_back("All go.com sites");
1078 submessages
.push_back("All google.com sites");
1079 submessages
.push_back("All news.com sites");
1080 submessages
.push_back("www.blogger.com");
1081 submessages
.push_back("www.foobar.com");
1082 ASSERT_TRUE(CheckManifestProducesPermissions(
1083 "Read your browsing history on all your signed-in devices",
1084 std::vector
<std::string
>(), "Capture content of your screen",
1085 std::vector
<std::string
>(), "Read and change your bookmarks",
1086 std::vector
<std::string
>(),
1087 "Read and change your data on a number of websites", submessages
,
1088 "Read and change your accessibility settings",
1089 std::vector
<std::string
>()));
1091 // Create an App instead, ensuring that the host permission messages are not
1097 " 'scripts': ['background.js']"
1103 " 'accessibilityFeatures.read',"
1104 " 'accessibilityFeatures.modify',"
1114 " 'unlimitedStorage',"
1115 " 'syncFileSystem',"
1116 " 'http://www.blogger.com/',"
1117 " 'http://*.google.com/',"
1118 " 'http://*.news.com/',"
1119 " 'http://www.foobar.com/',"
1120 " 'http://*.go.com/',"
1124 ASSERT_TRUE(CheckManifestProducesPermissions(
1125 "Access your serial devices", "Store data in your Google Drive account",
1126 "Read and change your accessibility settings"));
1130 // Tests that the 'plugin' manifest key produces the correct permission.
1131 TEST_F(PermissionMessageCombinationsUnittest
, PluginPermission
) {
1132 // Extensions can have plugins.
1136 " { 'path': 'extension_plugin.dll' }"
1141 ASSERT_TRUE(CheckManifestProducesPermissions());
1143 ASSERT_TRUE(CheckManifestProducesPermissions(
1144 "Read and change all your data on your computer and the websites you "
1148 // Apps can't have plugins.
1153 " 'scripts': ['background.js']"
1157 " { 'path': 'extension_plugin.dll' }"
1160 ASSERT_TRUE(CheckManifestProducesPermissions());
1163 // TODO(sashab): Add a test that checks that messages are generated correctly
1164 // for withheld permissions, when an app is granted the 'all sites' permission.
1166 // TODO(sashab): Add a test that ensures that all permissions that can generate
1167 // a coalesced message can also generate a message on their own (i.e. ensure
1168 // that no permissions only modify other permissions).
1170 // TODO(sashab): Add a test for every permission message combination that can
1171 // generate a message.
1173 // TODO(aboxhall): Add tests for the automation API permission messages.
1175 } // namespace extensions