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_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 } // namespace | 1434 } // namespace |
1435 | 1435 |
1436 // Verifies GetRootWindow() from ~Window returns a valid root. | 1436 // Verifies GetRootWindow() from ~Window returns a valid root. |
1437 TEST_F(WindowEventDispatcherTest, ValidRootDuringDestruction) { | 1437 TEST_F(WindowEventDispatcherTest, ValidRootDuringDestruction) { |
1438 bool got_destroying = false; | 1438 bool got_destroying = false; |
1439 bool has_valid_root = false; | 1439 bool has_valid_root = false; |
1440 ValidRootDuringDestructionWindowObserver observer(&got_destroying, | 1440 ValidRootDuringDestructionWindowObserver observer(&got_destroying, |
1441 &has_valid_root); | 1441 &has_valid_root); |
1442 { | 1442 { |
1443 scoped_ptr<WindowTreeHost> host( | 1443 scoped_ptr<WindowTreeHost> host( |
1444 WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100))); | 1444 WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100), |
| 1445 context_factory())); |
1445 host->InitHost(); | 1446 host->InitHost(); |
1446 // Owned by WindowEventDispatcher. | 1447 // Owned by WindowEventDispatcher. |
1447 Window* w1 = CreateNormalWindow(1, host->window(), NULL); | 1448 Window* w1 = CreateNormalWindow(1, host->window(), NULL); |
1448 w1->AddObserver(&observer); | 1449 w1->AddObserver(&observer); |
1449 } | 1450 } |
1450 EXPECT_TRUE(got_destroying); | 1451 EXPECT_TRUE(got_destroying); |
1451 EXPECT_TRUE(has_valid_root); | 1452 EXPECT_TRUE(has_valid_root); |
1452 } | 1453 } |
1453 | 1454 |
1454 namespace { | 1455 namespace { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 | 1543 |
1543 DISALLOW_COPY_AND_ASSIGN(DeleteHostFromHeldMouseEventDelegate); | 1544 DISALLOW_COPY_AND_ASSIGN(DeleteHostFromHeldMouseEventDelegate); |
1544 }; | 1545 }; |
1545 | 1546 |
1546 } // namespace | 1547 } // namespace |
1547 | 1548 |
1548 // Verifies if a WindowTreeHost is deleted from dispatching a held mouse event | 1549 // Verifies if a WindowTreeHost is deleted from dispatching a held mouse event |
1549 // we don't crash. | 1550 // we don't crash. |
1550 TEST_F(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { | 1551 TEST_F(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { |
1551 // Should be deleted by |delegate|. | 1552 // Should be deleted by |delegate|. |
1552 WindowTreeHost* h2 = WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100)); | 1553 WindowTreeHost* h2 = WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100), |
| 1554 context_factory()); |
1553 h2->InitHost(); | 1555 h2->InitHost(); |
1554 DeleteHostFromHeldMouseEventDelegate delegate(h2); | 1556 DeleteHostFromHeldMouseEventDelegate delegate(h2); |
1555 // Owned by |h2|. | 1557 // Owned by |h2|. |
1556 Window* w1 = CreateNormalWindow(1, h2->window(), &delegate); | 1558 Window* w1 = CreateNormalWindow(1, h2->window(), &delegate); |
1557 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1559 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
1558 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, | 1560 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, |
1559 gfx::Point(10, 10), gfx::Point(10, 10), | 1561 gfx::Point(10, 10), gfx::Point(10, 10), |
1560 ui::EF_SHIFT_DOWN, 0); | 1562 ui::EF_SHIFT_DOWN, 0); |
1561 h2->dispatcher()->RepostEvent(pressed); | 1563 h2->dispatcher()->RepostEvent(pressed); |
1562 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. | 1564 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 Window* root_window_to_move_to_; | 2014 Window* root_window_to_move_to_; |
2013 | 2015 |
2014 DISALLOW_COPY_AND_ASSIGN(MoveWindowHandler); | 2016 DISALLOW_COPY_AND_ASSIGN(MoveWindowHandler); |
2015 }; | 2017 }; |
2016 | 2018 |
2017 // Tests that nested event dispatch works correctly if the target of the older | 2019 // Tests that nested event dispatch works correctly if the target of the older |
2018 // event being dispatched is moved to a different dispatcher in response to an | 2020 // event being dispatched is moved to a different dispatcher in response to an |
2019 // event in the inner loop. | 2021 // event in the inner loop. |
2020 TEST_F(WindowEventDispatcherTest, NestedEventDispatchTargetMoved) { | 2022 TEST_F(WindowEventDispatcherTest, NestedEventDispatchTargetMoved) { |
2021 scoped_ptr<WindowTreeHost> second_host( | 2023 scoped_ptr<WindowTreeHost> second_host( |
2022 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50))); | 2024 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50), context_factory())); |
2023 second_host->InitHost(); | 2025 second_host->InitHost(); |
2024 Window* second_root = second_host->window(); | 2026 Window* second_root = second_host->window(); |
2025 | 2027 |
2026 // Create two windows parented to |root_window()|. | 2028 // Create two windows parented to |root_window()|. |
2027 test::TestWindowDelegate delegate; | 2029 test::TestWindowDelegate delegate; |
2028 scoped_ptr<Window> first(CreateTestWindowWithDelegate(&delegate, 123, | 2030 scoped_ptr<Window> first(CreateTestWindowWithDelegate(&delegate, 123, |
2029 gfx::Rect(20, 10, 10, 20), root_window())); | 2031 gfx::Rect(20, 10, 10, 20), root_window())); |
2030 scoped_ptr<Window> second(CreateTestWindowWithDelegate(&delegate, 234, | 2032 scoped_ptr<Window> second(CreateTestWindowWithDelegate(&delegate, 234, |
2031 gfx::Rect(40, 10, 50, 20), root_window())); | 2033 gfx::Rect(40, 10, 50, 20), root_window())); |
2032 | 2034 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2073 }; | 2075 }; |
2074 | 2076 |
2075 TEST_F(WindowEventDispatcherTest, | 2077 TEST_F(WindowEventDispatcherTest, |
2076 CursorVisibilityChangedWhileCaptureWindowInAnotherDispatcher) { | 2078 CursorVisibilityChangedWhileCaptureWindowInAnotherDispatcher) { |
2077 test::EventCountDelegate delegate; | 2079 test::EventCountDelegate delegate; |
2078 scoped_ptr<Window> window(CreateTestWindowWithDelegate(&delegate, 123, | 2080 scoped_ptr<Window> window(CreateTestWindowWithDelegate(&delegate, 123, |
2079 gfx::Rect(20, 10, 10, 20), root_window())); | 2081 gfx::Rect(20, 10, 10, 20), root_window())); |
2080 window->Show(); | 2082 window->Show(); |
2081 | 2083 |
2082 scoped_ptr<WindowTreeHost> second_host( | 2084 scoped_ptr<WindowTreeHost> second_host( |
2083 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50))); | 2085 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50), context_factory())); |
2084 second_host->InitHost(); | 2086 second_host->InitHost(); |
2085 WindowEventDispatcher* second_dispatcher = second_host->dispatcher(); | 2087 WindowEventDispatcher* second_dispatcher = second_host->dispatcher(); |
2086 | 2088 |
2087 // Install an InputStateLookup on the Env that always claims that a | 2089 // Install an InputStateLookup on the Env that always claims that a |
2088 // mouse-button is down. | 2090 // mouse-button is down. |
2089 test::EnvTestHelper(Env::GetInstance()).SetInputStateLookup( | 2091 test::EnvTestHelper(Env::GetInstance()).SetInputStateLookup( |
2090 scoped_ptr<InputStateLookup>(new AlwaysMouseDownInputStateLookup())); | 2092 scoped_ptr<InputStateLookup>(new AlwaysMouseDownInputStateLookup())); |
2091 | 2093 |
2092 window->SetCapture(); | 2094 window->SetCapture(); |
2093 | 2095 |
(...skipping 16 matching lines...) Expand all Loading... |
2110 delegate.GetMouseMotionCountsAndReset(); | 2112 delegate.GetMouseMotionCountsAndReset(); |
2111 | 2113 |
2112 // Notify both hosts that the cursor is now hidden. This should send a single | 2114 // Notify both hosts that the cursor is now hidden. This should send a single |
2113 // mouse-exit event to |window|. | 2115 // mouse-exit event to |window|. |
2114 host()->OnCursorVisibilityChanged(false); | 2116 host()->OnCursorVisibilityChanged(false); |
2115 second_host->OnCursorVisibilityChanged(false); | 2117 second_host->OnCursorVisibilityChanged(false); |
2116 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset()); | 2118 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset()); |
2117 } | 2119 } |
2118 | 2120 |
2119 } // namespace aura | 2121 } // namespace aura |
OLD | NEW |