diff options
author | reillyg <reillyg@chromium.org> | 2015-08-31 17:26:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-01 00:27:21 +0000 |
commit | 4775ef0d0533d12434c6ffd4a35eac76e4867018 (patch) | |
tree | 48658e311342f294854e82e995c26952524a4005 | |
parent | 9795b761ea1afd2399c7259a8d80c676d20fff4b (diff) | |
download | chromium_src-4775ef0d0533d12434c6ffd4a35eac76e4867018.zip chromium_src-4775ef0d0533d12434c6ffd4a35eac76e4867018.tar.gz chromium_src-4775ef0d0533d12434c6ffd4a35eac76e4867018.tar.bz2 |
Add unit tests for device picker UI strings.
These tests will break if the strings are changed without a matching
change to the test.
BUG=526342
Review URL: https://codereview.chromium.org/1303033007
Cr-Commit-Position: refs/heads/master@{#346534}
-rw-r--r-- | extensions/BUILD.gn | 2 | ||||
-rw-r--r-- | extensions/browser/api/device_permissions_prompt.cc | 23 | ||||
-rw-r--r-- | extensions/browser/api/device_permissions_prompt.h | 7 | ||||
-rw-r--r-- | extensions/browser/api/device_permissions_prompt_unittest.cc | 77 | ||||
-rw-r--r-- | extensions/extensions_strings.grd | 104 | ||||
-rw-r--r-- | extensions/extensions_tests.gyp | 2 | ||||
-rw-r--r-- | extensions/extensions_tests.gypi | 1 |
7 files changed, 173 insertions, 43 deletions
diff --git a/extensions/BUILD.gn b/extensions/BUILD.gn index 4c2cd35..e58246b 100644 --- a/extensions/BUILD.gn +++ b/extensions/BUILD.gn @@ -182,6 +182,8 @@ test("extensions_unittests") { "//components/user_prefs", "//content/test:test_support", "//device/bluetooth:mocks", + "//device/core", + "//device/hid", "//device/serial", "//device/serial:test_support", "//extensions/common", diff --git a/extensions/browser/api/device_permissions_prompt.cc b/extensions/browser/api/device_permissions_prompt.cc index 8069748..a72ebd3 100644 --- a/extensions/browser/api/device_permissions_prompt.cc +++ b/extensions/browser/api/device_permissions_prompt.cc @@ -38,6 +38,11 @@ namespace extensions { namespace { +void NoopHidCallback(const std::vector<scoped_refptr<device::HidDeviceInfo>>&) { +} + +void NoopUsbCallback(const std::vector<scoped_refptr<device::UsbDevice>>&) {} + class UsbDeviceInfo : public DevicePermissionsPrompt::Prompt::DeviceInfo { public: UsbDeviceInfo(scoped_refptr<UsbDevice> device) : device_(device) { @@ -373,4 +378,22 @@ void DevicePermissionsPrompt::AskForHidDevices( ShowDialog(); } +// static +scoped_refptr<DevicePermissionsPrompt::Prompt> +DevicePermissionsPrompt::CreateHidPromptForTest(const Extension* extension, + bool multiple) { + return make_scoped_refptr(new HidDevicePermissionsPrompt( + extension, nullptr, multiple, std::vector<HidDeviceFilter>(), + base::Bind(&NoopHidCallback))); +} + +// static +scoped_refptr<DevicePermissionsPrompt::Prompt> +DevicePermissionsPrompt::CreateUsbPromptForTest(const Extension* extension, + bool multiple) { + return make_scoped_refptr(new UsbDevicePermissionsPrompt( + extension, nullptr, multiple, std::vector<UsbDeviceFilter>(), + base::Bind(&NoopUsbCallback))); +} + } // namespace extensions diff --git a/extensions/browser/api/device_permissions_prompt.h b/extensions/browser/api/device_permissions_prompt.h index 6849851..38f5d48 100644 --- a/extensions/browser/api/device_permissions_prompt.h +++ b/extensions/browser/api/device_permissions_prompt.h @@ -134,6 +134,13 @@ class DevicePermissionsPrompt { const std::vector<device::HidDeviceFilter>& filters, const HidDevicesCallback& callback); + static scoped_refptr<Prompt> CreateHidPromptForTest( + const Extension* extension, + bool multiple); + static scoped_refptr<Prompt> CreateUsbPromptForTest( + const Extension* extension, + bool multiple); + protected: virtual void ShowDialog() = 0; diff --git a/extensions/browser/api/device_permissions_prompt_unittest.cc b/extensions/browser/api/device_permissions_prompt_unittest.cc new file mode 100644 index 0000000..2ab430d --- /dev/null +++ b/extensions/browser/api/device_permissions_prompt_unittest.cc @@ -0,0 +1,77 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/memory/ref_counted.h" +#include "base/strings/utf_string_conversions.h" +#include "extensions/browser/api/device_permissions_prompt.h" +#include "extensions/common/extension.h" +#include "extensions/common/extension_builder.h" +#include "extensions/common/value_builder.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace extensions { + +namespace { + +class DevicePermissionsPromptTest : public testing::Test {}; + +TEST_F(DevicePermissionsPromptTest, HidPromptMessages) { + scoped_refptr<Extension> extension = + ExtensionBuilder() + .SetManifest(DictionaryBuilder() + .Set("name", "Test Application") + .Set("manifest_version", 2) + .Set("version", "1.0")) + .Build(); + + scoped_refptr<DevicePermissionsPrompt::Prompt> prompt = + DevicePermissionsPrompt::CreateHidPromptForTest(extension.get(), false); + EXPECT_EQ(base::ASCIIToUTF16("Select a HID device"), prompt->GetHeading()); + EXPECT_EQ( + base::ASCIIToUTF16( + "The application \"Test Application\" is requesting access to one of " + "your devices."), + prompt->GetPromptMessage()); + + prompt = + DevicePermissionsPrompt::CreateHidPromptForTest(extension.get(), true); + EXPECT_EQ(base::ASCIIToUTF16("Select HID devices"), prompt->GetHeading()); + EXPECT_EQ( + base::ASCIIToUTF16( + "The application \"Test Application\" is requesting access to one or " + "more of your devices."), + prompt->GetPromptMessage()); +} + +TEST_F(DevicePermissionsPromptTest, UsbPromptMessages) { + scoped_refptr<Extension> extension = + ExtensionBuilder() + .SetManifest(DictionaryBuilder() + .Set("name", "Test Application") + .Set("manifest_version", 2) + .Set("version", "1.0")) + .Build(); + + scoped_refptr<DevicePermissionsPrompt::Prompt> prompt = + DevicePermissionsPrompt::CreateUsbPromptForTest(extension.get(), false); + EXPECT_EQ(base::ASCIIToUTF16("Select a USB device"), prompt->GetHeading()); + EXPECT_EQ( + base::ASCIIToUTF16( + "The application \"Test Application\" is requesting access to one of " + "your devices."), + prompt->GetPromptMessage()); + + prompt = + DevicePermissionsPrompt::CreateUsbPromptForTest(extension.get(), true); + EXPECT_EQ(base::ASCIIToUTF16("Select USB devices"), prompt->GetHeading()); + EXPECT_EQ( + base::ASCIIToUTF16( + "The application \"Test Application\" is requesting access to one or " + "more of your devices."), + prompt->GetPromptMessage()); +} + +} // namespace + +} // namespace extensions diff --git a/extensions/extensions_strings.grd b/extensions/extensions_strings.grd index df7127a..2ed74a0 100644 --- a/extensions/extensions_strings.grd +++ b/extensions/extensions_strings.grd @@ -302,27 +302,35 @@ Exchange data with the devices named: <ph name="HOSTNAMES">$1<ex>foo.example.com bar.example.com</ex></ph> </message> - <!-- Device API strings. Please keep alphabetized. --> + <!-- + Device API strings. Please keep alphabetized. + + To check UI that displays these strings please use one of the sample + applications such as: + + https://chrome.google.com/webstore/detail/igkmggljimacfdfalpeelenjeicmfnll + https://chrome.google.com/webstore/detail/ohndmecdhlgohpibepbboddcoecomnpc + + IDS_EXTENSION_PROMPT_WARNING_* messages appear on the extension details + page along with other permissions. IDS_*PERMISSIONS_PROMPT* messages + appear in the device picker displayed by the + chrome.usb.getUserSelectedDevices and chrome.hid.getUserSelectedDevices + APIs. + --> <message name="IDS_DEVICE_NAME_WITH_PRODUCT_SERIAL" desc="String describing a device by its product name and serial number."> <ph name="PRODUCT_NAME">$1<ex>Power Knob</ex></ph> (serial number <ph name="SERIAL_NUMBER">$2<ex>00001</ex></ph>) </message> - <message name="IDS_DEVICE_NAME_WITH_PRODUCT_VENDOR" desc="String describing a device by its product name and vendor."> - <ph name="PRODUCT_NAME">$1<ex>Power Knob</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> - </message> - <message name="IDS_DEVICE_NAME_WITH_PRODUCT_VENDOR_SERIAL" desc="String describing a device by its product name and vendor and serial number."> - <ph name="PRODUCT_NAME">$1<ex>Power Knob</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> (serial number <ph name="SERIAL_NUMBER">$3<ex>00001</ex></ph>) - </message> <message name="IDS_DEVICE_NAME_WITH_PRODUCT_UNKNOWN_VENDOR" desc="String describing a device by its product name when only the numeric vendor ID is available."> <ph name="PRODUCT_NAME">$1<ex>Power Knob</ex></ph> from vendor <ph name="VENDOR_ID">$2<ex>abcd</ex></ph> </message> <message name="IDS_DEVICE_NAME_WITH_PRODUCT_UNKNOWN_VENDOR_SERIAL" desc="String describing a device by its product name and serial number when the numeric vendor ID is available."> <ph name="PRODUCT_NAME">$1<ex>Power Knob</ex></ph> from vendor <ph name="VENDOR_ID">$2<ex>abcd</ex></ph> (serial number <ph name="SERIAL_NUMBER">$3<ex>00001</ex></ph>) </message> - <message name="IDS_DEVICE_NAME_WITH_UNKNOWN_PRODUCT_VENDOR" desc="String describing a device by its vendor name when only the numeric product ID is available."> - Unknown product <ph name="PRODUCT_ID">$1<ex>b33f</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> + <message name="IDS_DEVICE_NAME_WITH_PRODUCT_VENDOR" desc="String describing a device by its product name and vendor."> + <ph name="PRODUCT_NAME">$1<ex>Power Knob</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> </message> - <message name="IDS_DEVICE_NAME_WITH_UNKNOWN_PRODUCT_VENDOR_SERIAL" desc="String describing a device by its vendor name and serial number when only the numeric product ID is available."> - Unknown product <ph name="PRODUCT_ID">$1<ex>1234</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> (serial number <ph name="SERIAL_NUMBER">$3<ex>00001</ex></ph>) + <message name="IDS_DEVICE_NAME_WITH_PRODUCT_VENDOR_SERIAL" desc="String describing a device by its product name and vendor and serial number."> + <ph name="PRODUCT_NAME">$1<ex>Power Knob</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> (serial number <ph name="SERIAL_NUMBER">$3<ex>00001</ex></ph>) </message> <message name="IDS_DEVICE_NAME_WITH_UNKNOWN_PRODUCT_UNKNOWN_VENDOR" desc="String describing a device when only numeric vendor and product IDs are available."> Unknown product <ph name="PRODUCT_ID">$1<ex>1234</ex></ph> from vendor <ph name="VENDOR_ID">$2<ex>abcd</ex></ph> @@ -330,12 +338,45 @@ <message name="IDS_DEVICE_NAME_WITH_UNKNOWN_PRODUCT_UNKNOWN_VENDOR_SERIAL" desc="String describing a device by its serial number when only numeric vendor and product IDs are available."> Unknown product <ph name="PRODUCT_ID">$1<ex>1234</ex></ph> from vendor <ph name="VENDOR_ID">$2<ex>abcd</ex></ph> (serial number <ph name="SERIAL_NUMBER">$3<ex>00001</ex></ph>) </message> + <message name="IDS_DEVICE_NAME_WITH_UNKNOWN_PRODUCT_VENDOR" desc="String describing a device by its vendor name when only the numeric product ID is available."> + Unknown product <ph name="PRODUCT_ID">$1<ex>b33f</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> + </message> + <message name="IDS_DEVICE_NAME_WITH_UNKNOWN_PRODUCT_VENDOR_SERIAL" desc="String describing a device by its vendor name and serial number when only the numeric product ID is available."> + Unknown product <ph name="PRODUCT_ID">$1<ex>1234</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> (serial number <ph name="SERIAL_NUMBER">$3<ex>00001</ex></ph>) + </message> <message name="IDS_DEVICE_PERMISSIONS_PROMPT" desc="Instructions asking the user to select one or more devices for use with an app. [ICU Syntax]"> {0, select, single {The application "<ph name="APP_NAME">{1}<ex>Chrome Dev Editor</ex></ph>" is requesting access to one of your devices.} multiple {The application "<ph name="APP_NAME">{1}<ex>Chrome Dev Editor</ex></ph>" is requesting access to one or more of your devices.} other {UNUSED}} </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE" desc="Permission string for access to a specific USB device."> + Access any <ph name="PRODUCT_NAME_AND_VENDOR">$1<ex>SoundKnob from Griffin Technology</ex></ph> via USB + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST" desc="Permission string for access to a list of USB devices."> + Access any of these USB devices + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM" desc="Line item for a USB device listed under IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST."> + <ph name="PRODUCT_NAME_AND_VENDOR">$1<ex>SoundKnob from Griffin Technology</ex></ph> + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM_UNKNOWN_PRODUCT" desc="Line item for a USB device listed under IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST that has an unknown product ID."> + unknown devices from <ph name="VENDOR_NAME">$1<ex>Griffin Technology</ex></ph> + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM_UNKNOWN_VENDOR" desc="Line item for a USB device listed under IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST that has an unknown vendor ID."> + devices from an unknown vendor + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_PRODUCT_NAME_AND_VENDOR" desc="USB device name and vendor string, used in various permission messages for USB devices."> + <ph name="PRODUCT_NAME">$1<ex>SoundKnob</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_SERIAL" desc="Permission string for accessing a USB device with a known vendor name, product name and serial number."> + <ph name="PRODUCT_NAME">$1<ex>Nexus 5</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Google Inc.</ex></ph> (serial number <ph name="SERIAL_NUMBER">$3<ex>ABCDEF123456</ex></ph>) + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_UNKNOWN_PRODUCT" desc="Permission string for access to a specific USB device with an unknown product ID."> + Access USB devices from <ph name="VENDOR_NAME">$1<ex>Griffin Technology</ex></ph> + </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_UNKNOWN_VENDOR" desc="Permission string for acceess to a specific USB device with an unknown vendor ID."> + Access USB devices from an unknown vendor + </message> <message name="IDS_HID_DEVICE_PERMISSIONS_PROMPT_TITLE" desc="Title of the HID device selection dialog when the app will accept one or more selected devices. [ICU Syntax]"> {0, select, single {Select a HID device} multiple {Select HID devices} @@ -346,6 +387,8 @@ single {Select a USB device} multiple {Select USB devices} other {UNUSED}} </message> + + <!-- Extension permission strings. Please keep alphabetized. --> <message name="IDS_EXTENSION_PROMPT_WARNING_NETWORKING_CONFIG" desc="Permission string for Networking Config API."> Configure network connections </message> @@ -355,33 +398,17 @@ <message name="IDS_EXTENSION_PROMPT_WARNING_SERIAL" desc="Permission string for access to serial devices."> Access your serial devices </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_U2F_DEVICES" desc="Warning message which indicates that an extension has access to Universal 2nd Factor devices."> + Access your Universal 2nd Factor devices + </message> <message name="IDS_EXTENSION_PROMPT_WARNING_VPN" desc="Permission string for access to VPN API."> Access your network traffic </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_PRODUCT_NAME_AND_VENDOR" desc="USB device name and vendor string, used in various permission messages for USB devices."> - <ph name="PRODUCT_NAME">$1<ex>SoundKnob</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> - </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE" desc="Permission string for access to a specific USB device."> - Access any <ph name="PRODUCT_NAME_AND_VENDOR">$1<ex>SoundKnob from Griffin Technology</ex></ph> via USB - </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_UNKNOWN_PRODUCT" desc="Permission string for access to a specific USB device with an unknown product ID."> - Access USB devices from <ph name="VENDOR_NAME">$1<ex>Griffin Technology</ex></ph> - </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_UNKNOWN_VENDOR" desc="Permission string for acceess to a specific USB device with an unknown vendor ID."> - Access USB devices from an unknown vendor - </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST" desc="Permission string for access to a list of USB devices."> - Access any of these USB devices - </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM" desc="Line item for a USB device listed under IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST."> - <ph name="PRODUCT_NAME_AND_VENDOR">$1<ex>SoundKnob from Griffin Technology</ex></ph> - </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM_UNKNOWN_PRODUCT" desc="Line item for a USB device listed under IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST that has an unknown product ID."> - unknown devices from <ph name="VENDOR_NAME">$1<ex>Griffin Technology</ex></ph> - </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM_UNKNOWN_VENDOR" desc="Line item for a USB device listed under IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST that has an unknown vendor ID."> - devices from an unknown vendor + <message name="IDS_EXTENSION_PROMPT_WARNING_WEB_CONNECTABLE" desc="Permission string for allowing websites to connect to extensions."> + Communicate with cooperating websites </message> + + <!-- Extension task manager strings. Please keep alphabetized. --> <message name="IDS_EXTENSION_TASK_MANAGER_APPVIEW_TAG_PREFIX" desc="The prefix for a guest page loaded in an appview tag in the Task Manager"> Appview: <ph name="APPVIEW_TAG_NAME">$1<ex>Google Hangouts</ex></ph> </message> @@ -397,9 +424,6 @@ <message name="IDS_EXTENSION_TASK_MANAGER_WEBVIEW_TAG_PREFIX" desc="The prefix for a guest page loaded in a webview tag in the Task Manager"> Webview: <ph name="WEBVIEW_TAG_NAME">$1<ex>Google</ex></ph> </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_SERIAL" desc="Permission string for accessing a USB device with a known vendor name, product name and serial number."> - <ph name="PRODUCT_NAME">$1<ex>Nexus 5</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Google Inc.</ex></ph> (serial number <ph name="SERIAL_NUMBER">$3<ex>ABCDEF123456</ex></ph>) - </message> <!-- Global error messages for extensions. Please keep alphabetized. --> <message name="IDS_EXTENSION_WARNINGS_NETWORK_DELAY" desc="Warning message indicating that an extension caused excessive network delays for web requests"> @@ -426,12 +450,6 @@ <message name="IDS_EXTENSION_WARNING_RELOAD_TOO_FREQUENT" desc="Warning message which indates that an extension got stuck in a reload loop."> This extension reloaded itself too frequently. </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_U2F_DEVICES" desc="Warning message which indicates that an extension has access to Universal 2nd Factor devices."> - Access your Universal 2nd Factor devices - </message> - <message name="IDS_EXTENSION_PROMPT_WARNING_WEB_CONNECTABLE" desc="Permission string for allowing websites to connect to extensions."> - Communicate with cooperating websites - </message> <!-- Install related messages. Please keep alphabetized. --> <message name="IDS_EXTENSION_INSTALL_PROCESS_CRASHED" desc="Error message in case package fails to install because a utility process crashed."> diff --git a/extensions/extensions_tests.gyp b/extensions/extensions_tests.gyp index 9d06668..31e6caa 100644 --- a/extensions/extensions_tests.gyp +++ b/extensions/extensions_tests.gyp @@ -22,6 +22,8 @@ '../components/components.gyp:user_prefs', '../content/content_shell_and_tests.gyp:test_support_content', '../device/bluetooth/bluetooth.gyp:device_bluetooth_mocks', + '../device/core/core.gyp:device_core', + '../device/hid/hid.gyp:device_hid', '../device/serial/serial.gyp:device_serial', '../device/serial/serial.gyp:device_serial_test_util', '../mojo/mojo_base.gyp:mojo_application_bindings', diff --git a/extensions/extensions_tests.gypi b/extensions/extensions_tests.gypi index eed12fb..cd9f48c 100644 --- a/extensions/extensions_tests.gypi +++ b/extensions/extensions_tests.gypi @@ -55,6 +55,7 @@ 'browser/api/declarative/rules_registry_unittest.cc', 'browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc', 'browser/api/declarative_webrequest/webrequest_condition_unittest.cc', + 'browser/api/device_permissions_prompt_unittest.cc', 'browser/api/document_scan/document_scan_api_unittest.cc', 'browser/api/document_scan/document_scan_interface_chromeos_unittest.cc', 'browser/api/document_scan/mock_document_scan_interface.cc', |