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

Side by Side Diff: ash/test/ash_test_environment_default.cc

Issue 2846723004: Use ScopedTaskEnvironment instead of MessageLoopForUI in ash tests. (Closed)
Patch Set: 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 | « ash/system/power/power_status_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ash/test/ash_test_environment.h" 5 #include "ash/test/ash_test_environment.h"
6 6
7 #include "ash/test/ash_test_views_delegate.h" 7 #include "ash/test/ash_test_views_delegate.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/scoped_task_environment.h"
11 #include "base/test/sequenced_worker_pool_owner.h" 11 #include "base/test/sequenced_worker_pool_owner.h"
12 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 13
14 namespace ash { 14 namespace ash {
15 namespace test { 15 namespace test {
16 namespace { 16 namespace {
17 17
18 class AshTestEnvironmentDefault : public AshTestEnvironment { 18 class AshTestEnvironmentDefault : public AshTestEnvironment {
19 public: 19 public:
20 AshTestEnvironmentDefault() {} 20 AshTestEnvironmentDefault()
21 : scoped_task_environment_(
22 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
21 23
22 ~AshTestEnvironmentDefault() override { 24 ~AshTestEnvironmentDefault() override {
23 base::RunLoop().RunUntilIdle(); 25 base::RunLoop().RunUntilIdle();
24 blocking_pool_owner_.reset(); 26 blocking_pool_owner_.reset();
25 base::RunLoop().RunUntilIdle(); 27 base::RunLoop().RunUntilIdle();
26 } 28 }
27 29
28 // AshTestEnvironment: 30 // AshTestEnvironment:
29 base::SequencedWorkerPool* GetBlockingPool() override { 31 base::SequencedWorkerPool* GetBlockingPool() override {
30 if (!blocking_pool_owner_) { 32 if (!blocking_pool_owner_) {
31 const size_t kMaxNumberThreads = 3u; // Matches that of content. 33 const size_t kMaxNumberThreads = 3u; // Matches that of content.
32 const char kThreadNamePrefix[] = "AshBlocking"; 34 const char kThreadNamePrefix[] = "AshBlocking";
33 blocking_pool_owner_ = base::MakeUnique<base::SequencedWorkerPoolOwner>( 35 blocking_pool_owner_ = base::MakeUnique<base::SequencedWorkerPoolOwner>(
34 kMaxNumberThreads, kThreadNamePrefix); 36 kMaxNumberThreads, kThreadNamePrefix);
35 } 37 }
36 return blocking_pool_owner_->pool().get(); 38 return blocking_pool_owner_->pool().get();
37 } 39 }
38 std::unique_ptr<AshTestViewsDelegate> CreateViewsDelegate() override { 40 std::unique_ptr<AshTestViewsDelegate> CreateViewsDelegate() override {
39 return base::MakeUnique<AshTestViewsDelegate>(); 41 return base::MakeUnique<AshTestViewsDelegate>();
40 } 42 }
41 43
42 private: 44 private:
43 base::MessageLoopForUI message_loop_; 45 base::test::ScopedTaskEnvironment scoped_task_environment_;
44 std::unique_ptr<base::SequencedWorkerPoolOwner> blocking_pool_owner_; 46 std::unique_ptr<base::SequencedWorkerPoolOwner> blocking_pool_owner_;
45 47
46 DISALLOW_COPY_AND_ASSIGN(AshTestEnvironmentDefault); 48 DISALLOW_COPY_AND_ASSIGN(AshTestEnvironmentDefault);
47 }; 49 };
48 50
49 } // namespace 51 } // namespace
50 52
51 // static 53 // static
52 std::unique_ptr<AshTestEnvironment> AshTestEnvironment::Create() { 54 std::unique_ptr<AshTestEnvironment> AshTestEnvironment::Create() {
53 return base::MakeUnique<AshTestEnvironmentDefault>(); 55 return base::MakeUnique<AshTestEnvironmentDefault>();
54 } 56 }
55 57
56 // static 58 // static
57 std::string AshTestEnvironment::Get100PercentResourceFileName() { 59 std::string AshTestEnvironment::Get100PercentResourceFileName() {
58 return "ash_test_resources_100_percent.pak"; 60 return "ash_test_resources_100_percent.pak";
59 } 61 }
60 62
61 } // namespace test 63 } // namespace test
62 } // namespace ash 64 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/power/power_status_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698