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.
5 #ifndef COMPONENTS_PAIRING_FAKE_CONTROLLER_PAIRING_CONTROLLER_H_
6 #define COMPONENTS_PAIRING_FAKE_CONTROLLER_PAIRING_CONTROLLER_H_
11 #include "base/macros.h"
12 #include "base/observer_list.h"
13 #include "base/time/time.h"
14 #include "components/pairing/controller_pairing_controller.h"
16 namespace pairing_chromeos
{
18 class FakeControllerPairingController
19 : public ControllerPairingController
,
20 public ControllerPairingController::Observer
{
22 typedef ControllerPairingController::Observer Observer
;
24 enum DiscoveryEventType
{ DEVICE_FOUND
, DEVICE_LOST
, NOTHING_FOUND
};
26 typedef std::pair
<DiscoveryEventType
, std::string
> DiscoveryEvent
;
27 typedef std::vector
<DiscoveryEvent
> DiscoveryScenario
;
29 // Config is a coma separated list of key-value pairs separated by colon.
31 // * async_duration - integer. Default: 3000.
32 // * fail_connecting - {0,1}. Default: 0.
33 // * connection_lost - integer-integer. Default: 0-0.
34 // * fail_enrollment - {0,1}. Default: 0.
35 // * discovery - {F,L,N}-string(~{F,L,N}-string)*. Default:
36 // F-Device_1~F-Device_5~F-Device_3~L-Device_3~L-Device_1~F-Device_1
37 // * code - 6 digits or empty string. Default: empty string. If strings is
38 // empty, random code is generated.
39 explicit FakeControllerPairingController(const std::string
& config
);
40 ~FakeControllerPairingController() override
;
42 // Applies given |config| to controller.
43 void ApplyConfig(const std::string
& config
);
45 // Sets delay for asynchronous operations. like device searching or host
46 // enrollment. Default value is 3 seconds.
47 void set_async_duration(base::TimeDelta async_duration
) {
48 async_duration_
= async_duration
;
51 // Causing an error on |STAGE_ESTABLISHING_CONNECTION| stage once.
52 void SetShouldFailOnConnecting();
54 // Causing a connection loss on |stage_begin| and a connection recovery
55 // on |stage_end| once.
56 void SetShouldLoseConnection(Stage stage_begin
, Stage stage_end
);
58 // Makes host enrollment to fail once.
59 void SetEnrollmentShouldFail();
61 // Sets devices discovery scenario for |STAGE_DEVICES_DESCOVERY| stage.
62 // Events are executed with interval of |async_duration_|.
63 // For default scenario refer to implementation.
64 void SetDiscoveryScenario(const DiscoveryScenario
& discovery_scenario
);
66 // Overridden from ControllerPairingController:
67 void AddObserver(Observer
* observer
) override
;
68 void RemoveObserver(Observer
* observer
) override
;
69 Stage
GetCurrentStage() override
;
70 void StartPairing() override
;
71 DeviceIdList
GetDiscoveredDevices() override
;
72 void ChooseDeviceForPairing(const std::string
& device_id
) override
;
73 void RepeatDiscovery() override
;
74 std::string
GetConfirmationCode() override
;
75 void SetConfirmationCodeIsCorrect(bool correct
) override
;
76 void SetHostConfiguration(bool accepted_eula
,
77 const std::string
& lang
,
78 const std::string
& timezone
,
80 const std::string
& keyboard_layout
) override
;
81 void OnAuthenticationDone(const std::string
& domain
,
82 const std::string
& auth_token
) override
;
83 void StartSession() override
;
86 void ChangeStage(Stage new_stage
);
87 void ChangeStageLater(Stage new_stage
);
88 void ExecuteDiscoveryEvent(size_t event_position
);
89 void DeviceFound(const std::string
& device_id
);
90 void DeviceLost(const std::string
& device_id
);
92 // Overridden from ui::ControllerPairingController::Observer:
93 void PairingStageChanged(Stage new_stage
) override
;
94 void DiscoveredDevicesListChanged() override
;
96 ObserverList
<ControllerPairingController::Observer
> observers_
;
98 std::string confirmation_code_
;
99 std::string preset_confirmation_code_
;
100 base::TimeDelta async_duration_
;
101 DiscoveryScenario discovery_scenario_
;
102 std::set
<std::string
> discovered_devices_
;
103 std::string choosen_device_
;
104 bool should_fail_on_connecting_
;
105 Stage connection_lost_begin_
;
106 Stage connection_lost_end_
;
107 bool enrollment_should_fail_
;
109 DISALLOW_COPY_AND_ASSIGN(FakeControllerPairingController
);
112 } // namespace pairing_chromeos
114 #endif // COMPONENTS_PAIRING_FAKE_CONTROLLER_PAIRING_CONTROLLER_H_