Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Unified Diff: chrome/browser/extensions/permission_message_combinations_unittest.cc

Issue 795543002: Added PermissionIDSet to APIPermissions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permissions_patch_1_static_initializer_fix
Patch Set: Rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | extensions/common/api/sockets/sockets_manifest_permission.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/permission_message_combinations_unittest.cc
diff --git a/chrome/browser/extensions/permission_message_combinations_unittest.cc b/chrome/browser/extensions/permission_message_combinations_unittest.cc
index 42e2a202ec7ab43e2d966c00e73f100e919ffcee..fea89be6f9b5fe76869446cd95fa316d8637d8fa 100644
--- a/chrome/browser/extensions/permission_message_combinations_unittest.cc
+++ b/chrome/browser/extensions/permission_message_combinations_unittest.cc
@@ -589,9 +589,10 @@ TEST_F(PermissionMessageCombinationsUnittest, HostsPermissionMessages) {
ASSERT_TRUE(CheckManifestProducesHostPermissions());
}
-// Check that permission messages are generated correctly for the sockets
-// permission, which has host-like permission messages.
-TEST_F(PermissionMessageCombinationsUnittest, SocketsPermissionMessages) {
+// Check that permission messages are generated correctly for
+// SocketsManifestPermission, which has host-like permission messages.
+TEST_F(PermissionMessageCombinationsUnittest,
+ SocketsManifestPermissionMessages) {
CreateAndInstall(
"{"
" 'app': {"
@@ -756,6 +757,311 @@ TEST_F(PermissionMessageCombinationsUnittest, SocketsPermissionMessages) {
ASSERT_TRUE(CheckManifestProducesHostPermissions());
}
+// Check that permission messages are generated correctly for
+// MediaGalleriesPermission (an API permission with custom messages).
+TEST_F(PermissionMessageCombinationsUnittest,
+ MediaGalleriesPermissionMessages) {
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'mediaGalleries': ['read'] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions());
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'mediaGalleries': ['read', 'allAutoDetected'] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Access photos, music, and other media from your computer"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ // TODO(sashab): Add a test for the
+ // IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_READ_WRITE message (generated
+ // with the 'read' and 'copyTo' permissions, but not the 'delete' permission),
+ // if it's possible to get this message. Otherwise, remove it from the code.
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'mediaGalleries': ['read', 'delete', 'allAutoDetected'] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Read and delete photos, music, and other media from your computer"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'mediaGalleries':"
+ " [ 'read', 'delete', 'copyTo', 'allAutoDetected' ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Read, change and delete photos, music, and other media from your "
+ "computer"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ // Without the allAutoDetected permission, there should be no install-time
+ // permission messages.
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'mediaGalleries': ['read', 'delete', 'copyTo'] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions());
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+}
+
+// TODO(sashab): Add tests for SettingsOverrideAPIPermission (an API permission
+// with custom messages).
+
+// Check that permission messages are generated correctly for SocketPermission
+// (an API permission with custom messages).
+TEST_F(PermissionMessageCombinationsUnittest, SocketPermissionMessages) {
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'socket': ['tcp-connect:*:*'] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Exchange data with any computer on the local network or internet"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'socket': ["
+ " 'tcp-connect:*:443',"
+ " 'tcp-connect:*:50032',"
+ " 'tcp-connect:*:23',"
+ " ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Exchange data with any computer on the local network or internet"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'socket': ['tcp-connect:foo.example.com:443'] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Exchange data with the computer named foo.example.com"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'socket': ['tcp-connect:foo.example.com:443', 'udp-send-to'] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Exchange data with any computer on the local network or internet"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'socket': ["
+ " 'tcp-connect:foo.example.com:443',"
+ " 'udp-send-to:test.ping.com:50032',"
+ " ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Exchange data with the computers named: foo.example.com test.ping.com"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'socket': ["
+ " 'tcp-connect:foo.example.com:443',"
+ " 'udp-send-to:test.ping.com:50032',"
+ " 'udp-send-to:www.ping.com:50032',"
+ " 'udp-send-to:test2.ping.com:50032',"
+ " 'udp-bind:test.ping.com:50032',"
+ " 'udp-listen:other.ping.com:50032',"
+ " 'udp-listen:www.google.com:50032',"
+ " ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Exchange data with the computers named: foo.example.com test.ping.com "
+ "test2.ping.com www.ping.com"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'socket': ["
+ " 'tcp-connect:foo.example.com:443',"
+ " 'udp-send-to:test.ping.com:50032',"
+ " 'tcp-connect:*:23',"
+ " ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Exchange data with any computer on the local network or internet"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+}
+
+// Check that permission messages are generated correctly for
+// USBDevicePermission (an API permission with custom messages).
+TEST_F(PermissionMessageCombinationsUnittest, USBDevicePermissionMessages) {
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'usbDevices': ["
+ " { 'vendorId': 0, 'productId': 0 },"
+ " ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Access USB devices from an unknown vendor"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'usbDevices': ["
+ " { 'vendorId': 4179, 'productId': 529 },"
+ " ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(CheckManifestProducesPermissions(
+ "Access USB devices from Immanuel Electronics Co., Ltd"));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'usbDevices': ["
+ " { 'vendorId': 6353, 'productId': 20194 },"
+ " ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(
+ CheckManifestProducesPermissions("Access USB devices from Google Inc."));
+ ASSERT_TRUE(CheckManifestProducesHostPermissions());
+
+ CreateAndInstall(
+ "{"
+ " 'app': {"
+ " 'background': {"
+ " 'scripts': ['background.js']"
+ " }"
+ " },"
+ " 'permissions': ["
+ " { 'usbDevices': ["
+ " { 'vendorId': 4179, 'productId': 529 },"
+ " { 'vendorId': 6353, 'productId': 20194 },"
+ " ] }"
+ " ]"
+ "}");
+ ASSERT_TRUE(
+ CheckManifestProducesPermissions("Access any of these USB devices"));
+
+ // Although technically not host permissions, devices are currently stored in
+ // the 'host permissions' (details list) for the USB permission, in the same
+ // format.
+ // TODO(sashab): Rename host permissions to 'details list' or 'nested
+ // permissions', and change this test system to allow specifying each message
+ // as well as its corresponding nested messages, if any. Also add a test that
+ // uses this to test an app with multiple nested permission lists (e.g. both
+ // USB and host permissions).
+ ASSERT_TRUE(CheckManifestProducesHostPermissions(
+ "unknown devices from Immanuel Electronics Co., Ltd",
+ "unknown devices from Google Inc."));
+
+ // TODO(sashab): Add a test with a valid product/vendor USB device.
+}
+
// Test that hosted apps are not given any messages for host permissions.
TEST_F(PermissionMessageCombinationsUnittest,
PackagedAppsHaveNoHostPermissions) {
« no previous file with comments | « no previous file | extensions/common/api/sockets/sockets_manifest_permission.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698