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

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

Issue 2846723005: Use ScopedTaskEnvironment instead of MessageLoopForUI in components tests. (Closed)
Patch Set: fix-test-errors Created 3 years, 7 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 | « no previous file | components/autofill/core/browser/webdata/web_data_service_unittest.cc » ('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 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/test/scoped_task_environment.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 16 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "components/arc/arc_session_runner.h" 17 #include "components/arc/arc_session_runner.h"
17 #include "components/arc/test/fake_arc_session.h" 18 #include "components/arc/test/fake_arc_session.h"
18 #include "mojo/public/cpp/system/message_pipe.h" 19 #include "mojo/public/cpp/system/message_pipe.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace arc { 22 namespace arc {
22 23
23 namespace { 24 namespace {
24 25
25 class DoNothingObserver : public ArcSessionRunner::Observer { 26 class DoNothingObserver : public ArcSessionRunner::Observer {
26 public: 27 public:
27 void OnSessionStopped(ArcStopReason reason, bool restarting) override { 28 void OnSessionStopped(ArcStopReason reason, bool restarting) override {
28 // Do nothing. 29 // Do nothing.
29 } 30 }
30 }; 31 };
31 32
32 } // namespace 33 } // namespace
33 34
34 class ArcSessionRunnerTest : public testing::Test, 35 class ArcSessionRunnerTest : public testing::Test,
35 public ArcSessionRunner::Observer { 36 public ArcSessionRunner::Observer {
36 public: 37 public:
37 ArcSessionRunnerTest() = default; 38 ArcSessionRunnerTest()
39 : scoped_task_environment_(
40 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
38 41
39 void SetUp() override { 42 void SetUp() override {
40 chromeos::DBusThreadManager::Initialize(); 43 chromeos::DBusThreadManager::Initialize();
41 44
42 stop_reason_ = ArcStopReason::SHUTDOWN; 45 stop_reason_ = ArcStopReason::SHUTDOWN;
43 restarting_ = false; 46 restarting_ = false;
44 47
45 // We inject FakeArcSession here so we do not need task_runner. 48 // We inject FakeArcSession here so we do not need task_runner.
46 arc_session_runner_ = 49 arc_session_runner_ =
47 base::MakeUnique<ArcSessionRunner>(base::Bind(FakeArcSession::Create)); 50 base::MakeUnique<ArcSessionRunner>(base::Bind(FakeArcSession::Create));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 void OnSessionStopped(ArcStopReason stop_reason, bool restarting) override { 93 void OnSessionStopped(ArcStopReason stop_reason, bool restarting) override {
91 // The instance is already destructed in 94 // The instance is already destructed in
92 // ArcSessionRunner::OnSessionStopped(). 95 // ArcSessionRunner::OnSessionStopped().
93 stop_reason_ = stop_reason; 96 stop_reason_ = stop_reason;
94 restarting_ = restarting; 97 restarting_ = restarting;
95 } 98 }
96 99
97 ArcStopReason stop_reason_; 100 ArcStopReason stop_reason_;
98 bool restarting_; 101 bool restarting_;
99 std::unique_ptr<ArcSessionRunner> arc_session_runner_; 102 std::unique_ptr<ArcSessionRunner> arc_session_runner_;
100 base::MessageLoopForUI message_loop_; 103 base::test::ScopedTaskEnvironment scoped_task_environment_;
101 104
102 DISALLOW_COPY_AND_ASSIGN(ArcSessionRunnerTest); 105 DISALLOW_COPY_AND_ASSIGN(ArcSessionRunnerTest);
103 }; 106 };
104 107
105 // Exercises the basic functionality of the ArcSessionRunner. Observer should 108 // Exercises the basic functionality of the ArcSessionRunner. Observer should
106 // be notified. 109 // be notified.
107 TEST_F(ArcSessionRunnerTest, Basic) { 110 TEST_F(ArcSessionRunnerTest, Basic) {
108 class Observer : public ArcSessionRunner::Observer { 111 class Observer : public ArcSessionRunner::Observer {
109 public: 112 public:
110 Observer() = default; 113 Observer() = default;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 249
247 // Removing an unknown observer should be allowed. 250 // Removing an unknown observer should be allowed.
248 TEST_F(ArcSessionRunnerTest, RemoveUnknownObserver) { 251 TEST_F(ArcSessionRunnerTest, RemoveUnknownObserver) {
249 EXPECT_TRUE(arc_session_runner()->IsStopped()); 252 EXPECT_TRUE(arc_session_runner()->IsStopped());
250 253
251 DoNothingObserver do_nothing_observer; 254 DoNothingObserver do_nothing_observer;
252 arc_session_runner()->RemoveObserver(&do_nothing_observer); 255 arc_session_runner()->RemoveObserver(&do_nothing_observer);
253 } 256 }
254 257
255 } // namespace arc 258 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/webdata/web_data_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698