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

Side by Side Diff: ui/aura/test/aura_test_helper.cc

Issue 1871253002: aura: Require explicit ownership of the Env instance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tot.merge Created 4 years, 8 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 | « ui/aura/test/aura_test_helper.h ('k') | ui/aura/test/run_all_unittests.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/aura/test/aura_test_helper.h" 5 #include "ui/aura/test/aura_test_helper.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "ui/aura/client/default_capture_client.h" 9 #include "ui/aura/client/default_capture_client.h"
10 #include "ui/aura/client/focus_client.h" 10 #include "ui/aura/client/focus_client.h"
(...skipping 16 matching lines...) Expand all
27 #if defined(USE_X11) 27 #if defined(USE_X11)
28 #include "ui/aura/window_tree_host_x11.h" 28 #include "ui/aura/window_tree_host_x11.h"
29 #include "ui/base/x/x11_util.h" 29 #include "ui/base/x/x11_util.h"
30 #endif 30 #endif
31 31
32 namespace aura { 32 namespace aura {
33 namespace test { 33 namespace test {
34 34
35 AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop) 35 AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop)
36 : setup_called_(false), 36 : setup_called_(false),
37 teardown_called_(false), 37 teardown_called_(false) {
38 env_created_(false) {
39 DCHECK(message_loop); 38 DCHECK(message_loop);
40 message_loop_ = message_loop; 39 message_loop_ = message_loop;
41 // Disable animations during tests. 40 // Disable animations during tests.
42 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 41 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
43 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 42 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
44 #if defined(USE_X11) 43 #if defined(USE_X11)
45 test::SetUseOverrideRedirectWindowByDefault(true); 44 test::SetUseOverrideRedirectWindowByDefault(true);
46 #endif 45 #endif
47 InitializeAuraEventGeneratorDelegate(); 46 InitializeAuraEventGeneratorDelegate();
48 } 47 }
49 48
50 AuraTestHelper::~AuraTestHelper() { 49 AuraTestHelper::~AuraTestHelper() {
51 CHECK(setup_called_) 50 CHECK(setup_called_)
52 << "AuraTestHelper::SetUp() never called."; 51 << "AuraTestHelper::SetUp() never called.";
53 CHECK(teardown_called_) 52 CHECK(teardown_called_)
54 << "AuraTestHelper::TearDown() never called."; 53 << "AuraTestHelper::TearDown() never called.";
55 } 54 }
56 55
57 void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) { 56 void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) {
58 setup_called_ = true; 57 setup_called_ = true;
59 58
60 if (!Env::GetInstanceDontCreate()) { 59 if (!Env::GetInstanceDontCreate())
61 env_created_ = true; 60 env_ = aura::Env::CreateInstance();
62 Env::CreateInstance(true);
63 }
64 Env::GetInstance()->set_context_factory(context_factory); 61 Env::GetInstance()->set_context_factory(context_factory);
65 // Unit tests generally don't want to query the system, rather use the state 62 // Unit tests generally don't want to query the system, rather use the state
66 // from RootWindow. 63 // from RootWindow.
67 EnvTestHelper env_helper(Env::GetInstance()); 64 EnvTestHelper env_helper(Env::GetInstance());
68 env_helper.SetInputStateLookup(nullptr); 65 env_helper.SetInputStateLookup(nullptr);
69 env_helper.ResetEventState(); 66 env_helper.ResetEventState();
70 67
71 ui::InitializeInputMethodForTesting(); 68 ui::InitializeInputMethodForTesting();
72 69
73 gfx::Size host_size(800, 600); 70 gfx::Size host_size(800, 600);
(...skipping 22 matching lines...) Expand all
96 if (gfx::Screen::GetScreen() == test_screen_.get()) 93 if (gfx::Screen::GetScreen() == test_screen_.get())
97 gfx::Screen::SetScreenInstance(nullptr); 94 gfx::Screen::SetScreenInstance(nullptr);
98 test_screen_.reset(); 95 test_screen_.reset();
99 96
100 #if defined(USE_X11) 97 #if defined(USE_X11)
101 ui::test::ResetXCursorCache(); 98 ui::test::ResetXCursorCache();
102 #endif 99 #endif
103 100
104 ui::ShutdownInputMethodForTesting(); 101 ui::ShutdownInputMethodForTesting();
105 102
106 if (env_created_) 103 env_.reset();
107 Env::DeleteInstance();
108 } 104 }
109 105
110 void AuraTestHelper::RunAllPendingInMessageLoop() { 106 void AuraTestHelper::RunAllPendingInMessageLoop() {
111 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them 107 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them
112 // use run_loop.QuitClosure(). 108 // use run_loop.QuitClosure().
113 base::RunLoop run_loop; 109 base::RunLoop run_loop;
114 run_loop.RunUntilIdle(); 110 run_loop.RunUntilIdle();
115 } 111 }
116 112
117 } // namespace test 113 } // namespace test
118 } // namespace aura 114 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/aura_test_helper.h ('k') | ui/aura/test/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698