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 #include <utility> | |
6 | |
7 #include "base/bind.h" | 5 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
9 #include "base/macros.h" | 7 #include "base/macros.h" |
10 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
11 #include "chromeos/dbus/dbus_thread_manager.h" | 9 #include "chromeos/dbus/dbus_thread_manager.h" |
12 #include "components/arc/arc_bridge_service_impl.h" | 10 #include "components/arc/arc_bridge_service_impl.h" |
| 11 #include "components/arc/test/fake_arc_bridge_bootstrap.h" |
13 #include "components/arc/test/fake_arc_bridge_instance.h" | 12 #include "components/arc/test/fake_arc_bridge_instance.h" |
14 #include "ipc/mojo/scoped_ipc_support.h" | 13 #include "ipc/mojo/scoped_ipc_support.h" |
15 #include "mojo/public/cpp/system/message_pipe.h" | 14 #include "mojo/public/cpp/system/message_pipe.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 | 16 |
18 namespace arc { | 17 namespace arc { |
19 | 18 |
20 namespace { | |
21 | |
22 // A fake ArcBridgeBootstrap that creates a local connection. | |
23 class FakeArcBridgeBootstrap : public ArcBridgeBootstrap { | |
24 public: | |
25 explicit FakeArcBridgeBootstrap(FakeArcBridgeInstance* instance) | |
26 : instance_(instance) {} | |
27 ~FakeArcBridgeBootstrap() override {} | |
28 | |
29 void Start() override { | |
30 DCHECK(delegate_); | |
31 ArcBridgeInstancePtr instance; | |
32 instance_->Bind(mojo::GetProxy(&instance)); | |
33 delegate_->OnConnectionEstablished(std::move(instance)); | |
34 } | |
35 | |
36 void Stop() override { | |
37 DCHECK(delegate_); | |
38 instance_->Unbind(); | |
39 delegate_->OnStopped(); | |
40 } | |
41 | |
42 private: | |
43 // Owned by the caller. | |
44 FakeArcBridgeInstance* instance_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(FakeArcBridgeBootstrap); | |
47 }; | |
48 | |
49 } // namespace | |
50 | |
51 class ArcBridgeTest : public testing::Test, public ArcBridgeService::Observer { | 19 class ArcBridgeTest : public testing::Test, public ArcBridgeService::Observer { |
52 public: | 20 public: |
53 ArcBridgeTest() : ready_(false) {} | 21 ArcBridgeTest() : ready_(false) {} |
54 ~ArcBridgeTest() override {} | 22 ~ArcBridgeTest() override {} |
55 | 23 |
56 void OnStateChanged(ArcBridgeService::State state) override { | 24 void OnStateChanged(ArcBridgeService::State state) override { |
57 state_ = state; | 25 state_ = state; |
58 switch (state) { | 26 switch (state) { |
59 case ArcBridgeService::State::READY: | 27 case ArcBridgeService::State::READY: |
60 ready_ = true; | 28 ready_ = true; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 service_->OnChannelClosed(); | 128 service_->OnChannelClosed(); |
161 instance_->WaitForInitCall(); | 129 instance_->WaitForInitCall(); |
162 ASSERT_EQ(ArcBridgeService::State::READY, state()); | 130 ASSERT_EQ(ArcBridgeService::State::READY, state()); |
163 ASSERT_EQ(2, instance_->init_calls()); | 131 ASSERT_EQ(2, instance_->init_calls()); |
164 | 132 |
165 service_->Shutdown(); | 133 service_->Shutdown(); |
166 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); | 134 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); |
167 } | 135 } |
168 | 136 |
169 } // namespace arc | 137 } // namespace arc |
OLD | NEW |