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

Unified Diff: extensions/browser/api/hid/hid_apitest.cc

Issue 1115213004: Add chrome.hid.getUserSelectedDevices API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 months 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 | « extensions/browser/api/hid/hid_api.cc ('k') | extensions/browser/api/hid/hid_device_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/api/hid/hid_apitest.cc
diff --git a/extensions/browser/api/hid/hid_apitest.cc b/extensions/browser/api/hid/hid_apitest.cc
index c53bc336ce8c3bfc2314951a8a4d3170e2b2193a..ac114f2cd1421e275a8f8a79248dba595c671cad 100644
--- a/extensions/browser/api/hid/hid_apitest.cc
+++ b/extensions/browser/api/hid/hid_apitest.cc
@@ -10,6 +10,8 @@
#include "device/hid/hid_device_info.h"
#include "device/hid/hid_service.h"
#include "device/hid/hid_usage_and_page.h"
+#include "extensions/browser/api/device_permissions_prompt.h"
+#include "extensions/shell/browser/shell_extensions_api_client.h"
#include "extensions/shell/test/shell_apitest.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/base/io_buffer.h"
@@ -157,7 +159,7 @@ class MockHidService : public HidService {
kReportDescriptor + sizeof(kReportDescriptor));
}
HidService::AddDevice(new HidDeviceInfo(device_id, vendor_id, product_id,
- "", "", kHIDBusTypeUSB,
+ "Test Device", "A", kHIDBusTypeUSB,
report_descriptor));
}
@@ -170,6 +172,38 @@ class MockHidService : public HidService {
namespace extensions {
+class TestDevicePermissionsPrompt
+ : public DevicePermissionsPrompt,
+ public DevicePermissionsPrompt::Prompt::Observer {
+ public:
+ TestDevicePermissionsPrompt(content::WebContents* web_contents)
+ : DevicePermissionsPrompt(web_contents) {}
+
+ ~TestDevicePermissionsPrompt() override { prompt()->SetObserver(nullptr); }
+
+ void ShowDialog() override { prompt()->SetObserver(this); }
+
+ void OnDevicesChanged() override {
+ for (size_t i = 0; i < prompt()->GetDeviceCount(); ++i) {
+ prompt()->GrantDevicePermission(i);
+ if (!prompt()->multiple()) {
+ break;
+ }
+ }
+ prompt()->Dismissed();
+ }
+};
+
+class TestExtensionsAPIClient : public ShellExtensionsAPIClient {
+ public:
+ TestExtensionsAPIClient() : ShellExtensionsAPIClient() {}
+
+ scoped_ptr<DevicePermissionsPrompt> CreateDevicePermissionsPrompt(
+ content::WebContents* web_contents) const override {
+ return make_scoped_ptr(new TestDevicePermissionsPrompt(web_contents));
+ }
+};
+
class HidApiTest : public ShellApiTest {
public:
void SetUpOnMainThread() override {
@@ -219,4 +253,20 @@ IN_PROC_BROWSER_TEST_F(HidApiTest, OnDeviceRemoved) {
EXPECT_EQ("success", result_listener.message());
}
+IN_PROC_BROWSER_TEST_F(HidApiTest, GetUserSelectedDevices) {
+ ExtensionTestMessageListener open_listener("opened_device", false);
+
+ TestExtensionsAPIClient test_api_client;
+ ASSERT_TRUE(LoadApp("api_test/hid/get_user_selected_devices"));
+ ASSERT_TRUE(open_listener.WaitUntilSatisfied());
+
+ ExtensionTestMessageListener remove_listener("removed", false);
+ hid_service_->RemoveDevice(kTestDeviceIds[0]);
+ ASSERT_TRUE(remove_listener.WaitUntilSatisfied());
+
+ ExtensionTestMessageListener add_listener("added", false);
+ hid_service_->AddDevice(kTestDeviceIds[0], 0x18D1, 0x58F0, true);
+ ASSERT_TRUE(add_listener.WaitUntilSatisfied());
+}
+
} // namespace extensions
« no previous file with comments | « extensions/browser/api/hid/hid_api.cc ('k') | extensions/browser/api/hid/hid_device_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698