OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 #include "content/public/browser/browser_thread.h" | 6 #include "content/public/browser/browser_thread.h" |
7 #include "content/public/test/test_utils.h" | 7 #include "content/public/test/test_utils.h" |
8 #include "device/usb/usb_service.h" | 8 #include "device/usb/usb_service.h" |
9 #include "extensions/browser/api/device_permissions_prompt.h" | 9 #include "extensions/browser/api/device_permissions_prompt.h" |
10 #include "extensions/browser/api/usb/usb_api.h" | 10 #include "extensions/browser/api/usb/usb_api.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 class TestDevicePermissionsPrompt | 47 class TestDevicePermissionsPrompt |
48 : public DevicePermissionsPrompt, | 48 : public DevicePermissionsPrompt, |
49 public DevicePermissionsPrompt::Prompt::Observer { | 49 public DevicePermissionsPrompt::Prompt::Observer { |
50 public: | 50 public: |
51 TestDevicePermissionsPrompt(content::WebContents* web_contents) | 51 TestDevicePermissionsPrompt(content::WebContents* web_contents) |
52 : DevicePermissionsPrompt(web_contents) {} | 52 : DevicePermissionsPrompt(web_contents) {} |
53 | 53 |
54 void ShowDialog() override { prompt()->SetObserver(this); } | 54 void ShowDialog() override { prompt()->SetObserver(this); } |
55 | 55 |
56 void OnDevicesChanged() override { | 56 void OnDevicesChanged() override { |
57 std::vector<scoped_refptr<UsbDevice>> devices; | |
58 for (size_t i = 0; i < prompt()->GetDeviceCount(); ++i) { | 57 for (size_t i = 0; i < prompt()->GetDeviceCount(); ++i) { |
59 prompt()->GrantDevicePermission(i); | 58 prompt()->GrantDevicePermission(i); |
60 devices.push_back(prompt()->GetDevice(i)); | |
61 if (!prompt()->multiple()) { | 59 if (!prompt()->multiple()) { |
62 break; | 60 break; |
63 } | 61 } |
64 } | 62 } |
65 delegate()->OnUsbDevicesChosen(devices); | 63 prompt()->Dismissed(); |
66 } | 64 } |
67 }; | 65 }; |
68 | 66 |
69 class TestExtensionsAPIClient : public ShellExtensionsAPIClient { | 67 class TestExtensionsAPIClient : public ShellExtensionsAPIClient { |
70 public: | 68 public: |
71 TestExtensionsAPIClient() : ShellExtensionsAPIClient() {} | 69 TestExtensionsAPIClient() : ShellExtensionsAPIClient() {} |
72 | 70 |
73 scoped_ptr<DevicePermissionsPrompt> CreateDevicePermissionsPrompt( | 71 scoped_ptr<DevicePermissionsPrompt> CreateDevicePermissionsPrompt( |
74 content::WebContents* web_contents) const override { | 72 content::WebContents* web_contents) const override { |
75 return make_scoped_ptr(new TestDevicePermissionsPrompt(web_contents)); | 73 return make_scoped_ptr(new TestDevicePermissionsPrompt(web_contents)); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 336 |
339 TestExtensionsAPIClient test_api_client; | 337 TestExtensionsAPIClient test_api_client; |
340 ASSERT_TRUE(LoadApp("api_test/usb/get_user_selected_devices")); | 338 ASSERT_TRUE(LoadApp("api_test/usb/get_user_selected_devices")); |
341 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); | 339 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); |
342 | 340 |
343 mock_service_->NotifyDeviceRemoved(mock_device_); | 341 mock_service_->NotifyDeviceRemoved(mock_device_); |
344 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); | 342 ASSERT_TRUE(result_listener.WaitUntilSatisfied()); |
345 } | 343 } |
346 | 344 |
347 } // namespace extensions | 345 } // namespace extensions |
OLD | NEW |