fake_winrt_wgi_environment.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2021 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 DEVICE_GAMEPAD_TEST_SUPPORT_FAKE_WINRT_WGI_ENVIRONMENT_H_
  5. #define DEVICE_GAMEPAD_TEST_SUPPORT_FAKE_WINRT_WGI_ENVIRONMENT_H_
  6. #include <hstring.h>
  7. #include "base/win/windows_types.h"
  8. namespace device {
  9. enum class ErrorCode {
  10. kOk,
  11. kErrorWgiGamepadActivateFailed,
  12. kErrorWgiGamepadGetCurrentReadingFailed,
  13. kErrorWgiGamepadGetButtonLabelFailed,
  14. kErrorWgiRawGameControllerActivateFailed,
  15. kErrorWgiRawGameControllerFromGameControllerFailed,
  16. kErrorWgiRawGameControllerGetDisplayNameFailed,
  17. kErrorWgiRawGameControllerGetHardwareProductIdFailed,
  18. kErrorWgiRawGameControllerGetHardwareVendorIdFailed,
  19. kGamepadAddGamepadAddedFailed,
  20. kGamepadAddGamepadRemovedFailed,
  21. kGamepadRemoveGamepadAddedFailed,
  22. kGamepadRemoveGamepadRemovedFailed
  23. };
  24. // Overrides the WinRT WGI OS APIs used by the helper functions in
  25. // device/gamepad/wgi_data_fetcher_win.h. Also, it is used by the fake classes
  26. // in tests to simulate failures by returning error HRESULT codes from fake
  27. // WinRT API calls.
  28. class FakeWinrtWgiEnvironment final {
  29. public:
  30. static HRESULT FakeRoGetActivationFactory(HSTRING class_id,
  31. const IID& iid,
  32. void** out_factory);
  33. FakeWinrtWgiEnvironment(ErrorCode error_code);
  34. FakeWinrtWgiEnvironment(const FakeWinrtWgiEnvironment&) = delete;
  35. FakeWinrtWgiEnvironment& operator=(const FakeWinrtWgiEnvironment&) = delete;
  36. ~FakeWinrtWgiEnvironment();
  37. // Injects errors in the fake implementation of the WinRT WGI APIs.
  38. void SimulateError(ErrorCode error_code);
  39. // Used by the fake WinRT WGI APIs to determine when to generate errors.
  40. static ErrorCode GetError();
  41. private:
  42. // The errors the fake WinRT WGI APIs should simulate. Set to |kOk| to succeed
  43. // without error.
  44. static ErrorCode s_error_code_;
  45. };
  46. } // namespace device
  47. #endif // DEVICE_GAMEPAD_TEST_SUPPORT_FAKE_WINRT_WGI_ENVIRONMENT_H_