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