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 2016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2027 recorder.touch_locations()[0].ToString()); | 2027 recorder.touch_locations()[0].ToString()); |
2028 EXPECT_EQ(gfx::Point(-40, 10).ToString(), | 2028 EXPECT_EQ(gfx::Point(-40, 10).ToString(), |
2029 recorder.touch_locations()[1].ToString()); | 2029 recorder.touch_locations()[1].ToString()); |
2030 } | 2030 } |
2031 | 2031 |
2032 class SelfDestructDelegate : public test::TestWindowDelegate { | 2032 class SelfDestructDelegate : public test::TestWindowDelegate { |
2033 public: | 2033 public: |
2034 SelfDestructDelegate() {} | 2034 SelfDestructDelegate() {} |
2035 virtual ~SelfDestructDelegate() {} | 2035 virtual ~SelfDestructDelegate() {} |
2036 | 2036 |
2037 virtual void OnMouseEvent(ui::MouseEvent* event) override { | 2037 virtual void OnMouseEvent(ui::MouseEvent* event) override { |
sky
2014/10/21 20:08:10
When is a mouse event generated by the code you ha
mfomitchev
2014/10/21 20:35:33
Yes, the test fails without the patch. The mouse e
| |
2038 window_.reset(); | 2038 window_.reset(); |
2039 } | 2039 } |
2040 | 2040 |
2041 void set_window(scoped_ptr<aura::Window> window) { | 2041 void set_window(scoped_ptr<aura::Window> window) { |
2042 window_ = window.Pass(); | 2042 window_ = window.Pass(); |
2043 } | 2043 } |
2044 bool has_window() const { return !!window_.get(); } | 2044 bool has_window() const { return !!window_.get(); } |
2045 | 2045 |
2046 private: | 2046 private: |
2047 scoped_ptr<aura::Window> window_; | 2047 scoped_ptr<aura::Window> window_; |
(...skipping 24 matching lines...) Expand all 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 |