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