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

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

Issue 2807833002: [views-mus] Prevent creating a native OzonePlatform in mus tests. (Closed)
Patch Set: Use the same detection method at all levels. Created 3 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 | « no previous file | ui/views/BUILD.gn » ('j') | ui/views/BUILD.gn » ('J')
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/command_line.h"
7 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "ui/aura/client/default_capture_client.h" 11 #include "ui/aura/client/default_capture_client.h"
11 #include "ui/aura/client/focus_client.h" 12 #include "ui/aura/client/focus_client.h"
12 #include "ui/aura/env.h" 13 #include "ui/aura/env.h"
13 #include "ui/aura/input_state_lookup.h" 14 #include "ui/aura/input_state_lookup.h"
14 #include "ui/aura/mus/capture_synchronizer.h" 15 #include "ui/aura/mus/capture_synchronizer.h"
15 #include "ui/aura/mus/focus_synchronizer.h" 16 #include "ui/aura/mus/focus_synchronizer.h"
16 #include "ui/aura/mus/window_port_mus.h" 17 #include "ui/aura/mus/window_port_mus.h"
(...skipping 21 matching lines...) Expand all
38 #if defined(USE_X11) 39 #if defined(USE_X11)
39 #include "ui/base/x/x11_util.h" // nogncheck 40 #include "ui/base/x/x11_util.h" // nogncheck
40 #endif 41 #endif
41 42
42 namespace aura { 43 namespace aura {
43 namespace test { 44 namespace test {
44 namespace { 45 namespace {
45 46
46 AuraTestHelper* g_instance = nullptr; 47 AuraTestHelper* g_instance = nullptr;
47 48
49 // Returns true if running inside of mus. Checks for mojo specific flag.
50 bool RunningInsideMus() {
51 return base::CommandLine::ForCurrentProcess()->HasSwitch(
52 "primordial-pipe-token");
sky 2017/04/10 23:53:26 Use kPrimordialPipeToken?
Elliot Glaysher 2017/04/12 18:09:16 Removed.
53 }
54
48 } // namespace 55 } // namespace
49 56
50 AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop) 57 AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop)
51 : setup_called_(false), teardown_called_(false) { 58 : setup_called_(false), teardown_called_(false) {
52 DCHECK(message_loop); 59 DCHECK(message_loop);
53 // Disable animations during tests. 60 // Disable animations during tests.
54 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 61 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
55 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 62 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
56 ui::test::EnableTestConfigForPlatformWindows(); 63 ui::test::EnableTestConfigForPlatformWindows();
57 InitializeAuraEventGeneratorDelegate(); 64 InitializeAuraEventGeneratorDelegate();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 env_helper.SetAlwaysUseLastMouseLocation(true); 122 env_helper.SetAlwaysUseLastMouseLocation(true);
116 Env::GetInstance()->set_context_factory(context_factory); 123 Env::GetInstance()->set_context_factory(context_factory);
117 Env::GetInstance()->set_context_factory_private(context_factory_private); 124 Env::GetInstance()->set_context_factory_private(context_factory_private);
118 // Unit tests generally don't want to query the system, rather use the state 125 // Unit tests generally don't want to query the system, rather use the state
119 // from RootWindow. 126 // from RootWindow.
120 env_helper.SetInputStateLookup(nullptr); 127 env_helper.SetInputStateLookup(nullptr);
121 env_helper.ResetEventState(); 128 env_helper.ResetEventState();
122 129
123 ui::InitializeInputMethodForTesting(); 130 ui::InitializeInputMethodForTesting();
124 131
125 display::Screen* screen = display::Screen::GetScreen(); 132 if (!RunningInsideMus()) {
126 gfx::Size host_size(screen ? screen->GetPrimaryDisplay().GetSizeInPixel() 133 display::Screen* screen = display::Screen::GetScreen();
127 : gfx::Size(800, 600)); 134 gfx::Size host_size(screen ? screen->GetPrimaryDisplay().GetSizeInPixel()
128 // TODO(sky): creating the screen and host should not happen for mus. 135 : gfx::Size(800, 600));
129 test_screen_.reset(TestScreen::Create(host_size)); 136 // TODO(sky): creating the screen and host should not happen for mus.
sky 2017/04/10 23:53:26 You can remove this todo now.
Elliot Glaysher 2017/04/12 18:09:16 Done.
130 if (!screen) 137 test_screen_.reset(TestScreen::Create(host_size));
131 display::Screen::SetScreenInstance(test_screen_.get()); 138 if (!screen)
132 host_.reset(test_screen_->CreateHostForPrimaryDisplay()); 139 display::Screen::SetScreenInstance(test_screen_.get());
133 host_->window()->SetEventTargeter( 140 host_.reset(test_screen_->CreateHostForPrimaryDisplay());
134 std::unique_ptr<ui::EventTargeter>(new WindowTargeter())); 141 host_->window()->SetEventTargeter(
142 std::unique_ptr<ui::EventTargeter>(new WindowTargeter()));
135 143
136 client::SetFocusClient(root_window(), focus_client_.get()); 144 client::SetFocusClient(root_window(), focus_client_.get());
137 client::SetCaptureClient(root_window(), capture_client()); 145 client::SetCaptureClient(root_window(), capture_client());
138 parenting_client_.reset(new TestWindowParentingClient(root_window())); 146 parenting_client_.reset(new TestWindowParentingClient(root_window()));
139 147
140 root_window()->Show(); 148 root_window()->Show();
141 // Ensure width != height so tests won't confuse them. 149 // Ensure width != height so tests won't confuse them.
142 host()->SetBoundsInPixels(gfx::Rect(host_size)); 150 host()->SetBoundsInPixels(gfx::Rect(host_size));
151 }
143 152
144 if (mode_ == Mode::MUS_CREATE_WINDOW_TREE_CLIENT) { 153 if (mode_ == Mode::MUS_CREATE_WINDOW_TREE_CLIENT) {
145 window_tree_client_->focus_synchronizer()->SetActiveFocusClient( 154 window_tree_client_->focus_synchronizer()->SetActiveFocusClient(
146 focus_client_.get(), root_window()); 155 focus_client_.get(), root_window());
147 window_tree()->AckAllChanges(); 156 window_tree()->AckAllChanges();
148 } 157 }
149 158
150 g_instance = this; 159 g_instance = this;
151 } 160 }
152 161
153 void AuraTestHelper::TearDown() { 162 void AuraTestHelper::TearDown() {
154 g_instance = nullptr; 163 g_instance = nullptr;
155 teardown_called_ = true; 164 teardown_called_ = true;
156 parenting_client_.reset(); 165 parenting_client_.reset();
157 client::SetFocusClient(root_window(), nullptr); 166 if (!RunningInsideMus()) {
158 client::SetCaptureClient(root_window(), nullptr); 167 client::SetFocusClient(root_window(), nullptr);
159 host_.reset(); 168 client::SetCaptureClient(root_window(), nullptr);
169 host_.reset();
170
171 if (display::Screen::GetScreen() == test_screen_.get())
172 display::Screen::SetScreenInstance(nullptr);
173 test_screen_.reset();
174
175 window_tree_client_setup_.reset();
176 focus_client_.reset();
177 capture_client_.reset();
178 }
160 ui::GestureRecognizer::Reset(); 179 ui::GestureRecognizer::Reset();
161 if (display::Screen::GetScreen() == test_screen_.get())
162 display::Screen::SetScreenInstance(nullptr);
163 test_screen_.reset();
164
165 window_tree_client_setup_.reset();
166 focus_client_.reset();
167 capture_client_.reset();
168
169 ui::ShutdownInputMethodForTesting(); 180 ui::ShutdownInputMethodForTesting();
170 181
171 if (env_) 182 if (env_)
172 env_.reset(); 183 env_.reset();
173 else 184 else
174 EnvTestHelper().SetWindowTreeClient(nullptr); 185 EnvTestHelper().SetWindowTreeClient(nullptr);
175 wm_state_.reset(); 186 wm_state_.reset();
176 } 187 }
177 188
178 void AuraTestHelper::RunAllPendingInMessageLoop() { 189 void AuraTestHelper::RunAllPendingInMessageLoop() {
(...skipping 19 matching lines...) Expand all
198 window_tree_client_setup_ = base::MakeUnique<TestWindowTreeClientSetup>(); 209 window_tree_client_setup_ = base::MakeUnique<TestWindowTreeClientSetup>();
199 window_tree_client_setup_->InitForWindowManager(window_tree_delegate_, 210 window_tree_client_setup_->InitForWindowManager(window_tree_delegate_,
200 window_manager_delegate_); 211 window_manager_delegate_);
201 window_tree_client_ = window_tree_client_setup_->window_tree_client(); 212 window_tree_client_ = window_tree_client_setup_->window_tree_client();
202 window_tree_client_->capture_synchronizer()->AttachToCaptureClient( 213 window_tree_client_->capture_synchronizer()->AttachToCaptureClient(
203 capture_client_.get()); 214 capture_client_.get());
204 } 215 }
205 216
206 } // namespace test 217 } // namespace test
207 } // namespace aura 218 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/views/BUILD.gn » ('j') | ui/views/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698