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();
34 // Force creation of ExtensionPrefs before adding extensions.
35 env_
.GetExtensionPrefs();
39 // Create and install an app or extension with the given manifest JSON string.
40 // Single-quotes in the string will be replaced with double quotes.
41 void CreateAndInstall(const std::string
& json_manifest
) {
42 std::string json_manifest_with_double_quotes
= json_manifest
;
43 std::replace(json_manifest_with_double_quotes
.begin(),
44 json_manifest_with_double_quotes
.end(), '\'', '"');
45 app_
= env_
.MakeExtension(
46 *base::test::ParseJson(json_manifest_with_double_quotes
),
47 kWhitelistedExtensionID
);
50 // Checks whether the currently installed app or extension produces the given
51 // permission messages. Call this after installing an app with the expected
52 // permission messages. The messages are tested for existence in any order.
53 testing::AssertionResult
CheckManifestProducesPermissions() {
54 return VerifyNoPermissionMessages(app_
->permissions_data());
56 testing::AssertionResult
CheckManifestProducesPermissions(
57 const std::string
& expected_message_1
) {
58 return VerifyOnePermissionMessage(app_
->permissions_data(),
61 testing::AssertionResult
CheckManifestProducesPermissions(
62 const std::string
& expected_message_1
,
63 const std::string
& expected_message_2
) {
64 return VerifyTwoPermissionMessages(app_
->permissions_data(),
65 expected_message_1
, expected_message_2
,
68 testing::AssertionResult
CheckManifestProducesPermissions(
69 const std::string
& expected_message_1
,
70 const std::string
& expected_message_2
,
71 const std::string
& expected_message_3
) {
72 std::vector
<std::string
> expected_messages
;
73 expected_messages
.push_back(expected_message_1
);
74 expected_messages
.push_back(expected_message_2
);
75 expected_messages
.push_back(expected_message_3
);
76 return VerifyPermissionMessages(app_
->permissions_data(), expected_messages
,
79 testing::AssertionResult
CheckManifestProducesPermissions(
80 const std::string
& expected_message_1
,
81 const std::string
& expected_message_2
,
82 const std::string
& expected_message_3
,
83 const std::string
& expected_message_4
) {
84 std::vector
<std::string
> expected_messages
;
85 expected_messages
.push_back(expected_message_1
);
86 expected_messages
.push_back(expected_message_2
);
87 expected_messages
.push_back(expected_message_3
);
88 expected_messages
.push_back(expected_message_4
);
89 return VerifyPermissionMessages(app_
->permissions_data(), expected_messages
,
92 testing::AssertionResult
CheckManifestProducesPermissions(
93 const std::string
& expected_message_1
,
94 const std::string
& expected_message_2
,
95 const std::string
& expected_message_3
,
96 const std::string
& expected_message_4
,
97 const std::string
& expected_message_5
) {
98 std::vector
<std::string
> expected_messages
;
99 expected_messages
.push_back(expected_message_1
);
100 expected_messages
.push_back(expected_message_2
);
101 expected_messages
.push_back(expected_message_3
);
102 expected_messages
.push_back(expected_message_4
);
103 expected_messages
.push_back(expected_message_5
);
104 return VerifyPermissionMessages(app_
->permissions_data(), expected_messages
,
107 testing::AssertionResult
CheckManifestProducesPermissions(
108 const std::string
& expected_message_1
,
109 const std::vector
<std::string
>& expected_submessages_1
) {
110 return VerifyOnePermissionMessageWithSubmessages(
111 app_
->permissions_data(), expected_message_1
, expected_submessages_1
);
113 testing::AssertionResult
CheckManifestProducesPermissions(
114 const std::string
& expected_message_1
,
115 const std::vector
<std::string
>& expected_submessages_1
,
116 const std::string
& expected_message_2
,
117 const std::vector
<std::string
>& expected_submessages_2
) {
118 std::vector
<std::string
> expected_messages
;
119 expected_messages
.push_back(expected_message_1
);
120 expected_messages
.push_back(expected_message_2
);
121 std::vector
<std::vector
<std::string
>> expected_submessages
;
122 expected_submessages
.push_back(expected_submessages_1
);
123 expected_submessages
.push_back(expected_submessages_2
);
124 return VerifyPermissionMessagesWithSubmessages(app_
->permissions_data(),
126 expected_submessages
, false);
128 testing::AssertionResult
CheckManifestProducesPermissions(
129 const std::string
& expected_message_1
,
130 const std::vector
<std::string
>& expected_submessages_1
,
131 const std::string
& expected_message_2
,
132 const std::vector
<std::string
>& expected_submessages_2
,
133 const std::string
& expected_message_3
,
134 const std::vector
<std::string
>& expected_submessages_3
) {
135 std::vector
<std::string
> expected_messages
;
136 expected_messages
.push_back(expected_message_1
);
137 expected_messages
.push_back(expected_message_2
);
138 expected_messages
.push_back(expected_message_3
);
139 std::vector
<std::vector
<std::string
>> expected_submessages
;
140 expected_submessages
.push_back(expected_submessages_1
);
141 expected_submessages
.push_back(expected_submessages_2
);
142 expected_submessages
.push_back(expected_submessages_3
);
143 return VerifyPermissionMessagesWithSubmessages(app_
->permissions_data(),
145 expected_submessages
, false);
147 testing::AssertionResult
CheckManifestProducesPermissions(
148 const std::string
& expected_message_1
,
149 const std::vector
<std::string
>& expected_submessages_1
,
150 const std::string
& expected_message_2
,
151 const std::vector
<std::string
>& expected_submessages_2
,
152 const std::string
& expected_message_3
,
153 const std::vector
<std::string
>& expected_submessages_3
,
154 const std::string
& expected_message_4
,
155 const std::vector
<std::string
>& expected_submessages_4
) {
156 std::vector
<std::string
> expected_messages
;
157 expected_messages
.push_back(expected_message_1
);
158 expected_messages
.push_back(expected_message_2
);
159 expected_messages
.push_back(expected_message_3
);
160 expected_messages
.push_back(expected_message_4
);
161 std::vector
<std::vector
<std::string
>> expected_submessages
;
162 expected_submessages
.push_back(expected_submessages_1
);
163 expected_submessages
.push_back(expected_submessages_2
);
164 expected_submessages
.push_back(expected_submessages_3
);
165 expected_submessages
.push_back(expected_submessages_4
);
166 return VerifyPermissionMessagesWithSubmessages(app_
->permissions_data(),
168 expected_submessages
, false);
170 testing::AssertionResult
CheckManifestProducesPermissions(
171 const std::string
& expected_message_1
,
172 const std::vector
<std::string
>& expected_submessages_1
,
173 const std::string
& expected_message_2
,
174 const std::vector
<std::string
>& expected_submessages_2
,
175 const std::string
& expected_message_3
,
176 const std::vector
<std::string
>& expected_submessages_3
,
177 const std::string
& expected_message_4
,
178 const std::vector
<std::string
>& expected_submessages_4
,
179 const std::string
& expected_message_5
,
180 const std::vector
<std::string
>& expected_submessages_5
) {
181 std::vector
<std::string
> expected_messages
;
182 expected_messages
.push_back(expected_message_1
);
183 expected_messages
.push_back(expected_message_2
);
184 expected_messages
.push_back(expected_message_3
);
185 expected_messages
.push_back(expected_message_4
);
186 expected_messages
.push_back(expected_message_5
);
187 std::vector
<std::vector
<std::string
>> expected_submessages
;
188 expected_submessages
.push_back(expected_submessages_1
);
189 expected_submessages
.push_back(expected_submessages_2
);
190 expected_submessages
.push_back(expected_submessages_3
);
191 expected_submessages
.push_back(expected_submessages_4
);
192 expected_submessages
.push_back(expected_submessages_5
);
193 return VerifyPermissionMessagesWithSubmessages(app_
->permissions_data(),
195 expected_submessages
, false);
199 extensions::TestExtensionEnvironment env_
;
200 scoped_ptr
<ChromePermissionMessageProvider
> message_provider_
;
201 scoped_refptr
<const Extension
> app_
;
202 // Whitelist a known extension id so we can test all permissions. This ID
203 // will be used for each test app.
204 extensions::SimpleFeature::ScopedWhitelistForTest whitelisted_extension_id_
;
206 DISALLOW_COPY_AND_ASSIGN(PermissionMessageCombinationsUnittest
);
209 // Test that the USB, Bluetooth and Serial permissions do not coalesce on their
210 // own, but do coalesce when more than 1 is present.
211 TEST_F(PermissionMessageCombinationsUnittest
, USBSerialBluetoothCoalescing
) {
212 // Test that the USB permission does not coalesce on its own.
217 " 'scripts': ['background.js']"
221 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] }"
224 ASSERT_TRUE(CheckManifestProducesPermissions(
225 "Access USB devices from an unknown vendor"));
231 " 'scripts': ['background.js']"
235 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] }"
238 ASSERT_TRUE(CheckManifestProducesPermissions(
239 "Access USB devices from an unknown vendor"));
241 // Test that the serial permission does not coalesce on its own.
246 " 'scripts': ['background.js']"
253 ASSERT_TRUE(CheckManifestProducesPermissions("Access your serial devices"));
255 // Test that the bluetooth permission does not coalesce on its own.
260 " 'scripts': ['background.js']"
265 ASSERT_TRUE(CheckManifestProducesPermissions(
266 "Access information about Bluetooth devices paired with your system and "
267 "discover nearby Bluetooth devices."));
269 // Test that the bluetooth permission does not coalesce on its own, even
270 // when it specifies additional permissions.
275 " 'scripts': ['background.js']"
279 " 'uuids': ['1105', '1106']"
282 ASSERT_TRUE(CheckManifestProducesPermissions(
283 "Access information about Bluetooth devices paired with your system and "
284 "discover nearby Bluetooth devices."));
286 // Test that the USB and Serial permissions coalesce.
291 " 'scripts': ['background.js']"
295 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] },"
299 ASSERT_TRUE(CheckManifestProducesPermissions(
300 "Access USB devices from an unknown vendor",
301 "Access your serial devices"));
303 // Test that the USB, Serial and Bluetooth permissions coalesce.
308 " 'scripts': ['background.js']"
312 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] },"
317 ASSERT_TRUE(CheckManifestProducesPermissions(
318 "Access USB devices from an unknown vendor",
319 "Access your Bluetooth and Serial devices"));
321 // Test that the USB, Serial and Bluetooth permissions coalesce even when
322 // Bluetooth specifies multiple additional permissions.
327 " 'scripts': ['background.js']"
331 " { 'usbDevices': [{ 'vendorId': 123, 'productId': 456 }] },"
335 " 'uuids': ['1105', '1106'],"
337 " 'low_energy': true"
340 ASSERT_TRUE(CheckManifestProducesPermissions(
341 "Access USB devices from an unknown vendor",
342 "Access your Bluetooth and Serial devices"));
345 // Test that the History permission takes precedence over the Tabs permission,
346 // and that the Sessions permission modifies this final message.
347 TEST_F(PermissionMessageCombinationsUnittest
, TabsHistorySessionsCoalescing
) {
354 ASSERT_TRUE(CheckManifestProducesPermissions("Read your browsing history"));
359 " 'tabs', 'sessions'"
362 ASSERT_TRUE(CheckManifestProducesPermissions(
363 "Read your browsing history on all your signed-in devices"));
371 ASSERT_TRUE(CheckManifestProducesPermissions(
372 "Read and change your browsing history"));
377 " 'tabs', 'history', 'sessions'"
380 ASSERT_TRUE(CheckManifestProducesPermissions(
381 "Read and change your browsing history on all your signed-in devices"));
384 // Test that the fileSystem permission produces no messages by itself, unless it
385 // has both the 'write' and 'directory' additional permissions, in which case it
386 // displays a message.
387 TEST_F(PermissionMessageCombinationsUnittest
, FileSystemReadWriteCoalescing
) {
392 " 'scripts': ['background.js']"
399 ASSERT_TRUE(CheckManifestProducesPermissions());
405 " 'scripts': ['background.js']"
409 " 'fileSystem', {'fileSystem': ['retainEntries', 'write']}"
412 ASSERT_TRUE(CheckManifestProducesPermissions());
418 " 'scripts': ['background.js']"
422 " 'fileSystem', {'fileSystem': ["
423 " 'retainEntries', 'write', 'directory'"
427 ASSERT_TRUE(CheckManifestProducesPermissions(
428 "Write to files and folders that you open in the application"));
431 // Check that host permission messages are generated correctly when URLs are
432 // entered as permissions.
433 TEST_F(PermissionMessageCombinationsUnittest
, HostsPermissionMessages
) {
437 " 'http://www.blogger.com/',"
440 ASSERT_TRUE(CheckManifestProducesPermissions(
441 "Read and change your data on www.blogger.com"));
446 " 'http://*.google.com/',"
449 ASSERT_TRUE(CheckManifestProducesPermissions(
450 "Read and change your data on all google.com sites"));
455 " 'http://www.blogger.com/',"
456 " 'http://*.google.com/',"
459 ASSERT_TRUE(CheckManifestProducesPermissions(
460 "Read and change your data on all google.com sites and "
466 " 'http://www.blogger.com/',"
467 " 'http://*.google.com/',"
468 " 'http://*.news.com/',"
471 ASSERT_TRUE(CheckManifestProducesPermissions(
472 "Read and change your data on all google.com sites, all news.com sites, "
473 "and www.blogger.com"));
478 " 'http://www.blogger.com/',"
479 " 'http://*.google.com/',"
480 " 'http://*.news.com/',"
481 " 'http://www.foobar.com/',"
484 std::vector
<std::string
> submessages
;
485 submessages
.push_back("All google.com sites");
486 submessages
.push_back("All news.com sites");
487 submessages
.push_back("www.blogger.com");
488 submessages
.push_back("www.foobar.com");
489 ASSERT_TRUE(CheckManifestProducesPermissions(
490 "Read and change your data on a number of websites", submessages
));
495 " 'http://www.blogger.com/',"
496 " 'http://*.google.com/',"
497 " 'http://*.news.com/',"
498 " 'http://www.foobar.com/',"
499 " 'http://*.go.com/',"
503 submessages
.push_back("All go.com sites");
504 submessages
.push_back("All google.com sites");
505 submessages
.push_back("All news.com sites");
506 submessages
.push_back("www.blogger.com");
507 submessages
.push_back("www.foobar.com");
508 ASSERT_TRUE(CheckManifestProducesPermissions(
509 "Read and change your data on a number of websites", submessages
));
514 " 'http://*.go.com/',"
515 " 'chrome://favicon/',"
518 ASSERT_TRUE(CheckManifestProducesPermissions(
519 "Read and change your data on all go.com sites",
520 "Read the icons of the websites you visit"));
522 // Having the 'all sites' permission doesn't change the permission message,
523 // since its pseudo-granted at runtime.
527 " 'http://*.go.com/',"
528 " 'chrome://favicon/',"
532 ASSERT_TRUE(CheckManifestProducesPermissions(
533 "Read and change your data on all go.com sites",
534 "Read the icons of the websites you visit"));
537 // Check that permission messages are generated correctly for
538 // SocketsManifestPermission, which has host-like permission messages.
539 TEST_F(PermissionMessageCombinationsUnittest
,
540 SocketsManifestPermissionMessages
) {
545 " 'scripts': ['background.js']"
549 " 'udp': {'send': '*'},"
552 ASSERT_TRUE(CheckManifestProducesPermissions(
553 "Exchange data with any device on the local network or internet"));
559 " 'scripts': ['background.js']"
563 " 'udp': {'send': ':99'},"
566 ASSERT_TRUE(CheckManifestProducesPermissions(
567 "Exchange data with any device on the local network or internet"));
573 " 'scripts': ['background.js']"
577 " 'tcp': {'connect': '127.0.0.1:80'},"
580 ASSERT_TRUE(CheckManifestProducesPermissions(
581 "Exchange data with the device named 127.0.0.1"));
587 " 'scripts': ['background.js']"
591 " 'tcp': {'connect': 'www.example.com:23'},"
594 ASSERT_TRUE(CheckManifestProducesPermissions(
595 "Exchange data with the device named www.example.com"));
601 " 'scripts': ['background.js']"
605 " 'tcpServer': {'listen': '127.0.0.1:80'}"
608 ASSERT_TRUE(CheckManifestProducesPermissions(
609 "Exchange data with the device named 127.0.0.1"));
615 " 'scripts': ['background.js']"
619 " 'tcpServer': {'listen': ':8080'}"
622 ASSERT_TRUE(CheckManifestProducesPermissions(
623 "Exchange data with any device on the local network or internet"));
629 " 'scripts': ['background.js']"
637 " 'www.example.com:*',"
638 " 'www.foo.com:200',"
644 ASSERT_TRUE(CheckManifestProducesPermissions(
645 "Exchange data with the devices named: 127.0.0.1 www.bar.com "
646 "www.example.com www.foo.com www.google.com"));
652 " 'scripts': ['background.js']"
659 " 'www.mywebsite.com:320',"
660 " 'www.freestuff.com',"
669 " 'www.example.com:*',"
670 " 'www.foo.com:200',"
675 ASSERT_TRUE(CheckManifestProducesPermissions(
676 "Exchange data with the devices named: 127.0.0.1 www.abc.com "
677 "www.example.com www.foo.com www.freestuff.com www.google.com "
678 "www.mywebsite.com www.test.com"));
684 " 'scripts': ['background.js']"
688 " 'tcp': {'send': '*:*'},"
689 " 'tcpServer': {'listen': '*:*'},"
692 ASSERT_TRUE(CheckManifestProducesPermissions(
693 "Exchange data with any device on the local network or internet"));
696 // Check that permission messages are generated correctly for
697 // MediaGalleriesPermission (an API permission with custom messages).
698 TEST_F(PermissionMessageCombinationsUnittest
,
699 MediaGalleriesPermissionMessages
) {
704 " 'scripts': ['background.js']"
708 " { 'mediaGalleries': ['read'] }"
711 ASSERT_TRUE(CheckManifestProducesPermissions());
717 " 'scripts': ['background.js']"
721 " { 'mediaGalleries': ['read', 'allAutoDetected'] }"
724 ASSERT_TRUE(CheckManifestProducesPermissions(
725 "Access photos, music, and other media from your computer"));
727 // TODO(sashab): Add a test for the
728 // IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_READ_WRITE message (generated
729 // with the 'read' and 'copyTo' permissions, but not the 'delete' permission),
730 // if it's possible to get this message. Otherwise, remove it from the code.
736 " 'scripts': ['background.js']"
740 " { 'mediaGalleries': ['read', 'delete', 'allAutoDetected'] }"
743 ASSERT_TRUE(CheckManifestProducesPermissions(
744 "Read and delete photos, music, and other media from your computer"));
750 " 'scripts': ['background.js']"
754 " { 'mediaGalleries':"
755 " [ 'read', 'delete', 'copyTo', 'allAutoDetected' ] }"
758 ASSERT_TRUE(CheckManifestProducesPermissions(
759 "Read, change and delete photos, music, and other media from your "
762 // Without the allAutoDetected permission, there should be no install-time
763 // permission messages.
768 " 'scripts': ['background.js']"
772 " { 'mediaGalleries': ['read', 'delete', 'copyTo'] }"
775 ASSERT_TRUE(CheckManifestProducesPermissions());
778 // TODO(sashab): Add tests for SettingsOverrideAPIPermission (an API permission
779 // with custom messages).
781 // Check that permission messages are generated correctly for SocketPermission
782 // (an API permission with custom messages).
783 TEST_F(PermissionMessageCombinationsUnittest
, SocketPermissionMessages
) {
788 " 'scripts': ['background.js']"
792 " { 'socket': ['tcp-connect:*:*'] }"
795 ASSERT_TRUE(CheckManifestProducesPermissions(
796 "Exchange data with any device on the local network or internet"));
802 " 'scripts': ['background.js']"
807 " 'tcp-connect:*:443',"
808 " 'tcp-connect:*:50032',"
809 " 'tcp-connect:*:23',"
813 ASSERT_TRUE(CheckManifestProducesPermissions(
814 "Exchange data with any device on the local network or internet"));
820 " 'scripts': ['background.js']"
824 " { 'socket': ['tcp-connect:foo.example.com:443'] }"
827 ASSERT_TRUE(CheckManifestProducesPermissions(
828 "Exchange data with the device named foo.example.com"));
834 " 'scripts': ['background.js']"
838 " { 'socket': ['tcp-connect:foo.example.com:443', 'udp-send-to'] }"
841 ASSERT_TRUE(CheckManifestProducesPermissions(
842 "Exchange data with any device on the local network or internet"));
848 " 'scripts': ['background.js']"
853 " 'tcp-connect:foo.example.com:443',"
854 " 'udp-send-to:test.ping.com:50032',"
858 ASSERT_TRUE(CheckManifestProducesPermissions(
859 "Exchange data with the devices named: foo.example.com test.ping.com"));
865 " 'scripts': ['background.js']"
870 " 'tcp-connect:foo.example.com:443',"
871 " 'udp-send-to:test.ping.com:50032',"
872 " 'udp-send-to:www.ping.com:50032',"
873 " 'udp-send-to:test2.ping.com:50032',"
874 " 'udp-bind:test.ping.com:50032',"
878 ASSERT_TRUE(CheckManifestProducesPermissions(
879 "Exchange data with the devices named: foo.example.com test.ping.com "
880 "test2.ping.com www.ping.com"));
886 " 'scripts': ['background.js']"
891 " 'tcp-connect:foo.example.com:443',"
892 " 'udp-send-to:test.ping.com:50032',"
893 " 'tcp-connect:*:23',"
897 ASSERT_TRUE(CheckManifestProducesPermissions(
898 "Exchange data with any device on the local network or internet"));
901 // Check that permission messages are generated correctly for
902 // USBDevicePermission (an API permission with custom messages).
903 TEST_F(PermissionMessageCombinationsUnittest
, USBDevicePermissionMessages
) {
908 " 'scripts': ['background.js']"
913 " { 'vendorId': 0, 'productId': 0 },"
917 ASSERT_TRUE(CheckManifestProducesPermissions(
918 "Access USB devices from an unknown vendor"));
924 " 'scripts': ['background.js']"
929 " { 'vendorId': 4179, 'productId': 529 },"
933 ASSERT_TRUE(CheckManifestProducesPermissions(
934 "Access USB devices from Immanuel Electronics Co., Ltd"));
940 " 'scripts': ['background.js']"
945 " { 'vendorId': 6353, 'productId': 8192 },"
950 CheckManifestProducesPermissions("Access USB devices from Google Inc."));
956 " 'scripts': ['background.js']"
961 " { 'vendorId': 4179, 'productId': 529 },"
962 " { 'vendorId': 6353, 'productId': 8192 },"
966 std::vector
<std::string
> submessages
;
967 submessages
.push_back("unknown devices from Immanuel Electronics Co., Ltd");
968 submessages
.push_back("unknown devices from Google Inc.");
969 ASSERT_TRUE(CheckManifestProducesPermissions(
970 "Access any of these USB devices", submessages
));
972 // TODO(sashab): Add a test with a valid product/vendor USB device.
975 // Test that hosted apps are not given any messages for host permissions.
976 TEST_F(PermissionMessageCombinationsUnittest
,
977 PackagedAppsHaveNoHostPermissions
) {
982 " 'scripts': ['background.js']"
986 " 'http://www.blogger.com/',"
987 " 'http://*.google.com/',"
990 ASSERT_TRUE(CheckManifestProducesPermissions());
996 " 'scripts': ['background.js']"
1001 " 'http://www.blogger.com/',"
1002 " 'http://*.google.com/',"
1005 ASSERT_TRUE(CheckManifestProducesPermissions("Access your serial devices"));
1008 // Test various apps with lots of permissions, including those with no
1009 // permission messages, or those that only apply to apps or extensions even when
1010 // the given manifest is for a different type.
1011 TEST_F(PermissionMessageCombinationsUnittest
, PermissionMessageCombos
) {
1017 " 'http://www.blogger.com/',"
1018 " 'http://*.google.com/',"
1019 " 'unlimitedStorage',"
1022 ASSERT_TRUE(CheckManifestProducesPermissions(
1023 "Read and change your data on all google.com sites and www.blogger.com",
1024 "Read your browsing history", "Read and change your bookmarks"));
1032 " 'unlimitedStorage',"
1033 " 'syncFileSystem',"
1034 " 'http://www.blogger.com/',"
1035 " 'http://*.google.com/',"
1036 " 'http://*.news.com/',"
1037 " 'http://www.foobar.com/',"
1038 " 'http://*.go.com/',"
1041 std::vector
<std::string
> submessages
;
1042 submessages
.push_back("All go.com sites");
1043 submessages
.push_back("All google.com sites");
1044 submessages
.push_back("All news.com sites");
1045 submessages
.push_back("www.blogger.com");
1046 submessages
.push_back("www.foobar.com");
1047 ASSERT_TRUE(CheckManifestProducesPermissions(
1048 "Read your browsing history on all your signed-in devices",
1049 std::vector
<std::string
>(), "Read and change your bookmarks",
1050 std::vector
<std::string
>(),
1051 "Read and change your data on a number of websites", submessages
));
1059 " 'accessibilityFeatures.read',"
1060 " 'accessibilityFeatures.modify',"
1064 " 'desktopCapture',"
1068 " 'unlimitedStorage',"
1069 " 'syncFileSystem',"
1070 " 'http://www.blogger.com/',"
1071 " 'http://*.google.com/',"
1072 " 'http://*.news.com/',"
1073 " 'http://www.foobar.com/',"
1074 " 'http://*.go.com/',"
1078 submessages
.clear();
1079 submessages
.push_back("All go.com sites");
1080 submessages
.push_back("All google.com sites");
1081 submessages
.push_back("All news.com sites");
1082 submessages
.push_back("www.blogger.com");
1083 submessages
.push_back("www.foobar.com");
1084 ASSERT_TRUE(CheckManifestProducesPermissions(
1085 "Read your browsing history on all your signed-in devices",
1086 std::vector
<std::string
>(), "Capture content of your screen",
1087 std::vector
<std::string
>(), "Read and change your bookmarks",
1088 std::vector
<std::string
>(),
1089 "Read and change your data on a number of websites", submessages
,
1090 "Read and change your accessibility settings",
1091 std::vector
<std::string
>()));
1093 // Create an App instead, ensuring that the host permission messages are not
1099 " 'scripts': ['background.js']"
1105 " 'accessibilityFeatures.read',"
1106 " 'accessibilityFeatures.modify',"
1116 " 'unlimitedStorage',"
1117 " 'syncFileSystem',"
1118 " 'http://www.blogger.com/',"
1119 " 'http://*.google.com/',"
1120 " 'http://*.news.com/',"
1121 " 'http://www.foobar.com/',"
1122 " 'http://*.go.com/',"
1126 ASSERT_TRUE(CheckManifestProducesPermissions(
1127 "Access your serial devices", "Store data in your Google Drive account",
1128 "Read and change your accessibility settings"));
1132 // Tests that the 'plugin' manifest key produces the correct permission.
1133 TEST_F(PermissionMessageCombinationsUnittest
, PluginPermission
) {
1134 // Extensions can have plugins.
1138 " { 'path': 'extension_plugin.dll' }"
1143 ASSERT_TRUE(CheckManifestProducesPermissions());
1145 ASSERT_TRUE(CheckManifestProducesPermissions(
1146 "Read and change all your data on your computer and the websites you "
1150 // Apps can't have plugins.
1155 " 'scripts': ['background.js']"
1159 " { 'path': 'extension_plugin.dll' }"
1162 ASSERT_TRUE(CheckManifestProducesPermissions());
1165 // TODO(sashab): Add a test that checks that messages are generated correctly
1166 // for withheld permissions, when an app is granted the 'all sites' permission.
1168 // TODO(sashab): Add a test that ensures that all permissions that can generate
1169 // a coalesced message can also generate a message on their own (i.e. ensure
1170 // that no permissions only modify other permissions).
1172 // TODO(sashab): Add a test for every permission message combination that can
1173 // generate a message.
1175 // TODO(aboxhall): Add tests for the automation API permission messages.
1177 } // namespace extensions