OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_INSTANCE_H_ | 5 #ifndef COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_INSTANCE_H_ |
6 #define COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_INSTANCE_H_ | 6 #define COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_INSTANCE_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "components/arc/arc_bridge_service.h" | 9 #include "components/arc/arc_bridge_service.h" |
10 #include "components/arc/common/arc_bridge.mojom.h" | 10 #include "components/arc/common/arc_bridge.mojom.h" |
11 #include "mojo/public/cpp/bindings/binding.h" | 11 #include "mojo/public/cpp/bindings/binding.h" |
12 | 12 |
13 namespace arc { | 13 namespace arc { |
14 | 14 |
15 class FakeArcBridgeInstance : public mojom::ArcBridgeInstance { | 15 class FakeArcBridgeInstance : public mojom::ArcBridgeInstance { |
16 public: | 16 public: |
17 class Delegate { | 17 class Delegate { |
18 public: | 18 public: |
19 virtual ~Delegate() = default; | 19 virtual ~Delegate() = default; |
20 virtual void OnCrashed() = 0; | 20 virtual void OnStopped(ArcBridgeService::StopReason reason) = 0; |
21 }; | 21 }; |
22 | 22 |
23 FakeArcBridgeInstance(); | 23 FakeArcBridgeInstance(); |
24 ~FakeArcBridgeInstance() override; | 24 ~FakeArcBridgeInstance() override; |
25 | 25 |
26 void set_delegate(Delegate* delegate) { delegate_ = delegate; } | 26 void set_delegate(Delegate* delegate) { delegate_ = delegate; } |
27 | 27 |
28 // Finalizes the connection between the host and the instance, and signals | 28 // Finalizes the connection between the host and the instance, and signals |
29 // the host that the boot sequence has finished. | 29 // the host that the boot sequence has finished. |
30 void Bind(mojo::InterfaceRequest<mojom::ArcBridgeInstance> interface_request); | 30 void Bind(mojo::InterfaceRequest<mojom::ArcBridgeInstance> interface_request); |
31 | 31 |
32 // Resets the binding. Useful to simulate a restart. | 32 // Resets the binding. Useful to simulate a restart. |
33 void Unbind(); | 33 void Unbind(); |
34 | 34 |
35 // ArcBridgeInstance: | 35 // ArcBridgeInstance: |
36 void Init(mojom::ArcBridgeHostPtr host) override; | 36 void Init(mojom::ArcBridgeHostPtr host) override; |
37 | 37 |
38 // Ensures the call to Init() has been dispatched. | 38 // Ensures the call to Init() has been dispatched. |
39 void WaitForInitCall(); | 39 void WaitForInitCall(); |
40 | 40 |
41 // The number of times Init() has been called. | 41 // The number of times Init() has been called. |
42 int init_calls() const { return init_calls_; } | 42 int init_calls() const { return init_calls_; } |
43 | 43 |
44 // Simulates a crash by calling Stop() on the ArcBridgeBoostrap. | 44 // Stops the instance. |
45 void SimulateCrash(); | 45 void Stop(ArcBridgeService::StopReason reason); |
46 | 46 |
47 private: | 47 private: |
48 Delegate* delegate_ = nullptr; | 48 Delegate* delegate_ = nullptr; |
49 | 49 |
50 // Mojo endpoints. | 50 // Mojo endpoints. |
51 mojo::Binding<mojom::ArcBridgeInstance> binding_; | 51 mojo::Binding<mojom::ArcBridgeInstance> binding_; |
52 mojom::ArcBridgeHostPtr host_ptr_; | 52 mojom::ArcBridgeHostPtr host_ptr_; |
53 int init_calls_ = 0; | 53 int init_calls_ = 0; |
54 | 54 |
55 DISALLOW_COPY_AND_ASSIGN(FakeArcBridgeInstance); | 55 DISALLOW_COPY_AND_ASSIGN(FakeArcBridgeInstance); |
56 }; | 56 }; |
57 | 57 |
58 } // namespace arc | 58 } // namespace arc |
59 | 59 |
60 #endif // COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_INSTANCE_H_ | 60 #endif // COMPONENTS_ARC_TEST_FAKE_ARC_BRIDGE_INSTANCE_H_ |
OLD | NEW |