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> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
12 #include "components/arc/arc_bridge_service_impl.h" | 12 #include "components/arc/arc_bridge_service_impl.h" |
13 #include "components/arc/test/fake_arc_bridge_instance.h" | 13 #include "components/arc/test/fake_arc_bridge_instance.h" |
14 #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 { | 20 namespace { |
22 | 21 |
23 // A fake ArcBridgeBootstrap that creates a local connection. | 22 // A fake ArcBridgeBootstrap that creates a local connection. |
24 class FakeArcBridgeBootstrap : public ArcBridgeBootstrap { | 23 class FakeArcBridgeBootstrap : public ArcBridgeBootstrap { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 scoped_ptr<ArcBridgeServiceImpl> service_; | 76 scoped_ptr<ArcBridgeServiceImpl> service_; |
78 scoped_ptr<FakeArcBridgeInstance> instance_; | 77 scoped_ptr<FakeArcBridgeInstance> instance_; |
79 | 78 |
80 private: | 79 private: |
81 void SetUp() override { | 80 void SetUp() override { |
82 chromeos::DBusThreadManager::Initialize(); | 81 chromeos::DBusThreadManager::Initialize(); |
83 | 82 |
84 ready_ = false; | 83 ready_ = false; |
85 state_ = ArcBridgeService::State::STOPPED; | 84 state_ = ArcBridgeService::State::STOPPED; |
86 | 85 |
87 ipc_support_.reset(new IPC::ScopedIPCSupport(message_loop_.task_runner())); | |
88 instance_.reset(new FakeArcBridgeInstance()); | 86 instance_.reset(new FakeArcBridgeInstance()); |
89 service_.reset(new ArcBridgeServiceImpl( | 87 service_.reset(new ArcBridgeServiceImpl( |
90 make_scoped_ptr(new FakeArcBridgeBootstrap(instance_.get())))); | 88 make_scoped_ptr(new FakeArcBridgeBootstrap(instance_.get())))); |
91 | 89 |
92 service_->AddObserver(this); | 90 service_->AddObserver(this); |
93 } | 91 } |
94 | 92 |
95 void TearDown() override { | 93 void TearDown() override { |
96 service_->RemoveObserver(this); | 94 service_->RemoveObserver(this); |
97 instance_.reset(); | 95 instance_.reset(); |
98 service_.reset(); | 96 service_.reset(); |
99 ipc_support_.reset(); | |
100 | 97 |
101 chromeos::DBusThreadManager::Shutdown(); | 98 chromeos::DBusThreadManager::Shutdown(); |
102 } | 99 } |
103 | 100 |
104 bool ready_; | 101 bool ready_; |
105 ArcBridgeService::State state_; | 102 ArcBridgeService::State state_; |
106 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_; | |
107 base::MessageLoopForUI message_loop_; | 103 base::MessageLoopForUI message_loop_; |
108 | 104 |
109 DISALLOW_COPY_AND_ASSIGN(ArcBridgeTest); | 105 DISALLOW_COPY_AND_ASSIGN(ArcBridgeTest); |
110 }; | 106 }; |
111 | 107 |
112 // Exercises the basic functionality of the ARC Bridge Service. A message from | 108 // Exercises the basic functionality of the ARC Bridge Service. A message from |
113 // within the instance should cause the observer to be notified. | 109 // within the instance should cause the observer to be notified. |
114 TEST_F(ArcBridgeTest, Basic) { | 110 TEST_F(ArcBridgeTest, Basic) { |
115 ASSERT_FALSE(ready()); | 111 ASSERT_FALSE(ready()); |
116 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); | 112 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 service_->OnChannelClosed(); | 160 service_->OnChannelClosed(); |
165 instance_->WaitForInitCall(); | 161 instance_->WaitForInitCall(); |
166 ASSERT_EQ(ArcBridgeService::State::READY, state()); | 162 ASSERT_EQ(ArcBridgeService::State::READY, state()); |
167 ASSERT_EQ(2, instance_->init_calls()); | 163 ASSERT_EQ(2, instance_->init_calls()); |
168 | 164 |
169 service_->Shutdown(); | 165 service_->Shutdown(); |
170 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); | 166 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); |
171 } | 167 } |
172 | 168 |
173 } // namespace arc | 169 } // namespace arc |
OLD | NEW |