| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/aura/client/capture_client.h" | 16 #include "ui/aura/client/capture_client.h" |
| 17 #include "ui/aura/client/focus_change_observer.h" | 17 #include "ui/aura/client/focus_change_observer.h" |
| 18 #include "ui/aura/client/stacking_client.h" | |
| 19 #include "ui/aura/client/visibility_client.h" | 18 #include "ui/aura/client/visibility_client.h" |
| 19 #include "ui/aura/client/window_tree_client.h" |
| 20 #include "ui/aura/layout_manager.h" | 20 #include "ui/aura/layout_manager.h" |
| 21 #include "ui/aura/root_window.h" | 21 #include "ui/aura/root_window.h" |
| 22 #include "ui/aura/root_window_host.h" | 22 #include "ui/aura/root_window_host.h" |
| 23 #include "ui/aura/root_window_observer.h" | 23 #include "ui/aura/root_window_observer.h" |
| 24 #include "ui/aura/test/aura_test_base.h" | 24 #include "ui/aura/test/aura_test_base.h" |
| 25 #include "ui/aura/test/event_generator.h" | 25 #include "ui/aura/test/event_generator.h" |
| 26 #include "ui/aura/test/test_window_delegate.h" | 26 #include "ui/aura/test/test_window_delegate.h" |
| 27 #include "ui/aura/test/test_windows.h" | 27 #include "ui/aura/test/test_windows.h" |
| 28 #include "ui/aura/test/window_test_api.h" | 28 #include "ui/aura/test/window_test_api.h" |
| 29 #include "ui/aura/window_delegate.h" | 29 #include "ui/aura/window_delegate.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 60 ui::GestureConfiguration:: | 60 ui::GestureConfiguration:: |
| 61 set_max_separation_for_gesture_touches_in_pixels(0); | 61 set_max_separation_for_gesture_touches_in_pixels(0); |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void TearDown() OVERRIDE { | 64 virtual void TearDown() OVERRIDE { |
| 65 AuraTestBase::TearDown(); | 65 AuraTestBase::TearDown(); |
| 66 ui::GestureConfiguration:: | 66 ui::GestureConfiguration:: |
| 67 set_max_separation_for_gesture_touches_in_pixels(max_separation_); | 67 set_max_separation_for_gesture_touches_in_pixels(max_separation_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Adds |window| to |root_window_|, through the StackingClient. | |
| 71 void SetDefaultParentByPrimaryRootWindow(aura::Window* window) { | |
| 72 window->SetDefaultParentByRootWindow(root_window(), gfx::Rect()); | |
| 73 } | |
| 74 | |
| 75 private: | 70 private: |
| 76 int max_separation_; | 71 int max_separation_; |
| 77 | 72 |
| 78 DISALLOW_COPY_AND_ASSIGN(WindowTest); | 73 DISALLOW_COPY_AND_ASSIGN(WindowTest); |
| 79 }; | 74 }; |
| 80 | 75 |
| 81 namespace { | 76 namespace { |
| 82 | 77 |
| 83 // Used for verifying destruction methods are invoked. | 78 // Used for verifying destruction methods are invoked. |
| 84 class DestroyTrackingDelegateImpl : public TestWindowDelegate { | 79 class DestroyTrackingDelegateImpl : public TestWindowDelegate { |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 EXPECT_EQ("20,53", | 468 EXPECT_EQ("20,53", |
| 474 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 469 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 475 } | 470 } |
| 476 | 471 |
| 477 TEST_F(WindowTest, HitTest) { | 472 TEST_F(WindowTest, HitTest) { |
| 478 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); | 473 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); |
| 479 w1.set_id(1); | 474 w1.set_id(1); |
| 480 w1.Init(ui::LAYER_TEXTURED); | 475 w1.Init(ui::LAYER_TEXTURED); |
| 481 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); | 476 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
| 482 w1.Show(); | 477 w1.Show(); |
| 483 SetDefaultParentByPrimaryRootWindow(&w1); | 478 ParentWindow(&w1); |
| 484 | 479 |
| 485 // Points are in the Window's coordinates. | 480 // Points are in the Window's coordinates. |
| 486 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); | 481 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); |
| 487 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); | 482 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); |
| 488 | 483 |
| 489 // We can expand the bounds slightly to track events outside our border. | 484 // We can expand the bounds slightly to track events outside our border. |
| 490 w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), | 485 w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), |
| 491 gfx::Insets(-5, -5, -5, -5)); | 486 gfx::Insets(-5, -5, -5, -5)); |
| 492 EXPECT_TRUE(w1.HitTest(gfx::Point(-1, -1))); | 487 EXPECT_TRUE(w1.HitTest(gfx::Point(-1, -1))); |
| 493 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2))); | 488 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 505 | 500 |
| 506 // TODO(beng): clip Window to parent. | 501 // TODO(beng): clip Window to parent. |
| 507 } | 502 } |
| 508 | 503 |
| 509 TEST_F(WindowTest, HitTestMask) { | 504 TEST_F(WindowTest, HitTestMask) { |
| 510 MaskedWindowDelegate d1(gfx::Rect(5, 6, 20, 30)); | 505 MaskedWindowDelegate d1(gfx::Rect(5, 6, 20, 30)); |
| 511 Window w1(&d1); | 506 Window w1(&d1); |
| 512 w1.Init(ui::LAYER_NOT_DRAWN); | 507 w1.Init(ui::LAYER_NOT_DRAWN); |
| 513 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); | 508 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
| 514 w1.Show(); | 509 w1.Show(); |
| 515 SetDefaultParentByPrimaryRootWindow(&w1); | 510 ParentWindow(&w1); |
| 516 | 511 |
| 517 // Points inside the mask. | 512 // Points inside the mask. |
| 518 EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left | 513 EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left |
| 519 EXPECT_TRUE(w1.HitTest(gfx::Point(15, 21))); // center | 514 EXPECT_TRUE(w1.HitTest(gfx::Point(15, 21))); // center |
| 520 EXPECT_TRUE(w1.HitTest(gfx::Point(24, 35))); // bottom-right | 515 EXPECT_TRUE(w1.HitTest(gfx::Point(24, 35))); // bottom-right |
| 521 | 516 |
| 522 // Points outside the mask. | 517 // Points outside the mask. |
| 523 EXPECT_FALSE(w1.HitTest(gfx::Point(0, 0))); | 518 EXPECT_FALSE(w1.HitTest(gfx::Point(0, 0))); |
| 524 EXPECT_FALSE(w1.HitTest(gfx::Point(60, 80))); | 519 EXPECT_FALSE(w1.HitTest(gfx::Point(60, 80))); |
| 525 EXPECT_FALSE(w1.HitTest(gfx::Point(4, 6))); | 520 EXPECT_FALSE(w1.HitTest(gfx::Point(4, 6))); |
| (...skipping 2112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2638 }; | 2633 }; |
| 2639 | 2634 |
| 2640 TEST_F(WindowTest, RootWindowAttachment) { | 2635 TEST_F(WindowTest, RootWindowAttachment) { |
| 2641 RootWindowAttachmentObserver observer; | 2636 RootWindowAttachmentObserver observer; |
| 2642 | 2637 |
| 2643 // Test a direct add/remove from the RootWindow. | 2638 // Test a direct add/remove from the RootWindow. |
| 2644 scoped_ptr<Window> w1(new Window(NULL)); | 2639 scoped_ptr<Window> w1(new Window(NULL)); |
| 2645 w1->Init(ui::LAYER_NOT_DRAWN); | 2640 w1->Init(ui::LAYER_NOT_DRAWN); |
| 2646 w1->AddObserver(&observer); | 2641 w1->AddObserver(&observer); |
| 2647 | 2642 |
| 2648 SetDefaultParentByPrimaryRootWindow(w1.get()); | 2643 ParentWindow(w1.get()); |
| 2649 EXPECT_EQ(1, observer.added_count()); | 2644 EXPECT_EQ(1, observer.added_count()); |
| 2650 EXPECT_EQ(0, observer.removed_count()); | 2645 EXPECT_EQ(0, observer.removed_count()); |
| 2651 | 2646 |
| 2652 w1.reset(); | 2647 w1.reset(); |
| 2653 EXPECT_EQ(1, observer.added_count()); | 2648 EXPECT_EQ(1, observer.added_count()); |
| 2654 EXPECT_EQ(1, observer.removed_count()); | 2649 EXPECT_EQ(1, observer.removed_count()); |
| 2655 | 2650 |
| 2656 observer.Clear(); | 2651 observer.Clear(); |
| 2657 | 2652 |
| 2658 // Test an indirect add/remove from the RootWindow. | 2653 // Test an indirect add/remove from the RootWindow. |
| 2659 w1.reset(new Window(NULL)); | 2654 w1.reset(new Window(NULL)); |
| 2660 w1->Init(ui::LAYER_NOT_DRAWN); | 2655 w1->Init(ui::LAYER_NOT_DRAWN); |
| 2661 Window* w11 = new Window(NULL); | 2656 Window* w11 = new Window(NULL); |
| 2662 w11->Init(ui::LAYER_NOT_DRAWN); | 2657 w11->Init(ui::LAYER_NOT_DRAWN); |
| 2663 w11->AddObserver(&observer); | 2658 w11->AddObserver(&observer); |
| 2664 w1->AddChild(w11); | 2659 w1->AddChild(w11); |
| 2665 EXPECT_EQ(0, observer.added_count()); | 2660 EXPECT_EQ(0, observer.added_count()); |
| 2666 EXPECT_EQ(0, observer.removed_count()); | 2661 EXPECT_EQ(0, observer.removed_count()); |
| 2667 | 2662 |
| 2668 SetDefaultParentByPrimaryRootWindow(w1.get()); | 2663 ParentWindow(w1.get()); |
| 2669 EXPECT_EQ(1, observer.added_count()); | 2664 EXPECT_EQ(1, observer.added_count()); |
| 2670 EXPECT_EQ(0, observer.removed_count()); | 2665 EXPECT_EQ(0, observer.removed_count()); |
| 2671 | 2666 |
| 2672 w1.reset(); // Deletes w11. | 2667 w1.reset(); // Deletes w11. |
| 2673 w11 = NULL; | 2668 w11 = NULL; |
| 2674 EXPECT_EQ(1, observer.added_count()); | 2669 EXPECT_EQ(1, observer.added_count()); |
| 2675 EXPECT_EQ(1, observer.removed_count()); | 2670 EXPECT_EQ(1, observer.removed_count()); |
| 2676 | 2671 |
| 2677 observer.Clear(); | 2672 observer.Clear(); |
| 2678 | 2673 |
| 2679 // Test an indirect add/remove with nested observers. | 2674 // Test an indirect add/remove with nested observers. |
| 2680 w1.reset(new Window(NULL)); | 2675 w1.reset(new Window(NULL)); |
| 2681 w1->Init(ui::LAYER_NOT_DRAWN); | 2676 w1->Init(ui::LAYER_NOT_DRAWN); |
| 2682 w11 = new Window(NULL); | 2677 w11 = new Window(NULL); |
| 2683 w11->Init(ui::LAYER_NOT_DRAWN); | 2678 w11->Init(ui::LAYER_NOT_DRAWN); |
| 2684 w11->AddObserver(&observer); | 2679 w11->AddObserver(&observer); |
| 2685 w1->AddChild(w11); | 2680 w1->AddChild(w11); |
| 2686 Window* w111 = new Window(NULL); | 2681 Window* w111 = new Window(NULL); |
| 2687 w111->Init(ui::LAYER_NOT_DRAWN); | 2682 w111->Init(ui::LAYER_NOT_DRAWN); |
| 2688 w111->AddObserver(&observer); | 2683 w111->AddObserver(&observer); |
| 2689 w11->AddChild(w111); | 2684 w11->AddChild(w111); |
| 2690 | 2685 |
| 2691 EXPECT_EQ(0, observer.added_count()); | 2686 EXPECT_EQ(0, observer.added_count()); |
| 2692 EXPECT_EQ(0, observer.removed_count()); | 2687 EXPECT_EQ(0, observer.removed_count()); |
| 2693 | 2688 |
| 2694 SetDefaultParentByPrimaryRootWindow(w1.get()); | 2689 ParentWindow(w1.get()); |
| 2695 EXPECT_EQ(2, observer.added_count()); | 2690 EXPECT_EQ(2, observer.added_count()); |
| 2696 EXPECT_EQ(0, observer.removed_count()); | 2691 EXPECT_EQ(0, observer.removed_count()); |
| 2697 | 2692 |
| 2698 w1.reset(); // Deletes w11 and w111. | 2693 w1.reset(); // Deletes w11 and w111. |
| 2699 w11 = NULL; | 2694 w11 = NULL; |
| 2700 w111 = NULL; | 2695 w111 = NULL; |
| 2701 EXPECT_EQ(2, observer.added_count()); | 2696 EXPECT_EQ(2, observer.added_count()); |
| 2702 EXPECT_EQ(2, observer.removed_count()); | 2697 EXPECT_EQ(2, observer.removed_count()); |
| 2703 } | 2698 } |
| 2704 | 2699 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3168 parent->AddTransientChild(transient); | 3163 parent->AddTransientChild(transient); |
| 3169 parent.reset(); | 3164 parent.reset(); |
| 3170 | 3165 |
| 3171 ASSERT_EQ(2u, destruction_order.size()); | 3166 ASSERT_EQ(2u, destruction_order.size()); |
| 3172 EXPECT_EQ("transient", destruction_order[0]); | 3167 EXPECT_EQ("transient", destruction_order[0]); |
| 3173 EXPECT_EQ("parent", destruction_order[1]); | 3168 EXPECT_EQ("parent", destruction_order[1]); |
| 3174 } | 3169 } |
| 3175 | 3170 |
| 3176 } // namespace test | 3171 } // namespace test |
| 3177 } // namespace aura | 3172 } // namespace aura |
| OLD | NEW |