mock_usb_device_handle.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_DEVICE_USB_MOCK_USB_DEVICE_HANDLE_H_
  5. #define SERVICES_DEVICE_USB_MOCK_USB_DEVICE_HANDLE_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <vector>
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/memory/ref_counted_memory.h"
  11. #include "services/device/usb/usb_device_handle.h"
  12. #include "testing/gmock/include/gmock/gmock.h"
  13. namespace device {
  14. class MockUsbDeviceHandle : public UsbDeviceHandle {
  15. public:
  16. explicit MockUsbDeviceHandle(UsbDevice* device);
  17. scoped_refptr<UsbDevice> GetDevice() const override;
  18. MOCK_METHOD0(Close, void());
  19. // TODO(crbug.com/729950): Use MOCK_METHOD directly once GMock gets the
  20. // move-only type support.
  21. void SetConfiguration(int configuration_value,
  22. ResultCallback callback) override {
  23. SetConfigurationInternal(configuration_value, callback);
  24. }
  25. MOCK_METHOD2(SetConfigurationInternal,
  26. void(int configuration_value, ResultCallback& callback));
  27. void ClaimInterface(int interface_number, ResultCallback callback) override {
  28. ClaimInterfaceInternal(interface_number, callback);
  29. }
  30. MOCK_METHOD2(ClaimInterfaceInternal,
  31. void(int interface_number, ResultCallback& callback));
  32. void ReleaseInterface(int interface_number,
  33. ResultCallback callback) override {
  34. ReleaseInterfaceInternal(interface_number, callback);
  35. }
  36. MOCK_METHOD2(ReleaseInterfaceInternal,
  37. void(int interface_number, ResultCallback& callback));
  38. void SetInterfaceAlternateSetting(int interface_number,
  39. int alternate_setting,
  40. ResultCallback callback) override {
  41. SetInterfaceAlternateSettingInternal(interface_number, alternate_setting,
  42. callback);
  43. }
  44. MOCK_METHOD3(SetInterfaceAlternateSettingInternal,
  45. void(int interface_number,
  46. int alternate_setting,
  47. ResultCallback& callback));
  48. void ResetDevice(ResultCallback callback) override {
  49. ResetDeviceInternal(callback);
  50. }
  51. MOCK_METHOD1(ResetDeviceInternal, void(ResultCallback& callback));
  52. void ClearHalt(mojom::UsbTransferDirection direction,
  53. uint8_t endpoint_number,
  54. ResultCallback callback) override {
  55. ClearHaltInternal(direction, endpoint_number, callback);
  56. }
  57. MOCK_METHOD3(ClearHaltInternal,
  58. void(mojom::UsbTransferDirection direction,
  59. uint8_t endpoint_number,
  60. ResultCallback& callback));
  61. void ControlTransfer(mojom::UsbTransferDirection direction,
  62. mojom::UsbControlTransferType request_type,
  63. mojom::UsbControlTransferRecipient recipient,
  64. uint8_t request,
  65. uint16_t value,
  66. uint16_t index,
  67. scoped_refptr<base::RefCountedBytes> buffer,
  68. unsigned int timeout,
  69. TransferCallback callback) override {
  70. ControlTransferInternal(direction, request_type, recipient, request, value,
  71. index, buffer, timeout, callback);
  72. }
  73. MOCK_METHOD9(ControlTransferInternal,
  74. void(mojom::UsbTransferDirection direction,
  75. mojom::UsbControlTransferType request_type,
  76. mojom::UsbControlTransferRecipient recipient,
  77. uint8_t request,
  78. uint16_t value,
  79. uint16_t index,
  80. scoped_refptr<base::RefCountedBytes> buffer,
  81. unsigned int timeout,
  82. TransferCallback& callback));
  83. void IsochronousTransferIn(uint8_t endpoint,
  84. const std::vector<uint32_t>& packet_lengths,
  85. unsigned int timeout,
  86. IsochronousTransferCallback callback) override {
  87. IsochronousTransferInInternal(endpoint, packet_lengths, timeout, callback);
  88. }
  89. MOCK_METHOD4(IsochronousTransferInInternal,
  90. void(uint8_t endpoint,
  91. const std::vector<uint32_t>& packet_lengths,
  92. unsigned int timeout,
  93. IsochronousTransferCallback& callback));
  94. void IsochronousTransferOut(uint8_t endpoint,
  95. scoped_refptr<base::RefCountedBytes> buffer,
  96. const std::vector<uint32_t>& packet_lengths,
  97. unsigned int timeout,
  98. IsochronousTransferCallback callback) override {
  99. IsochronousTransferOutInternal(endpoint, buffer, packet_lengths, timeout,
  100. callback);
  101. }
  102. MOCK_METHOD5(IsochronousTransferOutInternal,
  103. void(uint8_t endpoint,
  104. scoped_refptr<base::RefCountedBytes> buffer,
  105. const std::vector<uint32_t>& packet_lengths,
  106. unsigned int timeout,
  107. IsochronousTransferCallback& callback));
  108. void GenericTransfer(mojom::UsbTransferDirection direction,
  109. uint8_t endpoint,
  110. scoped_refptr<base::RefCountedBytes> buffer,
  111. unsigned int timeout,
  112. TransferCallback callback) override {
  113. GenericTransferInternal(direction, endpoint, buffer, timeout, callback);
  114. }
  115. MOCK_METHOD5(GenericTransferInternal,
  116. void(mojom::UsbTransferDirection direction,
  117. uint8_t endpoint,
  118. scoped_refptr<base::RefCountedBytes> buffer,
  119. unsigned int timeout,
  120. TransferCallback& callback));
  121. MOCK_METHOD1(FindInterfaceByEndpoint,
  122. const mojom::UsbInterfaceInfo*(uint8_t endpoint_address));
  123. protected:
  124. ~MockUsbDeviceHandle() override;
  125. private:
  126. raw_ptr<UsbDevice> device_;
  127. };
  128. } // namespace device
  129. #endif // SERVICES_DEVICE_USB_MOCK_USB_DEVICE_HANDLE_H_