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

Side by Side Diff: ash/wm/window_manager_unittest.cc

Issue 11299219: Rework FocusManager as FocusClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
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 "ash/shell.h" 5 #include "ash/shell.h"
6 #include "ash/shell_window_ids.h" 6 #include "ash/shell_window_ids.h"
7 #include "ash/test/ash_test_base.h" 7 #include "ash/test/ash_test_base.h"
8 #include "ash/test/test_activation_delegate.h" 8 #include "ash/test/test_activation_delegate.h"
9 #include "ash/wm/activation_controller.h" 9 #include "ash/wm/activation_controller.h"
10 #include "ash/wm/cursor_manager.h" 10 #include "ash/wm/cursor_manager.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "ui/aura/client/activation_client.h" 12 #include "ui/aura/client/activation_client.h"
13 #include "ui/aura/client/activation_delegate.h" 13 #include "ui/aura/client/activation_delegate.h"
14 #include "ui/aura/client/focus_client.h"
14 #include "ui/aura/env.h" 15 #include "ui/aura/env.h"
15 #include "ui/aura/focus_manager.h"
16 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
17 #include "ui/aura/test/aura_test_base.h" 17 #include "ui/aura/test/aura_test_base.h"
18 #include "ui/aura/test/event_generator.h" 18 #include "ui/aura/test/event_generator.h"
19 #include "ui/aura/test/test_event_handler.h" 19 #include "ui/aura/test/test_event_handler.h"
20 #include "ui/aura/test/test_window_delegate.h" 20 #include "ui/aura/test/test_window_delegate.h"
21 #include "ui/aura/test/test_windows.h" 21 #include "ui/aura/test/test_windows.h"
22 #include "ui/base/cursor/cursor.h" 22 #include "ui/base/cursor/cursor.h"
23 #include "ui/base/events/event.h" 23 #include "ui/base/events/event.h"
24 #include "ui/base/hit_test.h" 24 #include "ui/base/hit_test.h"
25 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 scoped_ptr<aura::Window> w123(aura::test::CreateTestWindowWithDelegate( 142 scoped_ptr<aura::Window> w123(aura::test::CreateTestWindowWithDelegate(
143 w123delegate, -123, gfx::Rect(15, 5, 5, 5), w12.get())); 143 w123delegate, -123, gfx::Rect(15, 5, 5, 5), w12.get()));
144 scoped_ptr<aura::Window> w13(aura::test::CreateTestWindow( 144 scoped_ptr<aura::Window> w13(aura::test::CreateTestWindow(
145 SK_ColorGRAY, -13, gfx::Rect(5, 470, 50, 50), w1.get())); 145 SK_ColorGRAY, -13, gfx::Rect(5, 470, 50, 50), w1.get()));
146 146
147 // Click on a sub-window (w121) to focus it. 147 // Click on a sub-window (w121) to focus it.
148 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 148 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
149 w121.get()); 149 w121.get());
150 generator.ClickLeftButton(); 150 generator.ClickLeftButton();
151 151
152 aura::FocusManager* focus_manager = w121->GetFocusManager(); 152 aura::client::FocusClient* focus_client =
153 EXPECT_EQ(w121.get(), focus_manager->GetFocusedWindow()); 153 aura::client::GetFocusClient(w121.get());
154 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow());
154 155
155 // The key press should be sent to the focused sub-window. 156 // The key press should be sent to the focused sub-window.
156 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0, false); 157 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0, false);
157 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev); 158 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev);
158 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code()); 159 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code());
159 160
160 // Touch on a sub-window (w122) to focus it. 161 // Touch on a sub-window (w122) to focus it.
161 gfx::Point click_point = w122->bounds().CenterPoint(); 162 gfx::Point click_point = w122->bounds().CenterPoint();
162 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point); 163 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point);
163 ui::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0, getTime()); 164 ui::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0, getTime());
164 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev); 165 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev);
165 focus_manager = w122->GetFocusManager(); 166 focus_client = aura::client::GetFocusClient(w122.get());
166 EXPECT_EQ(w122.get(), focus_manager->GetFocusedWindow()); 167 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow());
167 168
168 // The key press should be sent to the focused sub-window. 169 // The key press should be sent to the focused sub-window.
169 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev); 170 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev);
170 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code()); 171 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code());
171 172
172 // Hiding the focused window will set the focus to its parent if 173 // Hiding the focused window will set the focus to its parent if
173 // it's focusable. 174 // it's focusable.
174 w122->Hide(); 175 w122->Hide();
175 EXPECT_EQ(w12->GetFocusManager(), w122->GetFocusManager()); 176 EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
176 EXPECT_EQ(w12.get(), w12->GetFocusManager()->GetFocusedWindow()); 177 aura::client::GetFocusClient(w122.get()));
178 EXPECT_EQ(w12.get(),
179 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
177 180
178 // Sets the focus back to w122. 181 // Sets the focus back to w122.
179 w122->Show(); 182 w122->Show();
180 w122->Focus(); 183 w122->Focus();
181 EXPECT_EQ(w122.get(), w12->GetFocusManager()->GetFocusedWindow()); 184 EXPECT_EQ(w122.get(),
185 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
182 186
183 // Removing the focused window from parent should set the focus to 187 // Removing the focused window from parent should set the focus to
184 // its parent if it's focusable. 188 // its parent if it's focusable.
185 w12->RemoveChild(w122.get()); 189 w12->RemoveChild(w122.get());
186 EXPECT_EQ(NULL, w122->GetFocusManager()); 190 EXPECT_EQ(NULL, aura::client::GetFocusClient(w122.get()));
187 EXPECT_EQ(w12.get(), w12->GetFocusManager()->GetFocusedWindow()); 191 EXPECT_EQ(w12.get(),
192 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
188 193
189 // Set the focus to w123, but make the w1 not activatable. 194 // Set the focus to w123, but make the w1 not activatable.
190 test::TestActivationDelegate activation_delegate(false); 195 test::TestActivationDelegate activation_delegate(false);
191 w123->Focus(); 196 w123->Focus();
192 EXPECT_EQ(w123.get(), w12->GetFocusManager()->GetFocusedWindow()); 197 EXPECT_EQ(w123.get(),
198 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
193 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); 199 aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
194 200
195 // Hiding the focused window will set the focus to NULL because 201 // Hiding the focused window will set the focus to NULL because
196 // parent window is not focusable. 202 // parent window is not focusable.
197 w123->Hide(); 203 w123->Hide();
198 EXPECT_EQ(w12->GetFocusManager(), w123->GetFocusManager()); 204 EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
199 EXPECT_EQ(NULL, w12->GetFocusManager()->GetFocusedWindow()); 205 aura::client::GetFocusClient(w123.get()));
206 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
200 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); 207 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev));
201 208
202 // Set the focus back to w123 209 // Set the focus back to w123
203 aura::client::SetActivationDelegate(w1.get(), NULL); 210 aura::client::SetActivationDelegate(w1.get(), NULL);
204 w123->Show(); 211 w123->Show();
205 w123->Focus(); 212 w123->Focus();
206 EXPECT_EQ(w123.get(), w12->GetFocusManager()->GetFocusedWindow()); 213 EXPECT_EQ(w123.get(),
214 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
207 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); 215 aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
208 216
209 // Removing the focused window will set the focus to NULL because 217 // Removing the focused window will set the focus to NULL because
210 // parent window is not focusable. 218 // parent window is not focusable.
211 w12->RemoveChild(w123.get()); 219 w12->RemoveChild(w123.get());
212 EXPECT_EQ(NULL, w123->GetFocusManager()); 220 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get()));
213 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); 221 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev));
214 } 222 }
215 223
216 // Various assertion testing for activating windows. 224 // Various assertion testing for activating windows.
217 TEST_F(WindowManagerTest, ActivateOnMouse) { 225 TEST_F(WindowManagerTest, ActivateOnMouse) {
218 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 226 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
219 227
220 test::TestActivationDelegate d1; 228 test::TestActivationDelegate d1;
221 aura::test::TestWindowDelegate wd; 229 aura::test::TestWindowDelegate wd;
222 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 230 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(
223 &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); 231 &wd, -1, gfx::Rect(10, 10, 50, 50), NULL));
224 d1.SetWindow(w1.get()); 232 d1.SetWindow(w1.get());
225 test::TestActivationDelegate d2; 233 test::TestActivationDelegate d2;
226 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 234 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate(
227 &wd, -1, gfx::Rect(70, 70, 50, 50), NULL)); 235 &wd, -1, gfx::Rect(70, 70, 50, 50), NULL));
228 d2.SetWindow(w2.get()); 236 d2.SetWindow(w2.get());
229 237
230 aura::FocusManager* focus_manager = w1->GetFocusManager(); 238 aura::client::FocusClient* focus_client =
239 aura::client::GetFocusClient(w1.get());
231 240
232 d1.Clear(); 241 d1.Clear();
233 d2.Clear(); 242 d2.Clear();
234 243
235 // Activate window1. 244 // Activate window1.
236 wm::ActivateWindow(w1.get()); 245 wm::ActivateWindow(w1.get());
237 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 246 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
238 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); 247 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
239 EXPECT_EQ(1, d1.activated_count()); 248 EXPECT_EQ(1, d1.activated_count());
240 EXPECT_EQ(0, d1.lost_active_count()); 249 EXPECT_EQ(0, d1.lost_active_count());
241 d1.Clear(); 250 d1.Clear();
242 251
243 { 252 {
244 // Click on window2. 253 // Click on window2.
245 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 254 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
246 w2.get()); 255 w2.get());
247 generator.ClickLeftButton(); 256 generator.ClickLeftButton();
248 257
249 // Window2 should have become active. 258 // Window2 should have become active.
250 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 259 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
251 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 260 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
252 EXPECT_EQ(0, d1.activated_count()); 261 EXPECT_EQ(0, d1.activated_count());
253 EXPECT_EQ(1, d1.lost_active_count()); 262 EXPECT_EQ(1, d1.lost_active_count());
254 EXPECT_EQ(1, d2.activated_count()); 263 EXPECT_EQ(1, d2.activated_count());
255 EXPECT_EQ(0, d2.lost_active_count()); 264 EXPECT_EQ(0, d2.lost_active_count());
256 d1.Clear(); 265 d1.Clear();
257 d2.Clear(); 266 d2.Clear();
258 } 267 }
259 268
260 { 269 {
261 // Click back on window1, but set it up so w1 doesn't activate on click. 270 // Click back on window1, but set it up so w1 doesn't activate on click.
262 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 271 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
263 w1.get()); 272 w1.get());
264 d1.set_activate(false); 273 d1.set_activate(false);
265 generator.ClickLeftButton(); 274 generator.ClickLeftButton();
266 275
267 // Window2 should still be active and focused. 276 // Window2 should still be active and focused.
268 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 277 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
269 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 278 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
270 EXPECT_EQ(0, d1.activated_count()); 279 EXPECT_EQ(0, d1.activated_count());
271 EXPECT_EQ(0, d1.lost_active_count()); 280 EXPECT_EQ(0, d1.lost_active_count());
272 EXPECT_EQ(0, d2.activated_count()); 281 EXPECT_EQ(0, d2.activated_count());
273 EXPECT_EQ(0, d2.lost_active_count()); 282 EXPECT_EQ(0, d2.lost_active_count());
274 d1.Clear(); 283 d1.Clear();
275 d2.Clear(); 284 d2.Clear();
276 } 285 }
277 286
278 // Destroy window2, this should make window1 active. 287 // Destroy window2, this should make window1 active.
279 d1.set_activate(true); 288 d1.set_activate(true);
280 w2.reset(); 289 w2.reset();
281 EXPECT_EQ(0, d2.activated_count()); 290 EXPECT_EQ(0, d2.activated_count());
282 EXPECT_EQ(0, d2.lost_active_count()); 291 EXPECT_EQ(0, d2.lost_active_count());
283 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 292 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
284 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); 293 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
285 EXPECT_EQ(1, d1.activated_count()); 294 EXPECT_EQ(1, d1.activated_count());
286 EXPECT_EQ(0, d1.lost_active_count()); 295 EXPECT_EQ(0, d1.lost_active_count());
287 296
288 // Clicking an active window with a child shouldn't steal the 297 // Clicking an active window with a child shouldn't steal the
289 // focus from the child. 298 // focus from the child.
290 { 299 {
291 scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate( 300 scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate(
292 &wd, -1, gfx::Rect(10, 10, 10, 10), w1.get())); 301 &wd, -1, gfx::Rect(10, 10, 10, 10), w1.get()));
293 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 302 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
294 w11.get()); 303 w11.get());
295 // First set the focus to the child |w11|. 304 // First set the focus to the child |w11|.
296 generator.ClickLeftButton(); 305 generator.ClickLeftButton();
297 EXPECT_EQ(w11.get(), focus_manager->GetFocusedWindow()); 306 EXPECT_EQ(w11.get(), focus_client->GetFocusedWindow());
298 EXPECT_EQ(w1.get(), wm::GetActiveWindow()); 307 EXPECT_EQ(w1.get(), wm::GetActiveWindow());
299 308
300 // Then click the parent active window. The focus shouldn't move. 309 // Then click the parent active window. The focus shouldn't move.
301 gfx::Point left_top = w1->bounds().origin(); 310 gfx::Point left_top = w1->bounds().origin();
302 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &left_top); 311 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &left_top);
303 left_top.Offset(1, 1); 312 left_top.Offset(1, 1);
304 generator.MoveMouseTo(left_top); 313 generator.MoveMouseTo(left_top);
305 generator.ClickLeftButton(); 314 generator.ClickLeftButton();
306 EXPECT_EQ(w11.get(), focus_manager->GetFocusedWindow()); 315 EXPECT_EQ(w11.get(), focus_client->GetFocusedWindow());
307 EXPECT_EQ(w1.get(), wm::GetActiveWindow()); 316 EXPECT_EQ(w1.get(), wm::GetActiveWindow());
308 } 317 }
309 318
310 // Clicking on a non-focusable window inside a background window should still 319 // Clicking on a non-focusable window inside a background window should still
311 // give focus to the background window. 320 // give focus to the background window.
312 { 321 {
313 NonFocusableDelegate nfd; 322 NonFocusableDelegate nfd;
314 scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate( 323 scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate(
315 &nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get())); 324 &nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get()));
316 // Move focus to |w2| first. 325 // Move focus to |w2| first.
317 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 326 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate(
318 &wd, -1, gfx::Rect(70, 70, 50, 50), NULL)); 327 &wd, -1, gfx::Rect(70, 70, 50, 50), NULL));
319 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 328 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
320 w2.get()); 329 w2.get());
321 generator.ClickLeftButton(); 330 generator.ClickLeftButton();
322 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 331 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
323 EXPECT_FALSE(w11->CanFocus()); 332 EXPECT_FALSE(w11->CanFocus());
324 333
325 // Click on |w11|. This should focus w1. 334 // Click on |w11|. This should focus w1.
326 generator.MoveMouseToCenterOf(w11.get()); 335 generator.MoveMouseToCenterOf(w11.get());
327 generator.ClickLeftButton(); 336 generator.ClickLeftButton();
328 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); 337 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
329 } 338 }
330 } 339 }
331 340
332 // Essentially the same as ActivateOnMouse, but for touch events. 341 // Essentially the same as ActivateOnMouse, but for touch events.
333 TEST_F(WindowManagerTest, ActivateOnTouch) { 342 TEST_F(WindowManagerTest, ActivateOnTouch) {
334 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 343 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
335 344
336 test::TestActivationDelegate d1; 345 test::TestActivationDelegate d1;
337 aura::test::TestWindowDelegate wd; 346 aura::test::TestWindowDelegate wd;
338 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 347 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(
339 &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); 348 &wd, -1, gfx::Rect(10, 10, 50, 50), NULL));
340 d1.SetWindow(w1.get()); 349 d1.SetWindow(w1.get());
341 test::TestActivationDelegate d2; 350 test::TestActivationDelegate d2;
342 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 351 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate(
343 &wd, -2, gfx::Rect(70, 70, 50, 50), NULL)); 352 &wd, -2, gfx::Rect(70, 70, 50, 50), NULL));
344 d2.SetWindow(w2.get()); 353 d2.SetWindow(w2.get());
345 354
346 aura::FocusManager* focus_manager = w1->GetFocusManager(); 355 aura::client::FocusClient* focus_client =
356 aura::client::GetFocusClient(w1.get());
347 357
348 d1.Clear(); 358 d1.Clear();
349 d2.Clear(); 359 d2.Clear();
350 360
351 // Activate window1. 361 // Activate window1.
352 wm::ActivateWindow(w1.get()); 362 wm::ActivateWindow(w1.get());
353 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 363 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
354 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); 364 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
355 EXPECT_EQ(1, d1.activated_count()); 365 EXPECT_EQ(1, d1.activated_count());
356 EXPECT_EQ(0, d1.lost_active_count()); 366 EXPECT_EQ(0, d1.lost_active_count());
357 d1.Clear(); 367 d1.Clear();
358 368
359 // Touch window2. 369 // Touch window2.
360 gfx::Point press_point = w2->bounds().CenterPoint(); 370 gfx::Point press_point = w2->bounds().CenterPoint();
361 aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point); 371 aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point);
362 ui::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0, getTime()); 372 ui::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0, getTime());
363 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev1); 373 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev1);
364 374
365 // Window2 should have become active. 375 // Window2 should have become active.
366 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 376 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
367 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 377 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
368 EXPECT_EQ(0, d1.activated_count()); 378 EXPECT_EQ(0, d1.activated_count());
369 EXPECT_EQ(1, d1.lost_active_count()); 379 EXPECT_EQ(1, d1.lost_active_count());
370 EXPECT_EQ(1, d2.activated_count()); 380 EXPECT_EQ(1, d2.activated_count());
371 EXPECT_EQ(0, d2.lost_active_count()); 381 EXPECT_EQ(0, d2.lost_active_count());
372 d1.Clear(); 382 d1.Clear();
373 d2.Clear(); 383 d2.Clear();
374 384
375 // Touch window1, but set it up so w1 doesn't activate on touch. 385 // Touch window1, but set it up so w1 doesn't activate on touch.
376 press_point = w1->bounds().CenterPoint(); 386 press_point = w1->bounds().CenterPoint();
377 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point); 387 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point);
378 d1.set_activate(false); 388 d1.set_activate(false);
379 ui::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 1, getTime()); 389 ui::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 1, getTime());
380 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev2); 390 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev2);
381 391
382 // Window2 should still be active and focused. 392 // Window2 should still be active and focused.
383 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 393 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
384 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 394 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
385 EXPECT_EQ(0, d1.activated_count()); 395 EXPECT_EQ(0, d1.activated_count());
386 EXPECT_EQ(0, d1.lost_active_count()); 396 EXPECT_EQ(0, d1.lost_active_count());
387 EXPECT_EQ(0, d2.activated_count()); 397 EXPECT_EQ(0, d2.activated_count());
388 EXPECT_EQ(0, d2.lost_active_count()); 398 EXPECT_EQ(0, d2.lost_active_count());
389 d1.Clear(); 399 d1.Clear();
390 d2.Clear(); 400 d2.Clear();
391 401
392 // Destroy window2, this should make window1 active. 402 // Destroy window2, this should make window1 active.
393 d1.set_activate(true); 403 d1.set_activate(true);
394 w2.reset(); 404 w2.reset();
395 EXPECT_EQ(0, d2.activated_count()); 405 EXPECT_EQ(0, d2.activated_count());
396 EXPECT_EQ(0, d2.lost_active_count()); 406 EXPECT_EQ(0, d2.lost_active_count());
397 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 407 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
398 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); 408 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
399 EXPECT_EQ(1, d1.activated_count()); 409 EXPECT_EQ(1, d1.activated_count());
400 EXPECT_EQ(0, d1.lost_active_count()); 410 EXPECT_EQ(0, d1.lost_active_count());
401 } 411 }
402 412
403 TEST_F(WindowManagerTest, MouseEventCursors) { 413 TEST_F(WindowManagerTest, MouseEventCursors) {
404 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 414 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
405 415
406 // Create a window. 416 // Create a window.
407 const int kWindowLeft = 123; 417 const int kWindowLeft = 123;
408 const int kWindowTop = 45; 418 const int kWindowTop = 45;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 d1.SetWindow(w1.get()); 528 d1.SetWindow(w1.get());
519 w1->Show(); 529 w1->Show();
520 530
521 gfx::Point miss_point(5, 5); 531 gfx::Point miss_point(5, 5);
522 transform.TransformPoint(miss_point); 532 transform.TransformPoint(miss_point);
523 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, 533 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED,
524 miss_point, 534 miss_point,
525 miss_point, 535 miss_point,
526 ui::EF_LEFT_MOUSE_BUTTON); 536 ui::EF_LEFT_MOUSE_BUTTON);
527 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev1); 537 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev1);
528 EXPECT_FALSE(w1->GetFocusManager()->GetFocusedWindow()); 538 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
529 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, 539 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED,
530 miss_point, 540 miss_point,
531 miss_point, 541 miss_point,
532 ui::EF_LEFT_MOUSE_BUTTON); 542 ui::EF_LEFT_MOUSE_BUTTON);
533 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseup); 543 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseup);
534 544
535 gfx::Point hit_point(5, 15); 545 gfx::Point hit_point(5, 15);
536 transform.TransformPoint(hit_point); 546 transform.TransformPoint(hit_point);
537 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, 547 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED,
538 hit_point, 548 hit_point,
539 hit_point, 549 hit_point,
540 ui::EF_LEFT_MOUSE_BUTTON); 550 ui::EF_LEFT_MOUSE_BUTTON);
541 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev2); 551 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev2);
542 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 552 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
543 EXPECT_EQ(w1.get(), w1->GetFocusManager()->GetFocusedWindow()); 553 EXPECT_EQ(w1.get(),
554 aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
544 } 555 }
545 556
546 TEST_F(WindowManagerTest, AdditionalFilters) { 557 TEST_F(WindowManagerTest, AdditionalFilters) {
547 // The IME event filter interferes with the basic key event propagation we 558 // The IME event filter interferes with the basic key event propagation we
548 // attempt to do here, so we remove it. 559 // attempt to do here, so we remove it.
549 Shell::TestApi shell_test(Shell::GetInstance()); 560 Shell::TestApi shell_test(Shell::GetInstance());
550 Shell::GetInstance()->RemovePreTargetHandler( 561 Shell::GetInstance()->RemovePreTargetHandler(
551 shell_test.input_method_event_filter()); 562 shell_test.input_method_event_filter());
552 563
553 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 564 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 EXPECT_TRUE(cursor_manager->cursor_visible()); 678 EXPECT_TRUE(cursor_manager->cursor_visible());
668 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); 679 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2);
669 EXPECT_FALSE(cursor_manager->cursor_visible()); 680 EXPECT_FALSE(cursor_manager->cursor_visible());
670 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); 681 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved);
671 EXPECT_TRUE(cursor_manager->cursor_visible()); 682 EXPECT_TRUE(cursor_manager->cursor_visible());
672 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); 683 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2);
673 EXPECT_TRUE(cursor_manager->cursor_visible()); 684 EXPECT_TRUE(cursor_manager->cursor_visible());
674 } 685 }
675 686
676 } // namespace ash 687 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_bubble_controller.cc ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698