Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / pairing / fake_controller_pairing_controller.h
blob99ac3de24863f7849eb921a0524c18567ad6f892
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_
8 #include <set>
9 #include <utility>
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 {
21 public:
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.
30 // Supported options:
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 virtual ~FakeControllerPairingController();
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 virtual void AddObserver(Observer* observer) OVERRIDE;
68 virtual void RemoveObserver(Observer* observer) OVERRIDE;
69 virtual Stage GetCurrentStage() OVERRIDE;
70 virtual void StartPairing() OVERRIDE;
71 virtual DeviceIdList GetDiscoveredDevices() OVERRIDE;
72 virtual void ChooseDeviceForPairing(const std::string& device_id) OVERRIDE;
73 virtual void RepeatDiscovery() OVERRIDE;
74 virtual std::string GetConfirmationCode() OVERRIDE;
75 virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE;
76 virtual void SetHostConfiguration(
77 bool accepted_eula,
78 const std::string& lang,
79 const std::string& timezone,
80 bool send_reports,
81 const std::string& keyboard_layout) OVERRIDE;
82 virtual void OnAuthenticationDone(const std::string& domain,
83 const std::string& auth_token) OVERRIDE;
84 virtual void StartSession() OVERRIDE;
86 private:
87 void ChangeStage(Stage new_stage);
88 void ChangeStageLater(Stage new_stage);
89 void ExecuteDiscoveryEvent(size_t event_position);
90 void DeviceFound(const std::string& device_id);
91 void DeviceLost(const std::string& device_id);
93 // Overridden from ui::ControllerPairingController::Observer:
94 virtual void PairingStageChanged(Stage new_stage) OVERRIDE;
95 virtual void DiscoveredDevicesListChanged() OVERRIDE;
97 ObserverList<ControllerPairingController::Observer> observers_;
98 Stage current_stage_;
99 std::string confirmation_code_;
100 std::string preset_confirmation_code_;
101 base::TimeDelta async_duration_;
102 DiscoveryScenario discovery_scenario_;
103 std::set<std::string> discovered_devices_;
104 std::string choosen_device_;
105 bool should_fail_on_connecting_;
106 Stage connection_lost_begin_;
107 Stage connection_lost_end_;
108 bool enrollment_should_fail_;
110 DISALLOW_COPY_AND_ASSIGN(FakeControllerPairingController);
113 } // namespace pairing_chromeos
115 #endif // COMPONENTS_PAIRING_FAKE_CONTROLLER_PAIRING_CONTROLLER_H_