OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 CHROMEOS_PAIRING_FAKE_CONTROLLER_PAIRING_FLOW_H_ |
| 6 #define CHROMEOS_PAIRING_FAKE_CONTROLLER_PAIRING_FLOW_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <utility> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" |
| 13 #include "base/time/time.h" |
| 14 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/pairing/controller_pairing_flow.h" |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 class CHROMEOS_EXPORT FakeControllerPairingFlow |
| 20 : public ControllerPairingFlow, |
| 21 public ControllerPairingFlow::Observer { |
| 22 public: |
| 23 using ControllerPairingFlow::Observer; |
| 24 |
| 25 enum DiscoveryEventType { DEVICE_FOUND, DEVICE_LOST }; |
| 26 |
| 27 typedef std::pair<DiscoveryEventType, std::string> DiscoveryEvent; |
| 28 typedef std::vector<DiscoveryEvent> DiscoveryScenario; |
| 29 |
| 30 static const char* kNotFoundDeviceID; |
| 31 |
| 32 FakeControllerPairingFlow(); |
| 33 virtual ~FakeControllerPairingFlow(); |
| 34 |
| 35 // Sets delay for asynchronous operations. like device searching or host |
| 36 // enrollment. Default value is 3 seconds. |
| 37 void set_async_duration(base::TimeDelta async_duration) { |
| 38 async_duration_ = async_duration; |
| 39 } |
| 40 |
| 41 // Causing an error on |STAGE_ESTABLISHING_CONNECTION| stage once. |
| 42 void SetShouldFailOnConnecting(); |
| 43 |
| 44 // Causing a connection loss on |stage_begin| and a connection recovery |
| 45 // on |stage_end| once. |
| 46 void SetShouldLoseConnection(Stage stage_begin, Stage stage_end); |
| 47 |
| 48 // Makes host enrollment to fail once. |
| 49 void SetEnrollmentShouldFail(); |
| 50 |
| 51 // Sets devices discovery scenario for |STAGE_DEVICES_DESCOVERY| stage. |
| 52 // Events are executed with interval of |async_duration_|. To emulate "device |
| 53 // not found" scenario pass single event with device ID equal to |
| 54 // |kNotFoundDeviceID| to this method. |
| 55 // For default scenario refer to implementation. |
| 56 void SetDiscoveryScenario(const DiscoveryScenario& discovery_scenario); |
| 57 |
| 58 // Overridden from ui::ControllerPairingFlow: |
| 59 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 60 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 61 virtual Stage GetCurrentStage() OVERRIDE; |
| 62 virtual void StartFlow() OVERRIDE; |
| 63 virtual DeviceIdList GetDiscoveredDevices() OVERRIDE; |
| 64 virtual void ChooseDeviceForPairing(const std::string& device_id) OVERRIDE; |
| 65 virtual void RepeatDiscovery() OVERRIDE; |
| 66 virtual std::string GetConfirmationCode() OVERRIDE; |
| 67 virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE; |
| 68 virtual void OnAuthenticationDone( |
| 69 const chromeos::UserContext& user_context, |
| 70 content::BrowserContext* browser_context) OVERRIDE; |
| 71 virtual void StartSession() OVERRIDE; |
| 72 |
| 73 private: |
| 74 void ChangeStage(Stage new_stage); |
| 75 void ChangeStageLater(Stage new_stage); |
| 76 void ExecuteDiscoveryEvent(size_t event_position); |
| 77 void DeviceFound(const std::string& device_id); |
| 78 void DeviceLost(const std::string& device_id); |
| 79 DiscoveryScenario GetDefaultScenario() const; |
| 80 |
| 81 // Overridden from ui::ControllerPairingFlow::Observer: |
| 82 virtual void PairingStageChanged(Stage new_stage) OVERRIDE; |
| 83 virtual void DiscoveredDevicesListChanged() OVERRIDE; |
| 84 |
| 85 ObserverList<ControllerPairingFlow::Observer> observers_; |
| 86 Stage current_stage_; |
| 87 std::string confirmation_code_; |
| 88 base::TimeDelta async_duration_; |
| 89 DiscoveryScenario discovery_scenario_; |
| 90 std::set<std::string> discovered_devices_; |
| 91 std::string choosen_device_; |
| 92 bool should_fail_on_connecting_; |
| 93 Stage connection_lost_begin_; |
| 94 Stage connection_lost_end_; |
| 95 bool enrollment_should_fail_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(FakeControllerPairingFlow); |
| 98 }; |
| 99 |
| 100 } // namespace chromeos |
| 101 |
| 102 #endif // CHROMEOS_PAIRING_FAKE_CONTROLLER_PAIRING_FLOW_H_ |
OLD | NEW |