Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: components/arc/arc_bridge_service_unittest.cc

Issue 2425753002: Rename ArcBridgeBootstrap to ArcSession. (Closed)
Patch Set: Address comment. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/arc/arc_bridge_service_impl.cc ('k') | components/arc/arc_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 5 #include <memory>
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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "components/arc/arc_bridge_service_impl.h" 14 #include "components/arc/arc_bridge_service_impl.h"
15 #include "components/arc/test/fake_arc_bridge_bootstrap.h" 15 #include "components/arc/test/fake_arc_session.h"
16 #include "mojo/public/cpp/system/message_pipe.h" 16 #include "mojo/public/cpp/system/message_pipe.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace arc { 19 namespace arc {
20 20
21 namespace { 21 namespace {
22 22
23 class DummyObserver : public ArcBridgeService::Observer {}; 23 class DummyObserver : public ArcBridgeService::Observer {};
24 24
25 } // namespace 25 } // namespace
(...skipping 13 matching lines...) Expand all
39 void OnBridgeStopped(ArcBridgeService::StopReason stop_reason) override { 39 void OnBridgeStopped(ArcBridgeService::StopReason stop_reason) override {
40 // The instance is already destructed in ArcBridgeServiceImpl::OnStopped(). 40 // The instance is already destructed in ArcBridgeServiceImpl::OnStopped().
41 state_ = ArcBridgeService::State::STOPPED; 41 state_ = ArcBridgeService::State::STOPPED;
42 stop_reason_ = stop_reason; 42 stop_reason_ = stop_reason;
43 message_loop_.task_runner()->PostTask(FROM_HERE, 43 message_loop_.task_runner()->PostTask(FROM_HERE,
44 message_loop_.QuitWhenIdleClosure()); 44 message_loop_.QuitWhenIdleClosure());
45 } 45 }
46 46
47 bool ready() const { return ready_; } 47 bool ready() const { return ready_; }
48 ArcBridgeService::State state() const { return state_; } 48 ArcBridgeService::State state() const { return state_; }
49 FakeArcBridgeBootstrap* bootstrap() const { 49 FakeArcSession* arc_session() const {
50 return static_cast<FakeArcBridgeBootstrap*>( 50 return static_cast<FakeArcSession*>(service_->GetArcSessionForTesting());
51 service_->GetBootstrapForTesting());
52 } 51 }
53 52
54 protected: 53 protected:
55 std::unique_ptr<ArcBridgeServiceImpl> service_; 54 std::unique_ptr<ArcBridgeServiceImpl> service_;
56 ArcBridgeService::StopReason stop_reason_; 55 ArcBridgeService::StopReason stop_reason_;
57 56
58 static std::unique_ptr<ArcBridgeBootstrap> CreateSuspendedBootstrap() { 57 static std::unique_ptr<ArcSession> CreateSuspendedArcSession() {
59 auto bootstrap = base::MakeUnique<FakeArcBridgeBootstrap>(); 58 auto arc_session = base::MakeUnique<FakeArcSession>();
60 bootstrap->SuspendBoot(); 59 arc_session->SuspendBoot();
61 return std::move(bootstrap); 60 return std::move(arc_session);
62 } 61 }
63 62
64 static std::unique_ptr<ArcBridgeBootstrap> CreateBootFailureBootstrap( 63 static std::unique_ptr<ArcSession> CreateBootFailureArcSession(
65 ArcBridgeService::StopReason reason) { 64 ArcBridgeService::StopReason reason) {
66 auto bootstrap = base::MakeUnique<FakeArcBridgeBootstrap>(); 65 auto arc_session = base::MakeUnique<FakeArcSession>();
67 bootstrap->EnableBootFailureEmulation(reason); 66 arc_session->EnableBootFailureEmulation(reason);
68 return std::move(bootstrap); 67 return std::move(arc_session);
69 } 68 }
70 69
71 private: 70 private:
72 void SetUp() override { 71 void SetUp() override {
73 chromeos::DBusThreadManager::Initialize(); 72 chromeos::DBusThreadManager::Initialize();
74 73
75 ready_ = false; 74 ready_ = false;
76 state_ = ArcBridgeService::State::STOPPED; 75 state_ = ArcBridgeService::State::STOPPED;
77 stop_reason_ = ArcBridgeService::StopReason::SHUTDOWN; 76 stop_reason_ = ArcBridgeService::StopReason::SHUTDOWN;
78 77
79 service_.reset(new ArcBridgeServiceImpl()); 78 service_.reset(new ArcBridgeServiceImpl());
80 service_->SetArcBridgeBootstrapFactoryForTesting( 79 service_->SetArcSessionFactoryForTesting(
81 base::Bind(FakeArcBridgeBootstrap::Create)); 80 base::Bind(FakeArcSession::Create));
82 service_->AddObserver(this); 81 service_->AddObserver(this);
83 } 82 }
84 83
85 void TearDown() override { 84 void TearDown() override {
86 service_->RemoveObserver(this); 85 service_->RemoveObserver(this);
87 service_.reset(); 86 service_.reset();
88 87
89 chromeos::DBusThreadManager::Shutdown(); 88 chromeos::DBusThreadManager::Shutdown();
90 } 89 }
91 90
(...skipping 15 matching lines...) Expand all
107 106
108 service_->Shutdown(); 107 service_->Shutdown();
109 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); 108 ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
110 } 109 }
111 110
112 // If the ArcBridgeService is shut down, it should be stopped, even 111 // If the ArcBridgeService is shut down, it should be stopped, even
113 // mid-startup. 112 // mid-startup.
114 TEST_F(ArcBridgeTest, ShutdownMidStartup) { 113 TEST_F(ArcBridgeTest, ShutdownMidStartup) {
115 ASSERT_FALSE(ready()); 114 ASSERT_FALSE(ready());
116 115
117 service_->SetArcBridgeBootstrapFactoryForTesting( 116 service_->SetArcSessionFactoryForTesting(
118 base::Bind(ArcBridgeTest::CreateSuspendedBootstrap)); 117 base::Bind(ArcBridgeTest::CreateSuspendedArcSession));
119 service_->HandleStartup(); 118 service_->HandleStartup();
120 ASSERT_FALSE(service_->stopped()); 119 ASSERT_FALSE(service_->stopped());
121 ASSERT_FALSE(service_->ready()); 120 ASSERT_FALSE(service_->ready());
122 121
123 service_->Shutdown(); 122 service_->Shutdown();
124 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); 123 ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
125 } 124 }
126 125
127 // If the boot procedure is failed, then restarting mechanism should not 126 // If the boot procedure is failed, then restarting mechanism should not
128 // triggered. 127 // triggered.
129 TEST_F(ArcBridgeTest, BootFailure) { 128 TEST_F(ArcBridgeTest, BootFailure) {
130 ASSERT_TRUE(service_->stopped()); 129 ASSERT_TRUE(service_->stopped());
131 130
132 service_->SetArcBridgeBootstrapFactoryForTesting( 131 service_->SetArcSessionFactoryForTesting(
133 base::Bind(ArcBridgeTest::CreateBootFailureBootstrap, 132 base::Bind(ArcBridgeTest::CreateBootFailureArcSession,
134 ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE)); 133 ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE));
135 service_->HandleStartup(); 134 service_->HandleStartup();
136 EXPECT_EQ(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE, stop_reason_); 135 EXPECT_EQ(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE, stop_reason_);
137 ASSERT_TRUE(service_->stopped()); 136 ASSERT_TRUE(service_->stopped());
138 } 137 }
139 138
140 // If the instance is stopped, it should be re-started. 139 // If the instance is stopped, it should be re-started.
141 TEST_F(ArcBridgeTest, Restart) { 140 TEST_F(ArcBridgeTest, Restart) {
142 ASSERT_FALSE(ready()); 141 ASSERT_FALSE(ready());
143 142
144 service_->HandleStartup(); 143 service_->HandleStartup();
145 ASSERT_EQ(ArcBridgeService::State::READY, state()); 144 ASSERT_EQ(ArcBridgeService::State::READY, state());
146 145
147 // Simulate a connection loss. 146 // Simulate a connection loss.
148 service_->DisableReconnectDelayForTesting(); 147 service_->DisableReconnectDelayForTesting();
149 ASSERT_TRUE(bootstrap()); 148 ASSERT_TRUE(arc_session());
150 bootstrap()->StopWithReason(ArcBridgeService::StopReason::CRASH); 149 arc_session()->StopWithReason(ArcBridgeService::StopReason::CRASH);
151 ASSERT_TRUE(service_->ready()); 150 ASSERT_TRUE(service_->ready());
152 151
153 service_->Shutdown(); 152 service_->Shutdown();
154 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); 153 ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
155 } 154 }
156 155
157 // Makes sure OnBridgeStopped is called on stop. 156 // Makes sure OnBridgeStopped is called on stop.
158 TEST_F(ArcBridgeTest, OnBridgeStopped) { 157 TEST_F(ArcBridgeTest, OnBridgeStopped) {
159 ASSERT_FALSE(ready()); 158 ASSERT_FALSE(ready());
160 159
161 service_->DisableReconnectDelayForTesting(); 160 service_->DisableReconnectDelayForTesting();
162 service_->HandleStartup(); 161 service_->HandleStartup();
163 ASSERT_EQ(ArcBridgeService::State::READY, state()); 162 ASSERT_EQ(ArcBridgeService::State::READY, state());
164 163
165 // Simulate boot failure. 164 // Simulate boot failure.
166 ASSERT_TRUE(bootstrap()); 165 ASSERT_TRUE(arc_session());
167 bootstrap()->StopWithReason( 166 arc_session()->StopWithReason(
168 ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE); 167 ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE);
169 EXPECT_EQ(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE, stop_reason_); 168 EXPECT_EQ(ArcBridgeService::StopReason::GENERIC_BOOT_FAILURE, stop_reason_);
170 ASSERT_TRUE(service_->ready()); 169 ASSERT_TRUE(service_->ready());
171 170
172 // Simulate crash. 171 // Simulate crash.
173 ASSERT_TRUE(bootstrap()); 172 ASSERT_TRUE(arc_session());
174 bootstrap()->StopWithReason(ArcBridgeService::StopReason::CRASH); 173 arc_session()->StopWithReason(ArcBridgeService::StopReason::CRASH);
175 EXPECT_EQ(ArcBridgeService::StopReason::CRASH, stop_reason_); 174 EXPECT_EQ(ArcBridgeService::StopReason::CRASH, stop_reason_);
176 ASSERT_TRUE(service_->ready()); 175 ASSERT_TRUE(service_->ready());
177 176
178 // Graceful shutdown. 177 // Graceful shutdown.
179 service_->Shutdown(); 178 service_->Shutdown();
180 ASSERT_EQ(ArcBridgeService::StopReason::SHUTDOWN, stop_reason_); 179 ASSERT_EQ(ArcBridgeService::StopReason::SHUTDOWN, stop_reason_);
181 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); 180 ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
182 } 181 }
183 182
184 // Removing the same observer more than once should be okay. 183 // Removing the same observer more than once should be okay.
185 TEST_F(ArcBridgeTest, RemoveObserverTwice) { 184 TEST_F(ArcBridgeTest, RemoveObserverTwice) {
186 ASSERT_FALSE(ready()); 185 ASSERT_FALSE(ready());
187 auto dummy_observer = base::MakeUnique<DummyObserver>(); 186 auto dummy_observer = base::MakeUnique<DummyObserver>();
188 service_->AddObserver(dummy_observer.get()); 187 service_->AddObserver(dummy_observer.get());
189 // Call RemoveObserver() twice. 188 // Call RemoveObserver() twice.
190 service_->RemoveObserver(dummy_observer.get()); 189 service_->RemoveObserver(dummy_observer.get());
191 service_->RemoveObserver(dummy_observer.get()); 190 service_->RemoveObserver(dummy_observer.get());
192 } 191 }
193 192
194 // Removing an unknown observer should be allowed. 193 // Removing an unknown observer should be allowed.
195 TEST_F(ArcBridgeTest, RemoveUnknownObserver) { 194 TEST_F(ArcBridgeTest, RemoveUnknownObserver) {
196 ASSERT_FALSE(ready()); 195 ASSERT_FALSE(ready());
197 auto dummy_observer = base::MakeUnique<DummyObserver>(); 196 auto dummy_observer = base::MakeUnique<DummyObserver>();
198 service_->RemoveObserver(dummy_observer.get()); 197 service_->RemoveObserver(dummy_observer.get());
199 } 198 }
200 199
201 } // namespace arc 200 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/arc_bridge_service_impl.cc ('k') | components/arc/arc_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698