| 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 <utility> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
| 14 #include "ui/aura/client/event_client.h" | 15 #include "ui/aura/client/event_client.h" |
| 15 #include "ui/aura/client/focus_client.h" | 16 #include "ui/aura/client/focus_client.h" |
| 16 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
| (...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2219 } | 2220 } |
| 2220 | 2221 |
| 2221 class SelfDestructDelegate : public test::TestWindowDelegate { | 2222 class SelfDestructDelegate : public test::TestWindowDelegate { |
| 2222 public: | 2223 public: |
| 2223 SelfDestructDelegate() {} | 2224 SelfDestructDelegate() {} |
| 2224 ~SelfDestructDelegate() override {} | 2225 ~SelfDestructDelegate() override {} |
| 2225 | 2226 |
| 2226 void OnMouseEvent(ui::MouseEvent* event) override { window_.reset(); } | 2227 void OnMouseEvent(ui::MouseEvent* event) override { window_.reset(); } |
| 2227 | 2228 |
| 2228 void set_window(scoped_ptr<aura::Window> window) { | 2229 void set_window(scoped_ptr<aura::Window> window) { |
| 2229 window_ = window.Pass(); | 2230 window_ = std::move(window); |
| 2230 } | 2231 } |
| 2231 bool has_window() const { return !!window_.get(); } | 2232 bool has_window() const { return !!window_.get(); } |
| 2232 | 2233 |
| 2233 private: | 2234 private: |
| 2234 scoped_ptr<aura::Window> window_; | 2235 scoped_ptr<aura::Window> window_; |
| 2235 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); | 2236 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); |
| 2236 }; | 2237 }; |
| 2237 | 2238 |
| 2238 TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { | 2239 TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { |
| 2239 ui::test::EventGenerator generator(root_window()); | 2240 ui::test::EventGenerator generator(root_window()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2250 | 2251 |
| 2251 generator.MoveMouseTo(0, 0); | 2252 generator.MoveMouseTo(0, 0); |
| 2252 EXPECT_EQ("0,0", | 2253 EXPECT_EQ("0,0", |
| 2253 Env::GetInstance()->last_mouse_location().ToString()); | 2254 Env::GetInstance()->last_mouse_location().ToString()); |
| 2254 | 2255 |
| 2255 // Make sure the location gets updated when a syntheiszed enter | 2256 // Make sure the location gets updated when a syntheiszed enter |
| 2256 // event destroyed the window. | 2257 // event destroyed the window. |
| 2257 SelfDestructDelegate delegate; | 2258 SelfDestructDelegate delegate; |
| 2258 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2259 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 2259 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 2260 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 2260 delegate.set_window(window.Pass()); | 2261 delegate.set_window(std::move(window)); |
| 2261 EXPECT_TRUE(delegate.has_window()); | 2262 EXPECT_TRUE(delegate.has_window()); |
| 2262 | 2263 |
| 2263 generator.MoveMouseTo(100, 100); | 2264 generator.MoveMouseTo(100, 100); |
| 2264 EXPECT_FALSE(delegate.has_window()); | 2265 EXPECT_FALSE(delegate.has_window()); |
| 2265 EXPECT_EQ("100,100", | 2266 EXPECT_EQ("100,100", |
| 2266 Env::GetInstance()->last_mouse_location().ToString()); | 2267 Env::GetInstance()->last_mouse_location().ToString()); |
| 2267 } | 2268 } |
| 2268 | 2269 |
| 2269 // Tests that the window which has capture can get destroyed as a result of | 2270 // Tests that the window which has capture can get destroyed as a result of |
| 2270 // ui::ET_MOUSE_CAPTURE_CHANGED event dispatched in | 2271 // ui::ET_MOUSE_CAPTURE_CHANGED event dispatched in |
| 2271 // WindowEventDispatcher::UpdateCapture without causing a "use after free". | 2272 // WindowEventDispatcher::UpdateCapture without causing a "use after free". |
| 2272 TEST_F(WindowEventDispatcherTest, DestroyWindowOnCaptureChanged) { | 2273 TEST_F(WindowEventDispatcherTest, DestroyWindowOnCaptureChanged) { |
| 2273 SelfDestructDelegate delegate; | 2274 SelfDestructDelegate delegate; |
| 2274 scoped_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( | 2275 scoped_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( |
| 2275 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); | 2276 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); |
| 2276 Window* window_first_raw = window_first.get(); | 2277 Window* window_first_raw = window_first.get(); |
| 2277 window_first->Show(); | 2278 window_first->Show(); |
| 2278 window_first->SetCapture(); | 2279 window_first->SetCapture(); |
| 2279 delegate.set_window(window_first.Pass()); | 2280 delegate.set_window(std::move(window_first)); |
| 2280 EXPECT_TRUE(delegate.has_window()); | 2281 EXPECT_TRUE(delegate.has_window()); |
| 2281 | 2282 |
| 2282 scoped_ptr<aura::Window> window_second( | 2283 scoped_ptr<aura::Window> window_second( |
| 2283 test::CreateTestWindowWithId(2, root_window())); | 2284 test::CreateTestWindowWithId(2, root_window())); |
| 2284 window_second->Show(); | 2285 window_second->Show(); |
| 2285 | 2286 |
| 2286 client::CaptureDelegate* capture_delegate = host()->dispatcher(); | 2287 client::CaptureDelegate* capture_delegate = host()->dispatcher(); |
| 2287 capture_delegate->UpdateCapture(window_first_raw, window_second.get()); | 2288 capture_delegate->UpdateCapture(window_first_raw, window_second.get()); |
| 2288 EXPECT_FALSE(delegate.has_window()); | 2289 EXPECT_FALSE(delegate.has_window()); |
| 2289 } | 2290 } |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2653 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. | 2654 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. |
| 2654 test_screen()->SetDeviceScaleFactor(2.f); | 2655 test_screen()->SetDeviceScaleFactor(2.f); |
| 2655 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); | 2656 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); |
| 2656 RunAllPendingInMessageLoop(); | 2657 RunAllPendingInMessageLoop(); |
| 2657 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); | 2658 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); |
| 2658 | 2659 |
| 2659 w->RemovePreTargetHandler(&recorder); | 2660 w->RemovePreTargetHandler(&recorder); |
| 2660 } | 2661 } |
| 2661 | 2662 |
| 2662 } // namespace aura | 2663 } // namespace aura |
| OLD | NEW |