| 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 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 | 1922 |
| 1923 class ExitMessageLoopOnMousePress : public ui::test::TestEventHandler { | 1923 class ExitMessageLoopOnMousePress : public ui::test::TestEventHandler { |
| 1924 public: | 1924 public: |
| 1925 ExitMessageLoopOnMousePress() {} | 1925 ExitMessageLoopOnMousePress() {} |
| 1926 ~ExitMessageLoopOnMousePress() override {} | 1926 ~ExitMessageLoopOnMousePress() override {} |
| 1927 | 1927 |
| 1928 protected: | 1928 protected: |
| 1929 void OnMouseEvent(ui::MouseEvent* event) override { | 1929 void OnMouseEvent(ui::MouseEvent* event) override { |
| 1930 ui::test::TestEventHandler::OnMouseEvent(event); | 1930 ui::test::TestEventHandler::OnMouseEvent(event); |
| 1931 if (event->type() == ui::ET_MOUSE_PRESSED) | 1931 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 1932 base::MessageLoopForUI::current()->Quit(); | 1932 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 1933 } | 1933 } |
| 1934 | 1934 |
| 1935 private: | 1935 private: |
| 1936 DISALLOW_COPY_AND_ASSIGN(ExitMessageLoopOnMousePress); | 1936 DISALLOW_COPY_AND_ASSIGN(ExitMessageLoopOnMousePress); |
| 1937 }; | 1937 }; |
| 1938 | 1938 |
| 1939 class WindowEventDispatcherTestWithMessageLoop | 1939 class WindowEventDispatcherTestWithMessageLoop |
| 1940 : public WindowEventDispatcherTest { | 1940 : public WindowEventDispatcherTest { |
| 1941 public: | 1941 public: |
| 1942 WindowEventDispatcherTestWithMessageLoop() {} | 1942 WindowEventDispatcherTestWithMessageLoop() {} |
| 1943 ~WindowEventDispatcherTestWithMessageLoop() override {} | 1943 ~WindowEventDispatcherTestWithMessageLoop() override {} |
| 1944 | 1944 |
| 1945 void RunTest() { | 1945 void RunTest() { |
| 1946 // Reset any event the window may have received when bringing up the window | 1946 // Reset any event the window may have received when bringing up the window |
| 1947 // (e.g. mouse-move events if the mouse cursor is over the window). | 1947 // (e.g. mouse-move events if the mouse cursor is over the window). |
| 1948 handler_.Reset(); | 1948 handler_.Reset(); |
| 1949 | 1949 |
| 1950 // Start a nested message-loop, post an event to be dispatched, and then | 1950 // Start a nested message-loop, post an event to be dispatched, and then |
| 1951 // terminate the message-loop. When the message-loop unwinds and gets back, | 1951 // terminate the message-loop. When the message-loop unwinds and gets back, |
| 1952 // the reposted event should not have fired. | 1952 // the reposted event should not have fired. |
| 1953 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( | 1953 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( |
| 1954 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), | 1954 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 1955 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); | 1955 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); |
| 1956 message_loop()->PostTask( | 1956 message_loop()->PostTask( |
| 1957 FROM_HERE, | 1957 FROM_HERE, |
| 1958 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, | 1958 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, |
| 1959 host()->dispatcher(), | 1959 host()->dispatcher(), |
| 1960 base::Passed(&mouse))); | 1960 base::Passed(&mouse))); |
| 1961 message_loop()->PostTask(FROM_HERE, message_loop()->QuitClosure()); | 1961 message_loop()->PostTask(FROM_HERE, message_loop()->QuitWhenIdleClosure()); |
| 1962 | 1962 |
| 1963 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); | 1963 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); |
| 1964 base::RunLoop loop; | 1964 base::RunLoop loop; |
| 1965 loop.Run(); | 1965 loop.Run(); |
| 1966 EXPECT_EQ(0, handler_.num_mouse_events()); | 1966 EXPECT_EQ(0, handler_.num_mouse_events()); |
| 1967 | 1967 |
| 1968 // Let the current message-loop run. The event-handler will terminate the | 1968 // Let the current message-loop run. The event-handler will terminate the |
| 1969 // message-loop when it receives the reposted event. | 1969 // message-loop when it receives the reposted event. |
| 1970 } | 1970 } |
| 1971 | 1971 |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2601 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. | 2601 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. |
| 2602 test_screen()->SetDeviceScaleFactor(2.f); | 2602 test_screen()->SetDeviceScaleFactor(2.f); |
| 2603 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); | 2603 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); |
| 2604 RunAllPendingInMessageLoop(); | 2604 RunAllPendingInMessageLoop(); |
| 2605 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); | 2605 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); |
| 2606 | 2606 |
| 2607 w->RemovePreTargetHandler(&recorder); | 2607 w->RemovePreTargetHandler(&recorder); |
| 2608 } | 2608 } |
| 2609 | 2609 |
| 2610 } // namespace aura | 2610 } // namespace aura |
| OLD | NEW |