OLD | NEW |
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/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 ui::GestureConfiguration:: | 53 ui::GestureConfiguration:: |
54 set_max_separation_for_gesture_touches_in_pixels(0); | 54 set_max_separation_for_gesture_touches_in_pixels(0); |
55 } | 55 } |
56 | 56 |
57 virtual void TearDown() OVERRIDE { | 57 virtual void TearDown() OVERRIDE { |
58 AuraTestBase::TearDown(); | 58 AuraTestBase::TearDown(); |
59 ui::GestureConfiguration:: | 59 ui::GestureConfiguration:: |
60 set_max_separation_for_gesture_touches_in_pixels(max_separation_); | 60 set_max_separation_for_gesture_touches_in_pixels(max_separation_); |
61 } | 61 } |
62 | 62 |
| 63 // Adds |window| to |root_window_|, through the StackingClient. |
| 64 void SetDefaultParentByPrimaryRootWindow(aura::Window* window) { |
| 65 window->SetDefaultParentByRootWindow(root_window(), gfx::Rect()); |
| 66 } |
| 67 |
63 private: | 68 private: |
64 int max_separation_; | 69 int max_separation_; |
65 | 70 |
66 DISALLOW_COPY_AND_ASSIGN(WindowTest); | 71 DISALLOW_COPY_AND_ASSIGN(WindowTest); |
67 }; | 72 }; |
68 | 73 |
69 namespace { | 74 namespace { |
70 | 75 |
71 // Used for verifying destruction methods are invoked. | 76 // Used for verifying destruction methods are invoked. |
72 class DestroyTrackingDelegateImpl : public TestWindowDelegate { | 77 class DestroyTrackingDelegateImpl : public TestWindowDelegate { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return false; | 251 return false; |
247 } | 252 } |
248 | 253 |
249 private: | 254 private: |
250 DISALLOW_COPY_AND_ASSIGN(SelfEventHandlingWindowDelegate); | 255 DISALLOW_COPY_AND_ASSIGN(SelfEventHandlingWindowDelegate); |
251 }; | 256 }; |
252 | 257 |
253 } // namespace | 258 } // namespace |
254 | 259 |
255 TEST_F(WindowTest, GetChildById) { | 260 TEST_F(WindowTest, GetChildById) { |
256 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 261 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
257 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); | 262 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); |
258 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 263 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
259 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); | 264 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); |
260 | 265 |
261 EXPECT_EQ(NULL, w1->GetChildById(57)); | 266 EXPECT_EQ(NULL, w1->GetChildById(57)); |
262 EXPECT_EQ(w12.get(), w1->GetChildById(12)); | 267 EXPECT_EQ(w12.get(), w1->GetChildById(12)); |
263 EXPECT_EQ(w111.get(), w1->GetChildById(111)); | 268 EXPECT_EQ(w111.get(), w1->GetChildById(111)); |
264 } | 269 } |
265 | 270 |
266 // Make sure that Window::Contains correctly handles children, grandchildren, | 271 // Make sure that Window::Contains correctly handles children, grandchildren, |
267 // and not containing NULL or parents. | 272 // and not containing NULL or parents. |
268 TEST_F(WindowTest, Contains) { | 273 TEST_F(WindowTest, Contains) { |
269 Window parent(NULL); | 274 Window parent(NULL); |
270 parent.Init(ui::LAYER_NOT_DRAWN); | 275 parent.Init(ui::LAYER_NOT_DRAWN); |
271 Window child1(NULL); | 276 Window child1(NULL); |
272 child1.Init(ui::LAYER_NOT_DRAWN); | 277 child1.Init(ui::LAYER_NOT_DRAWN); |
273 Window child2(NULL); | 278 Window child2(NULL); |
274 child2.Init(ui::LAYER_NOT_DRAWN); | 279 child2.Init(ui::LAYER_NOT_DRAWN); |
275 | 280 |
276 child1.SetParent(&parent); | 281 parent.AddChild(&child1); |
277 child2.SetParent(&child1); | 282 child1.AddChild(&child2); |
278 | 283 |
279 EXPECT_TRUE(parent.Contains(&parent)); | 284 EXPECT_TRUE(parent.Contains(&parent)); |
280 EXPECT_TRUE(parent.Contains(&child1)); | 285 EXPECT_TRUE(parent.Contains(&child1)); |
281 EXPECT_TRUE(parent.Contains(&child2)); | 286 EXPECT_TRUE(parent.Contains(&child2)); |
282 | 287 |
283 EXPECT_FALSE(parent.Contains(NULL)); | 288 EXPECT_FALSE(parent.Contains(NULL)); |
284 EXPECT_FALSE(child1.Contains(&parent)); | 289 EXPECT_FALSE(child1.Contains(&parent)); |
285 EXPECT_FALSE(child2.Contains(&child1)); | 290 EXPECT_FALSE(child2.Contains(&child1)); |
286 } | 291 } |
287 | 292 |
288 TEST_F(WindowTest, ContainsPointInRoot) { | 293 TEST_F(WindowTest, ContainsPointInRoot) { |
289 scoped_ptr<Window> w( | 294 scoped_ptr<Window> w( |
290 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), NULL)); | 295 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), |
| 296 root_window())); |
291 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9))); | 297 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9))); |
292 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10))); | 298 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10))); |
293 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14))); | 299 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14))); |
294 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15))); | 300 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15))); |
295 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20))); | 301 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20))); |
296 } | 302 } |
297 | 303 |
298 TEST_F(WindowTest, ContainsPoint) { | 304 TEST_F(WindowTest, ContainsPoint) { |
299 scoped_ptr<Window> w( | 305 scoped_ptr<Window> w( |
300 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), NULL)); | 306 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), |
| 307 root_window())); |
301 EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0))); | 308 EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0))); |
302 EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4))); | 309 EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4))); |
303 EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5))); | 310 EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5))); |
304 EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10))); | 311 EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10))); |
305 } | 312 } |
306 | 313 |
307 TEST_F(WindowTest, ConvertPointToWindow) { | 314 TEST_F(WindowTest, ConvertPointToWindow) { |
308 // Window::ConvertPointToWindow is mostly identical to | 315 // Window::ConvertPointToWindow is mostly identical to |
309 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, | 316 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, |
310 // in which case the function just returns. | 317 // in which case the function just returns. |
311 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 318 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
312 gfx::Point reference_point(100, 100); | 319 gfx::Point reference_point(100, 100); |
313 gfx::Point test_point = reference_point; | 320 gfx::Point test_point = reference_point; |
314 Window::ConvertPointToTarget(NULL, w1.get(), &test_point); | 321 Window::ConvertPointToTarget(NULL, w1.get(), &test_point); |
315 EXPECT_EQ(reference_point, test_point); | 322 EXPECT_EQ(reference_point, test_point); |
316 } | 323 } |
317 | 324 |
318 TEST_F(WindowTest, MoveCursorTo) { | 325 TEST_F(WindowTest, MoveCursorTo) { |
319 scoped_ptr<Window> w1( | 326 scoped_ptr<Window> w1( |
320 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 327 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 328 root_window())); |
321 scoped_ptr<Window> w11( | 329 scoped_ptr<Window> w11( |
322 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 330 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
323 scoped_ptr<Window> w111( | 331 scoped_ptr<Window> w111( |
324 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 332 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
325 scoped_ptr<Window> w1111( | 333 scoped_ptr<Window> w1111( |
326 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 334 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
327 | 335 |
328 RootWindow* root = root_window(); | 336 RootWindow* root = root_window(); |
329 root->MoveCursorTo(gfx::Point(10, 10)); | 337 root->MoveCursorTo(gfx::Point(10, 10)); |
330 EXPECT_EQ("10,10", | 338 EXPECT_EQ("10,10", |
331 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 339 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
332 w1->MoveCursorTo(gfx::Point(10, 10)); | 340 w1->MoveCursorTo(gfx::Point(10, 10)); |
333 EXPECT_EQ("20,20", | 341 EXPECT_EQ("20,20", |
334 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 342 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
335 w11->MoveCursorTo(gfx::Point(10, 10)); | 343 w11->MoveCursorTo(gfx::Point(10, 10)); |
336 EXPECT_EQ("25,25", | 344 EXPECT_EQ("25,25", |
337 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 345 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
338 w111->MoveCursorTo(gfx::Point(10, 10)); | 346 w111->MoveCursorTo(gfx::Point(10, 10)); |
339 EXPECT_EQ("30,30", | 347 EXPECT_EQ("30,30", |
340 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 348 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
341 w1111->MoveCursorTo(gfx::Point(10, 10)); | 349 w1111->MoveCursorTo(gfx::Point(10, 10)); |
342 EXPECT_EQ("35,35", | 350 EXPECT_EQ("35,35", |
343 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 351 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
344 } | 352 } |
345 | 353 |
346 TEST_F(WindowTest, ContainsMouse) { | 354 TEST_F(WindowTest, ContainsMouse) { |
347 scoped_ptr<Window> w( | 355 scoped_ptr<Window> w( |
348 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 356 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 357 root_window())); |
349 w->Show(); | 358 w->Show(); |
350 Window::TestApi w_test_api(w.get()); | 359 Window::TestApi w_test_api(w.get()); |
351 RootWindow* root = root_window(); | 360 RootWindow* root = root_window(); |
352 root->MoveCursorTo(gfx::Point(10, 10)); | 361 root->MoveCursorTo(gfx::Point(10, 10)); |
353 EXPECT_TRUE(w_test_api.ContainsMouse()); | 362 EXPECT_TRUE(w_test_api.ContainsMouse()); |
354 root->MoveCursorTo(gfx::Point(9, 10)); | 363 root->MoveCursorTo(gfx::Point(9, 10)); |
355 EXPECT_FALSE(w_test_api.ContainsMouse()); | 364 EXPECT_FALSE(w_test_api.ContainsMouse()); |
356 } | 365 } |
357 | 366 |
358 // Test Window::ConvertPointToWindow() with transform to root_window. | 367 // Test Window::ConvertPointToWindow() with transform to root_window. |
359 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { | 368 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { |
360 RootWindow* root = root_window(); | 369 RootWindow* root = root_window(); |
361 gfx::Transform transform; | 370 gfx::Transform transform; |
362 transform.Translate(100.0, 100.0); | 371 transform.Translate(100.0, 100.0); |
363 transform.Rotate(90.0); | 372 transform.Rotate(90.0); |
364 transform.Scale(2.0, 5.0); | 373 transform.Scale(2.0, 5.0); |
365 root->SetTransform(transform); | 374 root->SetTransform(transform); |
366 root->MoveCursorTo(gfx::Point(10, 10)); | 375 root->MoveCursorTo(gfx::Point(10, 10)); |
367 #if !defined(OS_WIN) | 376 #if !defined(OS_WIN) |
368 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD | 377 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD |
369 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); | 378 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); |
370 #endif | 379 #endif |
371 EXPECT_EQ("10,10", | 380 EXPECT_EQ("10,10", |
372 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 381 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
373 } | 382 } |
374 | 383 |
375 // Tests Window::ConvertPointToWindow() with transform to non-root windows. | 384 // Tests Window::ConvertPointToWindow() with transform to non-root windows. |
376 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { | 385 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { |
377 scoped_ptr<Window> w1( | 386 scoped_ptr<Window> w1( |
378 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 387 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 388 root_window())); |
379 | 389 |
380 gfx::Transform transform1; | 390 gfx::Transform transform1; |
381 transform1.Scale(2, 2); | 391 transform1.Scale(2, 2); |
382 w1->SetTransform(transform1); | 392 w1->SetTransform(transform1); |
383 w1->MoveCursorTo(gfx::Point(10, 10)); | 393 w1->MoveCursorTo(gfx::Point(10, 10)); |
384 EXPECT_EQ("30,30", | 394 EXPECT_EQ("30,30", |
385 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 395 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
386 | 396 |
387 gfx::Transform transform2; | 397 gfx::Transform transform2; |
388 transform2.Translate(-10, 20); | 398 transform2.Translate(-10, 20); |
(...skipping 16 matching lines...) Expand all Loading... |
405 w1->SetTransform(transform4); | 415 w1->SetTransform(transform4); |
406 w1->MoveCursorTo(gfx::Point(10, 10)); | 416 w1->MoveCursorTo(gfx::Point(10, 10)); |
407 EXPECT_EQ("60,130", | 417 EXPECT_EQ("60,130", |
408 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 418 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
409 } | 419 } |
410 | 420 |
411 // Test Window::ConvertPointToWindow() with complex transforms to both root and | 421 // Test Window::ConvertPointToWindow() with complex transforms to both root and |
412 // non-root windows. | 422 // non-root windows. |
413 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { | 423 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { |
414 scoped_ptr<Window> w1( | 424 scoped_ptr<Window> w1( |
415 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 425 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 426 root_window())); |
416 scoped_ptr<Window> w11( | 427 scoped_ptr<Window> w11( |
417 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 428 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
418 scoped_ptr<Window> w111( | 429 scoped_ptr<Window> w111( |
419 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 430 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
420 scoped_ptr<Window> w1111( | 431 scoped_ptr<Window> w1111( |
421 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 432 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
422 | 433 |
423 RootWindow* root = root_window(); | 434 RootWindow* root = root_window(); |
424 | 435 |
425 // The root window expects transforms that produce integer rects. | 436 // The root window expects transforms that produce integer rects. |
(...skipping 23 matching lines...) Expand all Loading... |
449 EXPECT_EQ("20,53", | 460 EXPECT_EQ("20,53", |
450 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 461 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
451 } | 462 } |
452 | 463 |
453 TEST_F(WindowTest, HitTest) { | 464 TEST_F(WindowTest, HitTest) { |
454 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); | 465 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); |
455 w1.set_id(1); | 466 w1.set_id(1); |
456 w1.Init(ui::LAYER_TEXTURED); | 467 w1.Init(ui::LAYER_TEXTURED); |
457 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); | 468 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
458 w1.Show(); | 469 w1.Show(); |
459 w1.SetParent(NULL); | 470 SetDefaultParentByPrimaryRootWindow(&w1); |
460 | 471 |
461 // Points are in the Window's coordinates. | 472 // Points are in the Window's coordinates. |
462 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); | 473 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); |
463 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); | 474 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); |
464 | 475 |
465 // We can expand the bounds slightly to track events outside our border. | 476 // We can expand the bounds slightly to track events outside our border. |
466 w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), 5); | 477 w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), 5); |
467 EXPECT_TRUE(w1.HitTest(gfx::Point(-1, -1))); | 478 EXPECT_TRUE(w1.HitTest(gfx::Point(-1, -1))); |
468 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2))); | 479 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2))); |
469 | 480 |
(...skipping 10 matching lines...) Expand all Loading... |
480 | 491 |
481 // TODO(beng): clip Window to parent. | 492 // TODO(beng): clip Window to parent. |
482 } | 493 } |
483 | 494 |
484 TEST_F(WindowTest, HitTestMask) { | 495 TEST_F(WindowTest, HitTestMask) { |
485 MaskedWindowDelegate d1(gfx::Rect(5, 6, 20, 30)); | 496 MaskedWindowDelegate d1(gfx::Rect(5, 6, 20, 30)); |
486 Window w1(&d1); | 497 Window w1(&d1); |
487 w1.Init(ui::LAYER_NOT_DRAWN); | 498 w1.Init(ui::LAYER_NOT_DRAWN); |
488 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); | 499 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
489 w1.Show(); | 500 w1.Show(); |
490 w1.SetParent(NULL); | 501 SetDefaultParentByPrimaryRootWindow(&w1); |
491 | 502 |
492 // Points inside the mask. | 503 // Points inside the mask. |
493 EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left | 504 EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left |
494 EXPECT_TRUE(w1.HitTest(gfx::Point(15, 21))); // center | 505 EXPECT_TRUE(w1.HitTest(gfx::Point(15, 21))); // center |
495 EXPECT_TRUE(w1.HitTest(gfx::Point(24, 35))); // bottom-right | 506 EXPECT_TRUE(w1.HitTest(gfx::Point(24, 35))); // bottom-right |
496 | 507 |
497 // Points outside the mask. | 508 // Points outside the mask. |
498 EXPECT_FALSE(w1.HitTest(gfx::Point(0, 0))); | 509 EXPECT_FALSE(w1.HitTest(gfx::Point(0, 0))); |
499 EXPECT_FALSE(w1.HitTest(gfx::Point(60, 80))); | 510 EXPECT_FALSE(w1.HitTest(gfx::Point(60, 80))); |
500 EXPECT_FALSE(w1.HitTest(gfx::Point(4, 6))); | 511 EXPECT_FALSE(w1.HitTest(gfx::Point(4, 6))); |
501 EXPECT_FALSE(w1.HitTest(gfx::Point(5, 5))); | 512 EXPECT_FALSE(w1.HitTest(gfx::Point(5, 5))); |
502 EXPECT_FALSE(w1.HitTest(gfx::Point(25, 36))); | 513 EXPECT_FALSE(w1.HitTest(gfx::Point(25, 36))); |
503 } | 514 } |
504 | 515 |
505 TEST_F(WindowTest, GetEventHandlerForPoint) { | 516 TEST_F(WindowTest, GetEventHandlerForPoint) { |
506 scoped_ptr<Window> w1( | 517 scoped_ptr<Window> w1( |
507 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 518 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 519 root_window())); |
508 scoped_ptr<Window> w11( | 520 scoped_ptr<Window> w11( |
509 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 521 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
510 scoped_ptr<Window> w111( | 522 scoped_ptr<Window> w111( |
511 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 523 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
512 scoped_ptr<Window> w1111( | 524 scoped_ptr<Window> w1111( |
513 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 525 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
514 scoped_ptr<Window> w12( | 526 scoped_ptr<Window> w12( |
515 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), | 527 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), |
516 w1.get())); | 528 w1.get())); |
517 scoped_ptr<Window> w121( | 529 scoped_ptr<Window> w121( |
(...skipping 10 matching lines...) Expand all Loading... |
528 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); | 540 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); |
529 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); | 541 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); |
530 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); | 542 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); |
531 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); | 543 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); |
532 } | 544 } |
533 | 545 |
534 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { | 546 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { |
535 // If our child is flush to our top-left corner he gets events just inside the | 547 // If our child is flush to our top-left corner he gets events just inside the |
536 // window edges. | 548 // window edges. |
537 scoped_ptr<Window> parent( | 549 scoped_ptr<Window> parent( |
538 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), NULL)); | 550 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), |
| 551 root_window())); |
539 scoped_ptr<Window> child( | 552 scoped_ptr<Window> child( |
540 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); | 553 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); |
541 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 554 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
542 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 555 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); |
543 | 556 |
544 // We can override the hit test bounds of the parent to make the parent grab | 557 // We can override the hit test bounds of the parent to make the parent grab |
545 // events along that edge. | 558 // events along that edge. |
546 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); | 559 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); |
547 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 560 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
548 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 561 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); |
549 } | 562 } |
550 | 563 |
551 TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) { | 564 TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) { |
552 scoped_ptr<SelfEventHandlingWindowDelegate> parent_delegate( | 565 scoped_ptr<SelfEventHandlingWindowDelegate> parent_delegate( |
553 new SelfEventHandlingWindowDelegate); | 566 new SelfEventHandlingWindowDelegate); |
554 scoped_ptr<Window> parent(CreateTestWindowWithDelegate( | 567 scoped_ptr<Window> parent(CreateTestWindowWithDelegate( |
555 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), NULL)); | 568 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), root_window())); |
556 scoped_ptr<Window> child( | 569 scoped_ptr<Window> child( |
557 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), | 570 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), |
558 parent.get())); | 571 parent.get())); |
559 | 572 |
560 // We can override ShouldDescendIntoChildForEventHandling to make the parent | 573 // We can override ShouldDescendIntoChildForEventHandling to make the parent |
561 // grab all events. | 574 // grab all events. |
562 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 575 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
563 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50))); | 576 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50))); |
564 } | 577 } |
565 | 578 |
566 TEST_F(WindowTest, GetTopWindowContainingPoint) { | 579 TEST_F(WindowTest, GetTopWindowContainingPoint) { |
567 Window* root = root_window(); | 580 Window* root = root_window(); |
568 root->SetBounds(gfx::Rect(0, 0, 300, 300)); | 581 root->SetBounds(gfx::Rect(0, 0, 300, 300)); |
569 | 582 |
570 scoped_ptr<Window> w1( | 583 scoped_ptr<Window> w1( |
571 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); | 584 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), |
| 585 root_window())); |
572 scoped_ptr<Window> w11( | 586 scoped_ptr<Window> w11( |
573 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); | 587 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); |
574 | 588 |
575 scoped_ptr<Window> w2( | 589 scoped_ptr<Window> w2( |
576 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), NULL)); | 590 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), |
| 591 root_window())); |
577 | 592 |
578 scoped_ptr<Window> w3( | 593 scoped_ptr<Window> w3( |
579 CreateTestWindowWithDelegate( | 594 CreateTestWindowWithDelegate( |
580 NULL, 3, gfx::Rect(200, 200, 100, 100), NULL)); | 595 NULL, 3, gfx::Rect(200, 200, 100, 100), root_window())); |
581 scoped_ptr<Window> w31( | 596 scoped_ptr<Window> w31( |
582 CreateTestWindow(SK_ColorCYAN, 31, gfx::Rect(0, 0, 50, 50), w3.get())); | 597 CreateTestWindow(SK_ColorCYAN, 31, gfx::Rect(0, 0, 50, 50), w3.get())); |
583 scoped_ptr<Window> w311( | 598 scoped_ptr<Window> w311( |
584 CreateTestWindow(SK_ColorBLUE, 311, gfx::Rect(0, 0, 10, 10), w31.get())); | 599 CreateTestWindow(SK_ColorBLUE, 311, gfx::Rect(0, 0, 10, 10), w31.get())); |
585 | 600 |
586 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(0, 0))); | 601 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(0, 0))); |
587 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(5, 5))); | 602 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(5, 5))); |
588 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(10, 10))); | 603 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(10, 10))); |
589 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(59, 59))); | 604 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(59, 59))); |
590 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(60, 60))); | 605 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(60, 60))); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 640 |
626 private: | 641 private: |
627 bool called_; | 642 bool called_; |
628 | 643 |
629 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); | 644 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); |
630 }; | 645 }; |
631 | 646 |
632 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { | 647 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { |
633 AddedToRootWindowObserver parent_observer; | 648 AddedToRootWindowObserver parent_observer; |
634 AddedToRootWindowObserver child_observer; | 649 AddedToRootWindowObserver child_observer; |
635 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, NULL)); | 650 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window())); |
636 scoped_ptr<Window> child_window(new Window(NULL)); | 651 scoped_ptr<Window> child_window(new Window(NULL)); |
637 child_window->Init(ui::LAYER_TEXTURED); | 652 child_window->Init(ui::LAYER_TEXTURED); |
638 child_window->Show(); | 653 child_window->Show(); |
639 | 654 |
640 parent_window->AddObserver(&parent_observer); | 655 parent_window->AddObserver(&parent_observer); |
641 child_window->AddObserver(&child_observer); | 656 child_window->AddObserver(&child_observer); |
642 | 657 |
643 parent_window->AddChild(child_window.get()); | 658 parent_window->AddChild(child_window.get()); |
644 | 659 |
645 EXPECT_FALSE(parent_observer.called()); | 660 EXPECT_FALSE(parent_observer.called()); |
646 EXPECT_TRUE(child_observer.called()); | 661 EXPECT_TRUE(child_observer.called()); |
647 | 662 |
648 parent_window->RemoveObserver(&parent_observer); | 663 parent_window->RemoveObserver(&parent_observer); |
649 child_window->RemoveObserver(&child_observer); | 664 child_window->RemoveObserver(&child_observer); |
650 } | 665 } |
651 | 666 |
652 // Various destruction assertions. | 667 // Various destruction assertions. |
653 TEST_F(WindowTest, DestroyTest) { | 668 TEST_F(WindowTest, DestroyTest) { |
654 DestroyTrackingDelegateImpl parent_delegate; | 669 DestroyTrackingDelegateImpl parent_delegate; |
655 ChildWindowDelegateImpl child_delegate(&parent_delegate); | 670 ChildWindowDelegateImpl child_delegate(&parent_delegate); |
656 { | 671 { |
657 scoped_ptr<Window> parent( | 672 scoped_ptr<Window> parent( |
658 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), NULL)); | 673 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), |
| 674 root_window())); |
659 CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get()); | 675 CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get()); |
660 } | 676 } |
661 // Both the parent and child should have been destroyed. | 677 // Both the parent and child should have been destroyed. |
662 EXPECT_EQ(1, parent_delegate.destroying_count()); | 678 EXPECT_EQ(1, parent_delegate.destroying_count()); |
663 EXPECT_EQ(1, parent_delegate.destroyed_count()); | 679 EXPECT_EQ(1, parent_delegate.destroyed_count()); |
664 EXPECT_EQ(1, child_delegate.destroying_count()); | 680 EXPECT_EQ(1, child_delegate.destroying_count()); |
665 EXPECT_EQ(1, child_delegate.destroyed_count()); | 681 EXPECT_EQ(1, child_delegate.destroyed_count()); |
666 } | 682 } |
667 | 683 |
668 // Tests that a window is orphaned before OnWindowDestroyed is called. | 684 // Tests that a window is orphaned before OnWindowDestroyed is called. |
669 TEST_F(WindowTest, OrphanedBeforeOnDestroyed) { | 685 TEST_F(WindowTest, OrphanedBeforeOnDestroyed) { |
670 TestWindowDelegate parent_delegate; | 686 TestWindowDelegate parent_delegate; |
671 DestroyOrphanDelegate child_delegate; | 687 DestroyOrphanDelegate child_delegate; |
672 { | 688 { |
673 scoped_ptr<Window> parent( | 689 scoped_ptr<Window> parent( |
674 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), NULL)); | 690 CreateTestWindowWithDelegate(&parent_delegate, 0, gfx::Rect(), |
| 691 root_window())); |
675 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, | 692 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, |
676 gfx::Rect(), parent.get())); | 693 gfx::Rect(), parent.get())); |
677 child_delegate.set_window(child.get()); | 694 child_delegate.set_window(child.get()); |
678 } | 695 } |
679 } | 696 } |
680 | 697 |
681 // Make sure StackChildAtTop moves both the window and layer to the front. | 698 // Make sure StackChildAtTop moves both the window and layer to the front. |
682 TEST_F(WindowTest, StackChildAtTop) { | 699 TEST_F(WindowTest, StackChildAtTop) { |
683 Window parent(NULL); | 700 Window parent(NULL); |
684 parent.Init(ui::LAYER_NOT_DRAWN); | 701 parent.Init(ui::LAYER_NOT_DRAWN); |
685 Window child1(NULL); | 702 Window child1(NULL); |
686 child1.Init(ui::LAYER_NOT_DRAWN); | 703 child1.Init(ui::LAYER_NOT_DRAWN); |
687 Window child2(NULL); | 704 Window child2(NULL); |
688 child2.Init(ui::LAYER_NOT_DRAWN); | 705 child2.Init(ui::LAYER_NOT_DRAWN); |
689 | 706 |
690 child1.SetParent(&parent); | 707 parent.AddChild(&child1); |
691 child2.SetParent(&parent); | 708 parent.AddChild(&child2); |
692 ASSERT_EQ(2u, parent.children().size()); | 709 ASSERT_EQ(2u, parent.children().size()); |
693 EXPECT_EQ(&child1, parent.children()[0]); | 710 EXPECT_EQ(&child1, parent.children()[0]); |
694 EXPECT_EQ(&child2, parent.children()[1]); | 711 EXPECT_EQ(&child2, parent.children()[1]); |
695 ASSERT_EQ(2u, parent.layer()->children().size()); | 712 ASSERT_EQ(2u, parent.layer()->children().size()); |
696 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); | 713 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); |
697 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); | 714 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); |
698 | 715 |
699 parent.StackChildAtTop(&child1); | 716 parent.StackChildAtTop(&child1); |
700 ASSERT_EQ(2u, parent.children().size()); | 717 ASSERT_EQ(2u, parent.children().size()); |
701 EXPECT_EQ(&child1, parent.children()[1]); | 718 EXPECT_EQ(&child1, parent.children()[1]); |
(...skipping 10 matching lines...) Expand all Loading... |
712 Window child1(NULL); | 729 Window child1(NULL); |
713 child1.Init(ui::LAYER_NOT_DRAWN); | 730 child1.Init(ui::LAYER_NOT_DRAWN); |
714 child1.set_id(1); | 731 child1.set_id(1); |
715 Window child2(NULL); | 732 Window child2(NULL); |
716 child2.Init(ui::LAYER_NOT_DRAWN); | 733 child2.Init(ui::LAYER_NOT_DRAWN); |
717 child2.set_id(2); | 734 child2.set_id(2); |
718 Window child3(NULL); | 735 Window child3(NULL); |
719 child3.Init(ui::LAYER_NOT_DRAWN); | 736 child3.Init(ui::LAYER_NOT_DRAWN); |
720 child3.set_id(3); | 737 child3.set_id(3); |
721 | 738 |
722 child1.SetParent(&parent); | 739 parent.AddChild(&child1); |
723 child2.SetParent(&parent); | 740 parent.AddChild(&child2); |
724 child3.SetParent(&parent); | 741 parent.AddChild(&child3); |
725 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); | 742 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); |
726 | 743 |
727 parent.StackChildBelow(&child1, &child2); | 744 parent.StackChildBelow(&child1, &child2); |
728 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); | 745 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); |
729 | 746 |
730 parent.StackChildBelow(&child2, &child1); | 747 parent.StackChildBelow(&child2, &child1); |
731 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); | 748 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); |
732 | 749 |
733 parent.StackChildBelow(&child3, &child2); | 750 parent.StackChildBelow(&child3, &child2); |
734 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); | 751 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); |
735 | 752 |
736 parent.StackChildBelow(&child3, &child1); | 753 parent.StackChildBelow(&child3, &child1); |
737 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); | 754 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); |
738 } | 755 } |
739 | 756 |
740 // Various assertions for StackChildAbove. | 757 // Various assertions for StackChildAbove. |
741 TEST_F(WindowTest, StackChildAbove) { | 758 TEST_F(WindowTest, StackChildAbove) { |
742 Window parent(NULL); | 759 Window parent(NULL); |
743 parent.Init(ui::LAYER_NOT_DRAWN); | 760 parent.Init(ui::LAYER_NOT_DRAWN); |
744 Window child1(NULL); | 761 Window child1(NULL); |
745 child1.Init(ui::LAYER_NOT_DRAWN); | 762 child1.Init(ui::LAYER_NOT_DRAWN); |
746 Window child2(NULL); | 763 Window child2(NULL); |
747 child2.Init(ui::LAYER_NOT_DRAWN); | 764 child2.Init(ui::LAYER_NOT_DRAWN); |
748 Window child3(NULL); | 765 Window child3(NULL); |
749 child3.Init(ui::LAYER_NOT_DRAWN); | 766 child3.Init(ui::LAYER_NOT_DRAWN); |
750 | 767 |
751 child1.SetParent(&parent); | 768 parent.AddChild(&child1); |
752 child2.SetParent(&parent); | 769 parent.AddChild(&child2); |
753 | 770 |
754 // Move 1 in front of 2. | 771 // Move 1 in front of 2. |
755 parent.StackChildAbove(&child1, &child2); | 772 parent.StackChildAbove(&child1, &child2); |
756 ASSERT_EQ(2u, parent.children().size()); | 773 ASSERT_EQ(2u, parent.children().size()); |
757 EXPECT_EQ(&child2, parent.children()[0]); | 774 EXPECT_EQ(&child2, parent.children()[0]); |
758 EXPECT_EQ(&child1, parent.children()[1]); | 775 EXPECT_EQ(&child1, parent.children()[1]); |
759 ASSERT_EQ(2u, parent.layer()->children().size()); | 776 ASSERT_EQ(2u, parent.layer()->children().size()); |
760 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 777 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
761 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 778 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
762 | 779 |
763 // Add 3, resulting in order [2, 1, 3], then move 2 in front of 1, resulting | 780 // Add 3, resulting in order [2, 1, 3], then move 2 in front of 1, resulting |
764 // in [1, 2, 3]. | 781 // in [1, 2, 3]. |
765 child3.SetParent(&parent); | 782 parent.AddChild(&child3); |
766 parent.StackChildAbove(&child2, &child1); | 783 parent.StackChildAbove(&child2, &child1); |
767 ASSERT_EQ(3u, parent.children().size()); | 784 ASSERT_EQ(3u, parent.children().size()); |
768 EXPECT_EQ(&child1, parent.children()[0]); | 785 EXPECT_EQ(&child1, parent.children()[0]); |
769 EXPECT_EQ(&child2, parent.children()[1]); | 786 EXPECT_EQ(&child2, parent.children()[1]); |
770 EXPECT_EQ(&child3, parent.children()[2]); | 787 EXPECT_EQ(&child3, parent.children()[2]); |
771 ASSERT_EQ(3u, parent.layer()->children().size()); | 788 ASSERT_EQ(3u, parent.layer()->children().size()); |
772 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); | 789 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); |
773 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); | 790 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); |
774 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); | 791 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); |
775 | 792 |
(...skipping 17 matching lines...) Expand all Loading... |
793 ASSERT_EQ(3u, parent.layer()->children().size()); | 810 ASSERT_EQ(3u, parent.layer()->children().size()); |
794 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 811 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
795 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 812 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
796 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); | 813 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); |
797 } | 814 } |
798 | 815 |
799 // Various capture assertions. | 816 // Various capture assertions. |
800 TEST_F(WindowTest, CaptureTests) { | 817 TEST_F(WindowTest, CaptureTests) { |
801 CaptureWindowDelegateImpl delegate; | 818 CaptureWindowDelegateImpl delegate; |
802 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 819 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
803 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 820 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
804 EXPECT_FALSE(window->HasCapture()); | 821 EXPECT_FALSE(window->HasCapture()); |
805 | 822 |
806 delegate.ResetCounts(); | 823 delegate.ResetCounts(); |
807 | 824 |
808 // Do a capture. | 825 // Do a capture. |
809 window->SetCapture(); | 826 window->SetCapture(); |
810 EXPECT_TRUE(window->HasCapture()); | 827 EXPECT_TRUE(window->HasCapture()); |
811 EXPECT_EQ(0, delegate.capture_lost_count()); | 828 EXPECT_EQ(0, delegate.capture_lost_count()); |
812 EXPECT_EQ(0, delegate.capture_changed_event_count()); | 829 EXPECT_EQ(0, delegate.capture_changed_event_count()); |
813 EventGenerator generator(root_window(), gfx::Point(50, 50)); | 830 EventGenerator generator(root_window(), gfx::Point(50, 50)); |
(...skipping 30 matching lines...) Expand all Loading... |
844 window->SetCapture(); | 861 window->SetCapture(); |
845 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window())); | 862 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window())); |
846 window->parent()->RemoveChild(window.get()); | 863 window->parent()->RemoveChild(window.get()); |
847 EXPECT_FALSE(window->HasCapture()); | 864 EXPECT_FALSE(window->HasCapture()); |
848 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); | 865 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); |
849 } | 866 } |
850 | 867 |
851 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) { | 868 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) { |
852 CaptureWindowDelegateImpl delegate1; | 869 CaptureWindowDelegateImpl delegate1; |
853 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( | 870 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( |
854 &delegate1, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 871 &delegate1, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
855 CaptureWindowDelegateImpl delegate2; | 872 CaptureWindowDelegateImpl delegate2; |
856 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 873 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( |
857 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL)); | 874 &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window())); |
858 | 875 |
859 // Press on w1. | 876 // Press on w1. |
860 ui::TouchEvent press( | 877 ui::TouchEvent press( |
861 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 878 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
862 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 879 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
863 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. | 880 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
864 EXPECT_EQ(2, delegate1.gesture_event_count()); | 881 EXPECT_EQ(2, delegate1.gesture_event_count()); |
865 delegate1.ResetCounts(); | 882 delegate1.ResetCounts(); |
866 w2->SetCapture(); | 883 w2->SetCapture(); |
867 | 884 |
(...skipping 24 matching lines...) Expand all Loading... |
892 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 909 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
893 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); | 910 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
894 EXPECT_EQ(0, delegate1.gesture_event_count()); | 911 EXPECT_EQ(0, delegate1.gesture_event_count()); |
895 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. | 912 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
896 EXPECT_EQ(2, delegate2.gesture_event_count()); | 913 EXPECT_EQ(2, delegate2.gesture_event_count()); |
897 } | 914 } |
898 | 915 |
899 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { | 916 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { |
900 CaptureWindowDelegateImpl delegate; | 917 CaptureWindowDelegateImpl delegate; |
901 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 918 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
902 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 919 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
903 | 920 |
904 ui::TouchEvent press( | 921 ui::TouchEvent press( |
905 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 922 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
906 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 923 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
907 | 924 |
908 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. | 925 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
909 EXPECT_EQ(2, delegate.gesture_event_count()); | 926 EXPECT_EQ(2, delegate.gesture_event_count()); |
910 delegate.ResetCounts(); | 927 delegate.ResetCounts(); |
911 | 928 |
912 window->SetCapture(); | 929 window->SetCapture(); |
913 EXPECT_EQ(0, delegate.gesture_event_count()); | 930 EXPECT_EQ(0, delegate.gesture_event_count()); |
914 delegate.ResetCounts(); | 931 delegate.ResetCounts(); |
915 | 932 |
916 // The move event should still create a gesture, as this touch was | 933 // The move event should still create a gesture, as this touch was |
917 // on the window which was captured. | 934 // on the window which was captured. |
918 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, | 935 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, |
919 gfx::Point(10, 10), 0, getTime() + | 936 gfx::Point(10, 10), 0, getTime() + |
920 base::TimeDelta::FromMilliseconds(50)); | 937 base::TimeDelta::FromMilliseconds(50)); |
921 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); | 938 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
922 EXPECT_EQ(2, delegate.gesture_event_count()); | 939 EXPECT_EQ(2, delegate.gesture_event_count()); |
923 } | 940 } |
924 | 941 |
925 // Assertions around SetCapture() and touch/gestures. | 942 // Assertions around SetCapture() and touch/gestures. |
926 TEST_F(WindowTest, TransferCaptureTouchEvents) { | 943 TEST_F(WindowTest, TransferCaptureTouchEvents) { |
927 // Touch on |w1|. | 944 // Touch on |w1|. |
928 CaptureWindowDelegateImpl d1; | 945 CaptureWindowDelegateImpl d1; |
929 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( | 946 scoped_ptr<Window> w1(CreateTestWindowWithDelegate( |
930 &d1, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 947 &d1, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
931 ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 948 ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
932 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p1); | 949 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p1); |
933 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. | 950 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
934 EXPECT_EQ(2, d1.gesture_event_count()); | 951 EXPECT_EQ(2, d1.gesture_event_count()); |
935 d1.ResetCounts(); | 952 d1.ResetCounts(); |
936 | 953 |
937 // Touch on |w2| with a different id. | 954 // Touch on |w2| with a different id. |
938 CaptureWindowDelegateImpl d2; | 955 CaptureWindowDelegateImpl d2; |
939 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 956 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( |
940 &d2, 0, gfx::Rect(40, 0, 40, 20), NULL)); | 957 &d2, 0, gfx::Rect(40, 0, 40, 20), root_window())); |
941 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime()); | 958 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(41, 10), 1, getTime()); |
942 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p2); | 959 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&p2); |
943 EXPECT_EQ(0, d1.gesture_event_count()); | 960 EXPECT_EQ(0, d1.gesture_event_count()); |
944 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window. | 961 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN for new target window. |
945 EXPECT_EQ(2, d2.gesture_event_count()); | 962 EXPECT_EQ(2, d2.gesture_event_count()); |
946 d1.ResetCounts(); | 963 d1.ResetCounts(); |
947 d2.ResetCounts(); | 964 d2.ResetCounts(); |
948 | 965 |
949 // Set capture on |w2|, this should send a cancel (TAP_CANCEL, END) to |w1| | 966 // Set capture on |w2|, this should send a cancel (TAP_CANCEL, END) to |w1| |
950 // but not |w2|. | 967 // but not |w2|. |
951 w2->SetCapture(); | 968 w2->SetCapture(); |
952 EXPECT_EQ(2, d1.gesture_event_count()); | 969 EXPECT_EQ(2, d1.gesture_event_count()); |
953 EXPECT_EQ(0, d2.gesture_event_count()); | 970 EXPECT_EQ(0, d2.gesture_event_count()); |
954 d1.ResetCounts(); | 971 d1.ResetCounts(); |
955 d2.ResetCounts(); | 972 d2.ResetCounts(); |
956 | 973 |
957 CaptureWindowDelegateImpl d3; | 974 CaptureWindowDelegateImpl d3; |
958 scoped_ptr<Window> w3(CreateTestWindowWithDelegate( | 975 scoped_ptr<Window> w3(CreateTestWindowWithDelegate( |
959 &d3, 0, gfx::Rect(0, 0, 100, 101), NULL)); | 976 &d3, 0, gfx::Rect(0, 0, 100, 101), root_window())); |
960 // Set capture on w3. No new events should be received. | 977 // Set capture on w3. No new events should be received. |
961 w3->SetCapture(); | 978 w3->SetCapture(); |
962 EXPECT_EQ(0, d1.gesture_event_count()); | 979 EXPECT_EQ(0, d1.gesture_event_count()); |
963 EXPECT_EQ(0, d2.gesture_event_count()); | 980 EXPECT_EQ(0, d2.gesture_event_count()); |
964 EXPECT_EQ(0, d3.gesture_event_count()); | 981 EXPECT_EQ(0, d3.gesture_event_count()); |
965 | 982 |
966 // Move touch id originally associated with |w2|. Since capture was transfered | 983 // Move touch id originally associated with |w2|. Since capture was transfered |
967 // from 2 to 3 only |w3| should get the event. | 984 // from 2 to 3 only |w3| should get the event. |
968 ui::TouchEvent m3(ui::ET_TOUCH_MOVED, gfx::Point(110, 105), 1, getTime()); | 985 ui::TouchEvent m3(ui::ET_TOUCH_MOVED, gfx::Point(110, 105), 1, getTime()); |
969 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&m3); | 986 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&m3); |
970 EXPECT_EQ(0, d1.gesture_event_count()); | 987 EXPECT_EQ(0, d1.gesture_event_count()); |
971 EXPECT_EQ(0, d2.gesture_event_count()); | 988 EXPECT_EQ(0, d2.gesture_event_count()); |
972 // |w3| gets a TAP_CANCEL and two scroll related events. | 989 // |w3| gets a TAP_CANCEL and two scroll related events. |
973 EXPECT_EQ(3, d3.gesture_event_count()); | 990 EXPECT_EQ(3, d3.gesture_event_count()); |
974 } | 991 } |
975 | 992 |
976 // Changes capture while capture is already ongoing. | 993 // Changes capture while capture is already ongoing. |
977 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) { | 994 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) { |
978 CaptureWindowDelegateImpl delegate; | 995 CaptureWindowDelegateImpl delegate; |
979 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 996 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
980 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 997 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
981 CaptureWindowDelegateImpl delegate2; | 998 CaptureWindowDelegateImpl delegate2; |
982 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( | 999 scoped_ptr<Window> w2(CreateTestWindowWithDelegate( |
983 &delegate2, 0, gfx::Rect(20, 20, 20, 20), NULL)); | 1000 &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window())); |
984 | 1001 |
985 // Execute the scheduled draws so that mouse events are not | 1002 // Execute the scheduled draws so that mouse events are not |
986 // aggregated. | 1003 // aggregated. |
987 RunAllPendingInMessageLoop(); | 1004 RunAllPendingInMessageLoop(); |
988 | 1005 |
989 EXPECT_FALSE(window->HasCapture()); | 1006 EXPECT_FALSE(window->HasCapture()); |
990 | 1007 |
991 // Do a capture. | 1008 // Do a capture. |
992 delegate.ResetCounts(); | 1009 delegate.ResetCounts(); |
993 window->SetCapture(); | 1010 window->SetCapture(); |
(...skipping 15 matching lines...) Expand all Loading... |
1009 EXPECT_EQ(1, delegate.capture_lost_count()); | 1026 EXPECT_EQ(1, delegate.capture_lost_count()); |
1010 EXPECT_EQ(1, delegate.capture_changed_event_count()); | 1027 EXPECT_EQ(1, delegate.capture_changed_event_count()); |
1011 EXPECT_EQ(1, delegate.mouse_event_count()); | 1028 EXPECT_EQ(1, delegate.mouse_event_count()); |
1012 EXPECT_EQ(2, delegate2.mouse_event_count()); | 1029 EXPECT_EQ(2, delegate2.mouse_event_count()); |
1013 } | 1030 } |
1014 | 1031 |
1015 // Verifies capture is reset when a window is destroyed. | 1032 // Verifies capture is reset when a window is destroyed. |
1016 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { | 1033 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { |
1017 CaptureWindowDelegateImpl delegate; | 1034 CaptureWindowDelegateImpl delegate; |
1018 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 1035 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
1019 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 1036 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
1020 EXPECT_FALSE(window->HasCapture()); | 1037 EXPECT_FALSE(window->HasCapture()); |
1021 | 1038 |
1022 // Do a capture. | 1039 // Do a capture. |
1023 window->SetCapture(); | 1040 window->SetCapture(); |
1024 EXPECT_TRUE(window->HasCapture()); | 1041 EXPECT_TRUE(window->HasCapture()); |
1025 | 1042 |
1026 // Destroy the window. | 1043 // Destroy the window. |
1027 window.reset(); | 1044 window.reset(); |
1028 | 1045 |
1029 // Make sure the root window doesn't reference the window anymore. | 1046 // Make sure the root window doesn't reference the window anymore. |
1030 EXPECT_EQ(NULL, root_window()->mouse_pressed_handler()); | 1047 EXPECT_EQ(NULL, root_window()->mouse_pressed_handler()); |
1031 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); | 1048 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); |
1032 } | 1049 } |
1033 | 1050 |
1034 TEST_F(WindowTest, GetBoundsInRootWindow) { | 1051 TEST_F(WindowTest, GetBoundsInRootWindow) { |
1035 scoped_ptr<Window> viewport(CreateTestWindowWithBounds( | 1052 scoped_ptr<Window> viewport(CreateTestWindowWithBounds( |
1036 gfx::Rect(0, 0, 300, 300), NULL)); | 1053 gfx::Rect(0, 0, 300, 300), root_window())); |
1037 scoped_ptr<Window> child(CreateTestWindowWithBounds( | 1054 scoped_ptr<Window> child(CreateTestWindowWithBounds( |
1038 gfx::Rect(0, 0, 100, 100), viewport.get())); | 1055 gfx::Rect(0, 0, 100, 100), viewport.get())); |
1039 // Sanity check. | 1056 // Sanity check. |
1040 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1057 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
1041 | 1058 |
1042 // The |child| window's screen bounds should move along with the |viewport|. | 1059 // The |child| window's screen bounds should move along with the |viewport|. |
1043 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); | 1060 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); |
1044 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); | 1061 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); |
1045 | 1062 |
1046 // The |child| window is moved to the 0,0 in screen coordinates. | 1063 // The |child| window is moved to the 0,0 in screen coordinates. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 | 1099 |
1083 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); | 1100 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); |
1084 }; | 1101 }; |
1085 | 1102 |
1086 | 1103 |
1087 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for | 1104 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for |
1088 // mouse transitions from window to window. | 1105 // mouse transitions from window to window. |
1089 TEST_F(WindowTest, MouseEnterExit) { | 1106 TEST_F(WindowTest, MouseEnterExit) { |
1090 MouseEnterExitWindowDelegate d1; | 1107 MouseEnterExitWindowDelegate d1; |
1091 scoped_ptr<Window> w1( | 1108 scoped_ptr<Window> w1( |
1092 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); | 1109 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), |
| 1110 root_window())); |
1093 MouseEnterExitWindowDelegate d2; | 1111 MouseEnterExitWindowDelegate d2; |
1094 scoped_ptr<Window> w2( | 1112 scoped_ptr<Window> w2( |
1095 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL)); | 1113 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), |
| 1114 root_window())); |
1096 | 1115 |
1097 test::EventGenerator generator(root_window()); | 1116 test::EventGenerator generator(root_window()); |
1098 generator.MoveMouseToCenterOf(w1.get()); | 1117 generator.MoveMouseToCenterOf(w1.get()); |
1099 EXPECT_TRUE(d1.entered()); | 1118 EXPECT_TRUE(d1.entered()); |
1100 EXPECT_FALSE(d1.exited()); | 1119 EXPECT_FALSE(d1.exited()); |
1101 EXPECT_FALSE(d2.entered()); | 1120 EXPECT_FALSE(d2.entered()); |
1102 EXPECT_FALSE(d2.exited()); | 1121 EXPECT_FALSE(d2.exited()); |
1103 | 1122 |
1104 generator.MoveMouseToCenterOf(w2.get()); | 1123 generator.MoveMouseToCenterOf(w2.get()); |
1105 EXPECT_TRUE(d1.entered()); | 1124 EXPECT_TRUE(d1.entered()); |
1106 EXPECT_TRUE(d1.exited()); | 1125 EXPECT_TRUE(d1.exited()); |
1107 EXPECT_TRUE(d2.entered()); | 1126 EXPECT_TRUE(d2.entered()); |
1108 EXPECT_FALSE(d2.exited()); | 1127 EXPECT_FALSE(d2.exited()); |
1109 } | 1128 } |
1110 | 1129 |
1111 #if !defined(OS_WIN) | 1130 #if !defined(OS_WIN) |
1112 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for | 1131 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for |
1113 // mouse transitions from window to window, even if the entered window sets | 1132 // mouse transitions from window to window, even if the entered window sets |
1114 // and releases capture. | 1133 // and releases capture. |
1115 TEST_F(WindowTest, MouseEnterExitWithClick) { | 1134 TEST_F(WindowTest, MouseEnterExitWithClick) { |
1116 MouseEnterExitWindowDelegate d1; | 1135 MouseEnterExitWindowDelegate d1; |
1117 scoped_ptr<Window> w1( | 1136 scoped_ptr<Window> w1( |
1118 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); | 1137 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), |
| 1138 root_window())); |
1119 MouseEnterExitWindowDelegate d2; | 1139 MouseEnterExitWindowDelegate d2; |
1120 scoped_ptr<Window> w2( | 1140 scoped_ptr<Window> w2( |
1121 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL)); | 1141 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), |
| 1142 root_window())); |
1122 | 1143 |
1123 test::EventGenerator generator(root_window()); | 1144 test::EventGenerator generator(root_window()); |
1124 generator.MoveMouseToCenterOf(w1.get()); | 1145 generator.MoveMouseToCenterOf(w1.get()); |
1125 EXPECT_TRUE(d1.entered()); | 1146 EXPECT_TRUE(d1.entered()); |
1126 EXPECT_FALSE(d1.exited()); | 1147 EXPECT_FALSE(d1.exited()); |
1127 EXPECT_FALSE(d2.entered()); | 1148 EXPECT_FALSE(d2.entered()); |
1128 EXPECT_FALSE(d2.exited()); | 1149 EXPECT_FALSE(d2.exited()); |
1129 | 1150 |
1130 // Emmulate what Views does on a click by grabbing and releasing capture. | 1151 // Emmulate what Views does on a click by grabbing and releasing capture. |
1131 generator.PressLeftButton(); | 1152 generator.PressLeftButton(); |
1132 w1->SetCapture(); | 1153 w1->SetCapture(); |
1133 w1->ReleaseCapture(); | 1154 w1->ReleaseCapture(); |
1134 generator.ReleaseLeftButton(); | 1155 generator.ReleaseLeftButton(); |
1135 | 1156 |
1136 generator.MoveMouseToCenterOf(w2.get()); | 1157 generator.MoveMouseToCenterOf(w2.get()); |
1137 EXPECT_TRUE(d1.entered()); | 1158 EXPECT_TRUE(d1.entered()); |
1138 EXPECT_TRUE(d1.exited()); | 1159 EXPECT_TRUE(d1.exited()); |
1139 EXPECT_TRUE(d2.entered()); | 1160 EXPECT_TRUE(d2.entered()); |
1140 EXPECT_FALSE(d2.exited()); | 1161 EXPECT_FALSE(d2.exited()); |
1141 } | 1162 } |
1142 | 1163 |
1143 // Temporarily disabled for windows. See crbug.com/112222. | 1164 // Temporarily disabled for windows. See crbug.com/112222. |
1144 // Verifies that enter / exits are sent if windows appear and are deleted | 1165 // Verifies that enter / exits are sent if windows appear and are deleted |
1145 // under the current mouse position.. | 1166 // under the current mouse position.. |
1146 TEST_F(WindowTest, MouseEnterExitWithDelete) { | 1167 TEST_F(WindowTest, MouseEnterExitWithDelete) { |
1147 MouseEnterExitWindowDelegate d1; | 1168 MouseEnterExitWindowDelegate d1; |
1148 scoped_ptr<Window> w1( | 1169 scoped_ptr<Window> w1( |
1149 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); | 1170 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), |
| 1171 root_window())); |
1150 | 1172 |
1151 test::EventGenerator generator(root_window()); | 1173 test::EventGenerator generator(root_window()); |
1152 generator.MoveMouseToCenterOf(w1.get()); | 1174 generator.MoveMouseToCenterOf(w1.get()); |
1153 EXPECT_TRUE(d1.entered()); | 1175 EXPECT_TRUE(d1.entered()); |
1154 EXPECT_FALSE(d1.exited()); | 1176 EXPECT_FALSE(d1.exited()); |
1155 | 1177 |
1156 { | 1178 { |
1157 MouseEnterExitWindowDelegate d2; | 1179 MouseEnterExitWindowDelegate d2; |
1158 scoped_ptr<Window> w2( | 1180 scoped_ptr<Window> w2( |
1159 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), NULL)); | 1181 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), |
| 1182 root_window())); |
1160 // Enters / exits can be send asynchronously. | 1183 // Enters / exits can be send asynchronously. |
1161 RunAllPendingInMessageLoop(); | 1184 RunAllPendingInMessageLoop(); |
1162 EXPECT_TRUE(d1.entered()); | 1185 EXPECT_TRUE(d1.entered()); |
1163 EXPECT_TRUE(d1.exited()); | 1186 EXPECT_TRUE(d1.exited()); |
1164 EXPECT_TRUE(d2.entered()); | 1187 EXPECT_TRUE(d2.entered()); |
1165 EXPECT_FALSE(d2.exited()); | 1188 EXPECT_FALSE(d2.exited()); |
1166 d1.ResetExpectations(); | 1189 d1.ResetExpectations(); |
1167 } | 1190 } |
1168 // Enters / exits can be send asynchronously. | 1191 // Enters / exits can be send asynchronously. |
1169 RunAllPendingInMessageLoop(); | 1192 RunAllPendingInMessageLoop(); |
1170 EXPECT_TRUE(d1.entered()); | 1193 EXPECT_TRUE(d1.entered()); |
1171 } | 1194 } |
1172 | 1195 |
1173 // Verifies that enter / exits are sent if windows appear and are hidden | 1196 // Verifies that enter / exits are sent if windows appear and are hidden |
1174 // under the current mouse position.. | 1197 // under the current mouse position.. |
1175 TEST_F(WindowTest, MouseEnterExitWithHide) { | 1198 TEST_F(WindowTest, MouseEnterExitWithHide) { |
1176 MouseEnterExitWindowDelegate d1; | 1199 MouseEnterExitWindowDelegate d1; |
1177 scoped_ptr<Window> w1( | 1200 scoped_ptr<Window> w1( |
1178 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); | 1201 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), |
| 1202 root_window())); |
1179 | 1203 |
1180 test::EventGenerator generator(root_window()); | 1204 test::EventGenerator generator(root_window()); |
1181 generator.MoveMouseToCenterOf(w1.get()); | 1205 generator.MoveMouseToCenterOf(w1.get()); |
1182 EXPECT_TRUE(d1.entered()); | 1206 EXPECT_TRUE(d1.entered()); |
1183 EXPECT_FALSE(d1.exited()); | 1207 EXPECT_FALSE(d1.exited()); |
1184 | 1208 |
1185 MouseEnterExitWindowDelegate d2; | 1209 MouseEnterExitWindowDelegate d2; |
1186 scoped_ptr<Window> w2( | 1210 scoped_ptr<Window> w2( |
1187 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), NULL)); | 1211 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), |
| 1212 root_window())); |
1188 // Enters / exits can be send asynchronously. | 1213 // Enters / exits can be send asynchronously. |
1189 RunAllPendingInMessageLoop(); | 1214 RunAllPendingInMessageLoop(); |
1190 EXPECT_TRUE(d1.entered()); | 1215 EXPECT_TRUE(d1.entered()); |
1191 EXPECT_TRUE(d1.exited()); | 1216 EXPECT_TRUE(d1.exited()); |
1192 EXPECT_TRUE(d2.entered()); | 1217 EXPECT_TRUE(d2.entered()); |
1193 EXPECT_FALSE(d2.exited()); | 1218 EXPECT_FALSE(d2.exited()); |
1194 | 1219 |
1195 d1.ResetExpectations(); | 1220 d1.ResetExpectations(); |
1196 w2->Hide(); | 1221 w2->Hide(); |
1197 // Enters / exits can be send asynchronously. | 1222 // Enters / exits can be send asynchronously. |
1198 RunAllPendingInMessageLoop(); | 1223 RunAllPendingInMessageLoop(); |
1199 EXPECT_TRUE(d1.entered()); | 1224 EXPECT_TRUE(d1.entered()); |
1200 } | 1225 } |
1201 #endif | 1226 #endif |
1202 | 1227 |
1203 // Creates a window with a delegate (w111) that can handle events at a lower | 1228 // Creates a window with a delegate (w111) that can handle events at a lower |
1204 // z-index than a window without a delegate (w12). w12 is sized to fill the | 1229 // z-index than a window without a delegate (w12). w12 is sized to fill the |
1205 // entire bounds of the container. This test verifies that | 1230 // entire bounds of the container. This test verifies that |
1206 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event, | 1231 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event, |
1207 // because it has no children that can handle the event and it has no delegate | 1232 // because it has no children that can handle the event and it has no delegate |
1208 // allowing it to handle the event itself. | 1233 // allowing it to handle the event itself. |
1209 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) { | 1234 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) { |
1210 TestWindowDelegate d111; | 1235 TestWindowDelegate d111; |
1211 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, | 1236 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, |
1212 gfx::Rect(0, 0, 500, 500), NULL)); | 1237 gfx::Rect(0, 0, 500, 500), root_window())); |
1213 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11, | 1238 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11, |
1214 gfx::Rect(0, 0, 500, 500), w1.get())); | 1239 gfx::Rect(0, 0, 500, 500), w1.get())); |
1215 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, | 1240 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, |
1216 gfx::Rect(50, 50, 450, 450), w11.get())); | 1241 gfx::Rect(50, 50, 450, 450), w11.get())); |
1217 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12, | 1242 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12, |
1218 gfx::Rect(0, 0, 500, 500), w1.get())); | 1243 gfx::Rect(0, 0, 500, 500), w1.get())); |
1219 | 1244 |
1220 gfx::Point target_point = w111->bounds().CenterPoint(); | 1245 gfx::Point target_point = w111->bounds().CenterPoint(); |
1221 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(target_point)); | 1246 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(target_point)); |
1222 } | 1247 } |
(...skipping 23 matching lines...) Expand all Loading... |
1246 int shown_; | 1271 int shown_; |
1247 int hidden_; | 1272 int hidden_; |
1248 | 1273 |
1249 DISALLOW_COPY_AND_ASSIGN(VisibilityWindowDelegate); | 1274 DISALLOW_COPY_AND_ASSIGN(VisibilityWindowDelegate); |
1250 }; | 1275 }; |
1251 | 1276 |
1252 // Verifies show/hide propagate correctly to children and the layer. | 1277 // Verifies show/hide propagate correctly to children and the layer. |
1253 TEST_F(WindowTest, Visibility) { | 1278 TEST_F(WindowTest, Visibility) { |
1254 VisibilityWindowDelegate d; | 1279 VisibilityWindowDelegate d; |
1255 VisibilityWindowDelegate d2; | 1280 VisibilityWindowDelegate d2; |
1256 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d, 1, gfx::Rect(), NULL)); | 1281 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d, 1, gfx::Rect(), |
| 1282 root_window())); |
1257 scoped_ptr<Window> w2( | 1283 scoped_ptr<Window> w2( |
1258 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get())); | 1284 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get())); |
1259 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w2.get())); | 1285 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w2.get())); |
1260 | 1286 |
1261 // Create shows all the windows. | 1287 // Create shows all the windows. |
1262 EXPECT_TRUE(w1->IsVisible()); | 1288 EXPECT_TRUE(w1->IsVisible()); |
1263 EXPECT_TRUE(w2->IsVisible()); | 1289 EXPECT_TRUE(w2->IsVisible()); |
1264 EXPECT_TRUE(w3->IsVisible()); | 1290 EXPECT_TRUE(w3->IsVisible()); |
1265 EXPECT_EQ(1, d.shown()); | 1291 EXPECT_EQ(1, d.shown()); |
1266 | 1292 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 EXPECT_EQ(0, d2.hidden()); | 1333 EXPECT_EQ(0, d2.hidden()); |
1308 EXPECT_EQ(1, d2.shown()); | 1334 EXPECT_EQ(1, d2.shown()); |
1309 } | 1335 } |
1310 | 1336 |
1311 TEST_F(WindowTest, IgnoreEventsTest) { | 1337 TEST_F(WindowTest, IgnoreEventsTest) { |
1312 TestWindowDelegate d11; | 1338 TestWindowDelegate d11; |
1313 TestWindowDelegate d12; | 1339 TestWindowDelegate d12; |
1314 TestWindowDelegate d111; | 1340 TestWindowDelegate d111; |
1315 TestWindowDelegate d121; | 1341 TestWindowDelegate d121; |
1316 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, | 1342 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, |
1317 gfx::Rect(0, 0, 500, 500), NULL)); | 1343 gfx::Rect(0, 0, 500, 500), root_window())); |
1318 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11, | 1344 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11, |
1319 gfx::Rect(0, 0, 500, 500), w1.get())); | 1345 gfx::Rect(0, 0, 500, 500), w1.get())); |
1320 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, | 1346 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, |
1321 gfx::Rect(50, 50, 450, 450), w11.get())); | 1347 gfx::Rect(50, 50, 450, 450), w11.get())); |
1322 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12, | 1348 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12, |
1323 gfx::Rect(0, 0, 500, 500), w1.get())); | 1349 gfx::Rect(0, 0, 500, 500), w1.get())); |
1324 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121, | 1350 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121, |
1325 gfx::Rect(150, 150, 50, 50), w12.get())); | 1351 gfx::Rect(150, 150, 50, 50), w12.get())); |
1326 | 1352 |
1327 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); | 1353 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 EXPECT_EQ(size.ToString(), | 1390 EXPECT_EQ(size.ToString(), |
1365 root_window()->GetHostSize().ToString()); | 1391 root_window()->GetHostSize().ToString()); |
1366 } | 1392 } |
1367 | 1393 |
1368 TEST_F(WindowTest, TransformGesture) { | 1394 TEST_F(WindowTest, TransformGesture) { |
1369 gfx::Size size = root_window()->GetHostSize(); | 1395 gfx::Size size = root_window()->GetHostSize(); |
1370 | 1396 |
1371 scoped_ptr<GestureTrackPositionDelegate> delegate( | 1397 scoped_ptr<GestureTrackPositionDelegate> delegate( |
1372 new GestureTrackPositionDelegate); | 1398 new GestureTrackPositionDelegate); |
1373 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, | 1399 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, |
1374 gfx::Rect(0, 0, 20, 20), NULL)); | 1400 gfx::Rect(0, 0, 20, 20), root_window())); |
1375 | 1401 |
1376 // Rotate the root-window clock-wise 90 degrees. | 1402 // Rotate the root-window clock-wise 90 degrees. |
1377 gfx::Transform transform; | 1403 gfx::Transform transform; |
1378 transform.Translate(size.height(), 0.0); | 1404 transform.Translate(size.height(), 0.0); |
1379 transform.Rotate(90.0); | 1405 transform.Rotate(90.0); |
1380 root_window()->SetTransform(transform); | 1406 root_window()->SetTransform(transform); |
1381 | 1407 |
1382 ui::TouchEvent press( | 1408 ui::TouchEvent press( |
1383 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); | 1409 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); |
1384 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 1410 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1385 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); | 1411 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); |
1386 } | 1412 } |
1387 | 1413 |
1388 // Various assertions for transient children. | 1414 // Various assertions for transient children. |
1389 TEST_F(WindowTest, TransientChildren) { | 1415 TEST_F(WindowTest, TransientChildren) { |
1390 scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL)); | 1416 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); |
1391 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); | 1417 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); |
1392 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get())); | 1418 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get())); |
1393 Window* w2 = CreateTestWindowWithId(2, parent.get()); | 1419 Window* w2 = CreateTestWindowWithId(2, parent.get()); |
1394 w1->AddTransientChild(w2); // w2 is now owned by w1. | 1420 w1->AddTransientChild(w2); // w2 is now owned by w1. |
1395 // Stack w1 at the top (end), this should force w2 to be last (on top of w1). | 1421 // Stack w1 at the top (end), this should force w2 to be last (on top of w1). |
1396 parent->StackChildAtTop(w1.get()); | 1422 parent->StackChildAtTop(w1.get()); |
1397 ASSERT_EQ(3u, parent->children().size()); | 1423 ASSERT_EQ(3u, parent->children().size()); |
1398 EXPECT_EQ(w2, parent->children().back()); | 1424 EXPECT_EQ(w2, parent->children().back()); |
1399 | 1425 |
1400 // Destroy w1, which should also destroy w3 (since it's a transient child). | 1426 // Destroy w1, which should also destroy w3 (since it's a transient child). |
(...skipping 14 matching lines...) Expand all Loading... |
1415 EXPECT_EQ(w1.get(), parent->children()[1]); | 1441 EXPECT_EQ(w1.get(), parent->children()[1]); |
1416 | 1442 |
1417 // Hiding parent should hide transient children. | 1443 // Hiding parent should hide transient children. |
1418 EXPECT_TRUE(w2->IsVisible()); | 1444 EXPECT_TRUE(w2->IsVisible()); |
1419 w1->Hide(); | 1445 w1->Hide(); |
1420 EXPECT_FALSE(w2->IsVisible()); | 1446 EXPECT_FALSE(w2->IsVisible()); |
1421 } | 1447 } |
1422 | 1448 |
1423 // Tests that when a focused window is closed, its parent inherits the focus. | 1449 // Tests that when a focused window is closed, its parent inherits the focus. |
1424 TEST_F(WindowTest, FocusedWindowTest) { | 1450 TEST_F(WindowTest, FocusedWindowTest) { |
1425 scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL)); | 1451 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); |
1426 scoped_ptr<Window> child(CreateTestWindowWithId(1, parent.get())); | 1452 scoped_ptr<Window> child(CreateTestWindowWithId(1, parent.get())); |
1427 | 1453 |
1428 parent->Show(); | 1454 parent->Show(); |
1429 | 1455 |
1430 child->Focus(); | 1456 child->Focus(); |
1431 EXPECT_TRUE(child->HasFocus()); | 1457 EXPECT_TRUE(child->HasFocus()); |
1432 EXPECT_FALSE(parent->HasFocus()); | 1458 EXPECT_FALSE(parent->HasFocus()); |
1433 | 1459 |
1434 child.reset(); | 1460 child.reset(); |
1435 EXPECT_TRUE(parent->HasFocus()); | 1461 EXPECT_TRUE(parent->HasFocus()); |
1436 } | 1462 } |
1437 | 1463 |
1438 // Tests that the previously-focused window is passed to | 1464 // Tests that the previously-focused window is passed to |
1439 // WindowDelegate::OnFocus(). | 1465 // WindowDelegate::OnFocus(). |
1440 TEST_F(WindowTest, OldFocusedWindowTest) { | 1466 TEST_F(WindowTest, OldFocusedWindowTest) { |
1441 const gfx::Rect kBounds(0, 0, 100, 100); | 1467 const gfx::Rect kBounds(0, 0, 100, 100); |
1442 | 1468 |
1443 FocusDelegate delegate1; | 1469 FocusDelegate delegate1; |
1444 scoped_ptr<Window> window1( | 1470 scoped_ptr<Window> window1( |
1445 CreateTestWindowWithDelegate(&delegate1, 0, kBounds, NULL)); | 1471 CreateTestWindowWithDelegate(&delegate1, 0, kBounds, root_window())); |
1446 window1->Focus(); | 1472 window1->Focus(); |
1447 ASSERT_TRUE(window1->HasFocus()); | 1473 ASSERT_TRUE(window1->HasFocus()); |
1448 EXPECT_TRUE(delegate1.previous_focused_window() == NULL); | 1474 EXPECT_TRUE(delegate1.previous_focused_window() == NULL); |
1449 | 1475 |
1450 FocusDelegate delegate2; | 1476 FocusDelegate delegate2; |
1451 scoped_ptr<Window> window2( | 1477 scoped_ptr<Window> window2( |
1452 CreateTestWindowWithDelegate(&delegate2, 1, kBounds, NULL)); | 1478 CreateTestWindowWithDelegate(&delegate2, 1, kBounds, root_window())); |
1453 window2->Focus(); | 1479 window2->Focus(); |
1454 ASSERT_TRUE(window2->HasFocus()); | 1480 ASSERT_TRUE(window2->HasFocus()); |
1455 EXPECT_FALSE(window1->HasFocus()); | 1481 EXPECT_FALSE(window1->HasFocus()); |
1456 EXPECT_EQ(window1.get(), delegate2.previous_focused_window()); | 1482 EXPECT_EQ(window1.get(), delegate2.previous_focused_window()); |
1457 } | 1483 } |
1458 | 1484 |
1459 namespace { | 1485 namespace { |
1460 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); | 1486 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); |
1461 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); | 1487 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); |
1462 } | 1488 } |
1463 | 1489 |
1464 TEST_F(WindowTest, Property) { | 1490 TEST_F(WindowTest, Property) { |
1465 scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL)); | 1491 scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window())); |
1466 | 1492 |
1467 static const char native_prop_key[] = "fnord"; | 1493 static const char native_prop_key[] = "fnord"; |
1468 | 1494 |
1469 // Non-existent properties should return the default values. | 1495 // Non-existent properties should return the default values. |
1470 EXPECT_EQ(-2, w->GetProperty(kIntKey)); | 1496 EXPECT_EQ(-2, w->GetProperty(kIntKey)); |
1471 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); | 1497 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); |
1472 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); | 1498 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); |
1473 | 1499 |
1474 // A set property value should be returned again (even if it's the default | 1500 // A set property value should be returned again (even if it's the default |
1475 // value). | 1501 // value). |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 DISALLOW_COPY_AND_ASSIGN(TestProperty); | 1540 DISALLOW_COPY_AND_ASSIGN(TestProperty); |
1515 }; | 1541 }; |
1516 | 1542 |
1517 TestProperty* TestProperty::last_deleted_ = NULL; | 1543 TestProperty* TestProperty::last_deleted_ = NULL; |
1518 | 1544 |
1519 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); | 1545 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); |
1520 | 1546 |
1521 } // namespace | 1547 } // namespace |
1522 | 1548 |
1523 TEST_F(WindowTest, OwnedProperty) { | 1549 TEST_F(WindowTest, OwnedProperty) { |
1524 scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL)); | 1550 scoped_ptr<Window> w(CreateTestWindowWithId(0, root_window())); |
1525 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); | 1551 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); |
1526 TestProperty* p1 = new TestProperty(); | 1552 TestProperty* p1 = new TestProperty(); |
1527 w->SetProperty(kOwnedKey, p1); | 1553 w->SetProperty(kOwnedKey, p1); |
1528 EXPECT_EQ(p1, w->GetProperty(kOwnedKey)); | 1554 EXPECT_EQ(p1, w->GetProperty(kOwnedKey)); |
1529 EXPECT_EQ(NULL, TestProperty::last_deleted()); | 1555 EXPECT_EQ(NULL, TestProperty::last_deleted()); |
1530 | 1556 |
1531 TestProperty* p2 = new TestProperty(); | 1557 TestProperty* p2 = new TestProperty(); |
1532 w->SetProperty(kOwnedKey, p2); | 1558 w->SetProperty(kOwnedKey, p2); |
1533 EXPECT_EQ(p2, w->GetProperty(kOwnedKey)); | 1559 EXPECT_EQ(p2, w->GetProperty(kOwnedKey)); |
1534 EXPECT_EQ(p1, TestProperty::last_deleted()); | 1560 EXPECT_EQ(p1, TestProperty::last_deleted()); |
1535 | 1561 |
1536 w->ClearProperty(kOwnedKey); | 1562 w->ClearProperty(kOwnedKey); |
1537 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); | 1563 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); |
1538 EXPECT_EQ(p2, TestProperty::last_deleted()); | 1564 EXPECT_EQ(p2, TestProperty::last_deleted()); |
1539 | 1565 |
1540 TestProperty* p3 = new TestProperty(); | 1566 TestProperty* p3 = new TestProperty(); |
1541 w->SetProperty(kOwnedKey, p3); | 1567 w->SetProperty(kOwnedKey, p3); |
1542 EXPECT_EQ(p3, w->GetProperty(kOwnedKey)); | 1568 EXPECT_EQ(p3, w->GetProperty(kOwnedKey)); |
1543 EXPECT_EQ(p2, TestProperty::last_deleted()); | 1569 EXPECT_EQ(p2, TestProperty::last_deleted()); |
1544 w.reset(); | 1570 w.reset(); |
1545 EXPECT_EQ(p3, TestProperty::last_deleted()); | 1571 EXPECT_EQ(p3, TestProperty::last_deleted()); |
1546 } | 1572 } |
1547 | 1573 |
1548 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { | 1574 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { |
1549 // We cannot short-circuit animations in this test. | 1575 // We cannot short-circuit animations in this test. |
1550 ui::LayerAnimator::set_disable_animations_for_test(false); | 1576 ui::LayerAnimator::set_disable_animations_for_test(false); |
1551 | 1577 |
1552 scoped_ptr<Window> w1( | 1578 scoped_ptr<Window> w1( |
1553 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), NULL)); | 1579 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); |
1554 | 1580 |
1555 EXPECT_FALSE(!w1->layer()); | 1581 EXPECT_FALSE(!w1->layer()); |
1556 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); | 1582 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); |
1557 ui::AnimationContainerElement* element = w1->layer()->GetAnimator(); | 1583 ui::AnimationContainerElement* element = w1->layer()->GetAnimator(); |
1558 | 1584 |
1559 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); | 1585 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); |
1560 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString()); | 1586 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString()); |
1561 | 1587 |
1562 // Animate to a different position. | 1588 // Animate to a different position. |
1563 { | 1589 { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 int destroyed_count_; | 1699 int destroyed_count_; |
1674 scoped_ptr<VisibilityInfo> visibility_info_; | 1700 scoped_ptr<VisibilityInfo> visibility_info_; |
1675 const void* property_key_; | 1701 const void* property_key_; |
1676 intptr_t old_property_value_; | 1702 intptr_t old_property_value_; |
1677 | 1703 |
1678 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); | 1704 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); |
1679 }; | 1705 }; |
1680 | 1706 |
1681 // Various assertions for WindowObserver. | 1707 // Various assertions for WindowObserver. |
1682 TEST_F(WindowObserverTest, WindowObserver) { | 1708 TEST_F(WindowObserverTest, WindowObserver) { |
1683 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 1709 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
1684 w1->AddObserver(this); | 1710 w1->AddObserver(this); |
1685 | 1711 |
1686 // Create a new window as a child of w1, our observer should be notified. | 1712 // Create a new window as a child of w1, our observer should be notified. |
1687 scoped_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); | 1713 scoped_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); |
1688 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear()); | 1714 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear()); |
1689 | 1715 |
1690 // Delete w2, which should result in the remove notification. | 1716 // Delete w2, which should result in the remove notification. |
1691 w2.reset(); | 1717 w2.reset(); |
1692 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear()); | 1718 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear()); |
1693 | 1719 |
1694 // Create a window that isn't parented to w1, we shouldn't get any | 1720 // Create a window that isn't parented to w1, we shouldn't get any |
1695 // notification. | 1721 // notification. |
1696 scoped_ptr<Window> w3(CreateTestWindowWithId(3, NULL)); | 1722 scoped_ptr<Window> w3(CreateTestWindowWithId(3, root_window())); |
1697 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); | 1723 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); |
1698 | 1724 |
1699 // Similarly destroying w3 shouldn't notify us either. | 1725 // Similarly destroying w3 shouldn't notify us either. |
1700 w3.reset(); | 1726 w3.reset(); |
1701 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); | 1727 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); |
1702 w1->RemoveObserver(this); | 1728 w1->RemoveObserver(this); |
1703 } | 1729 } |
1704 | 1730 |
1705 // Test if OnWindowVisibilityChagned is invoked with expected | 1731 // Test if OnWindowVisibilityChagned is invoked with expected |
1706 // parameters. | 1732 // parameters. |
1707 TEST_F(WindowObserverTest, WindowVisibility) { | 1733 TEST_F(WindowObserverTest, WindowVisibility) { |
1708 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 1734 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
1709 scoped_ptr<Window> w2(CreateTestWindowWithId(1, w1.get())); | 1735 scoped_ptr<Window> w2(CreateTestWindowWithId(1, w1.get())); |
1710 w2->AddObserver(this); | 1736 w2->AddObserver(this); |
1711 | 1737 |
1712 // Hide should make the window invisible and the passed visible | 1738 // Hide should make the window invisible and the passed visible |
1713 // parameter is false. | 1739 // parameter is false. |
1714 w2->Hide(); | 1740 w2->Hide(); |
1715 EXPECT_FALSE(!GetVisibilityInfo()); | 1741 EXPECT_FALSE(!GetVisibilityInfo()); |
1716 EXPECT_FALSE(!GetVisibilityInfo()); | 1742 EXPECT_FALSE(!GetVisibilityInfo()); |
1717 if (!GetVisibilityInfo()) | 1743 if (!GetVisibilityInfo()) |
1718 return; | 1744 return; |
(...skipping 21 matching lines...) Expand all Loading... |
1740 EXPECT_FALSE(!GetVisibilityInfo()); | 1766 EXPECT_FALSE(!GetVisibilityInfo()); |
1741 if (!GetVisibilityInfo()) | 1767 if (!GetVisibilityInfo()) |
1742 return; | 1768 return; |
1743 EXPECT_TRUE(GetVisibilityInfo()->window_visible); | 1769 EXPECT_TRUE(GetVisibilityInfo()->window_visible); |
1744 EXPECT_TRUE(GetVisibilityInfo()->visible_param); | 1770 EXPECT_TRUE(GetVisibilityInfo()->visible_param); |
1745 } | 1771 } |
1746 | 1772 |
1747 // Test if OnWindowDestroyed is invoked as expected. | 1773 // Test if OnWindowDestroyed is invoked as expected. |
1748 TEST_F(WindowObserverTest, WindowDestroyed) { | 1774 TEST_F(WindowObserverTest, WindowDestroyed) { |
1749 // Delete a window should fire a destroyed notification. | 1775 // Delete a window should fire a destroyed notification. |
1750 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 1776 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
1751 w1->AddObserver(this); | 1777 w1->AddObserver(this); |
1752 w1.reset(); | 1778 w1.reset(); |
1753 EXPECT_EQ(1, DestroyedCountAndClear()); | 1779 EXPECT_EQ(1, DestroyedCountAndClear()); |
1754 | 1780 |
1755 // Observe on child and delete parent window should fire a notification. | 1781 // Observe on child and delete parent window should fire a notification. |
1756 scoped_ptr<Window> parent(CreateTestWindowWithId(1, NULL)); | 1782 scoped_ptr<Window> parent(CreateTestWindowWithId(1, root_window())); |
1757 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent | 1783 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent |
1758 child->AddObserver(this); | 1784 child->AddObserver(this); |
1759 parent.reset(); | 1785 parent.reset(); |
1760 EXPECT_EQ(1, DestroyedCountAndClear()); | 1786 EXPECT_EQ(1, DestroyedCountAndClear()); |
1761 } | 1787 } |
1762 | 1788 |
1763 TEST_F(WindowObserverTest, PropertyChanged) { | 1789 TEST_F(WindowObserverTest, PropertyChanged) { |
1764 // Setting property should fire a property change notification. | 1790 // Setting property should fire a property change notification. |
1765 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 1791 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
1766 w1->AddObserver(this); | 1792 w1->AddObserver(this); |
1767 | 1793 |
1768 static const WindowProperty<int> prop = {-2}; | 1794 static const WindowProperty<int> prop = {-2}; |
1769 static const char native_prop_key[] = "fnord"; | 1795 static const char native_prop_key[] = "fnord"; |
1770 | 1796 |
1771 w1->SetProperty(&prop, 1); | 1797 w1->SetProperty(&prop, 1); |
1772 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); | 1798 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); |
1773 w1->SetProperty(&prop, -2); | 1799 w1->SetProperty(&prop, -2); |
1774 EXPECT_EQ(PropertyChangeInfo(&prop, 1), PropertyChangeInfoAndClear()); | 1800 EXPECT_EQ(PropertyChangeInfo(&prop, 1), PropertyChangeInfoAndClear()); |
1775 w1->SetProperty(&prop, 3); | 1801 w1->SetProperty(&prop, 3); |
1776 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); | 1802 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); |
1777 w1->ClearProperty(&prop); | 1803 w1->ClearProperty(&prop); |
1778 EXPECT_EQ(PropertyChangeInfo(&prop, 3), PropertyChangeInfoAndClear()); | 1804 EXPECT_EQ(PropertyChangeInfo(&prop, 3), PropertyChangeInfoAndClear()); |
1779 | 1805 |
1780 w1->SetNativeWindowProperty(native_prop_key, &*w1); | 1806 w1->SetNativeWindowProperty(native_prop_key, &*w1); |
1781 EXPECT_EQ(PropertyChangeInfo(native_prop_key, 0), | 1807 EXPECT_EQ(PropertyChangeInfo(native_prop_key, 0), |
1782 PropertyChangeInfoAndClear()); | 1808 PropertyChangeInfoAndClear()); |
1783 w1->SetNativeWindowProperty(native_prop_key, NULL); | 1809 w1->SetNativeWindowProperty(native_prop_key, NULL); |
1784 EXPECT_EQ(PropertyChangeInfo(native_prop_key, | 1810 EXPECT_EQ(PropertyChangeInfo(native_prop_key, |
1785 reinterpret_cast<intptr_t>(&*w1)), | 1811 reinterpret_cast<intptr_t>(&*w1)), |
1786 PropertyChangeInfoAndClear()); | 1812 PropertyChangeInfoAndClear()); |
1787 | 1813 |
1788 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. | 1814 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. |
1789 EXPECT_EQ(PropertyChangeInfo( | 1815 EXPECT_EQ(PropertyChangeInfo( |
1790 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear()); | 1816 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear()); |
1791 } | 1817 } |
1792 | 1818 |
1793 TEST_F(WindowTest, AcquireLayer) { | 1819 TEST_F(WindowTest, AcquireLayer) { |
1794 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); | 1820 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
1795 scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); | 1821 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); |
1796 ui::Layer* parent = window1->parent()->layer(); | 1822 ui::Layer* parent = window1->parent()->layer(); |
1797 EXPECT_EQ(2U, parent->children().size()); | 1823 EXPECT_EQ(2U, parent->children().size()); |
1798 | 1824 |
1799 Window::TestApi window1_test_api(window1.get()); | 1825 Window::TestApi window1_test_api(window1.get()); |
1800 Window::TestApi window2_test_api(window2.get()); | 1826 Window::TestApi window2_test_api(window2.get()); |
1801 | 1827 |
1802 EXPECT_TRUE(window1_test_api.OwnsLayer()); | 1828 EXPECT_TRUE(window1_test_api.OwnsLayer()); |
1803 EXPECT_TRUE(window2_test_api.OwnsLayer()); | 1829 EXPECT_TRUE(window2_test_api.OwnsLayer()); |
1804 | 1830 |
1805 // After acquisition, window1 should not own its layer, but it should still | 1831 // After acquisition, window1 should not own its layer, but it should still |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1839 EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type()); | 1865 EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type()); |
1840 EXPECT_FALSE(layer->scale_content()); | 1866 EXPECT_FALSE(layer->scale_content()); |
1841 EXPECT_FALSE(layer->visible()); | 1867 EXPECT_FALSE(layer->visible()); |
1842 EXPECT_EQ(1u, layer->children().size()); | 1868 EXPECT_EQ(1u, layer->children().size()); |
1843 } | 1869 } |
1844 | 1870 |
1845 // Ensure that acquiring a layer then recreating a layer does not crash | 1871 // Ensure that acquiring a layer then recreating a layer does not crash |
1846 // and that RecreateLayer returns null. | 1872 // and that RecreateLayer returns null. |
1847 TEST_F(WindowTest, AcquireThenRecreateLayer) { | 1873 TEST_F(WindowTest, AcquireThenRecreateLayer) { |
1848 scoped_ptr<Window> w( | 1874 scoped_ptr<Window> w( |
1849 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), NULL)); | 1875 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), |
| 1876 root_window())); |
1850 scoped_ptr<ui::Layer>acquired_layer(w->AcquireLayer()); | 1877 scoped_ptr<ui::Layer>acquired_layer(w->AcquireLayer()); |
1851 scoped_ptr<ui::Layer>doubly_acquired_layer(w->RecreateLayer()); | 1878 scoped_ptr<ui::Layer>doubly_acquired_layer(w->RecreateLayer()); |
1852 EXPECT_EQ(NULL, doubly_acquired_layer.get()); | 1879 EXPECT_EQ(NULL, doubly_acquired_layer.get()); |
1853 | 1880 |
1854 // Destroy window before layer gets destroyed. | 1881 // Destroy window before layer gets destroyed. |
1855 w.reset(); | 1882 w.reset(); |
1856 } | 1883 } |
1857 | 1884 |
1858 TEST_F(WindowTest, StackWindowsWhoseLayersHaveNoDelegate) { | 1885 TEST_F(WindowTest, StackWindowsWhoseLayersHaveNoDelegate) { |
1859 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); | 1886 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
1860 scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); | 1887 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); |
1861 | 1888 |
1862 // This brings window1 (and its layer) to the front. | 1889 // This brings window1 (and its layer) to the front. |
1863 root_window()->StackChildAbove(window1.get(), window2.get()); | 1890 root_window()->StackChildAbove(window1.get(), window2.get()); |
1864 EXPECT_EQ(root_window()->children().front(), window2.get()); | 1891 EXPECT_EQ(root_window()->children().front(), window2.get()); |
1865 EXPECT_EQ(root_window()->children().back(), window1.get()); | 1892 EXPECT_EQ(root_window()->children().back(), window1.get()); |
1866 EXPECT_EQ(root_window()->layer()->children().front(), window2->layer()); | 1893 EXPECT_EQ(root_window()->layer()->children().front(), window2->layer()); |
1867 EXPECT_EQ(root_window()->layer()->children().back(), window1->layer()); | 1894 EXPECT_EQ(root_window()->layer()->children().back(), window1->layer()); |
1868 | 1895 |
1869 // Since window1 does not have a delegate, window2 should not move in | 1896 // Since window1 does not have a delegate, window2 should not move in |
1870 // front of it, nor should its layer. | 1897 // front of it, nor should its layer. |
1871 window1->layer()->set_delegate(NULL); | 1898 window1->layer()->set_delegate(NULL); |
1872 root_window()->StackChildAbove(window2.get(), window1.get()); | 1899 root_window()->StackChildAbove(window2.get(), window1.get()); |
1873 EXPECT_EQ(root_window()->children().front(), window2.get()); | 1900 EXPECT_EQ(root_window()->children().front(), window2.get()); |
1874 EXPECT_EQ(root_window()->children().back(), window1.get()); | 1901 EXPECT_EQ(root_window()->children().back(), window1.get()); |
1875 EXPECT_EQ(root_window()->layer()->children().front(), window2->layer()); | 1902 EXPECT_EQ(root_window()->layer()->children().front(), window2->layer()); |
1876 EXPECT_EQ(root_window()->layer()->children().back(), window1->layer()); | 1903 EXPECT_EQ(root_window()->layer()->children().back(), window1->layer()); |
1877 } | 1904 } |
1878 | 1905 |
1879 TEST_F(WindowTest, StackTransientsWhoseLayersHaveNoDelegate) { | 1906 TEST_F(WindowTest, StackTransientsWhoseLayersHaveNoDelegate) { |
1880 RootWindow* root = root_window(); | 1907 RootWindow* root = root_window(); |
1881 | 1908 |
1882 // Create a window with several transients, then a couple windows on top. | 1909 // Create a window with several transients, then a couple windows on top. |
1883 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); | 1910 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
1884 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get())); | 1911 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get())); |
1885 scoped_ptr<Window> window12(CreateTransientChild(12, window1.get())); | 1912 scoped_ptr<Window> window12(CreateTransientChild(12, window1.get())); |
1886 scoped_ptr<Window> window13(CreateTransientChild(13, window1.get())); | 1913 scoped_ptr<Window> window13(CreateTransientChild(13, window1.get())); |
1887 scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); | 1914 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); |
1888 scoped_ptr<Window> window3(CreateTestWindowWithId(3, NULL)); | 1915 scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window())); |
1889 | 1916 |
1890 EXPECT_EQ("1 11 12 13 2 3", ChildWindowIDsAsString(root)); | 1917 EXPECT_EQ("1 11 12 13 2 3", ChildWindowIDsAsString(root)); |
1891 | 1918 |
1892 // Remove the delegates of a couple of transients, as if they are closing | 1919 // Remove the delegates of a couple of transients, as if they are closing |
1893 // and animating out. | 1920 // and animating out. |
1894 window11->layer()->set_delegate(NULL); | 1921 window11->layer()->set_delegate(NULL); |
1895 window13->layer()->set_delegate(NULL); | 1922 window13->layer()->set_delegate(NULL); |
1896 | 1923 |
1897 // Move window1 to the front. All transients should move with it, and their | 1924 // Move window1 to the front. All transients should move with it, and their |
1898 // order should be preserved. | 1925 // order should be preserved. |
(...skipping 23 matching lines...) Expand all Loading... |
1922 } | 1949 } |
1923 | 1950 |
1924 private: | 1951 private: |
1925 bool ignore_visibility_changes_; | 1952 bool ignore_visibility_changes_; |
1926 DISALLOW_COPY_AND_ASSIGN(TestVisibilityClient); | 1953 DISALLOW_COPY_AND_ASSIGN(TestVisibilityClient); |
1927 }; | 1954 }; |
1928 | 1955 |
1929 TEST_F(WindowTest, VisibilityClientIsVisible) { | 1956 TEST_F(WindowTest, VisibilityClientIsVisible) { |
1930 TestVisibilityClient client(root_window()); | 1957 TestVisibilityClient client(root_window()); |
1931 | 1958 |
1932 scoped_ptr<Window> window(CreateTestWindowWithId(1, NULL)); | 1959 scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window())); |
1933 EXPECT_TRUE(window->IsVisible()); | 1960 EXPECT_TRUE(window->IsVisible()); |
1934 EXPECT_TRUE(window->layer()->visible()); | 1961 EXPECT_TRUE(window->layer()->visible()); |
1935 | 1962 |
1936 window->Hide(); | 1963 window->Hide(); |
1937 EXPECT_FALSE(window->IsVisible()); | 1964 EXPECT_FALSE(window->IsVisible()); |
1938 EXPECT_FALSE(window->layer()->visible()); | 1965 EXPECT_FALSE(window->layer()->visible()); |
1939 window->Show(); | 1966 window->Show(); |
1940 | 1967 |
1941 client.set_ignore_visibility_changes(true); | 1968 client.set_ignore_visibility_changes(true); |
1942 window->Hide(); | 1969 window->Hide(); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 // should not be adjusted. | 2135 // should not be adjusted. |
2109 // One issue that can arise when a window opens two transient children, and the | 2136 // One issue that can arise when a window opens two transient children, and the |
2110 // first is hidden. Subsequent attempts to activate the transient parent can | 2137 // first is hidden. Subsequent attempts to activate the transient parent can |
2111 // result in the transient parent being stacked above the second transient | 2138 // result in the transient parent being stacked above the second transient |
2112 // child. A fix is made to Window::StackAbove to prevent this, and this test | 2139 // child. A fix is made to Window::StackAbove to prevent this, and this test |
2113 // verifies this fix. | 2140 // verifies this fix. |
2114 TEST_F(WindowTest, StackingMadrigal) { | 2141 TEST_F(WindowTest, StackingMadrigal) { |
2115 new StackingMadrigalLayoutManager(root_window()); | 2142 new StackingMadrigalLayoutManager(root_window()); |
2116 StackingMadrigalVisibilityClient visibility_client(root_window()); | 2143 StackingMadrigalVisibilityClient visibility_client(root_window()); |
2117 | 2144 |
2118 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); | 2145 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
2119 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get())); | 2146 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get())); |
2120 | 2147 |
2121 visibility_client.set_ignored_window(window11.get()); | 2148 visibility_client.set_ignored_window(window11.get()); |
2122 | 2149 |
2123 window11->Show(); | 2150 window11->Show(); |
2124 window11->Hide(); | 2151 window11->Hide(); |
2125 | 2152 |
2126 // As a transient, window11 should still be stacked above window1, even when | 2153 // As a transient, window11 should still be stacked above window1, even when |
2127 // hidden. | 2154 // hidden. |
2128 EXPECT_TRUE(WindowIsAbove(window11.get(), window1.get())); | 2155 EXPECT_TRUE(WindowIsAbove(window11.get(), window1.get())); |
(...skipping 17 matching lines...) Expand all Loading... |
2146 | 2173 |
2147 // Both window12 and its layer should be stacked above window1. | 2174 // Both window12 and its layer should be stacked above window1. |
2148 EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get())); | 2175 EXPECT_TRUE(WindowIsAbove(window12.get(), window1.get())); |
2149 EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get())); | 2176 EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get())); |
2150 } | 2177 } |
2151 | 2178 |
2152 // Test for an issue where attempting to stack a primary window on top of a | 2179 // Test for an issue where attempting to stack a primary window on top of a |
2153 // transient with a NULL layer delegate causes that primary window to be moved, | 2180 // transient with a NULL layer delegate causes that primary window to be moved, |
2154 // but the layer order not changed to match. http://crbug.com/112562 | 2181 // but the layer order not changed to match. http://crbug.com/112562 |
2155 TEST_F(WindowTest, StackOverClosingTransient) { | 2182 TEST_F(WindowTest, StackOverClosingTransient) { |
2156 scoped_ptr<Window> window1(CreateTestWindowWithId(1, NULL)); | 2183 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
2157 scoped_ptr<Window> transient1(CreateTransientChild(11, window1.get())); | 2184 scoped_ptr<Window> transient1(CreateTransientChild(11, window1.get())); |
2158 scoped_ptr<Window> window2(CreateTestWindowWithId(2, NULL)); | 2185 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); |
2159 scoped_ptr<Window> transient2(CreateTransientChild(21, window2.get())); | 2186 scoped_ptr<Window> transient2(CreateTransientChild(21, window2.get())); |
2160 | 2187 |
2161 // Both windows and layers are stacked in creation order. | 2188 // Both windows and layers are stacked in creation order. |
2162 RootWindow* root = root_window(); | 2189 RootWindow* root = root_window(); |
2163 ASSERT_EQ(4u, root->children().size()); | 2190 ASSERT_EQ(4u, root->children().size()); |
2164 EXPECT_EQ(root->children()[0], window1.get()); | 2191 EXPECT_EQ(root->children()[0], window1.get()); |
2165 EXPECT_EQ(root->children()[1], transient1.get()); | 2192 EXPECT_EQ(root->children()[1], transient1.get()); |
2166 EXPECT_EQ(root->children()[2], window2.get()); | 2193 EXPECT_EQ(root->children()[2], window2.get()); |
2167 EXPECT_EQ(root->children()[3], transient2.get()); | 2194 EXPECT_EQ(root->children()[3], transient2.get()); |
2168 ASSERT_EQ(4u, root->layer()->children().size()); | 2195 ASSERT_EQ(4u, root->layer()->children().size()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2205 ASSERT_EQ(3u, root->children().size()); | 2232 ASSERT_EQ(3u, root->children().size()); |
2206 EXPECT_EQ(root->children()[0], window1.get()); | 2233 EXPECT_EQ(root->children()[0], window1.get()); |
2207 EXPECT_EQ(root->children()[1], window2.get()); | 2234 EXPECT_EQ(root->children()[1], window2.get()); |
2208 EXPECT_EQ(root->children()[2], transient2.get()); | 2235 EXPECT_EQ(root->children()[2], transient2.get()); |
2209 ASSERT_EQ(3u, root->layer()->children().size()); | 2236 ASSERT_EQ(3u, root->layer()->children().size()); |
2210 EXPECT_EQ(root->layer()->children()[0], window1->layer()); | 2237 EXPECT_EQ(root->layer()->children()[0], window1->layer()); |
2211 EXPECT_EQ(root->layer()->children()[1], window2->layer()); | 2238 EXPECT_EQ(root->layer()->children()[1], window2->layer()); |
2212 EXPECT_EQ(root->layer()->children()[2], transient2->layer()); | 2239 EXPECT_EQ(root->layer()->children()[2], transient2->layer()); |
2213 | 2240 |
2214 // Open another window on top. | 2241 // Open another window on top. |
2215 scoped_ptr<Window> window3(CreateTestWindowWithId(3, NULL)); | 2242 scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window())); |
2216 | 2243 |
2217 ASSERT_EQ(4u, root->children().size()); | 2244 ASSERT_EQ(4u, root->children().size()); |
2218 EXPECT_EQ(root->children()[0], window1.get()); | 2245 EXPECT_EQ(root->children()[0], window1.get()); |
2219 EXPECT_EQ(root->children()[1], window2.get()); | 2246 EXPECT_EQ(root->children()[1], window2.get()); |
2220 EXPECT_EQ(root->children()[2], transient2.get()); | 2247 EXPECT_EQ(root->children()[2], transient2.get()); |
2221 EXPECT_EQ(root->children()[3], window3.get()); | 2248 EXPECT_EQ(root->children()[3], window3.get()); |
2222 ASSERT_EQ(4u, root->layer()->children().size()); | 2249 ASSERT_EQ(4u, root->layer()->children().size()); |
2223 EXPECT_EQ(root->layer()->children()[0], window1->layer()); | 2250 EXPECT_EQ(root->layer()->children()[0], window1->layer()); |
2224 EXPECT_EQ(root->layer()->children()[1], window2->layer()); | 2251 EXPECT_EQ(root->layer()->children()[1], window2->layer()); |
2225 EXPECT_EQ(root->layer()->children()[2], transient2->layer()); | 2252 EXPECT_EQ(root->layer()->children()[2], transient2->layer()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2286 }; | 2313 }; |
2287 | 2314 |
2288 TEST_F(WindowTest, RootWindowAttachment) { | 2315 TEST_F(WindowTest, RootWindowAttachment) { |
2289 RootWindowAttachmentObserver observer; | 2316 RootWindowAttachmentObserver observer; |
2290 | 2317 |
2291 // Test a direct add/remove from the RootWindow. | 2318 // Test a direct add/remove from the RootWindow. |
2292 scoped_ptr<Window> w1(new Window(NULL)); | 2319 scoped_ptr<Window> w1(new Window(NULL)); |
2293 w1->Init(ui::LAYER_NOT_DRAWN); | 2320 w1->Init(ui::LAYER_NOT_DRAWN); |
2294 w1->AddObserver(&observer); | 2321 w1->AddObserver(&observer); |
2295 | 2322 |
2296 w1->SetParent(NULL); | 2323 SetDefaultParentByPrimaryRootWindow(w1.get()); |
2297 EXPECT_EQ(1, observer.added_count()); | 2324 EXPECT_EQ(1, observer.added_count()); |
2298 EXPECT_EQ(0, observer.removed_count()); | 2325 EXPECT_EQ(0, observer.removed_count()); |
2299 | 2326 |
2300 w1.reset(); | 2327 w1.reset(); |
2301 EXPECT_EQ(1, observer.added_count()); | 2328 EXPECT_EQ(1, observer.added_count()); |
2302 EXPECT_EQ(1, observer.removed_count()); | 2329 EXPECT_EQ(1, observer.removed_count()); |
2303 | 2330 |
2304 observer.Clear(); | 2331 observer.Clear(); |
2305 | 2332 |
2306 // Test an indirect add/remove from the RootWindow. | 2333 // Test an indirect add/remove from the RootWindow. |
2307 w1.reset(new Window(NULL)); | 2334 w1.reset(new Window(NULL)); |
2308 w1->Init(ui::LAYER_NOT_DRAWN); | 2335 w1->Init(ui::LAYER_NOT_DRAWN); |
2309 Window* w11 = new Window(NULL); | 2336 Window* w11 = new Window(NULL); |
2310 w11->Init(ui::LAYER_NOT_DRAWN); | 2337 w11->Init(ui::LAYER_NOT_DRAWN); |
2311 w11->AddObserver(&observer); | 2338 w11->AddObserver(&observer); |
2312 w11->SetParent(w1.get()); | 2339 w1->AddChild(w11); |
2313 EXPECT_EQ(0, observer.added_count()); | 2340 EXPECT_EQ(0, observer.added_count()); |
2314 EXPECT_EQ(0, observer.removed_count()); | 2341 EXPECT_EQ(0, observer.removed_count()); |
2315 | 2342 |
2316 w1->SetParent(NULL); | 2343 SetDefaultParentByPrimaryRootWindow(w1.get()); |
2317 EXPECT_EQ(1, observer.added_count()); | 2344 EXPECT_EQ(1, observer.added_count()); |
2318 EXPECT_EQ(0, observer.removed_count()); | 2345 EXPECT_EQ(0, observer.removed_count()); |
2319 | 2346 |
2320 w1.reset(); // Deletes w11. | 2347 w1.reset(); // Deletes w11. |
2321 w11 = NULL; | 2348 w11 = NULL; |
2322 EXPECT_EQ(1, observer.added_count()); | 2349 EXPECT_EQ(1, observer.added_count()); |
2323 EXPECT_EQ(1, observer.removed_count()); | 2350 EXPECT_EQ(1, observer.removed_count()); |
2324 | 2351 |
2325 observer.Clear(); | 2352 observer.Clear(); |
2326 | 2353 |
2327 // Test an indirect add/remove with nested observers. | 2354 // Test an indirect add/remove with nested observers. |
2328 w1.reset(new Window(NULL)); | 2355 w1.reset(new Window(NULL)); |
2329 w1->Init(ui::LAYER_NOT_DRAWN); | 2356 w1->Init(ui::LAYER_NOT_DRAWN); |
2330 w11 = new Window(NULL); | 2357 w11 = new Window(NULL); |
2331 w11->Init(ui::LAYER_NOT_DRAWN); | 2358 w11->Init(ui::LAYER_NOT_DRAWN); |
2332 w11->AddObserver(&observer); | 2359 w11->AddObserver(&observer); |
2333 w11->SetParent(w1.get()); | 2360 w1->AddChild(w11); |
2334 Window* w111 = new Window(NULL); | 2361 Window* w111 = new Window(NULL); |
2335 w111->Init(ui::LAYER_NOT_DRAWN); | 2362 w111->Init(ui::LAYER_NOT_DRAWN); |
2336 w111->AddObserver(&observer); | 2363 w111->AddObserver(&observer); |
2337 w111->SetParent(w11); | 2364 w11->AddChild(w111); |
2338 | 2365 |
2339 EXPECT_EQ(0, observer.added_count()); | 2366 EXPECT_EQ(0, observer.added_count()); |
2340 EXPECT_EQ(0, observer.removed_count()); | 2367 EXPECT_EQ(0, observer.removed_count()); |
2341 | 2368 |
2342 w1->SetParent(NULL); | 2369 SetDefaultParentByPrimaryRootWindow(w1.get()); |
2343 EXPECT_EQ(2, observer.added_count()); | 2370 EXPECT_EQ(2, observer.added_count()); |
2344 EXPECT_EQ(0, observer.removed_count()); | 2371 EXPECT_EQ(0, observer.removed_count()); |
2345 | 2372 |
2346 w1.reset(); // Deletes w11 and w111. | 2373 w1.reset(); // Deletes w11 and w111. |
2347 w11 = NULL; | 2374 w11 = NULL; |
2348 w111 = NULL; | 2375 w111 = NULL; |
2349 EXPECT_EQ(2, observer.added_count()); | 2376 EXPECT_EQ(2, observer.added_count()); |
2350 EXPECT_EQ(2, observer.removed_count()); | 2377 EXPECT_EQ(2, observer.removed_count()); |
2351 } | 2378 } |
2352 | 2379 |
2353 TEST_F(WindowTest, OwnedByParentFalse) { | 2380 TEST_F(WindowTest, OwnedByParentFalse) { |
2354 // By default, a window is owned by its parent. If this is set to false, the | 2381 // By default, a window is owned by its parent. If this is set to false, the |
2355 // window will not be destroyed when its parent is. | 2382 // window will not be destroyed when its parent is. |
2356 | 2383 |
2357 scoped_ptr<Window> w1(new Window(NULL)); | 2384 scoped_ptr<Window> w1(new Window(NULL)); |
2358 w1->Init(ui::LAYER_NOT_DRAWN); | 2385 w1->Init(ui::LAYER_NOT_DRAWN); |
2359 scoped_ptr<Window> w2(new Window(NULL)); | 2386 scoped_ptr<Window> w2(new Window(NULL)); |
2360 w2->set_owned_by_parent(false); | 2387 w2->set_owned_by_parent(false); |
2361 w2->Init(ui::LAYER_NOT_DRAWN); | 2388 w2->Init(ui::LAYER_NOT_DRAWN); |
2362 w2->SetParent(w1.get()); | 2389 w1->AddChild(w2.get()); |
2363 | 2390 |
2364 w1.reset(); | 2391 w1.reset(); |
2365 | 2392 |
2366 // We should be able to deref w2 still, but its parent should now be NULL. | 2393 // We should be able to deref w2 still, but its parent should now be NULL. |
2367 EXPECT_EQ(NULL, w2->parent()); | 2394 EXPECT_EQ(NULL, w2->parent()); |
2368 } | 2395 } |
2369 | 2396 |
2370 namespace { | 2397 namespace { |
2371 | 2398 |
2372 // Used By DeleteWindowFromOnWindowDestroyed. Destroys a Window from | 2399 // Used By DeleteWindowFromOnWindowDestroyed. Destroys a Window from |
(...skipping 22 matching lines...) Expand all Loading... |
2395 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. | 2422 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. |
2396 // This synthesizes BrowserView and the status bubble. Both are children of the | 2423 // This synthesizes BrowserView and the status bubble. Both are children of the |
2397 // same parent and destroying BrowserView triggers it destroying the status | 2424 // same parent and destroying BrowserView triggers it destroying the status |
2398 // bubble. | 2425 // bubble. |
2399 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { | 2426 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { |
2400 scoped_ptr<Window> parent(new Window(NULL)); | 2427 scoped_ptr<Window> parent(new Window(NULL)); |
2401 parent->Init(ui::LAYER_NOT_DRAWN); | 2428 parent->Init(ui::LAYER_NOT_DRAWN); |
2402 OwningWindowDelegate delegate; | 2429 OwningWindowDelegate delegate; |
2403 Window* c1 = new Window(&delegate); | 2430 Window* c1 = new Window(&delegate); |
2404 c1->Init(ui::LAYER_NOT_DRAWN); | 2431 c1->Init(ui::LAYER_NOT_DRAWN); |
2405 c1->SetParent(parent.get()); | 2432 parent->AddChild(c1); |
2406 Window* c2 = new Window(NULL); | 2433 Window* c2 = new Window(NULL); |
2407 c2->Init(ui::LAYER_NOT_DRAWN); | 2434 c2->Init(ui::LAYER_NOT_DRAWN); |
2408 c2->SetParent(parent.get()); | 2435 parent->AddChild(c2); |
2409 delegate.SetOwnedWindow(c2); | 2436 delegate.SetOwnedWindow(c2); |
2410 parent.reset(); | 2437 parent.reset(); |
2411 } | 2438 } |
2412 | 2439 |
2413 namespace { | 2440 namespace { |
2414 | 2441 |
2415 // Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is | 2442 // Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is |
2416 // invoked. | 2443 // invoked. |
2417 class BoundsChangeDelegate : public TestWindowDelegate { | 2444 class BoundsChangeDelegate : public TestWindowDelegate { |
2418 public: | 2445 public: |
(...skipping 22 matching lines...) Expand all Loading... |
2441 // Verifies the delegate is notified when the actual bounds of the layer | 2468 // Verifies the delegate is notified when the actual bounds of the layer |
2442 // change. | 2469 // change. |
2443 TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) { | 2470 TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) { |
2444 BoundsChangeDelegate delegate; | 2471 BoundsChangeDelegate delegate; |
2445 | 2472 |
2446 // We cannot short-circuit animations in this test. | 2473 // We cannot short-circuit animations in this test. |
2447 ui::LayerAnimator::set_disable_animations_for_test(false); | 2474 ui::LayerAnimator::set_disable_animations_for_test(false); |
2448 | 2475 |
2449 scoped_ptr<Window> window( | 2476 scoped_ptr<Window> window( |
2450 CreateTestWindowWithDelegate(&delegate, 1, | 2477 CreateTestWindowWithDelegate(&delegate, 1, |
2451 gfx::Rect(0, 0, 100, 100), NULL)); | 2478 gfx::Rect(0, 0, 100, 100), root_window())); |
2452 window->layer()->GetAnimator()->set_disable_timer_for_test(true); | 2479 window->layer()->GetAnimator()->set_disable_timer_for_test(true); |
2453 | 2480 |
2454 delegate.clear_bounds_changed(); | 2481 delegate.clear_bounds_changed(); |
2455 | 2482 |
2456 // Animate to a different position. | 2483 // Animate to a different position. |
2457 { | 2484 { |
2458 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 2485 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
2459 window->SetBounds(gfx::Rect(100, 100, 100, 100)); | 2486 window->SetBounds(gfx::Rect(100, 100, 100, 100)); |
2460 } | 2487 } |
2461 | 2488 |
(...skipping 13 matching lines...) Expand all Loading... |
2475 // Verifies the delegate is notified when the actual bounds of the layer | 2502 // Verifies the delegate is notified when the actual bounds of the layer |
2476 // change even when the window is not the layer's delegate | 2503 // change even when the window is not the layer's delegate |
2477 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { | 2504 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { |
2478 BoundsChangeDelegate delegate; | 2505 BoundsChangeDelegate delegate; |
2479 | 2506 |
2480 // We cannot short-circuit animations in this test. | 2507 // We cannot short-circuit animations in this test. |
2481 ui::LayerAnimator::set_disable_animations_for_test(false); | 2508 ui::LayerAnimator::set_disable_animations_for_test(false); |
2482 | 2509 |
2483 scoped_ptr<Window> window( | 2510 scoped_ptr<Window> window( |
2484 CreateTestWindowWithDelegate(&delegate, 1, | 2511 CreateTestWindowWithDelegate(&delegate, 1, |
2485 gfx::Rect(0, 0, 100, 100), NULL)); | 2512 gfx::Rect(0, 0, 100, 100), root_window())); |
2486 window->layer()->GetAnimator()->set_disable_timer_for_test(true); | 2513 window->layer()->GetAnimator()->set_disable_timer_for_test(true); |
2487 | 2514 |
2488 delegate.clear_bounds_changed(); | 2515 delegate.clear_bounds_changed(); |
2489 | 2516 |
2490 // Suppress paint on the window since it is hidden (should reset the layer's | 2517 // Suppress paint on the window since it is hidden (should reset the layer's |
2491 // delegate to NULL) | 2518 // delegate to NULL) |
2492 window->SuppressPaint(); | 2519 window->SuppressPaint(); |
2493 EXPECT_EQ(NULL, window->layer()->delegate()); | 2520 EXPECT_EQ(NULL, window->layer()->delegate()); |
2494 | 2521 |
2495 // Animate to a different position. | 2522 // Animate to a different position. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2543 int removed_count_; | 2570 int removed_count_; |
2544 | 2571 |
2545 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); | 2572 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); |
2546 }; | 2573 }; |
2547 | 2574 |
2548 } // namespace | 2575 } // namespace |
2549 | 2576 |
2550 // Assertions around when root window notifications are sent. | 2577 // Assertions around when root window notifications are sent. |
2551 TEST_F(WindowTest, AddChildNotifications) { | 2578 TEST_F(WindowTest, AddChildNotifications) { |
2552 AddChildNotificationsObserver observer; | 2579 AddChildNotificationsObserver observer; |
2553 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 2580 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
2554 scoped_ptr<Window> w2(CreateTestWindowWithId(1, NULL)); | 2581 scoped_ptr<Window> w2(CreateTestWindowWithId(1, root_window())); |
2555 w2->AddObserver(&observer); | 2582 w2->AddObserver(&observer); |
2556 w2->Focus(); | 2583 w2->Focus(); |
2557 EXPECT_TRUE(w2->HasFocus()); | 2584 EXPECT_TRUE(w2->HasFocus()); |
2558 | 2585 |
2559 // Move |w2| to be a child of |w1|. | 2586 // Move |w2| to be a child of |w1|. |
2560 w1->AddChild(w2.get()); | 2587 w1->AddChild(w2.get()); |
2561 // Sine we moved in the same root, observer shouldn't be notified. | 2588 // Sine we moved in the same root, observer shouldn't be notified. |
2562 EXPECT_EQ("0 0", observer.CountStringAndReset()); | 2589 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
2563 // |w2| should still have focus after moving. | 2590 // |w2| should still have focus after moving. |
2564 EXPECT_TRUE(w2->HasFocus()); | 2591 EXPECT_TRUE(w2->HasFocus()); |
2565 } | 2592 } |
2566 | 2593 |
2567 } // namespace test | 2594 } // namespace test |
2568 } // namespace aura | 2595 } // namespace aura |
OLD | NEW |