| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_BOOTSTRAP_H_ | 5 #ifndef COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_BOOTSTRAP_H_ |
| 6 #define COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_BOOTSTRAP_H_ | 6 #define COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_BOOTSTRAP_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "components/arc/arc_bridge_bootstrap.h" | 11 #include "components/arc/arc_bridge_bootstrap.h" |
| 10 #include "components/arc/test/fake_arc_bridge_instance.h" | 12 #include "components/arc/test/fake_arc_bridge_instance.h" |
| 11 | 13 |
| 12 namespace arc { | 14 namespace arc { |
| 13 | 15 |
| 14 // A fake ArcBridgeBootstrap that creates a local connection. | 16 // A fake ArcBridgeBootstrap that creates a local connection. |
| 15 class FakeArcBridgeBootstrap : public ArcBridgeBootstrap, | 17 class FakeArcBridgeBootstrap : public ArcBridgeBootstrap { |
| 16 public FakeArcBridgeInstance::Delegate { | |
| 17 public: | 18 public: |
| 18 explicit FakeArcBridgeBootstrap(FakeArcBridgeInstance* instance); | 19 FakeArcBridgeBootstrap(); |
| 19 ~FakeArcBridgeBootstrap() override = default; | 20 ~FakeArcBridgeBootstrap() override; |
| 20 | 21 |
| 21 // ArcBridgeBootstrap: | 22 // ArcBridgeBootstrap: |
| 22 void Start() override; | 23 void Start() override; |
| 23 void Stop() override; | 24 void Stop() override; |
| 24 | 25 |
| 26 // To emulate unexpected stop, such as crash. |
| 27 void StopWithReason(ArcBridgeService::StopReason reason); |
| 28 |
| 29 // The following control Start() behavior for testing various situations. |
| 30 |
| 31 // Enables/disables boot failure emulation, in which OnStopped(reason) will |
| 32 // be called when Start() is called. |
| 33 void EnableBootFailureEmulation(ArcBridgeService::StopReason reason); |
| 34 |
| 35 // Emulate Start() is suspended at some phase, before OnReady() is invoked. |
| 36 void SuspendBoot(); |
| 37 |
| 38 // Returns FakeArcBridgeBootstrap instance. This can be used for a factory |
| 39 // in ArcBridgeServiceImpl. |
| 40 static std::unique_ptr<ArcBridgeBootstrap> Create(); |
| 41 |
| 25 private: | 42 private: |
| 26 // FakeArcBridgeInstance::Delegate: | 43 bool boot_failure_emulation_enabled_ = false; |
| 27 void OnStopped(ArcBridgeService::StopReason reason) override; | 44 ArcBridgeService::StopReason boot_failure_reason_; |
| 45 FakeArcBridgeInstance instance_; |
| 28 | 46 |
| 29 // Owned by the caller. | 47 bool boot_suspended_ = false; |
| 30 FakeArcBridgeInstance* instance_; | |
| 31 | 48 |
| 32 DISALLOW_COPY_AND_ASSIGN(FakeArcBridgeBootstrap); | 49 DISALLOW_COPY_AND_ASSIGN(FakeArcBridgeBootstrap); |
| 33 }; | 50 }; |
| 34 | 51 |
| 35 } // namespace arc | 52 } // namespace arc |
| 36 | 53 |
| 37 #endif // COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_BOOTSTRAP_H_ | 54 #endif // COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_BOOTSTRAP_H_ |
| OLD | NEW |