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

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

Issue 2133653002: arc: Notify ARC instance failures via callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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
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"
(...skipping 23 matching lines...) Expand all
34 34
35 case ArcBridgeService::State::STOPPED: 35 case ArcBridgeService::State::STOPPED:
36 message_loop_.PostTask(FROM_HERE, message_loop_.QuitWhenIdleClosure()); 36 message_loop_.PostTask(FROM_HERE, message_loop_.QuitWhenIdleClosure());
37 break; 37 break;
38 38
39 default: 39 default:
40 break; 40 break;
41 } 41 }
42 } 42 }
43 43
44 void OnBridgeAborting(ArcBridgeService::AbortReason reason) override {
45 aborted_ = true;
46 abort_reason_ = reason;
47 }
48
44 bool ready() const { return ready_; } 49 bool ready() const { return ready_; }
45 ArcBridgeService::State state() const { return state_; } 50 ArcBridgeService::State state() const { return state_; }
46 51
47 protected: 52 protected:
48 std::unique_ptr<ArcBridgeServiceImpl> service_; 53 std::unique_ptr<ArcBridgeServiceImpl> service_;
49 std::unique_ptr<FakeArcBridgeInstance> instance_; 54 std::unique_ptr<FakeArcBridgeInstance> instance_;
55 bool aborted_;
56 ArcBridgeService::AbortReason abort_reason_;
50 57
51 private: 58 private:
52 void SetUp() override { 59 void SetUp() override {
53 chromeos::DBusThreadManager::Initialize(); 60 chromeos::DBusThreadManager::Initialize();
54 61
55 ready_ = false; 62 ready_ = false;
56 state_ = ArcBridgeService::State::STOPPED; 63 state_ = ArcBridgeService::State::STOPPED;
64 aborted_ = false;
65 abort_reason_ = ArcBridgeService::AbortReason::GENERIC_BOOT_FAILURE;
57 66
58 instance_.reset(new FakeArcBridgeInstance()); 67 instance_.reset(new FakeArcBridgeInstance());
59 service_.reset(new ArcBridgeServiceImpl( 68 service_.reset(new ArcBridgeServiceImpl(
60 base::MakeUnique<FakeArcBridgeBootstrap>(instance_.get()))); 69 base::MakeUnique<FakeArcBridgeBootstrap>(instance_.get())));
61 70
62 service_->AddObserver(this); 71 service_->AddObserver(this);
63 } 72 }
64 73
65 void TearDown() override { 74 void TearDown() override {
66 service_->RemoveObserver(this); 75 service_->RemoveObserver(this);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 ASSERT_EQ(1, instance_->init_calls()); 142 ASSERT_EQ(1, instance_->init_calls());
134 143
135 // Simulate a connection loss. 144 // Simulate a connection loss.
136 service_->DisableReconnectDelayForTesting(); 145 service_->DisableReconnectDelayForTesting();
137 service_->OnChannelClosed(); 146 service_->OnChannelClosed();
138 instance_->SimulateCrash(); 147 instance_->SimulateCrash();
139 instance_->WaitForInitCall(); 148 instance_->WaitForInitCall();
140 ASSERT_EQ(ArcBridgeService::State::READY, state()); 149 ASSERT_EQ(ArcBridgeService::State::READY, state());
141 ASSERT_EQ(2, instance_->init_calls()); 150 ASSERT_EQ(2, instance_->init_calls());
142 151
152 ASSERT_TRUE(aborted_);
153 ASSERT_EQ(ArcBridgeService::AbortReason::CRASH, abort_reason_);
hidehiko 2016/07/11 05:40:08 Could you add GENERIC_BOOT_FAILURE case, too?
Shuhei Takahashi 2016/07/11 08:25:19 Done.
154
143 service_->Shutdown(); 155 service_->Shutdown();
144 ASSERT_EQ(ArcBridgeService::State::STOPPED, state()); 156 ASSERT_EQ(ArcBridgeService::State::STOPPED, state());
145 } 157 }
146 158
147 // Removing the same observer more than once should be okay. 159 // Removing the same observer more than once should be okay.
148 TEST_F(ArcBridgeTest, RemoveObserverTwice) { 160 TEST_F(ArcBridgeTest, RemoveObserverTwice) {
149 ASSERT_FALSE(ready()); 161 ASSERT_FALSE(ready());
150 service_->RemoveObserver(this); 162 service_->RemoveObserver(this);
151 // The teardown method will also remove |this|. 163 // The teardown method will also remove |this|.
152 } 164 }
153 165
154 // Removing an unknown observer should be allowed. 166 // Removing an unknown observer should be allowed.
155 TEST_F(ArcBridgeTest, RemoveUnknownObserver) { 167 TEST_F(ArcBridgeTest, RemoveUnknownObserver) {
156 ASSERT_FALSE(ready()); 168 ASSERT_FALSE(ready());
157 auto dummy_observer = base::MakeUnique<DummyObserver>(); 169 auto dummy_observer = base::MakeUnique<DummyObserver>();
158 service_->RemoveObserver(dummy_observer.get()); 170 service_->RemoveObserver(dummy_observer.get());
159 } 171 }
160 172
161 } // namespace arc 173 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698