| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 } // namespace | 121 } // namespace |
| 122 | 122 |
| 123 DECLARE_WINDOW_PROPERTY_TYPE(TestProperty*); | 123 DECLARE_WINDOW_PROPERTY_TYPE(TestProperty*); |
| 124 | 124 |
| 125 DECLARE_WINDOW_PROPERTY_TYPE(DeletionTestProperty*); | 125 DECLARE_WINDOW_PROPERTY_TYPE(DeletionTestProperty*); |
| 126 | 126 |
| 127 namespace aura { | 127 namespace aura { |
| 128 namespace test { | 128 namespace test { |
| 129 | 129 |
| 130 class WindowTest : public AuraTestBase { | 130 class WindowTest : public AuraTestBaseWithType { |
| 131 public: | 131 public: |
| 132 WindowTest() : max_separation_(0) { | 132 WindowTest() : max_separation_(0) { |
| 133 } | 133 } |
| 134 | 134 |
| 135 void SetUp() override { | 135 void SetUp() override { |
| 136 AuraTestBase::SetUp(); | 136 AuraTestBaseWithType::SetUp(); |
| 137 // TODO: there needs to be an easier way to do this. | 137 // TODO: there needs to be an easier way to do this. |
| 138 max_separation_ = ui::GestureConfiguration::GetInstance() | 138 max_separation_ = ui::GestureConfiguration::GetInstance() |
| 139 ->max_separation_for_gesture_touches_in_pixels(); | 139 ->max_separation_for_gesture_touches_in_pixels(); |
| 140 ui::GestureConfiguration::GetInstance() | 140 ui::GestureConfiguration::GetInstance() |
| 141 ->set_max_separation_for_gesture_touches_in_pixels(0); | 141 ->set_max_separation_for_gesture_touches_in_pixels(0); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void TearDown() override { | 144 void TearDown() override { |
| 145 AuraTestBase::TearDown(); | 145 AuraTestBase::TearDown(); |
| 146 ui::GestureConfiguration::GetInstance() | 146 ui::GestureConfiguration::GetInstance() |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 }; | 324 }; |
| 325 | 325 |
| 326 void OffsetBounds(Window* window, int horizontal, int vertical) { | 326 void OffsetBounds(Window* window, int horizontal, int vertical) { |
| 327 gfx::Rect bounds = window->bounds(); | 327 gfx::Rect bounds = window->bounds(); |
| 328 bounds.Offset(horizontal, vertical); | 328 bounds.Offset(horizontal, vertical); |
| 329 window->SetBounds(bounds); | 329 window->SetBounds(bounds); |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace | 332 } // namespace |
| 333 | 333 |
| 334 TEST_F(WindowTest, GetChildById) { | 334 TEST_P(WindowTest, GetChildById) { |
| 335 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 335 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 336 std::unique_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); | 336 std::unique_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); |
| 337 std::unique_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 337 std::unique_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
| 338 std::unique_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); | 338 std::unique_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); |
| 339 | 339 |
| 340 EXPECT_EQ(NULL, w1->GetChildById(57)); | 340 EXPECT_EQ(NULL, w1->GetChildById(57)); |
| 341 EXPECT_EQ(w12.get(), w1->GetChildById(12)); | 341 EXPECT_EQ(w12.get(), w1->GetChildById(12)); |
| 342 EXPECT_EQ(w111.get(), w1->GetChildById(111)); | 342 EXPECT_EQ(w111.get(), w1->GetChildById(111)); |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Make sure that Window::Contains correctly handles children, grandchildren, | 345 // Make sure that Window::Contains correctly handles children, grandchildren, |
| 346 // and not containing NULL or parents. | 346 // and not containing NULL or parents. |
| 347 TEST_F(WindowTest, Contains) { | 347 TEST_P(WindowTest, Contains) { |
| 348 Window parent(NULL); | 348 Window parent(NULL); |
| 349 parent.Init(ui::LAYER_NOT_DRAWN); | 349 parent.Init(ui::LAYER_NOT_DRAWN); |
| 350 Window child1(NULL); | 350 Window child1(NULL); |
| 351 child1.Init(ui::LAYER_NOT_DRAWN); | 351 child1.Init(ui::LAYER_NOT_DRAWN); |
| 352 Window child2(NULL); | 352 Window child2(NULL); |
| 353 child2.Init(ui::LAYER_NOT_DRAWN); | 353 child2.Init(ui::LAYER_NOT_DRAWN); |
| 354 | 354 |
| 355 parent.AddChild(&child1); | 355 parent.AddChild(&child1); |
| 356 child1.AddChild(&child2); | 356 child1.AddChild(&child2); |
| 357 | 357 |
| 358 EXPECT_TRUE(parent.Contains(&parent)); | 358 EXPECT_TRUE(parent.Contains(&parent)); |
| 359 EXPECT_TRUE(parent.Contains(&child1)); | 359 EXPECT_TRUE(parent.Contains(&child1)); |
| 360 EXPECT_TRUE(parent.Contains(&child2)); | 360 EXPECT_TRUE(parent.Contains(&child2)); |
| 361 | 361 |
| 362 EXPECT_FALSE(parent.Contains(NULL)); | 362 EXPECT_FALSE(parent.Contains(NULL)); |
| 363 EXPECT_FALSE(child1.Contains(&parent)); | 363 EXPECT_FALSE(child1.Contains(&parent)); |
| 364 EXPECT_FALSE(child2.Contains(&child1)); | 364 EXPECT_FALSE(child2.Contains(&child1)); |
| 365 } | 365 } |
| 366 | 366 |
| 367 TEST_F(WindowTest, ContainsPointInRoot) { | 367 TEST_P(WindowTest, ContainsPointInRoot) { |
| 368 std::unique_ptr<Window> w(CreateTestWindow( | 368 std::unique_ptr<Window> w(CreateTestWindow( |
| 369 SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), root_window())); | 369 SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), root_window())); |
| 370 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9))); | 370 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(9, 9))); |
| 371 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10))); | 371 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(10, 10))); |
| 372 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14))); | 372 EXPECT_TRUE(w->ContainsPointInRoot(gfx::Point(14, 14))); |
| 373 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15))); | 373 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(15, 15))); |
| 374 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20))); | 374 EXPECT_FALSE(w->ContainsPointInRoot(gfx::Point(20, 20))); |
| 375 } | 375 } |
| 376 | 376 |
| 377 TEST_F(WindowTest, ContainsPoint) { | 377 TEST_P(WindowTest, ContainsPoint) { |
| 378 std::unique_ptr<Window> w(CreateTestWindow( | 378 std::unique_ptr<Window> w(CreateTestWindow( |
| 379 SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), root_window())); | 379 SK_ColorWHITE, 1, gfx::Rect(10, 10, 5, 5), root_window())); |
| 380 EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0))); | 380 EXPECT_TRUE(w->ContainsPoint(gfx::Point(0, 0))); |
| 381 EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4))); | 381 EXPECT_TRUE(w->ContainsPoint(gfx::Point(4, 4))); |
| 382 EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5))); | 382 EXPECT_FALSE(w->ContainsPoint(gfx::Point(5, 5))); |
| 383 EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10))); | 383 EXPECT_FALSE(w->ContainsPoint(gfx::Point(10, 10))); |
| 384 } | 384 } |
| 385 | 385 |
| 386 TEST_F(WindowTest, ConvertPointToWindow) { | 386 TEST_P(WindowTest, ConvertPointToWindow) { |
| 387 // Window::ConvertPointToWindow is mostly identical to | 387 // Window::ConvertPointToWindow is mostly identical to |
| 388 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, | 388 // Layer::ConvertPointToLayer, except NULL values for |source| are permitted, |
| 389 // in which case the function just returns. | 389 // in which case the function just returns. |
| 390 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 390 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 391 gfx::Point reference_point(100, 100); | 391 gfx::Point reference_point(100, 100); |
| 392 gfx::Point test_point = reference_point; | 392 gfx::Point test_point = reference_point; |
| 393 Window::ConvertPointToTarget(NULL, w1.get(), &test_point); | 393 Window::ConvertPointToTarget(NULL, w1.get(), &test_point); |
| 394 EXPECT_EQ(reference_point, test_point); | 394 EXPECT_EQ(reference_point, test_point); |
| 395 } | 395 } |
| 396 | 396 |
| 397 TEST_F(WindowTest, MoveCursorTo) { | 397 TEST_P(WindowTest, MoveCursorTo) { |
| 398 std::unique_ptr<Window> w1(CreateTestWindow( | 398 std::unique_ptr<Window> w1(CreateTestWindow( |
| 399 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); | 399 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 400 std::unique_ptr<Window> w11( | 400 std::unique_ptr<Window> w11( |
| 401 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 401 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 402 std::unique_ptr<Window> w111( | 402 std::unique_ptr<Window> w111( |
| 403 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 403 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 404 std::unique_ptr<Window> w1111( | 404 std::unique_ptr<Window> w1111( |
| 405 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 405 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 406 | 406 |
| 407 Window* root = root_window(); | 407 Window* root = root_window(); |
| 408 root->MoveCursorTo(gfx::Point(10, 10)); | 408 root->MoveCursorTo(gfx::Point(10, 10)); |
| 409 EXPECT_EQ("10,10", | 409 EXPECT_EQ("10,10", |
| 410 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 410 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 411 w1->MoveCursorTo(gfx::Point(10, 10)); | 411 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 412 EXPECT_EQ("20,20", | 412 EXPECT_EQ("20,20", |
| 413 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 413 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 414 w11->MoveCursorTo(gfx::Point(10, 10)); | 414 w11->MoveCursorTo(gfx::Point(10, 10)); |
| 415 EXPECT_EQ("25,25", | 415 EXPECT_EQ("25,25", |
| 416 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 416 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 417 w111->MoveCursorTo(gfx::Point(10, 10)); | 417 w111->MoveCursorTo(gfx::Point(10, 10)); |
| 418 EXPECT_EQ("30,30", | 418 EXPECT_EQ("30,30", |
| 419 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 419 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 420 w1111->MoveCursorTo(gfx::Point(10, 10)); | 420 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 421 EXPECT_EQ("35,35", | 421 EXPECT_EQ("35,35", |
| 422 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 422 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 423 } | 423 } |
| 424 | 424 |
| 425 TEST_F(WindowTest, ContainsMouse) { | 425 TEST_P(WindowTest, ContainsMouse) { |
| 426 std::unique_ptr<Window> w(CreateTestWindow( | 426 std::unique_ptr<Window> w(CreateTestWindow( |
| 427 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); | 427 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 428 w->Show(); | 428 w->Show(); |
| 429 WindowTestApi w_test_api(w.get()); | 429 WindowTestApi w_test_api(w.get()); |
| 430 Window* root = root_window(); | 430 Window* root = root_window(); |
| 431 root->MoveCursorTo(gfx::Point(10, 10)); | 431 root->MoveCursorTo(gfx::Point(10, 10)); |
| 432 EXPECT_TRUE(w_test_api.ContainsMouse()); | 432 EXPECT_TRUE(w_test_api.ContainsMouse()); |
| 433 root->MoveCursorTo(gfx::Point(9, 10)); | 433 root->MoveCursorTo(gfx::Point(9, 10)); |
| 434 EXPECT_FALSE(w_test_api.ContainsMouse()); | 434 EXPECT_FALSE(w_test_api.ContainsMouse()); |
| 435 } | 435 } |
| 436 | 436 |
| 437 // Test Window::ConvertPointToWindow() with transform to root_window. | 437 // Test Window::ConvertPointToWindow() with transform to root_window. |
| 438 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { | 438 TEST_P(WindowTest, MoveCursorToWithTransformRootWindow) { |
| 439 gfx::Transform transform; | 439 gfx::Transform transform; |
| 440 transform.Translate(100.0, 100.0); | 440 transform.Translate(100.0, 100.0); |
| 441 transform.Rotate(90.0); | 441 transform.Rotate(90.0); |
| 442 transform.Scale(2.0, 5.0); | 442 transform.Scale(2.0, 5.0); |
| 443 host()->SetRootTransform(transform); | 443 host()->SetRootTransform(transform); |
| 444 host()->MoveCursorTo(gfx::Point(10, 10)); | 444 host()->MoveCursorTo(gfx::Point(10, 10)); |
| 445 #if !defined(OS_WIN) | 445 #if !defined(OS_WIN) |
| 446 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD | 446 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD |
| 447 EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString()); | 447 EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString()); |
| 448 #endif | 448 #endif |
| 449 EXPECT_EQ("10,10", | 449 EXPECT_EQ("10,10", |
| 450 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 450 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 451 } | 451 } |
| 452 | 452 |
| 453 // Tests Window::ConvertPointToWindow() with transform to non-root windows. | 453 // Tests Window::ConvertPointToWindow() with transform to non-root windows. |
| 454 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { | 454 TEST_P(WindowTest, MoveCursorToWithTransformWindow) { |
| 455 std::unique_ptr<Window> w1(CreateTestWindow( | 455 std::unique_ptr<Window> w1(CreateTestWindow( |
| 456 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); | 456 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 457 | 457 |
| 458 gfx::Transform transform1; | 458 gfx::Transform transform1; |
| 459 transform1.Scale(2, 2); | 459 transform1.Scale(2, 2); |
| 460 w1->SetTransform(transform1); | 460 w1->SetTransform(transform1); |
| 461 w1->MoveCursorTo(gfx::Point(10, 10)); | 461 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 462 EXPECT_EQ("30,30", | 462 EXPECT_EQ("30,30", |
| 463 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 463 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 464 | 464 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 482 transform4.Scale(2.0, 5.0); | 482 transform4.Scale(2.0, 5.0); |
| 483 w1->SetTransform(transform4); | 483 w1->SetTransform(transform4); |
| 484 w1->MoveCursorTo(gfx::Point(10, 10)); | 484 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 485 EXPECT_EQ("60,130", | 485 EXPECT_EQ("60,130", |
| 486 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 486 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 487 } | 487 } |
| 488 | 488 |
| 489 // Test Window::ConvertPointToWindow() with complex transforms to both root and | 489 // Test Window::ConvertPointToWindow() with complex transforms to both root and |
| 490 // non-root windows. | 490 // non-root windows. |
| 491 // Test Window::ConvertPointToWindow() with transform to root_window. | 491 // Test Window::ConvertPointToWindow() with transform to root_window. |
| 492 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { | 492 TEST_P(WindowTest, MoveCursorToWithComplexTransform) { |
| 493 std::unique_ptr<Window> w1(CreateTestWindow( | 493 std::unique_ptr<Window> w1(CreateTestWindow( |
| 494 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); | 494 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 495 std::unique_ptr<Window> w11( | 495 std::unique_ptr<Window> w11( |
| 496 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 496 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 497 std::unique_ptr<Window> w111( | 497 std::unique_ptr<Window> w111( |
| 498 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 498 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 499 std::unique_ptr<Window> w1111( | 499 std::unique_ptr<Window> w1111( |
| 500 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 500 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 501 | 501 |
| 502 // The root window expects transforms that produce integer rects. | 502 // The root window expects transforms that produce integer rects. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 521 #if !defined(OS_WIN) | 521 #if !defined(OS_WIN) |
| 522 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413. | 522 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413. |
| 523 EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString()); | 523 EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString()); |
| 524 #endif | 524 #endif |
| 525 EXPECT_EQ("20,53", | 525 EXPECT_EQ("20,53", |
| 526 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); | 526 display::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 527 } | 527 } |
| 528 | 528 |
| 529 // Tests that we do not crash when a Window is destroyed by going out of | 529 // Tests that we do not crash when a Window is destroyed by going out of |
| 530 // scope (as opposed to being explicitly deleted by its WindowDelegate). | 530 // scope (as opposed to being explicitly deleted by its WindowDelegate). |
| 531 TEST_F(WindowTest, NoCrashOnWindowDelete) { | 531 TEST_P(WindowTest, NoCrashOnWindowDelete) { |
| 532 CaptureWindowDelegateImpl delegate; | 532 CaptureWindowDelegateImpl delegate; |
| 533 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 533 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 534 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 534 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 535 } | 535 } |
| 536 | 536 |
| 537 TEST_F(WindowTest, GetEventHandlerForPoint) { | 537 TEST_P(WindowTest, GetEventHandlerForPoint) { |
| 538 std::unique_ptr<Window> w1(CreateTestWindow( | 538 std::unique_ptr<Window> w1(CreateTestWindow( |
| 539 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); | 539 SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), root_window())); |
| 540 std::unique_ptr<Window> w11( | 540 std::unique_ptr<Window> w11( |
| 541 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 541 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 542 std::unique_ptr<Window> w111( | 542 std::unique_ptr<Window> w111( |
| 543 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 543 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 544 std::unique_ptr<Window> w1111( | 544 std::unique_ptr<Window> w1111( |
| 545 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 545 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 546 std::unique_ptr<Window> w12(CreateTestWindow( | 546 std::unique_ptr<Window> w12(CreateTestWindow( |
| 547 SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), w1.get())); | 547 SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), w1.get())); |
| 548 std::unique_ptr<Window> w121( | 548 std::unique_ptr<Window> w121( |
| 549 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); | 549 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); |
| 550 std::unique_ptr<Window> w13( | 550 std::unique_ptr<Window> w13( |
| 551 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); | 551 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); |
| 552 | 552 |
| 553 Window* root = root_window(); | 553 Window* root = root_window(); |
| 554 w1->parent()->SetBounds(gfx::Rect(500, 500)); | 554 w1->parent()->SetBounds(gfx::Rect(500, 500)); |
| 555 EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5))); | 555 EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5))); |
| 556 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11))); | 556 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11))); |
| 557 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint(gfx::Point(16, 16))); | 557 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint(gfx::Point(16, 16))); |
| 558 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint(gfx::Point(21, 21))); | 558 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint(gfx::Point(21, 21))); |
| 559 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); | 559 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); |
| 560 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); | 560 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); |
| 561 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); | 561 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); |
| 562 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); | 562 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); |
| 563 } | 563 } |
| 564 | 564 |
| 565 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { | 565 TEST_P(WindowTest, GetEventHandlerForPointWithOverride) { |
| 566 // If our child is flush to our top-left corner it gets events just inside the | 566 // If our child is flush to our top-left corner it gets events just inside the |
| 567 // window edges. | 567 // window edges. |
| 568 std::unique_ptr<Window> parent(CreateTestWindow( | 568 std::unique_ptr<Window> parent(CreateTestWindow( |
| 569 SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), root_window())); | 569 SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), root_window())); |
| 570 std::unique_ptr<Window> child( | 570 std::unique_ptr<Window> child( |
| 571 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); | 571 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); |
| 572 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 572 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
| 573 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 573 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); |
| 574 | 574 |
| 575 // We can override the hit test bounds of the parent to make the parent grab | 575 // We can override the hit test bounds of the parent to make the parent grab |
| 576 // events along that edge. | 576 // events along that edge. |
| 577 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); | 577 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); |
| 578 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 578 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
| 579 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 579 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); |
| 580 } | 580 } |
| 581 | 581 |
| 582 TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) { | 582 TEST_P(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) { |
| 583 std::unique_ptr<SelfEventHandlingWindowDelegate> parent_delegate( | 583 std::unique_ptr<SelfEventHandlingWindowDelegate> parent_delegate( |
| 584 new SelfEventHandlingWindowDelegate); | 584 new SelfEventHandlingWindowDelegate); |
| 585 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( | 585 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( |
| 586 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), root_window())); | 586 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), root_window())); |
| 587 std::unique_ptr<Window> child(CreateTestWindow( | 587 std::unique_ptr<Window> child(CreateTestWindow( |
| 588 SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), parent.get())); | 588 SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), parent.get())); |
| 589 | 589 |
| 590 // We can override ShouldDescendIntoChildForEventHandling to make the parent | 590 // We can override ShouldDescendIntoChildForEventHandling to make the parent |
| 591 // grab all events. | 591 // grab all events. |
| 592 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 592 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
| 593 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50))); | 593 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50))); |
| 594 } | 594 } |
| 595 | 595 |
| 596 TEST_F(WindowTest, GetTopWindowContainingPoint) { | 596 TEST_P(WindowTest, GetTopWindowContainingPoint) { |
| 597 Window* root = root_window(); | 597 Window* root = root_window(); |
| 598 root->SetBounds(gfx::Rect(0, 0, 300, 300)); | 598 root->SetBounds(gfx::Rect(0, 0, 300, 300)); |
| 599 | 599 |
| 600 std::unique_ptr<Window> w1(CreateTestWindow( | 600 std::unique_ptr<Window> w1(CreateTestWindow( |
| 601 SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), root_window())); | 601 SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), root_window())); |
| 602 std::unique_ptr<Window> w11( | 602 std::unique_ptr<Window> w11( |
| 603 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); | 603 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); |
| 604 | 604 |
| 605 std::unique_ptr<Window> w2( | 605 std::unique_ptr<Window> w2( |
| 606 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), root_window())); | 606 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), root_window())); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 617 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(10, 10))); | 617 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(10, 10))); |
| 618 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(59, 59))); | 618 EXPECT_EQ(w2.get(), root->GetTopWindowContainingPoint(gfx::Point(59, 59))); |
| 619 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(60, 60))); | 619 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(60, 60))); |
| 620 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(109, 109))); | 620 EXPECT_EQ(w1.get(), root->GetTopWindowContainingPoint(gfx::Point(109, 109))); |
| 621 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(110, 110))); | 621 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(110, 110))); |
| 622 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(200, 200))); | 622 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(200, 200))); |
| 623 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(220, 220))); | 623 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(220, 220))); |
| 624 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(260, 260))); | 624 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(260, 260))); |
| 625 } | 625 } |
| 626 | 626 |
| 627 TEST_F(WindowTest, GetToplevelWindow) { | 627 TEST_P(WindowTest, GetToplevelWindow) { |
| 628 const gfx::Rect kBounds(0, 0, 10, 10); | 628 const gfx::Rect kBounds(0, 0, 10, 10); |
| 629 TestWindowDelegate delegate; | 629 TestWindowDelegate delegate; |
| 630 | 630 |
| 631 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 631 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 632 std::unique_ptr<Window> w11( | 632 std::unique_ptr<Window> w11( |
| 633 CreateTestWindowWithDelegate(&delegate, 11, kBounds, w1.get())); | 633 CreateTestWindowWithDelegate(&delegate, 11, kBounds, w1.get())); |
| 634 std::unique_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 634 std::unique_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
| 635 std::unique_ptr<Window> w1111( | 635 std::unique_ptr<Window> w1111( |
| 636 CreateTestWindowWithDelegate(&delegate, 1111, kBounds, w111.get())); | 636 CreateTestWindowWithDelegate(&delegate, 1111, kBounds, w111.get())); |
| 637 | 637 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 649 void OnWindowAddedToRootWindow(Window* window) override { called_ = true; } | 649 void OnWindowAddedToRootWindow(Window* window) override { called_ = true; } |
| 650 | 650 |
| 651 bool called() const { return called_; } | 651 bool called() const { return called_; } |
| 652 | 652 |
| 653 private: | 653 private: |
| 654 bool called_; | 654 bool called_; |
| 655 | 655 |
| 656 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); | 656 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); |
| 657 }; | 657 }; |
| 658 | 658 |
| 659 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { | 659 TEST_P(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { |
| 660 AddedToRootWindowObserver parent_observer; | 660 AddedToRootWindowObserver parent_observer; |
| 661 AddedToRootWindowObserver child_observer; | 661 AddedToRootWindowObserver child_observer; |
| 662 std::unique_ptr<Window> parent_window( | 662 std::unique_ptr<Window> parent_window( |
| 663 CreateTestWindowWithId(1, root_window())); | 663 CreateTestWindowWithId(1, root_window())); |
| 664 std::unique_ptr<Window> child_window(new Window(NULL)); | 664 std::unique_ptr<Window> child_window(new Window(NULL)); |
| 665 child_window->Init(ui::LAYER_TEXTURED); | 665 child_window->Init(ui::LAYER_TEXTURED); |
| 666 child_window->Show(); | 666 child_window->Show(); |
| 667 | 667 |
| 668 parent_window->AddObserver(&parent_observer); | 668 parent_window->AddObserver(&parent_observer); |
| 669 child_window->AddObserver(&child_observer); | 669 child_window->AddObserver(&child_observer); |
| 670 | 670 |
| 671 parent_window->AddChild(child_window.get()); | 671 parent_window->AddChild(child_window.get()); |
| 672 | 672 |
| 673 EXPECT_FALSE(parent_observer.called()); | 673 EXPECT_FALSE(parent_observer.called()); |
| 674 EXPECT_TRUE(child_observer.called()); | 674 EXPECT_TRUE(child_observer.called()); |
| 675 | 675 |
| 676 parent_window->RemoveObserver(&parent_observer); | 676 parent_window->RemoveObserver(&parent_observer); |
| 677 child_window->RemoveObserver(&child_observer); | 677 child_window->RemoveObserver(&child_observer); |
| 678 } | 678 } |
| 679 | 679 |
| 680 // Various destruction assertions. | 680 // Various destruction assertions. |
| 681 TEST_F(WindowTest, DestroyTest) { | 681 TEST_P(WindowTest, DestroyTest) { |
| 682 DestroyTrackingDelegateImpl parent_delegate; | 682 DestroyTrackingDelegateImpl parent_delegate; |
| 683 ChildWindowDelegateImpl child_delegate(&parent_delegate); | 683 ChildWindowDelegateImpl child_delegate(&parent_delegate); |
| 684 { | 684 { |
| 685 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( | 685 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( |
| 686 &parent_delegate, 0, gfx::Rect(), root_window())); | 686 &parent_delegate, 0, gfx::Rect(), root_window())); |
| 687 CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get()); | 687 CreateTestWindowWithDelegate(&child_delegate, 0, gfx::Rect(), parent.get()); |
| 688 } | 688 } |
| 689 // Both the parent and child should have been destroyed. | 689 // Both the parent and child should have been destroyed. |
| 690 EXPECT_EQ(1, parent_delegate.destroying_count()); | 690 EXPECT_EQ(1, parent_delegate.destroying_count()); |
| 691 EXPECT_EQ(1, parent_delegate.destroyed_count()); | 691 EXPECT_EQ(1, parent_delegate.destroyed_count()); |
| 692 EXPECT_EQ(1, child_delegate.destroying_count()); | 692 EXPECT_EQ(1, child_delegate.destroying_count()); |
| 693 EXPECT_EQ(1, child_delegate.destroyed_count()); | 693 EXPECT_EQ(1, child_delegate.destroyed_count()); |
| 694 } | 694 } |
| 695 | 695 |
| 696 // Tests that a window is orphaned before OnWindowDestroyed is called. | 696 // Tests that a window is orphaned before OnWindowDestroyed is called. |
| 697 TEST_F(WindowTest, OrphanedBeforeOnDestroyed) { | 697 TEST_P(WindowTest, OrphanedBeforeOnDestroyed) { |
| 698 TestWindowDelegate parent_delegate; | 698 TestWindowDelegate parent_delegate; |
| 699 DestroyOrphanDelegate child_delegate; | 699 DestroyOrphanDelegate child_delegate; |
| 700 { | 700 { |
| 701 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( | 701 std::unique_ptr<Window> parent(CreateTestWindowWithDelegate( |
| 702 &parent_delegate, 0, gfx::Rect(), root_window())); | 702 &parent_delegate, 0, gfx::Rect(), root_window())); |
| 703 std::unique_ptr<Window> child(CreateTestWindowWithDelegate( | 703 std::unique_ptr<Window> child(CreateTestWindowWithDelegate( |
| 704 &child_delegate, 0, gfx::Rect(), parent.get())); | 704 &child_delegate, 0, gfx::Rect(), parent.get())); |
| 705 child_delegate.set_window(child.get()); | 705 child_delegate.set_window(child.get()); |
| 706 } | 706 } |
| 707 } | 707 } |
| 708 | 708 |
| 709 // Make sure StackChildAtTop moves both the window and layer to the front. | 709 // Make sure StackChildAtTop moves both the window and layer to the front. |
| 710 TEST_F(WindowTest, StackChildAtTop) { | 710 TEST_P(WindowTest, StackChildAtTop) { |
| 711 Window parent(NULL); | 711 Window parent(NULL); |
| 712 parent.Init(ui::LAYER_NOT_DRAWN); | 712 parent.Init(ui::LAYER_NOT_DRAWN); |
| 713 Window child1(NULL); | 713 Window child1(NULL); |
| 714 child1.Init(ui::LAYER_NOT_DRAWN); | 714 child1.Init(ui::LAYER_NOT_DRAWN); |
| 715 Window child2(NULL); | 715 Window child2(NULL); |
| 716 child2.Init(ui::LAYER_NOT_DRAWN); | 716 child2.Init(ui::LAYER_NOT_DRAWN); |
| 717 | 717 |
| 718 parent.AddChild(&child1); | 718 parent.AddChild(&child1); |
| 719 parent.AddChild(&child2); | 719 parent.AddChild(&child2); |
| 720 ASSERT_EQ(2u, parent.children().size()); | 720 ASSERT_EQ(2u, parent.children().size()); |
| 721 EXPECT_EQ(&child1, parent.children()[0]); | 721 EXPECT_EQ(&child1, parent.children()[0]); |
| 722 EXPECT_EQ(&child2, parent.children()[1]); | 722 EXPECT_EQ(&child2, parent.children()[1]); |
| 723 ASSERT_EQ(2u, parent.layer()->children().size()); | 723 ASSERT_EQ(2u, parent.layer()->children().size()); |
| 724 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); | 724 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); |
| 725 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); | 725 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); |
| 726 | 726 |
| 727 parent.StackChildAtTop(&child1); | 727 parent.StackChildAtTop(&child1); |
| 728 ASSERT_EQ(2u, parent.children().size()); | 728 ASSERT_EQ(2u, parent.children().size()); |
| 729 EXPECT_EQ(&child1, parent.children()[1]); | 729 EXPECT_EQ(&child1, parent.children()[1]); |
| 730 EXPECT_EQ(&child2, parent.children()[0]); | 730 EXPECT_EQ(&child2, parent.children()[0]); |
| 731 ASSERT_EQ(2u, parent.layer()->children().size()); | 731 ASSERT_EQ(2u, parent.layer()->children().size()); |
| 732 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 732 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
| 733 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 733 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
| 734 } | 734 } |
| 735 | 735 |
| 736 // Make sure StackChildBelow works. | 736 // Make sure StackChildBelow works. |
| 737 TEST_F(WindowTest, StackChildBelow) { | 737 TEST_P(WindowTest, StackChildBelow) { |
| 738 Window parent(NULL); | 738 Window parent(NULL); |
| 739 parent.Init(ui::LAYER_NOT_DRAWN); | 739 parent.Init(ui::LAYER_NOT_DRAWN); |
| 740 Window child1(NULL); | 740 Window child1(NULL); |
| 741 child1.Init(ui::LAYER_NOT_DRAWN); | 741 child1.Init(ui::LAYER_NOT_DRAWN); |
| 742 child1.set_id(1); | 742 child1.set_id(1); |
| 743 Window child2(NULL); | 743 Window child2(NULL); |
| 744 child2.Init(ui::LAYER_NOT_DRAWN); | 744 child2.Init(ui::LAYER_NOT_DRAWN); |
| 745 child2.set_id(2); | 745 child2.set_id(2); |
| 746 Window child3(NULL); | 746 Window child3(NULL); |
| 747 child3.Init(ui::LAYER_NOT_DRAWN); | 747 child3.Init(ui::LAYER_NOT_DRAWN); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 759 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); | 759 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); |
| 760 | 760 |
| 761 parent.StackChildBelow(&child3, &child2); | 761 parent.StackChildBelow(&child3, &child2); |
| 762 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); | 762 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); |
| 763 | 763 |
| 764 parent.StackChildBelow(&child3, &child1); | 764 parent.StackChildBelow(&child3, &child1); |
| 765 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); | 765 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); |
| 766 } | 766 } |
| 767 | 767 |
| 768 // Various assertions for StackChildAbove. | 768 // Various assertions for StackChildAbove. |
| 769 TEST_F(WindowTest, StackChildAbove) { | 769 TEST_P(WindowTest, StackChildAbove) { |
| 770 Window parent(NULL); | 770 Window parent(NULL); |
| 771 parent.Init(ui::LAYER_NOT_DRAWN); | 771 parent.Init(ui::LAYER_NOT_DRAWN); |
| 772 Window child1(NULL); | 772 Window child1(NULL); |
| 773 child1.Init(ui::LAYER_NOT_DRAWN); | 773 child1.Init(ui::LAYER_NOT_DRAWN); |
| 774 Window child2(NULL); | 774 Window child2(NULL); |
| 775 child2.Init(ui::LAYER_NOT_DRAWN); | 775 child2.Init(ui::LAYER_NOT_DRAWN); |
| 776 Window child3(NULL); | 776 Window child3(NULL); |
| 777 child3.Init(ui::LAYER_NOT_DRAWN); | 777 child3.Init(ui::LAYER_NOT_DRAWN); |
| 778 | 778 |
| 779 parent.AddChild(&child1); | 779 parent.AddChild(&child1); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 EXPECT_EQ(&child2, parent.children()[0]); | 818 EXPECT_EQ(&child2, parent.children()[0]); |
| 819 EXPECT_EQ(&child1, parent.children()[1]); | 819 EXPECT_EQ(&child1, parent.children()[1]); |
| 820 EXPECT_EQ(&child3, parent.children()[2]); | 820 EXPECT_EQ(&child3, parent.children()[2]); |
| 821 ASSERT_EQ(3u, parent.layer()->children().size()); | 821 ASSERT_EQ(3u, parent.layer()->children().size()); |
| 822 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 822 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
| 823 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 823 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
| 824 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); | 824 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); |
| 825 } | 825 } |
| 826 | 826 |
| 827 // Various capture assertions. | 827 // Various capture assertions. |
| 828 TEST_F(WindowTest, CaptureTests) { | 828 TEST_P(WindowTest, CaptureTests) { |
| 829 CaptureWindowDelegateImpl delegate; | 829 CaptureWindowDelegateImpl delegate; |
| 830 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 830 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 831 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 831 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 832 EXPECT_FALSE(window->HasCapture()); | 832 EXPECT_FALSE(window->HasCapture()); |
| 833 | 833 |
| 834 delegate.ResetCounts(); | 834 delegate.ResetCounts(); |
| 835 | 835 |
| 836 // Do a capture. | 836 // Do a capture. |
| 837 window->SetCapture(); | 837 window->SetCapture(); |
| 838 EXPECT_TRUE(window->HasCapture()); | 838 EXPECT_TRUE(window->HasCapture()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 869 | 869 |
| 870 // Removing the capture window from parent should reset the capture window | 870 // Removing the capture window from parent should reset the capture window |
| 871 // in the root window. | 871 // in the root window. |
| 872 window->SetCapture(); | 872 window->SetCapture(); |
| 873 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window())); | 873 EXPECT_EQ(window.get(), aura::client::GetCaptureWindow(root_window())); |
| 874 window->parent()->RemoveChild(window.get()); | 874 window->parent()->RemoveChild(window.get()); |
| 875 EXPECT_FALSE(window->HasCapture()); | 875 EXPECT_FALSE(window->HasCapture()); |
| 876 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); | 876 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); |
| 877 } | 877 } |
| 878 | 878 |
| 879 TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) { | 879 TEST_P(WindowTest, TouchCaptureCancelsOtherTouches) { |
| 880 CaptureWindowDelegateImpl delegate1; | 880 CaptureWindowDelegateImpl delegate1; |
| 881 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 881 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 882 &delegate1, 0, gfx::Rect(0, 0, 50, 50), root_window())); | 882 &delegate1, 0, gfx::Rect(0, 0, 50, 50), root_window())); |
| 883 CaptureWindowDelegateImpl delegate2; | 883 CaptureWindowDelegateImpl delegate2; |
| 884 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( | 884 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 885 &delegate2, 0, gfx::Rect(50, 50, 50, 50), root_window())); | 885 &delegate2, 0, gfx::Rect(50, 50, 50, 50), root_window())); |
| 886 | 886 |
| 887 // Press on w1. | 887 // Press on w1. |
| 888 ui::TouchEvent press1( | 888 ui::TouchEvent press1( |
| 889 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 889 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 delegate2.ResetCounts(); | 924 delegate2.ResetCounts(); |
| 925 | 925 |
| 926 // And releasing capture changes nothing. | 926 // And releasing capture changes nothing. |
| 927 w2->ReleaseCapture(); | 927 w2->ReleaseCapture(); |
| 928 EXPECT_EQ(0, delegate1.gesture_event_count()); | 928 EXPECT_EQ(0, delegate1.gesture_event_count()); |
| 929 EXPECT_EQ(0, delegate1.touch_event_count()); | 929 EXPECT_EQ(0, delegate1.touch_event_count()); |
| 930 EXPECT_EQ(0, delegate2.gesture_event_count()); | 930 EXPECT_EQ(0, delegate2.gesture_event_count()); |
| 931 EXPECT_EQ(0, delegate2.touch_event_count()); | 931 EXPECT_EQ(0, delegate2.touch_event_count()); |
| 932 } | 932 } |
| 933 | 933 |
| 934 TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { | 934 TEST_P(WindowTest, TouchCaptureDoesntCancelCapturedTouches) { |
| 935 CaptureWindowDelegateImpl delegate; | 935 CaptureWindowDelegateImpl delegate; |
| 936 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 936 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 937 &delegate, 0, gfx::Rect(0, 0, 50, 50), root_window())); | 937 &delegate, 0, gfx::Rect(0, 0, 50, 50), root_window())); |
| 938 base::TimeTicks time = getTime(); | 938 base::TimeTicks time = getTime(); |
| 939 const int kTimeDelta = 100; | 939 const int kTimeDelta = 100; |
| 940 | 940 |
| 941 ui::TouchEvent press( | 941 ui::TouchEvent press( |
| 942 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time); | 942 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time); |
| 943 DispatchEventUsingWindowDispatcher(&press); | 943 DispatchEventUsingWindowDispatcher(&press); |
| 944 | 944 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 time += base::TimeDelta::FromMilliseconds(kTimeDelta); | 979 time += base::TimeDelta::FromMilliseconds(kTimeDelta); |
| 980 ui::TouchEvent release( | 980 ui::TouchEvent release( |
| 981 ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 0, time); | 981 ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 0, time); |
| 982 DispatchEventUsingWindowDispatcher(&release); | 982 DispatchEventUsingWindowDispatcher(&release); |
| 983 EXPECT_EQ(1, delegate.touch_event_count()); | 983 EXPECT_EQ(1, delegate.touch_event_count()); |
| 984 EXPECT_EQ(2, delegate.gesture_event_count()); | 984 EXPECT_EQ(2, delegate.gesture_event_count()); |
| 985 } | 985 } |
| 986 | 986 |
| 987 | 987 |
| 988 // Assertions around SetCapture() and touch/gestures. | 988 // Assertions around SetCapture() and touch/gestures. |
| 989 TEST_F(WindowTest, TransferCaptureTouchEvents) { | 989 TEST_P(WindowTest, TransferCaptureTouchEvents) { |
| 990 // Touch on |w1|. | 990 // Touch on |w1|. |
| 991 CaptureWindowDelegateImpl d1; | 991 CaptureWindowDelegateImpl d1; |
| 992 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 992 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 993 &d1, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 993 &d1, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 994 ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); | 994 ui::TouchEvent p1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime()); |
| 995 DispatchEventUsingWindowDispatcher(&p1); | 995 DispatchEventUsingWindowDispatcher(&p1); |
| 996 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. | 996 // We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN. |
| 997 EXPECT_EQ(1, d1.touch_event_count()); | 997 EXPECT_EQ(1, d1.touch_event_count()); |
| 998 EXPECT_EQ(2, d1.gesture_event_count()); | 998 EXPECT_EQ(2, d1.gesture_event_count()); |
| 999 d1.ResetCounts(); | 999 d1.ResetCounts(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 DispatchEventUsingWindowDispatcher(&m4); | 1060 DispatchEventUsingWindowDispatcher(&m4); |
| 1061 EXPECT_EQ(0, d1.touch_event_count()); | 1061 EXPECT_EQ(0, d1.touch_event_count()); |
| 1062 EXPECT_EQ(0, d1.gesture_event_count()); | 1062 EXPECT_EQ(0, d1.gesture_event_count()); |
| 1063 EXPECT_EQ(0, d2.touch_event_count()); | 1063 EXPECT_EQ(0, d2.touch_event_count()); |
| 1064 EXPECT_EQ(0, d2.gesture_event_count()); | 1064 EXPECT_EQ(0, d2.gesture_event_count()); |
| 1065 EXPECT_EQ(0, d3.touch_event_count()); | 1065 EXPECT_EQ(0, d3.touch_event_count()); |
| 1066 EXPECT_EQ(0, d3.gesture_event_count()); | 1066 EXPECT_EQ(0, d3.gesture_event_count()); |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 // Changes capture while capture is already ongoing. | 1069 // Changes capture while capture is already ongoing. |
| 1070 TEST_F(WindowTest, ChangeCaptureWhileMouseDown) { | 1070 TEST_P(WindowTest, ChangeCaptureWhileMouseDown) { |
| 1071 CaptureWindowDelegateImpl delegate; | 1071 CaptureWindowDelegateImpl delegate; |
| 1072 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 1072 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 1073 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 1073 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 1074 CaptureWindowDelegateImpl delegate2; | 1074 CaptureWindowDelegateImpl delegate2; |
| 1075 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( | 1075 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1076 &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window())); | 1076 &delegate2, 0, gfx::Rect(20, 20, 20, 20), root_window())); |
| 1077 | 1077 |
| 1078 // Execute the scheduled draws so that mouse events are not | 1078 // Execute the scheduled draws so that mouse events are not |
| 1079 // aggregated. | 1079 // aggregated. |
| 1080 RunAllPendingInMessageLoop(); | 1080 RunAllPendingInMessageLoop(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1099 w2->SetCapture(); | 1099 w2->SetCapture(); |
| 1100 | 1100 |
| 1101 generator.MoveMouseTo(gfx::Point(40, 40), 2); | 1101 generator.MoveMouseTo(gfx::Point(40, 40), 2); |
| 1102 EXPECT_EQ(1, delegate.capture_lost_count()); | 1102 EXPECT_EQ(1, delegate.capture_lost_count()); |
| 1103 EXPECT_EQ(1, delegate.capture_changed_event_count()); | 1103 EXPECT_EQ(1, delegate.capture_changed_event_count()); |
| 1104 EXPECT_EQ(1, delegate.mouse_event_count()); | 1104 EXPECT_EQ(1, delegate.mouse_event_count()); |
| 1105 EXPECT_EQ(2, delegate2.mouse_event_count()); | 1105 EXPECT_EQ(2, delegate2.mouse_event_count()); |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 // Verifies capture is reset when a window is destroyed. | 1108 // Verifies capture is reset when a window is destroyed. |
| 1109 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { | 1109 TEST_P(WindowTest, ReleaseCaptureOnDestroy) { |
| 1110 CaptureWindowDelegateImpl delegate; | 1110 CaptureWindowDelegateImpl delegate; |
| 1111 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 1111 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 1112 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 1112 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 1113 EXPECT_FALSE(window->HasCapture()); | 1113 EXPECT_FALSE(window->HasCapture()); |
| 1114 | 1114 |
| 1115 // Do a capture. | 1115 // Do a capture. |
| 1116 window->SetCapture(); | 1116 window->SetCapture(); |
| 1117 EXPECT_TRUE(window->HasCapture()); | 1117 EXPECT_TRUE(window->HasCapture()); |
| 1118 | 1118 |
| 1119 // Destroy the window. | 1119 // Destroy the window. |
| 1120 window.reset(); | 1120 window.reset(); |
| 1121 | 1121 |
| 1122 // Make sure the root window doesn't reference the window anymore. | 1122 // Make sure the root window doesn't reference the window anymore. |
| 1123 EXPECT_EQ(NULL, host()->dispatcher()->mouse_pressed_handler()); | 1123 EXPECT_EQ(NULL, host()->dispatcher()->mouse_pressed_handler()); |
| 1124 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); | 1124 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); |
| 1125 } | 1125 } |
| 1126 | 1126 |
| 1127 TEST_F(WindowTest, GetBoundsInRootWindow) { | 1127 TEST_P(WindowTest, GetBoundsInRootWindow) { |
| 1128 std::unique_ptr<Window> viewport( | 1128 std::unique_ptr<Window> viewport( |
| 1129 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); | 1129 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); |
| 1130 std::unique_ptr<Window> child( | 1130 std::unique_ptr<Window> child( |
| 1131 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), viewport.get())); | 1131 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), viewport.get())); |
| 1132 // Sanity check. | 1132 // Sanity check. |
| 1133 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1133 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1134 | 1134 |
| 1135 // The |child| window's screen bounds should move along with the |viewport|. | 1135 // The |child| window's screen bounds should move along with the |viewport|. |
| 1136 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); | 1136 viewport->SetBounds(gfx::Rect(-100, -100, 300, 300)); |
| 1137 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); | 1137 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1138 | 1138 |
| 1139 // The |child| window is moved to the 0,0 in screen coordinates. | 1139 // The |child| window is moved to the 0,0 in screen coordinates. |
| 1140 // |GetBoundsInRootWindow()| should return 0,0. | 1140 // |GetBoundsInRootWindow()| should return 0,0. |
| 1141 child->SetBounds(gfx::Rect(100, 100, 100, 100)); | 1141 child->SetBounds(gfx::Rect(100, 100, 100, 100)); |
| 1142 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1142 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 TEST_F(WindowTest, GetBoundsInRootWindowWithLayers) { | 1145 TEST_P(WindowTest, GetBoundsInRootWindowWithLayers) { |
| 1146 std::unique_ptr<Window> viewport( | 1146 std::unique_ptr<Window> viewport( |
| 1147 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); | 1147 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); |
| 1148 | 1148 |
| 1149 std::unique_ptr<Window> widget( | 1149 std::unique_ptr<Window> widget( |
| 1150 CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); | 1150 CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); |
| 1151 | 1151 |
| 1152 std::unique_ptr<Window> child( | 1152 std::unique_ptr<Window> child( |
| 1153 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); | 1153 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); |
| 1154 | 1154 |
| 1155 // Sanity check. | 1155 // Sanity check. |
| 1156 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1156 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1157 | 1157 |
| 1158 // The |child| window's screen bounds should move along with the |viewport|. | 1158 // The |child| window's screen bounds should move along with the |viewport|. |
| 1159 OffsetBounds(viewport.get(), -100, -100); | 1159 OffsetBounds(viewport.get(), -100, -100); |
| 1160 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); | 1160 EXPECT_EQ("-100,-100 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1161 | 1161 |
| 1162 OffsetBounds(widget.get(), 50, 50); | 1162 OffsetBounds(widget.get(), 50, 50); |
| 1163 EXPECT_EQ("-50,-50 100x100", child->GetBoundsInRootWindow().ToString()); | 1163 EXPECT_EQ("-50,-50 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1164 | 1164 |
| 1165 // The |child| window is moved to the 0,0 in screen coordinates. | 1165 // The |child| window is moved to the 0,0 in screen coordinates. |
| 1166 // |GetBoundsInRootWindow()| should return 0,0. | 1166 // |GetBoundsInRootWindow()| should return 0,0. |
| 1167 OffsetBounds(child.get(), 50, 50); | 1167 OffsetBounds(child.get(), 50, 50); |
| 1168 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1168 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 TEST_F(WindowTest, GetBoundsInRootWindowWithLayersAndTranslations) { | 1171 TEST_P(WindowTest, GetBoundsInRootWindowWithLayersAndTranslations) { |
| 1172 std::unique_ptr<Window> viewport( | 1172 std::unique_ptr<Window> viewport( |
| 1173 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); | 1173 CreateTestWindowWithBounds(gfx::Rect(0, 0, 300, 300), root_window())); |
| 1174 | 1174 |
| 1175 std::unique_ptr<Window> widget( | 1175 std::unique_ptr<Window> widget( |
| 1176 CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); | 1176 CreateTestWindowWithBounds(gfx::Rect(0, 0, 200, 200), viewport.get())); |
| 1177 | 1177 |
| 1178 std::unique_ptr<Window> child( | 1178 std::unique_ptr<Window> child( |
| 1179 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); | 1179 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), widget.get())); |
| 1180 | 1180 |
| 1181 // Sanity check. | 1181 // Sanity check. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 | 1242 |
| 1243 private: | 1243 private: |
| 1244 bool entered_; | 1244 bool entered_; |
| 1245 bool exited_; | 1245 bool exited_; |
| 1246 | 1246 |
| 1247 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); | 1247 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); |
| 1248 }; | 1248 }; |
| 1249 | 1249 |
| 1250 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for | 1250 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for |
| 1251 // mouse transitions from window to window. | 1251 // mouse transitions from window to window. |
| 1252 TEST_F(WindowTest, MouseEnterExit) { | 1252 TEST_P(WindowTest, MouseEnterExit) { |
| 1253 MouseEnterExitWindowDelegate d1; | 1253 MouseEnterExitWindowDelegate d1; |
| 1254 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1254 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1255 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 1255 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1256 MouseEnterExitWindowDelegate d2; | 1256 MouseEnterExitWindowDelegate d2; |
| 1257 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( | 1257 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1258 &d2, 2, gfx::Rect(70, 70, 50, 50), root_window())); | 1258 &d2, 2, gfx::Rect(70, 70, 50, 50), root_window())); |
| 1259 | 1259 |
| 1260 ui::test::EventGenerator generator(root_window()); | 1260 ui::test::EventGenerator generator(root_window()); |
| 1261 generator.MoveMouseToCenterOf(w1.get()); | 1261 generator.MoveMouseToCenterOf(w1.get()); |
| 1262 EXPECT_TRUE(d1.entered()); | 1262 EXPECT_TRUE(d1.entered()); |
| 1263 EXPECT_FALSE(d1.exited()); | 1263 EXPECT_FALSE(d1.exited()); |
| 1264 EXPECT_FALSE(d2.entered()); | 1264 EXPECT_FALSE(d2.entered()); |
| 1265 EXPECT_FALSE(d2.exited()); | 1265 EXPECT_FALSE(d2.exited()); |
| 1266 | 1266 |
| 1267 generator.MoveMouseToCenterOf(w2.get()); | 1267 generator.MoveMouseToCenterOf(w2.get()); |
| 1268 EXPECT_TRUE(d1.entered()); | 1268 EXPECT_TRUE(d1.entered()); |
| 1269 EXPECT_TRUE(d1.exited()); | 1269 EXPECT_TRUE(d1.exited()); |
| 1270 EXPECT_TRUE(d2.entered()); | 1270 EXPECT_TRUE(d2.entered()); |
| 1271 EXPECT_FALSE(d2.exited()); | 1271 EXPECT_FALSE(d2.exited()); |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 // Verifies that the WindowDelegate receives MouseExit from ET_MOUSE_EXITED. | 1274 // Verifies that the WindowDelegate receives MouseExit from ET_MOUSE_EXITED. |
| 1275 TEST_F(WindowTest, WindowTreeHostExit) { | 1275 TEST_P(WindowTest, WindowTreeHostExit) { |
| 1276 MouseEnterExitWindowDelegate d1; | 1276 MouseEnterExitWindowDelegate d1; |
| 1277 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1277 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1278 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 1278 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1279 | 1279 |
| 1280 ui::test::EventGenerator generator(root_window()); | 1280 ui::test::EventGenerator generator(root_window()); |
| 1281 generator.MoveMouseToCenterOf(w1.get()); | 1281 generator.MoveMouseToCenterOf(w1.get()); |
| 1282 EXPECT_TRUE(d1.entered()); | 1282 EXPECT_TRUE(d1.entered()); |
| 1283 EXPECT_FALSE(d1.exited()); | 1283 EXPECT_FALSE(d1.exited()); |
| 1284 d1.ResetExpectations(); | 1284 d1.ResetExpectations(); |
| 1285 | 1285 |
| 1286 ui::MouseEvent exit_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 1286 ui::MouseEvent exit_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), |
| 1287 ui::EventTimeForNow(), 0, 0); | 1287 ui::EventTimeForNow(), 0, 0); |
| 1288 DispatchEventUsingWindowDispatcher(&exit_event); | 1288 DispatchEventUsingWindowDispatcher(&exit_event); |
| 1289 EXPECT_FALSE(d1.entered()); | 1289 EXPECT_FALSE(d1.entered()); |
| 1290 EXPECT_TRUE(d1.exited()); | 1290 EXPECT_TRUE(d1.exited()); |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for | 1293 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for |
| 1294 // mouse transitions from window to window, even if the entered window sets | 1294 // mouse transitions from window to window, even if the entered window sets |
| 1295 // and releases capture. | 1295 // and releases capture. |
| 1296 TEST_F(WindowTest, MouseEnterExitWithClick) { | 1296 TEST_P(WindowTest, MouseEnterExitWithClick) { |
| 1297 MouseEnterExitWindowDelegate d1; | 1297 MouseEnterExitWindowDelegate d1; |
| 1298 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1298 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1299 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 1299 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1300 MouseEnterExitWindowDelegate d2; | 1300 MouseEnterExitWindowDelegate d2; |
| 1301 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( | 1301 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1302 &d2, 2, gfx::Rect(70, 70, 50, 50), root_window())); | 1302 &d2, 2, gfx::Rect(70, 70, 50, 50), root_window())); |
| 1303 | 1303 |
| 1304 ui::test::EventGenerator generator(root_window()); | 1304 ui::test::EventGenerator generator(root_window()); |
| 1305 generator.MoveMouseToCenterOf(w1.get()); | 1305 generator.MoveMouseToCenterOf(w1.get()); |
| 1306 EXPECT_TRUE(d1.entered()); | 1306 EXPECT_TRUE(d1.entered()); |
| 1307 EXPECT_FALSE(d1.exited()); | 1307 EXPECT_FALSE(d1.exited()); |
| 1308 EXPECT_FALSE(d2.entered()); | 1308 EXPECT_FALSE(d2.entered()); |
| 1309 EXPECT_FALSE(d2.exited()); | 1309 EXPECT_FALSE(d2.exited()); |
| 1310 | 1310 |
| 1311 // Emmulate what Views does on a click by grabbing and releasing capture. | 1311 // Emmulate what Views does on a click by grabbing and releasing capture. |
| 1312 generator.PressLeftButton(); | 1312 generator.PressLeftButton(); |
| 1313 w1->SetCapture(); | 1313 w1->SetCapture(); |
| 1314 w1->ReleaseCapture(); | 1314 w1->ReleaseCapture(); |
| 1315 generator.ReleaseLeftButton(); | 1315 generator.ReleaseLeftButton(); |
| 1316 | 1316 |
| 1317 generator.MoveMouseToCenterOf(w2.get()); | 1317 generator.MoveMouseToCenterOf(w2.get()); |
| 1318 EXPECT_TRUE(d1.entered()); | 1318 EXPECT_TRUE(d1.entered()); |
| 1319 EXPECT_TRUE(d1.exited()); | 1319 EXPECT_TRUE(d1.exited()); |
| 1320 EXPECT_TRUE(d2.entered()); | 1320 EXPECT_TRUE(d2.entered()); |
| 1321 EXPECT_FALSE(d2.exited()); | 1321 EXPECT_FALSE(d2.exited()); |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 TEST_F(WindowTest, MouseEnterExitWhenDeleteWithCapture) { | 1324 TEST_P(WindowTest, MouseEnterExitWhenDeleteWithCapture) { |
| 1325 MouseEnterExitWindowDelegate delegate; | 1325 MouseEnterExitWindowDelegate delegate; |
| 1326 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 1326 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 1327 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 1327 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1328 | 1328 |
| 1329 ui::test::EventGenerator generator(root_window()); | 1329 ui::test::EventGenerator generator(root_window()); |
| 1330 generator.MoveMouseToCenterOf(window.get()); | 1330 generator.MoveMouseToCenterOf(window.get()); |
| 1331 EXPECT_TRUE(delegate.entered()); | 1331 EXPECT_TRUE(delegate.entered()); |
| 1332 EXPECT_FALSE(delegate.exited()); | 1332 EXPECT_FALSE(delegate.exited()); |
| 1333 | 1333 |
| 1334 // Emmulate what Views does on a click by grabbing and releasing capture. | 1334 // Emmulate what Views does on a click by grabbing and releasing capture. |
| 1335 generator.PressLeftButton(); | 1335 generator.PressLeftButton(); |
| 1336 window->SetCapture(); | 1336 window->SetCapture(); |
| 1337 | 1337 |
| 1338 delegate.ResetExpectations(); | 1338 delegate.ResetExpectations(); |
| 1339 generator.MoveMouseTo(0, 0); | 1339 generator.MoveMouseTo(0, 0); |
| 1340 EXPECT_FALSE(delegate.entered()); | 1340 EXPECT_FALSE(delegate.entered()); |
| 1341 EXPECT_FALSE(delegate.exited()); | 1341 EXPECT_FALSE(delegate.exited()); |
| 1342 | 1342 |
| 1343 delegate.ResetExpectations(); | 1343 delegate.ResetExpectations(); |
| 1344 window.reset(); | 1344 window.reset(); |
| 1345 EXPECT_FALSE(delegate.entered()); | 1345 EXPECT_FALSE(delegate.entered()); |
| 1346 EXPECT_FALSE(delegate.exited()); | 1346 EXPECT_FALSE(delegate.exited()); |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 // Verifies that the correct enter / exits are sent if windows appear and are | 1349 // Verifies that the correct enter / exits are sent if windows appear and are |
| 1350 // deleted under the current mouse position. | 1350 // deleted under the current mouse position. |
| 1351 TEST_F(WindowTest, MouseEnterExitWithWindowAppearAndDelete) { | 1351 TEST_P(WindowTest, MouseEnterExitWithWindowAppearAndDelete) { |
| 1352 MouseEnterExitWindowDelegate d1; | 1352 MouseEnterExitWindowDelegate d1; |
| 1353 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1353 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1354 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 1354 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1355 | 1355 |
| 1356 // The cursor is moved into the bounds of |w1|. We expect the delegate | 1356 // The cursor is moved into the bounds of |w1|. We expect the delegate |
| 1357 // of |w1| to see an ET_MOUSE_ENTERED event. | 1357 // of |w1| to see an ET_MOUSE_ENTERED event. |
| 1358 ui::test::EventGenerator generator(root_window()); | 1358 ui::test::EventGenerator generator(root_window()); |
| 1359 generator.MoveMouseToCenterOf(w1.get()); | 1359 generator.MoveMouseToCenterOf(w1.get()); |
| 1360 EXPECT_TRUE(d1.entered()); | 1360 EXPECT_TRUE(d1.entered()); |
| 1361 EXPECT_FALSE(d1.exited()); | 1361 EXPECT_FALSE(d1.exited()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1384 // |w2| has been destroyed, so its delegate should see no further events. | 1384 // |w2| has been destroyed, so its delegate should see no further events. |
| 1385 // The delegate of |w1| should see an ET_MOUSE_ENTERED event. | 1385 // The delegate of |w1| should see an ET_MOUSE_ENTERED event. |
| 1386 EXPECT_TRUE(d1.entered()); | 1386 EXPECT_TRUE(d1.entered()); |
| 1387 EXPECT_FALSE(d1.exited()); | 1387 EXPECT_FALSE(d1.exited()); |
| 1388 EXPECT_FALSE(d2.entered()); | 1388 EXPECT_FALSE(d2.entered()); |
| 1389 EXPECT_FALSE(d2.exited()); | 1389 EXPECT_FALSE(d2.exited()); |
| 1390 } | 1390 } |
| 1391 | 1391 |
| 1392 // Verifies that enter / exits are sent if windows appear and are hidden | 1392 // Verifies that enter / exits are sent if windows appear and are hidden |
| 1393 // under the current mouse position.. | 1393 // under the current mouse position.. |
| 1394 TEST_F(WindowTest, MouseEnterExitWithHide) { | 1394 TEST_P(WindowTest, MouseEnterExitWithHide) { |
| 1395 MouseEnterExitWindowDelegate d1; | 1395 MouseEnterExitWindowDelegate d1; |
| 1396 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1396 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1397 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 1397 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1398 | 1398 |
| 1399 ui::test::EventGenerator generator(root_window()); | 1399 ui::test::EventGenerator generator(root_window()); |
| 1400 generator.MoveMouseToCenterOf(w1.get()); | 1400 generator.MoveMouseToCenterOf(w1.get()); |
| 1401 EXPECT_TRUE(d1.entered()); | 1401 EXPECT_TRUE(d1.entered()); |
| 1402 EXPECT_FALSE(d1.exited()); | 1402 EXPECT_FALSE(d1.exited()); |
| 1403 | 1403 |
| 1404 MouseEnterExitWindowDelegate d2; | 1404 MouseEnterExitWindowDelegate d2; |
| 1405 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( | 1405 std::unique_ptr<Window> w2(CreateTestWindowWithDelegate( |
| 1406 &d2, 2, gfx::Rect(10, 10, 50, 50), root_window())); | 1406 &d2, 2, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1407 // Enters / exits can be send asynchronously. | 1407 // Enters / exits can be send asynchronously. |
| 1408 RunAllPendingInMessageLoop(); | 1408 RunAllPendingInMessageLoop(); |
| 1409 EXPECT_TRUE(d1.entered()); | 1409 EXPECT_TRUE(d1.entered()); |
| 1410 EXPECT_TRUE(d1.exited()); | 1410 EXPECT_TRUE(d1.exited()); |
| 1411 EXPECT_TRUE(d2.entered()); | 1411 EXPECT_TRUE(d2.entered()); |
| 1412 EXPECT_FALSE(d2.exited()); | 1412 EXPECT_FALSE(d2.exited()); |
| 1413 | 1413 |
| 1414 d1.ResetExpectations(); | 1414 d1.ResetExpectations(); |
| 1415 w2->Hide(); | 1415 w2->Hide(); |
| 1416 // Enters / exits can be send asynchronously. | 1416 // Enters / exits can be send asynchronously. |
| 1417 RunAllPendingInMessageLoop(); | 1417 RunAllPendingInMessageLoop(); |
| 1418 EXPECT_TRUE(d2.exited()); | 1418 EXPECT_TRUE(d2.exited()); |
| 1419 EXPECT_TRUE(d1.entered()); | 1419 EXPECT_TRUE(d1.entered()); |
| 1420 } | 1420 } |
| 1421 | 1421 |
| 1422 TEST_F(WindowTest, MouseEnterExitWithParentHide) { | 1422 TEST_P(WindowTest, MouseEnterExitWithParentHide) { |
| 1423 MouseEnterExitWindowDelegate d1; | 1423 MouseEnterExitWindowDelegate d1; |
| 1424 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1424 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1425 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 1425 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1426 MouseEnterExitWindowDelegate d2; | 1426 MouseEnterExitWindowDelegate d2; |
| 1427 Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), | 1427 Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), |
| 1428 w1.get()); | 1428 w1.get()); |
| 1429 ui::test::EventGenerator generator(root_window()); | 1429 ui::test::EventGenerator generator(root_window()); |
| 1430 generator.MoveMouseToCenterOf(w2); | 1430 generator.MoveMouseToCenterOf(w2); |
| 1431 // Enters / exits can be send asynchronously. | 1431 // Enters / exits can be send asynchronously. |
| 1432 RunAllPendingInMessageLoop(); | 1432 RunAllPendingInMessageLoop(); |
| 1433 EXPECT_TRUE(d2.entered()); | 1433 EXPECT_TRUE(d2.entered()); |
| 1434 EXPECT_FALSE(d2.exited()); | 1434 EXPECT_FALSE(d2.exited()); |
| 1435 | 1435 |
| 1436 d2.ResetExpectations(); | 1436 d2.ResetExpectations(); |
| 1437 w1->Hide(); | 1437 w1->Hide(); |
| 1438 RunAllPendingInMessageLoop(); | 1438 RunAllPendingInMessageLoop(); |
| 1439 EXPECT_FALSE(d2.entered()); | 1439 EXPECT_FALSE(d2.entered()); |
| 1440 EXPECT_TRUE(d2.exited()); | 1440 EXPECT_TRUE(d2.exited()); |
| 1441 | 1441 |
| 1442 w1.reset(); | 1442 w1.reset(); |
| 1443 } | 1443 } |
| 1444 | 1444 |
| 1445 TEST_F(WindowTest, MouseEnterExitWithParentDelete) { | 1445 TEST_P(WindowTest, MouseEnterExitWithParentDelete) { |
| 1446 MouseEnterExitWindowDelegate d1; | 1446 MouseEnterExitWindowDelegate d1; |
| 1447 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1447 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1448 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 1448 &d1, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 1449 MouseEnterExitWindowDelegate d2; | 1449 MouseEnterExitWindowDelegate d2; |
| 1450 Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), | 1450 Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50), |
| 1451 w1.get()); | 1451 w1.get()); |
| 1452 ui::test::EventGenerator generator(root_window()); | 1452 ui::test::EventGenerator generator(root_window()); |
| 1453 generator.MoveMouseToCenterOf(w2); | 1453 generator.MoveMouseToCenterOf(w2); |
| 1454 | 1454 |
| 1455 // Enters / exits can be send asynchronously. | 1455 // Enters / exits can be send asynchronously. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1468 EXPECT_FALSE(d2.entered()); | 1468 EXPECT_FALSE(d2.entered()); |
| 1469 EXPECT_FALSE(d2.exited()); | 1469 EXPECT_FALSE(d2.exited()); |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 1472 // Creates a window with a delegate (w111) that can handle events at a lower | 1472 // Creates a window with a delegate (w111) that can handle events at a lower |
| 1473 // z-index than a window without a delegate (w12). w12 is sized to fill the | 1473 // z-index than a window without a delegate (w12). w12 is sized to fill the |
| 1474 // entire bounds of the container. This test verifies that | 1474 // entire bounds of the container. This test verifies that |
| 1475 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event, | 1475 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event, |
| 1476 // because it has no children that can handle the event and it has no delegate | 1476 // because it has no children that can handle the event and it has no delegate |
| 1477 // allowing it to handle the event itself. | 1477 // allowing it to handle the event itself. |
| 1478 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) { | 1478 TEST_P(WindowTest, GetEventHandlerForPoint_NoDelegate) { |
| 1479 TestWindowDelegate d111; | 1479 TestWindowDelegate d111; |
| 1480 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1480 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1481 NULL, 1, gfx::Rect(0, 0, 500, 500), root_window())); | 1481 NULL, 1, gfx::Rect(0, 0, 500, 500), root_window())); |
| 1482 std::unique_ptr<Window> w11(CreateTestWindowWithDelegate( | 1482 std::unique_ptr<Window> w11(CreateTestWindowWithDelegate( |
| 1483 NULL, 11, gfx::Rect(0, 0, 500, 500), w1.get())); | 1483 NULL, 11, gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1484 std::unique_ptr<Window> w111(CreateTestWindowWithDelegate( | 1484 std::unique_ptr<Window> w111(CreateTestWindowWithDelegate( |
| 1485 &d111, 111, gfx::Rect(50, 50, 450, 450), w11.get())); | 1485 &d111, 111, gfx::Rect(50, 50, 450, 450), w11.get())); |
| 1486 std::unique_ptr<Window> w12(CreateTestWindowWithDelegate( | 1486 std::unique_ptr<Window> w12(CreateTestWindowWithDelegate( |
| 1487 NULL, 12, gfx::Rect(0, 0, 500, 500), w1.get())); | 1487 NULL, 12, gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1488 | 1488 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1512 } | 1512 } |
| 1513 | 1513 |
| 1514 private: | 1514 private: |
| 1515 int shown_; | 1515 int shown_; |
| 1516 int hidden_; | 1516 int hidden_; |
| 1517 | 1517 |
| 1518 DISALLOW_COPY_AND_ASSIGN(VisibilityWindowDelegate); | 1518 DISALLOW_COPY_AND_ASSIGN(VisibilityWindowDelegate); |
| 1519 }; | 1519 }; |
| 1520 | 1520 |
| 1521 // Verifies show/hide propagate correctly to children and the layer. | 1521 // Verifies show/hide propagate correctly to children and the layer. |
| 1522 TEST_F(WindowTest, Visibility) { | 1522 TEST_P(WindowTest, Visibility) { |
| 1523 VisibilityWindowDelegate d; | 1523 VisibilityWindowDelegate d; |
| 1524 VisibilityWindowDelegate d2; | 1524 VisibilityWindowDelegate d2; |
| 1525 std::unique_ptr<Window> w1( | 1525 std::unique_ptr<Window> w1( |
| 1526 CreateTestWindowWithDelegate(&d, 1, gfx::Rect(), root_window())); | 1526 CreateTestWindowWithDelegate(&d, 1, gfx::Rect(), root_window())); |
| 1527 std::unique_ptr<Window> w2( | 1527 std::unique_ptr<Window> w2( |
| 1528 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get())); | 1528 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), w1.get())); |
| 1529 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, w2.get())); | 1529 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, w2.get())); |
| 1530 | 1530 |
| 1531 // Create shows all the windows. | 1531 // Create shows all the windows. |
| 1532 EXPECT_TRUE(w1->IsVisible()); | 1532 EXPECT_TRUE(w1->IsVisible()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 d2.Clear(); | 1571 d2.Clear(); |
| 1572 w2->Hide(); | 1572 w2->Hide(); |
| 1573 EXPECT_EQ(1, d2.hidden()); | 1573 EXPECT_EQ(1, d2.hidden()); |
| 1574 EXPECT_EQ(0, d2.shown()); | 1574 EXPECT_EQ(0, d2.shown()); |
| 1575 d2.Clear(); | 1575 d2.Clear(); |
| 1576 w2->Show(); | 1576 w2->Show(); |
| 1577 EXPECT_EQ(0, d2.hidden()); | 1577 EXPECT_EQ(0, d2.hidden()); |
| 1578 EXPECT_EQ(1, d2.shown()); | 1578 EXPECT_EQ(1, d2.shown()); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 TEST_F(WindowTest, IgnoreEventsTest) { | 1581 TEST_P(WindowTest, IgnoreEventsTest) { |
| 1582 TestWindowDelegate d11; | 1582 TestWindowDelegate d11; |
| 1583 TestWindowDelegate d12; | 1583 TestWindowDelegate d12; |
| 1584 TestWindowDelegate d111; | 1584 TestWindowDelegate d111; |
| 1585 TestWindowDelegate d121; | 1585 TestWindowDelegate d121; |
| 1586 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 1586 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 1587 NULL, 1, gfx::Rect(0, 0, 500, 500), root_window())); | 1587 NULL, 1, gfx::Rect(0, 0, 500, 500), root_window())); |
| 1588 std::unique_ptr<Window> w11(CreateTestWindowWithDelegate( | 1588 std::unique_ptr<Window> w11(CreateTestWindowWithDelegate( |
| 1589 &d11, 11, gfx::Rect(0, 0, 500, 500), w1.get())); | 1589 &d11, 11, gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1590 std::unique_ptr<Window> w111(CreateTestWindowWithDelegate( | 1590 std::unique_ptr<Window> w111(CreateTestWindowWithDelegate( |
| 1591 &d111, 111, gfx::Rect(50, 50, 450, 450), w11.get())); | 1591 &d111, 111, gfx::Rect(50, 50, 450, 450), w11.get())); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1602 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1602 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1603 w121->set_ignore_events(true); | 1603 w121->set_ignore_events(true); |
| 1604 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1604 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1605 w12->set_ignore_events(true); | 1605 w12->set_ignore_events(true); |
| 1606 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1606 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1607 w111->set_ignore_events(true); | 1607 w111->set_ignore_events(true); |
| 1608 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1608 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1609 } | 1609 } |
| 1610 | 1610 |
| 1611 // Tests transformation on the root window. | 1611 // Tests transformation on the root window. |
| 1612 TEST_F(WindowTest, Transform) { | 1612 TEST_P(WindowTest, Transform) { |
| 1613 gfx::Size size = host()->GetBounds().size(); | 1613 gfx::Size size = host()->GetBounds().size(); |
| 1614 EXPECT_EQ(gfx::Rect(size), display::Screen::GetScreen() | 1614 EXPECT_EQ(gfx::Rect(size), display::Screen::GetScreen() |
| 1615 ->GetDisplayNearestPoint(gfx::Point()) | 1615 ->GetDisplayNearestPoint(gfx::Point()) |
| 1616 .bounds()); | 1616 .bounds()); |
| 1617 | 1617 |
| 1618 // Rotate it clock-wise 90 degrees. | 1618 // Rotate it clock-wise 90 degrees. |
| 1619 gfx::Transform transform; | 1619 gfx::Transform transform; |
| 1620 transform.Translate(size.height(), 0); | 1620 transform.Translate(size.height(), 0); |
| 1621 transform.Rotate(90.0); | 1621 transform.Rotate(90.0); |
| 1622 host()->SetRootTransform(transform); | 1622 host()->SetRootTransform(transform); |
| 1623 | 1623 |
| 1624 // The size should be the transformed size. | 1624 // The size should be the transformed size. |
| 1625 gfx::Size transformed_size(size.height(), size.width()); | 1625 gfx::Size transformed_size(size.height(), size.width()); |
| 1626 EXPECT_EQ(transformed_size.ToString(), | 1626 EXPECT_EQ(transformed_size.ToString(), |
| 1627 root_window()->bounds().size().ToString()); | 1627 root_window()->bounds().size().ToString()); |
| 1628 EXPECT_EQ(gfx::Rect(transformed_size).ToString(), | 1628 EXPECT_EQ(gfx::Rect(transformed_size).ToString(), |
| 1629 display::Screen::GetScreen() | 1629 display::Screen::GetScreen() |
| 1630 ->GetDisplayNearestPoint(gfx::Point()) | 1630 ->GetDisplayNearestPoint(gfx::Point()) |
| 1631 .bounds() | 1631 .bounds() |
| 1632 .ToString()); | 1632 .ToString()); |
| 1633 | 1633 |
| 1634 // Host size shouldn't change. | 1634 // Host size shouldn't change. |
| 1635 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString()); | 1635 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString()); |
| 1636 } | 1636 } |
| 1637 | 1637 |
| 1638 TEST_F(WindowTest, TransformGesture) { | 1638 TEST_P(WindowTest, TransformGesture) { |
| 1639 gfx::Size size = host()->GetBounds().size(); | 1639 gfx::Size size = host()->GetBounds().size(); |
| 1640 | 1640 |
| 1641 std::unique_ptr<GestureTrackPositionDelegate> delegate( | 1641 std::unique_ptr<GestureTrackPositionDelegate> delegate( |
| 1642 new GestureTrackPositionDelegate); | 1642 new GestureTrackPositionDelegate); |
| 1643 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 1643 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 1644 delegate.get(), -1234, gfx::Rect(0, 0, 20, 20), root_window())); | 1644 delegate.get(), -1234, gfx::Rect(0, 0, 20, 20), root_window())); |
| 1645 | 1645 |
| 1646 // Rotate the root-window clock-wise 90 degrees. | 1646 // Rotate the root-window clock-wise 90 degrees. |
| 1647 gfx::Transform transform; | 1647 gfx::Transform transform; |
| 1648 transform.Translate(size.height(), 0.0); | 1648 transform.Translate(size.height(), 0.0); |
| 1649 transform.Rotate(90.0); | 1649 transform.Rotate(90.0); |
| 1650 host()->SetRootTransform(transform); | 1650 host()->SetRootTransform(transform); |
| 1651 | 1651 |
| 1652 ui::TouchEvent press( | 1652 ui::TouchEvent press( |
| 1653 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); | 1653 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); |
| 1654 DispatchEventUsingWindowDispatcher(&press); | 1654 DispatchEventUsingWindowDispatcher(&press); |
| 1655 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); | 1655 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); |
| 1656 } | 1656 } |
| 1657 | 1657 |
| 1658 namespace { | 1658 namespace { |
| 1659 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); | 1659 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); |
| 1660 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); | 1660 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); |
| 1661 } | 1661 } |
| 1662 | 1662 |
| 1663 TEST_F(WindowTest, Property) { | 1663 TEST_P(WindowTest, Property) { |
| 1664 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); | 1664 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); |
| 1665 | 1665 |
| 1666 static const char native_prop_key[] = "fnord"; | 1666 static const char native_prop_key[] = "fnord"; |
| 1667 | 1667 |
| 1668 // Non-existent properties should return the default values. | 1668 // Non-existent properties should return the default values. |
| 1669 EXPECT_EQ(-2, w->GetProperty(kIntKey)); | 1669 EXPECT_EQ(-2, w->GetProperty(kIntKey)); |
| 1670 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); | 1670 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); |
| 1671 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); | 1671 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); |
| 1672 | 1672 |
| 1673 // A set property value should be returned again (even if it's the default | 1673 // A set property value should be returned again (even if it's the default |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1691 w->SetNativeWindowProperty(native_prop_key, NULL); | 1691 w->SetNativeWindowProperty(native_prop_key, NULL); |
| 1692 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); | 1692 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); |
| 1693 | 1693 |
| 1694 // ClearProperty should restore the default value. | 1694 // ClearProperty should restore the default value. |
| 1695 w->ClearProperty(kIntKey); | 1695 w->ClearProperty(kIntKey); |
| 1696 EXPECT_EQ(-2, w->GetProperty(kIntKey)); | 1696 EXPECT_EQ(-2, w->GetProperty(kIntKey)); |
| 1697 w->ClearProperty(kStringKey); | 1697 w->ClearProperty(kStringKey); |
| 1698 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); | 1698 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); |
| 1699 } | 1699 } |
| 1700 | 1700 |
| 1701 TEST_F(WindowTest, OwnedProperty) { | 1701 TEST_P(WindowTest, OwnedProperty) { |
| 1702 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); | 1702 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); |
| 1703 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); | 1703 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); |
| 1704 TestProperty* last_deleted = TestProperty::last_deleted(); | 1704 TestProperty* last_deleted = TestProperty::last_deleted(); |
| 1705 TestProperty* p1 = new TestProperty(); | 1705 TestProperty* p1 = new TestProperty(); |
| 1706 w->SetProperty(kOwnedKey, p1); | 1706 w->SetProperty(kOwnedKey, p1); |
| 1707 EXPECT_EQ(p1, w->GetProperty(kOwnedKey)); | 1707 EXPECT_EQ(p1, w->GetProperty(kOwnedKey)); |
| 1708 EXPECT_EQ(last_deleted, TestProperty::last_deleted()); | 1708 EXPECT_EQ(last_deleted, TestProperty::last_deleted()); |
| 1709 | 1709 |
| 1710 TestProperty* p2 = new TestProperty(); | 1710 TestProperty* p2 = new TestProperty(); |
| 1711 w->SetProperty(kOwnedKey, p2); | 1711 w->SetProperty(kOwnedKey, p2); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1742 void SetChildBounds(Window* child, | 1742 void SetChildBounds(Window* child, |
| 1743 const gfx::Rect& requested_bounds) override {} | 1743 const gfx::Rect& requested_bounds) override {} |
| 1744 | 1744 |
| 1745 DeletionTracker* tracker_; | 1745 DeletionTracker* tracker_; |
| 1746 | 1746 |
| 1747 DISALLOW_COPY_AND_ASSIGN(DeletionTestLayoutManager); | 1747 DISALLOW_COPY_AND_ASSIGN(DeletionTestLayoutManager); |
| 1748 }; | 1748 }; |
| 1749 | 1749 |
| 1750 } // namespace | 1750 } // namespace |
| 1751 | 1751 |
| 1752 TEST_F(WindowTest, DeleteLayoutManagerBeforeOwnedProps) { | 1752 TEST_P(WindowTest, DeleteLayoutManagerBeforeOwnedProps) { |
| 1753 DeletionTracker tracker; | 1753 DeletionTracker tracker; |
| 1754 { | 1754 { |
| 1755 Window w(nullptr); | 1755 Window w(nullptr); |
| 1756 w.Init(ui::LAYER_NOT_DRAWN); | 1756 w.Init(ui::LAYER_NOT_DRAWN); |
| 1757 w.SetLayoutManager(new DeletionTestLayoutManager(&tracker)); | 1757 w.SetLayoutManager(new DeletionTestLayoutManager(&tracker)); |
| 1758 w.SetProperty(kDeletionTestPropertyKey, new DeletionTestProperty(&tracker)); | 1758 w.SetProperty(kDeletionTestPropertyKey, new DeletionTestProperty(&tracker)); |
| 1759 } | 1759 } |
| 1760 EXPECT_TRUE(tracker.property_deleted()); | 1760 EXPECT_TRUE(tracker.property_deleted()); |
| 1761 EXPECT_TRUE(tracker.layout_manager_deleted()); | 1761 EXPECT_TRUE(tracker.layout_manager_deleted()); |
| 1762 EXPECT_EQ(DeletionOrder::LAYOUT_MANAGER_FIRST, tracker.order()); | 1762 EXPECT_EQ(DeletionOrder::LAYOUT_MANAGER_FIRST, tracker.order()); |
| 1763 } | 1763 } |
| 1764 | 1764 |
| 1765 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { | 1765 TEST_P(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { |
| 1766 // We cannot short-circuit animations in this test. | 1766 // We cannot short-circuit animations in this test. |
| 1767 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 1767 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 1768 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 1768 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 1769 | 1769 |
| 1770 std::unique_ptr<Window> w1( | 1770 std::unique_ptr<Window> w1( |
| 1771 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); | 1771 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); |
| 1772 | 1772 |
| 1773 EXPECT_TRUE(w1->layer()); | 1773 EXPECT_TRUE(w1->layer()); |
| 1774 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); | 1774 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); |
| 1775 ui::LayerAnimator* animator = w1->layer()->GetAnimator(); | 1775 ui::LayerAnimator* animator = w1->layer()->GetAnimator(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1908 int destroyed_count_; | 1908 int destroyed_count_; |
| 1909 std::unique_ptr<VisibilityInfo> visibility_info_; | 1909 std::unique_ptr<VisibilityInfo> visibility_info_; |
| 1910 const void* property_key_; | 1910 const void* property_key_; |
| 1911 intptr_t old_property_value_; | 1911 intptr_t old_property_value_; |
| 1912 std::vector<std::pair<int, int> > transform_notifications_; | 1912 std::vector<std::pair<int, int> > transform_notifications_; |
| 1913 | 1913 |
| 1914 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); | 1914 DISALLOW_COPY_AND_ASSIGN(WindowObserverTest); |
| 1915 }; | 1915 }; |
| 1916 | 1916 |
| 1917 // Various assertions for WindowObserver. | 1917 // Various assertions for WindowObserver. |
| 1918 TEST_F(WindowObserverTest, WindowObserver) { | 1918 TEST_P(WindowObserverTest, WindowObserver) { |
| 1919 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 1919 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 1920 w1->AddObserver(this); | 1920 w1->AddObserver(this); |
| 1921 | 1921 |
| 1922 // Create a new window as a child of w1, our observer should be notified. | 1922 // Create a new window as a child of w1, our observer should be notified. |
| 1923 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); | 1923 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); |
| 1924 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear()); | 1924 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear()); |
| 1925 | 1925 |
| 1926 // Delete w2, which should result in the remove notification. | 1926 // Delete w2, which should result in the remove notification. |
| 1927 w2.reset(); | 1927 w2.reset(); |
| 1928 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear()); | 1928 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear()); |
| 1929 | 1929 |
| 1930 // Create a window that isn't parented to w1, we shouldn't get any | 1930 // Create a window that isn't parented to w1, we shouldn't get any |
| 1931 // notification. | 1931 // notification. |
| 1932 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, root_window())); | 1932 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, root_window())); |
| 1933 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); | 1933 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); |
| 1934 | 1934 |
| 1935 // Similarly destroying w3 shouldn't notify us either. | 1935 // Similarly destroying w3 shouldn't notify us either. |
| 1936 w3.reset(); | 1936 w3.reset(); |
| 1937 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); | 1937 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); |
| 1938 w1->RemoveObserver(this); | 1938 w1->RemoveObserver(this); |
| 1939 } | 1939 } |
| 1940 | 1940 |
| 1941 // Test if OnWindowVisibilityChanged is invoked with expected | 1941 // Test if OnWindowVisibilityChanged is invoked with expected |
| 1942 // parameters. | 1942 // parameters. |
| 1943 TEST_F(WindowObserverTest, WindowVisibility) { | 1943 TEST_P(WindowObserverTest, WindowVisibility) { |
| 1944 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 1944 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 1945 std::unique_ptr<Window> w2(CreateTestWindowWithId(1, w1.get())); | 1945 std::unique_ptr<Window> w2(CreateTestWindowWithId(1, w1.get())); |
| 1946 w2->AddObserver(this); | 1946 w2->AddObserver(this); |
| 1947 | 1947 |
| 1948 // Hide should make the window invisible and the passed visible | 1948 // Hide should make the window invisible and the passed visible |
| 1949 // parameter is false. | 1949 // parameter is false. |
| 1950 w2->Hide(); | 1950 w2->Hide(); |
| 1951 EXPECT_TRUE(GetVisibilityInfo()); | 1951 EXPECT_TRUE(GetVisibilityInfo()); |
| 1952 EXPECT_TRUE(GetVisibilityInfo()); | 1952 EXPECT_TRUE(GetVisibilityInfo()); |
| 1953 if (!GetVisibilityInfo()) | 1953 if (!GetVisibilityInfo()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 // Verify that the OnWindowVisibilityChanged only once | 1985 // Verify that the OnWindowVisibilityChanged only once |
| 1986 // per visibility change. | 1986 // per visibility change. |
| 1987 w2->Hide(); | 1987 w2->Hide(); |
| 1988 EXPECT_EQ(2, GetVisibilityInfo()->changed_count); | 1988 EXPECT_EQ(2, GetVisibilityInfo()->changed_count); |
| 1989 | 1989 |
| 1990 w2->Hide(); | 1990 w2->Hide(); |
| 1991 EXPECT_EQ(2, GetVisibilityInfo()->changed_count); | 1991 EXPECT_EQ(2, GetVisibilityInfo()->changed_count); |
| 1992 } | 1992 } |
| 1993 | 1993 |
| 1994 // Test if OnWindowDestroyed is invoked as expected. | 1994 // Test if OnWindowDestroyed is invoked as expected. |
| 1995 TEST_F(WindowObserverTest, WindowDestroyed) { | 1995 TEST_P(WindowObserverTest, WindowDestroyed) { |
| 1996 // Delete a window should fire a destroyed notification. | 1996 // Delete a window should fire a destroyed notification. |
| 1997 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 1997 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 1998 w1->AddObserver(this); | 1998 w1->AddObserver(this); |
| 1999 w1.reset(); | 1999 w1.reset(); |
| 2000 EXPECT_EQ(1, DestroyedCountAndClear()); | 2000 EXPECT_EQ(1, DestroyedCountAndClear()); |
| 2001 | 2001 |
| 2002 // Observe on child and delete parent window should fire a notification. | 2002 // Observe on child and delete parent window should fire a notification. |
| 2003 std::unique_ptr<Window> parent(CreateTestWindowWithId(1, root_window())); | 2003 std::unique_ptr<Window> parent(CreateTestWindowWithId(1, root_window())); |
| 2004 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent | 2004 Window* child = CreateTestWindowWithId(1, parent.get()); // owned by parent |
| 2005 child->AddObserver(this); | 2005 child->AddObserver(this); |
| 2006 parent.reset(); | 2006 parent.reset(); |
| 2007 EXPECT_EQ(1, DestroyedCountAndClear()); | 2007 EXPECT_EQ(1, DestroyedCountAndClear()); |
| 2008 } | 2008 } |
| 2009 | 2009 |
| 2010 TEST_F(WindowObserverTest, PropertyChanged) { | 2010 TEST_P(WindowObserverTest, PropertyChanged) { |
| 2011 // Setting property should fire a property change notification. | 2011 // Setting property should fire a property change notification. |
| 2012 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 2012 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 2013 w1->AddObserver(this); | 2013 w1->AddObserver(this); |
| 2014 | 2014 |
| 2015 static const WindowProperty<int> prop = {-2}; | 2015 static const WindowProperty<int> prop = {-2}; |
| 2016 static const char native_prop_key[] = "fnord"; | 2016 static const char native_prop_key[] = "fnord"; |
| 2017 | 2017 |
| 2018 w1->SetProperty(&prop, 1); | 2018 w1->SetProperty(&prop, 1); |
| 2019 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); | 2019 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); |
| 2020 w1->SetProperty(&prop, -2); | 2020 w1->SetProperty(&prop, -2); |
| 2021 EXPECT_EQ(PropertyChangeInfo(&prop, 1), PropertyChangeInfoAndClear()); | 2021 EXPECT_EQ(PropertyChangeInfo(&prop, 1), PropertyChangeInfoAndClear()); |
| 2022 w1->SetProperty(&prop, 3); | 2022 w1->SetProperty(&prop, 3); |
| 2023 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); | 2023 EXPECT_EQ(PropertyChangeInfo(&prop, -2), PropertyChangeInfoAndClear()); |
| 2024 w1->ClearProperty(&prop); | 2024 w1->ClearProperty(&prop); |
| 2025 EXPECT_EQ(PropertyChangeInfo(&prop, 3), PropertyChangeInfoAndClear()); | 2025 EXPECT_EQ(PropertyChangeInfo(&prop, 3), PropertyChangeInfoAndClear()); |
| 2026 | 2026 |
| 2027 w1->SetNativeWindowProperty(native_prop_key, &*w1); | 2027 w1->SetNativeWindowProperty(native_prop_key, &*w1); |
| 2028 EXPECT_EQ(PropertyChangeInfo(native_prop_key, 0), | 2028 EXPECT_EQ(PropertyChangeInfo(native_prop_key, 0), |
| 2029 PropertyChangeInfoAndClear()); | 2029 PropertyChangeInfoAndClear()); |
| 2030 w1->SetNativeWindowProperty(native_prop_key, NULL); | 2030 w1->SetNativeWindowProperty(native_prop_key, NULL); |
| 2031 EXPECT_EQ(PropertyChangeInfo(native_prop_key, | 2031 EXPECT_EQ(PropertyChangeInfo(native_prop_key, |
| 2032 reinterpret_cast<intptr_t>(&*w1)), | 2032 reinterpret_cast<intptr_t>(&*w1)), |
| 2033 PropertyChangeInfoAndClear()); | 2033 PropertyChangeInfoAndClear()); |
| 2034 | 2034 |
| 2035 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. | 2035 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. |
| 2036 EXPECT_EQ(PropertyChangeInfo( | 2036 EXPECT_EQ(PropertyChangeInfo( |
| 2037 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear()); | 2037 reinterpret_cast<const void*>(NULL), -3), PropertyChangeInfoAndClear()); |
| 2038 } | 2038 } |
| 2039 | 2039 |
| 2040 TEST_F(WindowObserverTest, AncestorTransformed) { | 2040 TEST_P(WindowObserverTest, AncestorTransformed) { |
| 2041 // Create following window hierarchy: | 2041 // Create following window hierarchy: |
| 2042 // root_window | 2042 // root_window |
| 2043 // +-- w1 | 2043 // +-- w1 |
| 2044 // +-- w2 | 2044 // +-- w2 |
| 2045 // +-- w3 | 2045 // +-- w3 |
| 2046 // +-- w4 | 2046 // +-- w4 |
| 2047 // Then, apply a transform to |w1| and ensure all its descendants are | 2047 // Then, apply a transform to |w1| and ensure all its descendants are |
| 2048 // notified. | 2048 // notified. |
| 2049 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 2049 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 2050 w1->AddObserver(this); | 2050 w1->AddObserver(this); |
| 2051 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); | 2051 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); |
| 2052 w2->AddObserver(this); | 2052 w2->AddObserver(this); |
| 2053 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, w1.get())); | 2053 std::unique_ptr<Window> w3(CreateTestWindowWithId(3, w1.get())); |
| 2054 w3->AddObserver(this); | 2054 w3->AddObserver(this); |
| 2055 std::unique_ptr<Window> w4(CreateTestWindowWithId(4, w3.get())); | 2055 std::unique_ptr<Window> w4(CreateTestWindowWithId(4, w3.get())); |
| 2056 w4->AddObserver(this); | 2056 w4->AddObserver(this); |
| 2057 | 2057 |
| 2058 EXPECT_EQ(std::string(), TransformNotificationsAndClear()); | 2058 EXPECT_EQ(std::string(), TransformNotificationsAndClear()); |
| 2059 | 2059 |
| 2060 gfx::Transform transform; | 2060 gfx::Transform transform; |
| 2061 transform.Translate(10, 10); | 2061 transform.Translate(10, 10); |
| 2062 w1->SetTransform(transform); | 2062 w1->SetTransform(transform); |
| 2063 | 2063 |
| 2064 EXPECT_EQ("(1,1)(1,2)(1,3)(1,4)", TransformNotificationsAndClear()); | 2064 EXPECT_EQ("(1,1)(1,2)(1,3)(1,4)", TransformNotificationsAndClear()); |
| 2065 } | 2065 } |
| 2066 | 2066 |
| 2067 TEST_F(WindowTest, AcquireLayer) { | 2067 TEST_P(WindowTest, AcquireLayer) { |
| 2068 std::unique_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); | 2068 std::unique_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
| 2069 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); | 2069 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); |
| 2070 ui::Layer* parent = window1->parent()->layer(); | 2070 ui::Layer* parent = window1->parent()->layer(); |
| 2071 EXPECT_EQ(2U, parent->children().size()); | 2071 EXPECT_EQ(2U, parent->children().size()); |
| 2072 | 2072 |
| 2073 WindowTestApi window1_test_api(window1.get()); | 2073 WindowTestApi window1_test_api(window1.get()); |
| 2074 WindowTestApi window2_test_api(window2.get()); | 2074 WindowTestApi window2_test_api(window2.get()); |
| 2075 | 2075 |
| 2076 EXPECT_TRUE(window1_test_api.OwnsLayer()); | 2076 EXPECT_TRUE(window1_test_api.OwnsLayer()); |
| 2077 EXPECT_TRUE(window2_test_api.OwnsLayer()); | 2077 EXPECT_TRUE(window2_test_api.OwnsLayer()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2093 window1.reset(); | 2093 window1.reset(); |
| 2094 window2.reset(); | 2094 window2.reset(); |
| 2095 | 2095 |
| 2096 // This should be set by the window's destructor. | 2096 // This should be set by the window's destructor. |
| 2097 EXPECT_TRUE(window1_layer->delegate() == NULL); | 2097 EXPECT_TRUE(window1_layer->delegate() == NULL); |
| 2098 EXPECT_EQ(1U, parent->children().size()); | 2098 EXPECT_EQ(1U, parent->children().size()); |
| 2099 } | 2099 } |
| 2100 | 2100 |
| 2101 // Make sure that properties which should persist from the old layer to the new | 2101 // Make sure that properties which should persist from the old layer to the new |
| 2102 // layer actually do. | 2102 // layer actually do. |
| 2103 TEST_F(WindowTest, RecreateLayer) { | 2103 TEST_P(WindowTest, RecreateLayer) { |
| 2104 // Set properties to non default values. | 2104 // Set properties to non default values. |
| 2105 gfx::Rect window_bounds(100, 100); | 2105 gfx::Rect window_bounds(100, 100); |
| 2106 Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); | 2106 Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); |
| 2107 w.set_id(1); | 2107 w.set_id(1); |
| 2108 w.Init(ui::LAYER_SOLID_COLOR); | 2108 w.Init(ui::LAYER_SOLID_COLOR); |
| 2109 w.SetBounds(window_bounds); | 2109 w.SetBounds(window_bounds); |
| 2110 | 2110 |
| 2111 ui::Layer* layer = w.layer(); | 2111 ui::Layer* layer = w.layer(); |
| 2112 layer->SetVisible(false); | 2112 layer->SetVisible(false); |
| 2113 layer->SetMasksToBounds(true); | 2113 layer->SetMasksToBounds(true); |
| 2114 | 2114 |
| 2115 ui::Layer child_layer; | 2115 ui::Layer child_layer; |
| 2116 layer->Add(&child_layer); | 2116 layer->Add(&child_layer); |
| 2117 | 2117 |
| 2118 std::unique_ptr<ui::Layer> old_layer(w.RecreateLayer()); | 2118 std::unique_ptr<ui::Layer> old_layer(w.RecreateLayer()); |
| 2119 layer = w.layer(); | 2119 layer = w.layer(); |
| 2120 EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type()); | 2120 EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type()); |
| 2121 EXPECT_FALSE(layer->visible()); | 2121 EXPECT_FALSE(layer->visible()); |
| 2122 EXPECT_EQ(1u, layer->children().size()); | 2122 EXPECT_EQ(1u, layer->children().size()); |
| 2123 EXPECT_TRUE(layer->GetMasksToBounds()); | 2123 EXPECT_TRUE(layer->GetMasksToBounds()); |
| 2124 EXPECT_EQ("0,0 100x100", w.bounds().ToString()); | 2124 EXPECT_EQ("0,0 100x100", w.bounds().ToString()); |
| 2125 EXPECT_EQ("0,0 100x100", layer->bounds().ToString()); | 2125 EXPECT_EQ("0,0 100x100", layer->bounds().ToString()); |
| 2126 } | 2126 } |
| 2127 | 2127 |
| 2128 // Verify that RecreateLayer() stacks the old layer above the newly creatd | 2128 // Verify that RecreateLayer() stacks the old layer above the newly creatd |
| 2129 // layer. | 2129 // layer. |
| 2130 TEST_F(WindowTest, RecreateLayerZOrder) { | 2130 TEST_P(WindowTest, RecreateLayerZOrder) { |
| 2131 std::unique_ptr<Window> w(CreateTestWindow( | 2131 std::unique_ptr<Window> w(CreateTestWindow( |
| 2132 SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 2132 SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2133 std::unique_ptr<ui::Layer> old_layer(w->RecreateLayer()); | 2133 std::unique_ptr<ui::Layer> old_layer(w->RecreateLayer()); |
| 2134 | 2134 |
| 2135 const std::vector<ui::Layer*>& child_layers = | 2135 const std::vector<ui::Layer*>& child_layers = |
| 2136 root_window()->layer()->children(); | 2136 root_window()->layer()->children(); |
| 2137 ASSERT_EQ(2u, child_layers.size()); | 2137 ASSERT_EQ(2u, child_layers.size()); |
| 2138 EXPECT_EQ(w->layer(), child_layers[0]); | 2138 EXPECT_EQ(w->layer(), child_layers[0]); |
| 2139 EXPECT_EQ(old_layer.get(), child_layers[1]); | 2139 EXPECT_EQ(old_layer.get(), child_layers[1]); |
| 2140 } | 2140 } |
| 2141 | 2141 |
| 2142 // Ensure that acquiring a layer then recreating a layer does not crash | 2142 // Ensure that acquiring a layer then recreating a layer does not crash |
| 2143 // and that RecreateLayer returns null. | 2143 // and that RecreateLayer returns null. |
| 2144 TEST_F(WindowTest, AcquireThenRecreateLayer) { | 2144 TEST_P(WindowTest, AcquireThenRecreateLayer) { |
| 2145 std::unique_ptr<Window> w(CreateTestWindow( | 2145 std::unique_ptr<Window> w(CreateTestWindow( |
| 2146 SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 2146 SK_ColorWHITE, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2147 std::unique_ptr<ui::Layer> acquired_layer(w->AcquireLayer()); | 2147 std::unique_ptr<ui::Layer> acquired_layer(w->AcquireLayer()); |
| 2148 std::unique_ptr<ui::Layer> doubly_acquired_layer(w->RecreateLayer()); | 2148 std::unique_ptr<ui::Layer> doubly_acquired_layer(w->RecreateLayer()); |
| 2149 EXPECT_EQ(NULL, doubly_acquired_layer.get()); | 2149 EXPECT_EQ(NULL, doubly_acquired_layer.get()); |
| 2150 | 2150 |
| 2151 // Destroy window before layer gets destroyed. | 2151 // Destroy window before layer gets destroyed. |
| 2152 w.reset(); | 2152 w.reset(); |
| 2153 } | 2153 } |
| 2154 | 2154 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2168 void UpdateLayerVisibility(aura::Window* window, bool visible) override { | 2168 void UpdateLayerVisibility(aura::Window* window, bool visible) override { |
| 2169 if (!ignore_visibility_changes_) | 2169 if (!ignore_visibility_changes_) |
| 2170 window->layer()->SetVisible(visible); | 2170 window->layer()->SetVisible(visible); |
| 2171 } | 2171 } |
| 2172 | 2172 |
| 2173 private: | 2173 private: |
| 2174 bool ignore_visibility_changes_; | 2174 bool ignore_visibility_changes_; |
| 2175 DISALLOW_COPY_AND_ASSIGN(TestVisibilityClient); | 2175 DISALLOW_COPY_AND_ASSIGN(TestVisibilityClient); |
| 2176 }; | 2176 }; |
| 2177 | 2177 |
| 2178 TEST_F(WindowTest, VisibilityClientIsVisible) { | 2178 TEST_P(WindowTest, VisibilityClientIsVisible) { |
| 2179 TestVisibilityClient client(root_window()); | 2179 TestVisibilityClient client(root_window()); |
| 2180 | 2180 |
| 2181 std::unique_ptr<Window> window(CreateTestWindowWithId(1, root_window())); | 2181 std::unique_ptr<Window> window(CreateTestWindowWithId(1, root_window())); |
| 2182 EXPECT_TRUE(window->IsVisible()); | 2182 EXPECT_TRUE(window->IsVisible()); |
| 2183 EXPECT_TRUE(window->layer()->visible()); | 2183 EXPECT_TRUE(window->layer()->visible()); |
| 2184 | 2184 |
| 2185 window->Hide(); | 2185 window->Hide(); |
| 2186 EXPECT_FALSE(window->IsVisible()); | 2186 EXPECT_FALSE(window->IsVisible()); |
| 2187 EXPECT_FALSE(window->layer()->visible()); | 2187 EXPECT_FALSE(window->layer()->visible()); |
| 2188 window->Show(); | 2188 window->Show(); |
| 2189 | 2189 |
| 2190 client.set_ignore_visibility_changes(true); | 2190 client.set_ignore_visibility_changes(true); |
| 2191 window->Hide(); | 2191 window->Hide(); |
| 2192 EXPECT_FALSE(window->IsVisible()); | 2192 EXPECT_FALSE(window->IsVisible()); |
| 2193 EXPECT_TRUE(window->layer()->visible()); | 2193 EXPECT_TRUE(window->layer()->visible()); |
| 2194 } | 2194 } |
| 2195 | 2195 |
| 2196 // Tests the mouse events seen by WindowDelegates in a Window hierarchy when | 2196 // Tests the mouse events seen by WindowDelegates in a Window hierarchy when |
| 2197 // changing the properties of a leaf Window. | 2197 // changing the properties of a leaf Window. |
| 2198 TEST_F(WindowTest, MouseEventsOnLeafWindowChange) { | 2198 TEST_P(WindowTest, MouseEventsOnLeafWindowChange) { |
| 2199 ui::test::EventGenerator generator(root_window()); | 2199 ui::test::EventGenerator generator(root_window()); |
| 2200 generator.MoveMouseTo(50, 50); | 2200 generator.MoveMouseTo(50, 50); |
| 2201 | 2201 |
| 2202 EventCountDelegate d1; | 2202 EventCountDelegate d1; |
| 2203 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 2203 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 2204 &d1, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 2204 &d1, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2205 RunAllPendingInMessageLoop(); | 2205 RunAllPendingInMessageLoop(); |
| 2206 // The format of result is "Enter/Move/Leave". | 2206 // The format of result is "Enter/Move/Leave". |
| 2207 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); | 2207 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); |
| 2208 | 2208 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2287 | 2287 |
| 2288 // Close |w11|. | 2288 // Close |w11|. |
| 2289 w11.reset(); | 2289 w11.reset(); |
| 2290 RunAllPendingInMessageLoop(); | 2290 RunAllPendingInMessageLoop(); |
| 2291 EXPECT_EQ("0 0 0", d1.GetMouseMotionCountsAndReset()); | 2291 EXPECT_EQ("0 0 0", d1.GetMouseMotionCountsAndReset()); |
| 2292 EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset()); | 2292 EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset()); |
| 2293 } | 2293 } |
| 2294 | 2294 |
| 2295 // Tests the mouse events seen by WindowDelegates in a Window hierarchy when | 2295 // Tests the mouse events seen by WindowDelegates in a Window hierarchy when |
| 2296 // deleting a non-leaf Window. | 2296 // deleting a non-leaf Window. |
| 2297 TEST_F(WindowTest, MouseEventsOnNonLeafWindowDelete) { | 2297 TEST_P(WindowTest, MouseEventsOnNonLeafWindowDelete) { |
| 2298 ui::test::EventGenerator generator(root_window()); | 2298 ui::test::EventGenerator generator(root_window()); |
| 2299 generator.MoveMouseTo(50, 50); | 2299 generator.MoveMouseTo(50, 50); |
| 2300 | 2300 |
| 2301 EventCountDelegate d1; | 2301 EventCountDelegate d1; |
| 2302 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( | 2302 std::unique_ptr<Window> w1(CreateTestWindowWithDelegate( |
| 2303 &d1, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 2303 &d1, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2304 RunAllPendingInMessageLoop(); | 2304 RunAllPendingInMessageLoop(); |
| 2305 // The format of result is "Enter/Move/Leave". | 2305 // The format of result is "Enter/Move/Leave". |
| 2306 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); | 2306 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); |
| 2307 | 2307 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2352 ++removed_count_; | 2352 ++removed_count_; |
| 2353 } | 2353 } |
| 2354 | 2354 |
| 2355 private: | 2355 private: |
| 2356 int added_count_; | 2356 int added_count_; |
| 2357 int removed_count_; | 2357 int removed_count_; |
| 2358 | 2358 |
| 2359 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); | 2359 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); |
| 2360 }; | 2360 }; |
| 2361 | 2361 |
| 2362 TEST_F(WindowTest, RootWindowAttachment) { | 2362 TEST_P(WindowTest, RootWindowAttachment) { |
| 2363 RootWindowAttachmentObserver observer; | 2363 RootWindowAttachmentObserver observer; |
| 2364 | 2364 |
| 2365 // Test a direct add/remove from the RootWindow. | 2365 // Test a direct add/remove from the RootWindow. |
| 2366 std::unique_ptr<Window> w1(new Window(NULL)); | 2366 std::unique_ptr<Window> w1(new Window(NULL)); |
| 2367 w1->Init(ui::LAYER_NOT_DRAWN); | 2367 w1->Init(ui::LAYER_NOT_DRAWN); |
| 2368 w1->AddObserver(&observer); | 2368 w1->AddObserver(&observer); |
| 2369 | 2369 |
| 2370 ParentWindow(w1.get()); | 2370 ParentWindow(w1.get()); |
| 2371 EXPECT_EQ(1, observer.added_count()); | 2371 EXPECT_EQ(1, observer.added_count()); |
| 2372 EXPECT_EQ(0, observer.removed_count()); | 2372 EXPECT_EQ(0, observer.removed_count()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2435 } | 2435 } |
| 2436 | 2436 |
| 2437 bool root_set() const { return root_set_; } | 2437 bool root_set() const { return root_set_; } |
| 2438 | 2438 |
| 2439 private: | 2439 private: |
| 2440 bool root_set_; | 2440 bool root_set_; |
| 2441 | 2441 |
| 2442 DISALLOW_COPY_AND_ASSIGN(BoundsChangedWindowObserver); | 2442 DISALLOW_COPY_AND_ASSIGN(BoundsChangedWindowObserver); |
| 2443 }; | 2443 }; |
| 2444 | 2444 |
| 2445 TEST_F(WindowTest, RootWindowSetWhenReparenting) { | 2445 TEST_P(WindowTest, RootWindowSetWhenReparenting) { |
| 2446 Window parent1(NULL); | 2446 Window parent1(NULL); |
| 2447 parent1.Init(ui::LAYER_NOT_DRAWN); | 2447 parent1.Init(ui::LAYER_NOT_DRAWN); |
| 2448 Window parent2(NULL); | 2448 Window parent2(NULL); |
| 2449 parent2.Init(ui::LAYER_NOT_DRAWN); | 2449 parent2.Init(ui::LAYER_NOT_DRAWN); |
| 2450 ParentWindow(&parent1); | 2450 ParentWindow(&parent1); |
| 2451 ParentWindow(&parent2); | 2451 ParentWindow(&parent2); |
| 2452 parent1.SetBounds(gfx::Rect(10, 10, 300, 300)); | 2452 parent1.SetBounds(gfx::Rect(10, 10, 300, 300)); |
| 2453 parent2.SetBounds(gfx::Rect(20, 20, 300, 300)); | 2453 parent2.SetBounds(gfx::Rect(20, 20, 300, 300)); |
| 2454 | 2454 |
| 2455 BoundsChangedWindowObserver observer; | 2455 BoundsChangedWindowObserver observer; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2473 parent2.AddChild(&child); | 2473 parent2.AddChild(&child); |
| 2474 EXPECT_TRUE(observer.root_set()); | 2474 EXPECT_TRUE(observer.root_set()); |
| 2475 | 2475 |
| 2476 // Animations should stop and the bounds should be as set before the |child| | 2476 // Animations should stop and the bounds should be as set before the |child| |
| 2477 // got reparented. | 2477 // got reparented. |
| 2478 EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString()); | 2478 EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString()); |
| 2479 EXPECT_EQ(new_bounds.ToString(), child.bounds().ToString()); | 2479 EXPECT_EQ(new_bounds.ToString(), child.bounds().ToString()); |
| 2480 EXPECT_EQ("55,55 50x50", child.GetBoundsInRootWindow().ToString()); | 2480 EXPECT_EQ("55,55 50x50", child.GetBoundsInRootWindow().ToString()); |
| 2481 } | 2481 } |
| 2482 | 2482 |
| 2483 TEST_F(WindowTest, OwnedByParentFalse) { | 2483 TEST_P(WindowTest, OwnedByParentFalse) { |
| 2484 // By default, a window is owned by its parent. If this is set to false, the | 2484 // By default, a window is owned by its parent. If this is set to false, the |
| 2485 // window will not be destroyed when its parent is. | 2485 // window will not be destroyed when its parent is. |
| 2486 | 2486 |
| 2487 std::unique_ptr<Window> w1(new Window(NULL)); | 2487 std::unique_ptr<Window> w1(new Window(NULL)); |
| 2488 w1->Init(ui::LAYER_NOT_DRAWN); | 2488 w1->Init(ui::LAYER_NOT_DRAWN); |
| 2489 std::unique_ptr<Window> w2(new Window(NULL)); | 2489 std::unique_ptr<Window> w2(new Window(NULL)); |
| 2490 w2->set_owned_by_parent(false); | 2490 w2->set_owned_by_parent(false); |
| 2491 w2->Init(ui::LAYER_NOT_DRAWN); | 2491 w2->Init(ui::LAYER_NOT_DRAWN); |
| 2492 w1->AddChild(w2.get()); | 2492 w1->AddChild(w2.get()); |
| 2493 | 2493 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2517 DISALLOW_COPY_AND_ASSIGN(OwningWindowDelegate); | 2517 DISALLOW_COPY_AND_ASSIGN(OwningWindowDelegate); |
| 2518 }; | 2518 }; |
| 2519 | 2519 |
| 2520 } // namespace | 2520 } // namespace |
| 2521 | 2521 |
| 2522 // Creates a window with two child windows. When the first child window is | 2522 // Creates a window with two child windows. When the first child window is |
| 2523 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. | 2523 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. |
| 2524 // This synthesizes BrowserView and the status bubble. Both are children of the | 2524 // This synthesizes BrowserView and the status bubble. Both are children of the |
| 2525 // same parent and destroying BrowserView triggers it destroying the status | 2525 // same parent and destroying BrowserView triggers it destroying the status |
| 2526 // bubble. | 2526 // bubble. |
| 2527 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { | 2527 TEST_P(WindowTest, DeleteWindowFromOnWindowDestroyed) { |
| 2528 std::unique_ptr<Window> parent(new Window(NULL)); | 2528 std::unique_ptr<Window> parent(new Window(NULL)); |
| 2529 parent->Init(ui::LAYER_NOT_DRAWN); | 2529 parent->Init(ui::LAYER_NOT_DRAWN); |
| 2530 OwningWindowDelegate delegate; | 2530 OwningWindowDelegate delegate; |
| 2531 Window* c1 = new Window(&delegate); | 2531 Window* c1 = new Window(&delegate); |
| 2532 c1->Init(ui::LAYER_NOT_DRAWN); | 2532 c1->Init(ui::LAYER_NOT_DRAWN); |
| 2533 parent->AddChild(c1); | 2533 parent->AddChild(c1); |
| 2534 Window* c2 = new Window(NULL); | 2534 Window* c2 = new Window(NULL); |
| 2535 c2->Init(ui::LAYER_NOT_DRAWN); | 2535 c2->Init(ui::LAYER_NOT_DRAWN); |
| 2536 parent->AddChild(c2); | 2536 parent->AddChild(c2); |
| 2537 delegate.SetOwnedWindow(c2); | 2537 delegate.SetOwnedWindow(c2); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2561 // Was OnBoundsChanged() invoked? | 2561 // Was OnBoundsChanged() invoked? |
| 2562 bool bounds_changed_; | 2562 bool bounds_changed_; |
| 2563 | 2563 |
| 2564 DISALLOW_COPY_AND_ASSIGN(BoundsChangeDelegate); | 2564 DISALLOW_COPY_AND_ASSIGN(BoundsChangeDelegate); |
| 2565 }; | 2565 }; |
| 2566 | 2566 |
| 2567 } // namespace | 2567 } // namespace |
| 2568 | 2568 |
| 2569 // Verifies the delegate is notified when the actual bounds of the layer | 2569 // Verifies the delegate is notified when the actual bounds of the layer |
| 2570 // change. | 2570 // change. |
| 2571 TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) { | 2571 TEST_P(WindowTest, DelegateNotifiedAsBoundsChange) { |
| 2572 BoundsChangeDelegate delegate; | 2572 BoundsChangeDelegate delegate; |
| 2573 | 2573 |
| 2574 // We cannot short-circuit animations in this test. | 2574 // We cannot short-circuit animations in this test. |
| 2575 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 2575 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 2576 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 2576 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 2577 | 2577 |
| 2578 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 2578 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 2579 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 2579 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2580 window->layer()->GetAnimator()->set_disable_timer_for_test(true); | 2580 window->layer()->GetAnimator()->set_disable_timer_for_test(true); |
| 2581 | 2581 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2595 base::TimeTicks start_time = | 2595 base::TimeTicks start_time = |
| 2596 window->layer()->GetAnimator()->last_step_time(); | 2596 window->layer()->GetAnimator()->last_step_time(); |
| 2597 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 2597 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| 2598 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 2598 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 2599 EXPECT_TRUE(delegate.bounds_changed()); | 2599 EXPECT_TRUE(delegate.bounds_changed()); |
| 2600 EXPECT_NE("0,0 100x100", window->bounds().ToString()); | 2600 EXPECT_NE("0,0 100x100", window->bounds().ToString()); |
| 2601 } | 2601 } |
| 2602 | 2602 |
| 2603 // Verifies the delegate is notified when the actual bounds of the layer | 2603 // Verifies the delegate is notified when the actual bounds of the layer |
| 2604 // change even when the window is not the layer's delegate | 2604 // change even when the window is not the layer's delegate |
| 2605 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { | 2605 TEST_P(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { |
| 2606 BoundsChangeDelegate delegate; | 2606 BoundsChangeDelegate delegate; |
| 2607 | 2607 |
| 2608 // We cannot short-circuit animations in this test. | 2608 // We cannot short-circuit animations in this test. |
| 2609 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 2609 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 2610 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 2610 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 2611 | 2611 |
| 2612 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( | 2612 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 2613 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 2613 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 2614 window->layer()->GetAnimator()->set_disable_timer_for_test(true); | 2614 window->layer()->GetAnimator()->set_disable_timer_for_test(true); |
| 2615 | 2615 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2668 private: | 2668 private: |
| 2669 int added_count_; | 2669 int added_count_; |
| 2670 int removed_count_; | 2670 int removed_count_; |
| 2671 | 2671 |
| 2672 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); | 2672 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); |
| 2673 }; | 2673 }; |
| 2674 | 2674 |
| 2675 } // namespace | 2675 } // namespace |
| 2676 | 2676 |
| 2677 // Assertions around when root window notifications are sent. | 2677 // Assertions around when root window notifications are sent. |
| 2678 TEST_F(WindowTest, AddChildNotifications) { | 2678 TEST_P(WindowTest, AddChildNotifications) { |
| 2679 AddChildNotificationsObserver observer; | 2679 AddChildNotificationsObserver observer; |
| 2680 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); | 2680 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, root_window())); |
| 2681 std::unique_ptr<Window> w2(CreateTestWindowWithId(1, root_window())); | 2681 std::unique_ptr<Window> w2(CreateTestWindowWithId(1, root_window())); |
| 2682 w2->AddObserver(&observer); | 2682 w2->AddObserver(&observer); |
| 2683 w2->Focus(); | 2683 w2->Focus(); |
| 2684 EXPECT_TRUE(w2->HasFocus()); | 2684 EXPECT_TRUE(w2->HasFocus()); |
| 2685 | 2685 |
| 2686 // Move |w2| to be a child of |w1|. | 2686 // Move |w2| to be a child of |w1|. |
| 2687 w1->AddChild(w2.get()); | 2687 w1->AddChild(w2.get()); |
| 2688 // Sine we moved in the same root, observer shouldn't be notified. | 2688 // Sine we moved in the same root, observer shouldn't be notified. |
| 2689 EXPECT_EQ("0 0", observer.CountStringAndReset()); | 2689 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
| 2690 // |w2| should still have focus after moving. | 2690 // |w2| should still have focus after moving. |
| 2691 EXPECT_TRUE(w2->HasFocus()); | 2691 EXPECT_TRUE(w2->HasFocus()); |
| 2692 } | 2692 } |
| 2693 | 2693 |
| 2694 // Tests that a delegate that destroys itself when the window is destroyed does | 2694 // Tests that a delegate that destroys itself when the window is destroyed does |
| 2695 // not break. | 2695 // not break. |
| 2696 TEST_F(WindowTest, DelegateDestroysSelfOnWindowDestroy) { | 2696 TEST_P(WindowTest, DelegateDestroysSelfOnWindowDestroy) { |
| 2697 std::unique_ptr<Window> w1( | 2697 std::unique_ptr<Window> w1( |
| 2698 CreateTestWindowWithDelegate(new DestroyWindowDelegate(), 0, | 2698 CreateTestWindowWithDelegate(new DestroyWindowDelegate(), 0, |
| 2699 gfx::Rect(10, 20, 30, 40), root_window())); | 2699 gfx::Rect(10, 20, 30, 40), root_window())); |
| 2700 } | 2700 } |
| 2701 | 2701 |
| 2702 class HierarchyObserver : public WindowObserver { | 2702 class HierarchyObserver : public WindowObserver { |
| 2703 public: | 2703 public: |
| 2704 explicit HierarchyObserver(Window* target) : target_(target) { | 2704 explicit HierarchyObserver(Window* target) : target_(target) { |
| 2705 target_->AddObserver(this); | 2705 target_->AddObserver(this); |
| 2706 } | 2706 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2734 EXPECT_EQ(p1.receiver, p2.receiver); | 2734 EXPECT_EQ(p1.receiver, p2.receiver); |
| 2735 } | 2735 } |
| 2736 | 2736 |
| 2737 Window* target_; | 2737 Window* target_; |
| 2738 std::vector<WindowObserver::HierarchyChangeParams> params_; | 2738 std::vector<WindowObserver::HierarchyChangeParams> params_; |
| 2739 | 2739 |
| 2740 DISALLOW_COPY_AND_ASSIGN(HierarchyObserver); | 2740 DISALLOW_COPY_AND_ASSIGN(HierarchyObserver); |
| 2741 }; | 2741 }; |
| 2742 | 2742 |
| 2743 // Tests hierarchy change notifications. | 2743 // Tests hierarchy change notifications. |
| 2744 TEST_F(WindowTest, OnWindowHierarchyChange) { | 2744 TEST_P(WindowTest, OnWindowHierarchyChange) { |
| 2745 { | 2745 { |
| 2746 // Simple add & remove. | 2746 // Simple add & remove. |
| 2747 HierarchyObserver oroot(root_window()); | 2747 HierarchyObserver oroot(root_window()); |
| 2748 | 2748 |
| 2749 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 2749 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
| 2750 HierarchyObserver o1(w1.get()); | 2750 HierarchyObserver o1(w1.get()); |
| 2751 | 2751 |
| 2752 // Add. | 2752 // Add. |
| 2753 root_window()->AddChild(w1.get()); | 2753 root_window()->AddChild(w1.get()); |
| 2754 | 2754 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2926 ui::LayerAnimationSequence* sequence) override {} | 2926 ui::LayerAnimationSequence* sequence) override {} |
| 2927 | 2927 |
| 2928 bool animation_completed_; | 2928 bool animation_completed_; |
| 2929 bool animation_aborted_; | 2929 bool animation_aborted_; |
| 2930 | 2930 |
| 2931 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationObserver); | 2931 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationObserver); |
| 2932 }; | 2932 }; |
| 2933 | 2933 |
| 2934 } // namespace | 2934 } // namespace |
| 2935 | 2935 |
| 2936 TEST_F(WindowTest, WindowDestroyCompletesAnimations) { | 2936 TEST_P(WindowTest, WindowDestroyCompletesAnimations) { |
| 2937 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 2937 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 2938 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 2938 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 2939 scoped_refptr<ui::LayerAnimator> animator = | 2939 scoped_refptr<ui::LayerAnimator> animator = |
| 2940 ui::LayerAnimator::CreateImplicitAnimator(); | 2940 ui::LayerAnimator::CreateImplicitAnimator(); |
| 2941 TestLayerAnimationObserver observer; | 2941 TestLayerAnimationObserver observer; |
| 2942 animator->AddObserver(&observer); | 2942 animator->AddObserver(&observer); |
| 2943 // Make sure destroying a Window completes the animation. | 2943 // Make sure destroying a Window completes the animation. |
| 2944 { | 2944 { |
| 2945 std::unique_ptr<Window> window(CreateTestWindowWithId(1, root_window())); | 2945 std::unique_ptr<Window> window(CreateTestWindowWithId(1, root_window())); |
| 2946 window->layer()->SetAnimator(animator.get()); | 2946 window->layer()->SetAnimator(animator.get()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2975 EXPECT_FALSE(observer.animation_completed()); | 2975 EXPECT_FALSE(observer.animation_completed()); |
| 2976 } | 2976 } |
| 2977 | 2977 |
| 2978 EXPECT_TRUE(animator.get()); | 2978 EXPECT_TRUE(animator.get()); |
| 2979 EXPECT_FALSE(animator->is_animating()); | 2979 EXPECT_FALSE(animator->is_animating()); |
| 2980 EXPECT_TRUE(observer.animation_completed()); | 2980 EXPECT_TRUE(observer.animation_completed()); |
| 2981 EXPECT_FALSE(observer.animation_aborted()); | 2981 EXPECT_FALSE(observer.animation_aborted()); |
| 2982 animator->RemoveObserver(&observer); | 2982 animator->RemoveObserver(&observer); |
| 2983 } | 2983 } |
| 2984 | 2984 |
| 2985 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
| 2986 WindowTest, |
| 2987 ::testing::Values(BackendType::CLASSIC, |
| 2988 BackendType::MUS)); |
| 2989 |
| 2990 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
| 2991 WindowObserverTest, |
| 2992 ::testing::Values(BackendType::CLASSIC, |
| 2993 BackendType::MUS)); |
| 2994 |
| 2985 } // namespace test | 2995 } // namespace test |
| 2986 } // namespace aura | 2996 } // namespace aura |
| OLD | NEW |