| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/usb/usb_chooser_controller.h" | 10 #include "chrome/browser/usb/usb_chooser_controller.h" |
| 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 12 #include "content/public/test/web_contents_tester.h" | 12 #include "content/public/test/web_contents_tester.h" |
| 13 #include "device/base/mock_device_client.h" | 13 #include "device/base/mock_device_client.h" |
| 14 #include "device/usb/mock_usb_device.h" | 14 #include "device/usb/mock_usb_device.h" |
| 15 #include "device/usb/mock_usb_service.h" | 15 #include "device/usb/mock_usb_service.h" |
| 16 #include "device/usb/public/interfaces/device_manager.mojom.h" | 16 #include "device/usb/public/interfaces/device_manager.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/array.h" | |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 const char kDefaultTestUrl[] = "https://www.google.com/"; | 23 const char kDefaultTestUrl[] = "https://www.google.com/"; |
| 25 | 24 |
| 26 class MockUsbChooserView : public ChooserController::View { | 25 class MockUsbChooserView : public ChooserController::View { |
| 27 public: | 26 public: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 | 40 |
| 42 } // namespace | 41 } // namespace |
| 43 | 42 |
| 44 class UsbChooserControllerTest : public ChromeRenderViewHostTestHarness { | 43 class UsbChooserControllerTest : public ChromeRenderViewHostTestHarness { |
| 45 public: | 44 public: |
| 46 UsbChooserControllerTest() {} | 45 UsbChooserControllerTest() {} |
| 47 | 46 |
| 48 void SetUp() override { | 47 void SetUp() override { |
| 49 ChromeRenderViewHostTestHarness::SetUp(); | 48 ChromeRenderViewHostTestHarness::SetUp(); |
| 50 | 49 |
| 51 mojo::Array<device::usb::DeviceFilterPtr> device_filters; | 50 std::vector<device::usb::DeviceFilterPtr> device_filters; |
| 52 device::usb::ChooserService::GetPermissionCallback callback; | 51 device::usb::ChooserService::GetPermissionCallback callback; |
| 53 content::WebContentsTester* web_contents_tester = | 52 content::WebContentsTester* web_contents_tester = |
| 54 content::WebContentsTester::For(web_contents()); | 53 content::WebContentsTester::For(web_contents()); |
| 55 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 54 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 56 usb_chooser_controller_.reset(new UsbChooserController( | 55 usb_chooser_controller_.reset( |
| 57 main_rfh(), std::move(device_filters), callback)); | 56 new UsbChooserController(main_rfh(), device_filters, callback)); |
| 58 mock_usb_chooser_view_.reset(new MockUsbChooserView()); | 57 mock_usb_chooser_view_.reset(new MockUsbChooserView()); |
| 59 usb_chooser_controller_->set_view(mock_usb_chooser_view_.get()); | 58 usb_chooser_controller_->set_view(mock_usb_chooser_view_.get()); |
| 60 } | 59 } |
| 61 | 60 |
| 62 protected: | 61 protected: |
| 63 scoped_refptr<device::MockUsbDevice> CreateMockUsbDevice( | 62 scoped_refptr<device::MockUsbDevice> CreateMockUsbDevice( |
| 64 const std::string& product_string, | 63 const std::string& product_string, |
| 65 const std::string& serial_number) { | 64 const std::string& serial_number) { |
| 66 scoped_refptr<device::MockUsbDevice> device(new device::MockUsbDevice( | 65 scoped_refptr<device::MockUsbDevice> device(new device::MockUsbDevice( |
| 67 0, 1, "Google", product_string, serial_number)); | 66 0, 1, "Google", product_string, serial_number)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 EXPECT_EQ(base::ASCIIToUTF16("a (001)"), | 151 EXPECT_EQ(base::ASCIIToUTF16("a (001)"), |
| 153 usb_chooser_controller_->GetOption(0)); | 152 usb_chooser_controller_->GetOption(0)); |
| 154 EXPECT_EQ(base::ASCIIToUTF16("b"), usb_chooser_controller_->GetOption(1)); | 153 EXPECT_EQ(base::ASCIIToUTF16("b"), usb_chooser_controller_->GetOption(1)); |
| 155 EXPECT_EQ(base::ASCIIToUTF16("a (002)"), | 154 EXPECT_EQ(base::ASCIIToUTF16("a (002)"), |
| 156 usb_chooser_controller_->GetOption(2)); | 155 usb_chooser_controller_->GetOption(2)); |
| 157 | 156 |
| 158 device_client_.usb_service()->RemoveDevice(device_a_1); | 157 device_client_.usb_service()->RemoveDevice(device_a_1); |
| 159 EXPECT_EQ(base::ASCIIToUTF16("b"), usb_chooser_controller_->GetOption(0)); | 158 EXPECT_EQ(base::ASCIIToUTF16("b"), usb_chooser_controller_->GetOption(0)); |
| 160 EXPECT_EQ(base::ASCIIToUTF16("a"), usb_chooser_controller_->GetOption(1)); | 159 EXPECT_EQ(base::ASCIIToUTF16("a"), usb_chooser_controller_->GetOption(1)); |
| 161 } | 160 } |
| OLD | NEW |