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 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2072 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 2072 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
2073 delegate.set_window(window.Pass()); | 2073 delegate.set_window(window.Pass()); |
2074 EXPECT_TRUE(delegate.has_window()); | 2074 EXPECT_TRUE(delegate.has_window()); |
2075 | 2075 |
2076 generator.MoveMouseTo(100, 100); | 2076 generator.MoveMouseTo(100, 100); |
2077 EXPECT_FALSE(delegate.has_window()); | 2077 EXPECT_FALSE(delegate.has_window()); |
2078 EXPECT_EQ("100,100", | 2078 EXPECT_EQ("100,100", |
2079 Env::GetInstance()->last_mouse_location().ToString()); | 2079 Env::GetInstance()->last_mouse_location().ToString()); |
2080 } | 2080 } |
2081 | 2081 |
| 2082 // Tests that the window which has capture can get destroyed as a result of |
| 2083 // ui::ET_MOUSE_CAPTURE_CHANGED event dispatched in |
| 2084 // WindowEventDispatcher::UpdateCapture without causing a "use after free". |
| 2085 TEST_F(WindowEventDispatcherTest, DestroyWindowOnCaptureChanged) { |
| 2086 SelfDestructDelegate delegate; |
| 2087 scoped_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( |
| 2088 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); |
| 2089 Window* window_first_raw = window_first.get(); |
| 2090 window_first->Show(); |
| 2091 window_first->SetCapture(); |
| 2092 delegate.set_window(window_first.Pass()); |
| 2093 EXPECT_TRUE(delegate.has_window()); |
| 2094 |
| 2095 scoped_ptr<aura::Window> window_second( |
| 2096 test::CreateTestWindowWithId(2, root_window())); |
| 2097 window_second->Show(); |
| 2098 |
| 2099 client::CaptureDelegate* capture_delegate = host()->dispatcher(); |
| 2100 capture_delegate->UpdateCapture(window_first_raw, window_second.get()); |
| 2101 EXPECT_FALSE(delegate.has_window()); |
| 2102 } |
| 2103 |
2082 class StaticFocusClient : public client::FocusClient { | 2104 class StaticFocusClient : public client::FocusClient { |
2083 public: | 2105 public: |
2084 explicit StaticFocusClient(Window* focused) | 2106 explicit StaticFocusClient(Window* focused) |
2085 : focused_(focused) {} | 2107 : focused_(focused) {} |
2086 virtual ~StaticFocusClient() {} | 2108 virtual ~StaticFocusClient() {} |
2087 | 2109 |
2088 private: | 2110 private: |
2089 // client::FocusClient: | 2111 // client::FocusClient: |
2090 virtual void AddObserver(client::FocusChangeObserver* observer) override {} | 2112 virtual void AddObserver(client::FocusChangeObserver* observer) override {} |
2091 virtual void RemoveObserver(client::FocusChangeObserver* observer) override {} | 2113 virtual void RemoveObserver(client::FocusChangeObserver* observer) override {} |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2360 ASSERT_EQ(1u, recorder.touch_locations().size()); | 2382 ASSERT_EQ(1u, recorder.touch_locations().size()); |
2361 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), | 2383 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), |
2362 recorder.touch_locations()[0].ToString()); | 2384 recorder.touch_locations()[0].ToString()); |
2363 | 2385 |
2364 ASSERT_EQ(2u, recorder.gesture_locations().size()); | 2386 ASSERT_EQ(2u, recorder.gesture_locations().size()); |
2365 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), | 2387 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), |
2366 recorder.gesture_locations()[0].ToString()); | 2388 recorder.gesture_locations()[0].ToString()); |
2367 } | 2389 } |
2368 | 2390 |
2369 } // namespace aura | 2391 } // namespace aura |
OLD | NEW |