fake_bluetooth_chooser_controller.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2017 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 COMPONENTS_PERMISSIONS_FAKE_BLUETOOTH_CHOOSER_CONTROLLER_H_
  5. #define COMPONENTS_PERMISSIONS_FAKE_BLUETOOTH_CHOOSER_CONTROLLER_H_
  6. #include <string>
  7. #include "components/permissions/chooser_controller.h"
  8. #include "testing/gmock/include/gmock/gmock.h"
  9. namespace permissions {
  10. // A subclass of ChooserController that pretends to be a Bluetooth device
  11. // chooser for testing. The result should be visually similar to the real
  12. // version of the dialog for interactive tests.
  13. class FakeBluetoothChooserController : public ChooserController {
  14. public:
  15. enum class BluetoothStatus {
  16. UNAVAILABLE,
  17. IDLE,
  18. SCANNING,
  19. };
  20. enum ConnectionStatus {
  21. NOT_CONNECTED = false,
  22. CONNECTED = true,
  23. };
  24. enum PairStatus {
  25. NOT_PAIRED = false,
  26. PAIRED = true,
  27. };
  28. static constexpr int kSignalStrengthUnknown = -1;
  29. static constexpr int kSignalStrengthLevel0 = 0;
  30. static constexpr int kSignalStrengthLevel1 = 1;
  31. static constexpr int kSignalStrengthLevel2 = 2;
  32. static constexpr int kSignalStrengthLevel3 = 3;
  33. static constexpr int kSignalStrengthLevel4 = 4;
  34. struct FakeDevice {
  35. std::string name;
  36. bool connected;
  37. bool paired;
  38. int signal_strength;
  39. };
  40. explicit FakeBluetoothChooserController(std::vector<FakeDevice> devices = {});
  41. FakeBluetoothChooserController(const FakeBluetoothChooserController&) =
  42. delete;
  43. FakeBluetoothChooserController& operator=(
  44. const FakeBluetoothChooserController&) = delete;
  45. ~FakeBluetoothChooserController() override;
  46. // ChooserController:
  47. bool ShouldShowIconBeforeText() const override;
  48. bool ShouldShowReScanButton() const override;
  49. std::u16string GetNoOptionsText() const override;
  50. std::u16string GetOkButtonLabel() const override;
  51. std::pair<std::u16string, std::u16string> GetThrobberLabelAndTooltip()
  52. const override;
  53. bool TableViewAlwaysDisabled() const override;
  54. size_t NumOptions() const override;
  55. int GetSignalStrengthLevel(size_t index) const override;
  56. std::u16string GetOption(size_t index) const override;
  57. bool IsConnected(size_t index) const override;
  58. bool IsPaired(size_t index) const override;
  59. MOCK_METHOD0(RefreshOptions, void());
  60. MOCK_METHOD1(Select, void(const std::vector<size_t>& indices));
  61. MOCK_METHOD0(Cancel, void());
  62. MOCK_METHOD0(Close, void());
  63. MOCK_CONST_METHOD0(OpenHelpCenterUrl, void());
  64. MOCK_CONST_METHOD0(OpenAdapterOffHelpUrl, void());
  65. void SetBluetoothStatus(BluetoothStatus status);
  66. void SetBluetoothPermission(bool has_permission);
  67. void AddDevice(FakeDevice device);
  68. void RemoveDevice(size_t index);
  69. void UpdateDevice(size_t index, FakeDevice new_device);
  70. void set_table_view_always_disabled(bool table_view_always_disabled) {
  71. table_view_always_disabled_ = table_view_always_disabled;
  72. }
  73. private:
  74. std::vector<FakeDevice> devices_;
  75. bool table_view_always_disabled_ = false;
  76. };
  77. } // namespace permissions
  78. #endif // COMPONENTS_PERMISSIONS_FAKE_BLUETOOTH_CHOOSER_CONTROLLER_H_