Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: chromeos/pairing/fake_controller_pairing_flow.h

Issue 343433003: Implemented fake controller pairing flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/pairing/fake_controller_pairing_flow.h
diff --git a/chromeos/pairing/fake_controller_pairing_flow.h b/chromeos/pairing/fake_controller_pairing_flow.h
new file mode 100644
index 0000000000000000000000000000000000000000..803dafefda424a152ec87b3cafe4fffbe23539ad
--- /dev/null
+++ b/chromeos/pairing/fake_controller_pairing_flow.h
@@ -0,0 +1,102 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PAIRING_FAKE_CONTROLLER_PAIRING_FLOW_H_
+#define CHROMEOS_PAIRING_FAKE_CONTROLLER_PAIRING_FLOW_H_
+
+#include <set>
+#include <utility>
+
+#include "base/macros.h"
+#include "base/observer_list.h"
+#include "base/time/time.h"
+#include "chromeos/chromeos_export.h"
+#include "chromeos/pairing/controller_pairing_flow.h"
+
+namespace chromeos {
+
+class CHROMEOS_EXPORT FakeControllerPairingFlow
+ : public ControllerPairingFlow,
+ public ControllerPairingFlow::Observer {
+ public:
+ using ControllerPairingFlow::Observer;
+
+ enum DiscoveryEventType { DEVICE_FOUND, DEVICE_LOST };
+
+ typedef std::pair<DiscoveryEventType, std::string> DiscoveryEvent;
+ typedef std::vector<DiscoveryEvent> DiscoveryScenario;
+
+ static const char* kNotFoundDeviceID;
+
+ FakeControllerPairingFlow();
+ virtual ~FakeControllerPairingFlow();
+
+ // Sets delay for asynchronous operations. like device searching or host
+ // enrollment. Default value is 3 seconds.
+ void set_async_duration(base::TimeDelta async_duration) {
+ async_duration_ = async_duration;
+ }
+
+ // Causing an error on |STAGE_ESTABLISHING_CONNECTION| stage once.
+ void SetShouldFailOnConnecting();
+
+ // Causing a connection loss on |stage_begin| and a connection recovery
+ // on |stage_end| once.
+ void SetShouldLoseConnection(Stage stage_begin, Stage stage_end);
+
+ // Makes host enrollment to fail once.
+ void SetEnrollmentShouldFail();
+
+ // Sets devices discovery scenario for |STAGE_DEVICES_DESCOVERY| stage.
+ // Events are executed with interval of |async_duration_|. To emulate "device
+ // not found" scenario pass single event with device ID equal to
+ // |kNotFoundDeviceID| to this method.
+ // For default scenario refer to implementation.
+ void SetDiscoveryScenario(const DiscoveryScenario& discovery_scenario);
+
+ // Overridden from ui::ControllerPairingFlow:
+ virtual void AddObserver(Observer* observer) OVERRIDE;
+ virtual void RemoveObserver(Observer* observer) OVERRIDE;
+ virtual Stage GetCurrentStage() OVERRIDE;
+ virtual void StartFlow() OVERRIDE;
+ virtual DeviceIdList GetDiscoveredDevices() OVERRIDE;
+ virtual void ChooseDeviceForPairing(const std::string& device_id) OVERRIDE;
+ virtual void RepeatDiscovery() OVERRIDE;
+ virtual std::string GetConfirmationCode() OVERRIDE;
+ virtual void SetConfirmationCodeIsCorrect(bool correct) OVERRIDE;
+ virtual void OnAuthenticationDone(
+ const chromeos::UserContext& user_context,
+ content::BrowserContext* browser_context) OVERRIDE;
+ virtual void StartSession() OVERRIDE;
+
+ private:
+ void ChangeStage(Stage new_stage);
+ void ChangeStageLater(Stage new_stage);
+ void ExecuteDiscoveryEvent(size_t event_position);
+ void DeviceFound(const std::string& device_id);
+ void DeviceLost(const std::string& device_id);
+ DiscoveryScenario GetDefaultScenario() const;
+
+ // Overridden from ui::ControllerPairingFlow::Observer:
+ virtual void PairingStageChanged(Stage new_stage) OVERRIDE;
+ virtual void DiscoveredDevicesListChanged() OVERRIDE;
+
+ ObserverList<ControllerPairingFlow::Observer> observers_;
+ Stage current_stage_;
+ std::string confirmation_code_;
+ base::TimeDelta async_duration_;
+ DiscoveryScenario discovery_scenario_;
+ std::set<std::string> discovered_devices_;
+ std::string choosen_device_;
+ bool should_fail_on_connecting_;
+ Stage connection_lost_begin_;
+ Stage connection_lost_end_;
+ bool enrollment_should_fail_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeControllerPairingFlow);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_PAIRING_FAKE_CONTROLLER_PAIRING_FLOW_H_

Powered by Google App Engine
This is Rietveld 408576698