| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "device/usb/webusb_descriptors.h" | 5 #include "device/usb/webusb_descriptors.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 'm', 'p', 'l', 'e', '.', 'c', | 68 'm', 'p', 'l', 'e', '.', 'c', |
| 69 'o', 'm', ':', '8', '4'}; | 69 'o', 'm', ':', '8', '4'}; |
| 70 | 70 |
| 71 const uint8_t kExampleUrlDescriptor6[] = {0x11, 0x03, 0x01, 'e', 'x', 'a', | 71 const uint8_t kExampleUrlDescriptor6[] = {0x11, 0x03, 0x01, 'e', 'x', 'a', |
| 72 'm', 'p', 'l', 'e', '.', 'c', | 72 'm', 'p', 'l', 'e', '.', 'c', |
| 73 'o', 'm', ':', '8', '5'}; | 73 'o', 'm', ':', '8', '5'}; |
| 74 | 74 |
| 75 ACTION_P2(InvokeCallback, data, length) { | 75 ACTION_P2(InvokeCallback, data, length) { |
| 76 size_t transferred_length = std::min(length, arg7); | 76 size_t transferred_length = std::min(length, arg7); |
| 77 memcpy(arg6->data(), data, transferred_length); | 77 memcpy(arg6->data(), data, transferred_length); |
| 78 arg9.Run(USB_TRANSFER_COMPLETED, arg6, transferred_length); | 78 arg9.Run(UsbTransferStatus::COMPLETED, arg6, transferred_length); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void ExpectAllowedOriginsAndLandingPage( | 81 void ExpectAllowedOriginsAndLandingPage( |
| 82 std::unique_ptr<WebUsbAllowedOrigins> allowed_origins, | 82 std::unique_ptr<WebUsbAllowedOrigins> allowed_origins, |
| 83 const GURL& landing_page) { | 83 const GURL& landing_page) { |
| 84 EXPECT_EQ(GURL("https://example.com/index.html"), landing_page); | 84 EXPECT_EQ(GURL("https://example.com/index.html"), landing_page); |
| 85 ASSERT_TRUE(allowed_origins); | 85 ASSERT_TRUE(allowed_origins); |
| 86 ASSERT_EQ(2u, allowed_origins->origins.size()); | 86 ASSERT_EQ(2u, allowed_origins->origins.size()); |
| 87 EXPECT_EQ(GURL("https://example.com"), allowed_origins->origins[0]); | 87 EXPECT_EQ(GURL("https://example.com"), allowed_origins->origins[0]); |
| 88 EXPECT_EQ(GURL("https://example.com:81"), allowed_origins->origins[1]); | 88 EXPECT_EQ(GURL("https://example.com:81"), allowed_origins->origins[1]); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 GURL url; | 400 GURL url; |
| 401 ASSERT_FALSE(ParseWebUsbUrlDescriptor( | 401 ASSERT_FALSE(ParseWebUsbUrlDescriptor( |
| 402 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &url)); | 402 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &url)); |
| 403 } | 403 } |
| 404 | 404 |
| 405 TEST_F(WebUsbDescriptorsTest, ReadDescriptors) { | 405 TEST_F(WebUsbDescriptorsTest, ReadDescriptors) { |
| 406 scoped_refptr<MockUsbDeviceHandle> device_handle( | 406 scoped_refptr<MockUsbDeviceHandle> device_handle( |
| 407 new MockUsbDeviceHandle(nullptr)); | 407 new MockUsbDeviceHandle(nullptr)); |
| 408 | 408 |
| 409 EXPECT_CALL(*device_handle, | 409 EXPECT_CALL(*device_handle, |
| 410 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, | 410 ControlTransfer(UsbTransferDirection::INBOUND, |
| 411 UsbDeviceHandle::DEVICE, 0x06, 0x0F00, 0x0000, _, | 411 UsbControlTransferType::STANDARD, |
| 412 _, _, _)) | 412 UsbControlTransferRecipient::DEVICE, 0x06, 0x0F00, |
| 413 0x0000, _, _, _, _)) |
| 413 .Times(2) | 414 .Times(2) |
| 414 .WillRepeatedly( | 415 .WillRepeatedly( |
| 415 InvokeCallback(kExampleBosDescriptor, sizeof(kExampleBosDescriptor))); | 416 InvokeCallback(kExampleBosDescriptor, sizeof(kExampleBosDescriptor))); |
| 416 EXPECT_CALL(*device_handle, | 417 EXPECT_CALL(*device_handle, |
| 417 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, | 418 ControlTransfer(UsbTransferDirection::INBOUND, |
| 418 UsbDeviceHandle::DEVICE, 0x42, 0x0000, 0x0001, _, | 419 UsbControlTransferType::VENDOR, |
| 419 _, _, _)) | 420 UsbControlTransferRecipient::DEVICE, 0x42, 0x0000, |
| 421 0x0001, _, _, _, _)) |
| 420 .Times(2) | 422 .Times(2) |
| 421 .WillRepeatedly(InvokeCallback(kExampleAllowedOrigins, | 423 .WillRepeatedly(InvokeCallback(kExampleAllowedOrigins, |
| 422 sizeof(kExampleAllowedOrigins))); | 424 sizeof(kExampleAllowedOrigins))); |
| 423 EXPECT_CALL(*device_handle, | 425 EXPECT_CALL(*device_handle, |
| 424 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, | 426 ControlTransfer(UsbTransferDirection::INBOUND, |
| 425 UsbDeviceHandle::DEVICE, 0x42, 0x0001, 0x0002, _, | 427 UsbControlTransferType::VENDOR, |
| 426 _, _, _)) | 428 UsbControlTransferRecipient::DEVICE, 0x42, 0x0001, |
| 429 0x0002, _, _, _, _)) |
| 427 .WillOnce(InvokeCallback(kExampleUrlDescriptor1, | 430 .WillOnce(InvokeCallback(kExampleUrlDescriptor1, |
| 428 sizeof(kExampleUrlDescriptor1))); | 431 sizeof(kExampleUrlDescriptor1))); |
| 429 EXPECT_CALL(*device_handle, | 432 EXPECT_CALL(*device_handle, |
| 430 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, | 433 ControlTransfer(UsbTransferDirection::INBOUND, |
| 431 UsbDeviceHandle::DEVICE, 0x42, 0x0002, 0x0002, _, | 434 UsbControlTransferType::VENDOR, |
| 432 _, _, _)) | 435 UsbControlTransferRecipient::DEVICE, 0x42, 0x0002, |
| 436 0x0002, _, _, _, _)) |
| 433 .WillOnce(InvokeCallback(kExampleUrlDescriptor2, | 437 .WillOnce(InvokeCallback(kExampleUrlDescriptor2, |
| 434 sizeof(kExampleUrlDescriptor2))); | 438 sizeof(kExampleUrlDescriptor2))); |
| 435 EXPECT_CALL(*device_handle, | 439 EXPECT_CALL(*device_handle, |
| 436 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, | 440 ControlTransfer(UsbTransferDirection::INBOUND, |
| 437 UsbDeviceHandle::DEVICE, 0x42, 0x0003, 0x0002, _, | 441 UsbControlTransferType::VENDOR, |
| 438 _, _, _)) | 442 UsbControlTransferRecipient::DEVICE, 0x42, 0x0003, |
| 443 0x0002, _, _, _, _)) |
| 439 .WillOnce(InvokeCallback(kExampleUrlDescriptor3, | 444 .WillOnce(InvokeCallback(kExampleUrlDescriptor3, |
| 440 sizeof(kExampleUrlDescriptor3))); | 445 sizeof(kExampleUrlDescriptor3))); |
| 441 EXPECT_CALL(*device_handle, | 446 EXPECT_CALL(*device_handle, |
| 442 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, | 447 ControlTransfer(UsbTransferDirection::INBOUND, |
| 443 UsbDeviceHandle::DEVICE, 0x42, 0x0004, 0x0002, _, | 448 UsbControlTransferType::VENDOR, |
| 444 _, _, _)) | 449 UsbControlTransferRecipient::DEVICE, 0x42, 0x0004, |
| 450 0x0002, _, _, _, _)) |
| 445 .WillOnce(InvokeCallback(kExampleUrlDescriptor4, | 451 .WillOnce(InvokeCallback(kExampleUrlDescriptor4, |
| 446 sizeof(kExampleUrlDescriptor4))); | 452 sizeof(kExampleUrlDescriptor4))); |
| 447 EXPECT_CALL(*device_handle, | 453 EXPECT_CALL(*device_handle, |
| 448 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, | 454 ControlTransfer(UsbTransferDirection::INBOUND, |
| 449 UsbDeviceHandle::DEVICE, 0x42, 0x0005, 0x0002, _, | 455 UsbControlTransferType::VENDOR, |
| 450 _, _, _)) | 456 UsbControlTransferRecipient::DEVICE, 0x42, 0x0005, |
| 457 0x0002, _, _, _, _)) |
| 451 .WillOnce(InvokeCallback(kExampleUrlDescriptor5, | 458 .WillOnce(InvokeCallback(kExampleUrlDescriptor5, |
| 452 sizeof(kExampleUrlDescriptor5))); | 459 sizeof(kExampleUrlDescriptor5))); |
| 453 EXPECT_CALL(*device_handle, | 460 EXPECT_CALL(*device_handle, |
| 454 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, | 461 ControlTransfer(UsbTransferDirection::INBOUND, |
| 455 UsbDeviceHandle::DEVICE, 0x42, 0x0006, 0x0002, _, | 462 UsbControlTransferType::VENDOR, |
| 456 _, _, _)) | 463 UsbControlTransferRecipient::DEVICE, 0x42, 0x0006, |
| 464 0x0002, _, _, _, _)) |
| 457 .WillOnce(InvokeCallback(kExampleUrlDescriptor6, | 465 .WillOnce(InvokeCallback(kExampleUrlDescriptor6, |
| 458 sizeof(kExampleUrlDescriptor6))); | 466 sizeof(kExampleUrlDescriptor6))); |
| 459 | 467 |
| 460 ReadWebUsbDescriptors(device_handle, | 468 ReadWebUsbDescriptors(device_handle, |
| 461 base::Bind(&ExpectAllowedOriginsAndLandingPage)); | 469 base::Bind(&ExpectAllowedOriginsAndLandingPage)); |
| 462 } | 470 } |
| 463 | 471 |
| 464 } // namespace | 472 } // namespace |
| 465 | 473 |
| 466 } // namespace device | 474 } // namespace device |
| OLD | NEW |