OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/aura/desktop.h" | 9 #include "ui/aura/desktop.h" |
10 #include "ui/aura/event.h" | 10 #include "ui/aura/event.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 const gfx::Rect& new_bounds) OVERRIDE {} | 35 const gfx::Rect& new_bounds) OVERRIDE {} |
36 virtual void OnFocus() OVERRIDE {} | 36 virtual void OnFocus() OVERRIDE {} |
37 virtual void OnBlur() OVERRIDE {} | 37 virtual void OnBlur() OVERRIDE {} |
38 virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE { | 38 virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE { |
39 return false; | 39 return false; |
40 } | 40 } |
41 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { | 41 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
42 return HTCLIENT; | 42 return HTCLIENT; |
43 } | 43 } |
44 virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { return false; } | 44 virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { return false; } |
| 45 virtual void OnCaptureLost() OVERRIDE {} |
45 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {} | 46 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {} |
46 virtual void OnWindowDestroying() OVERRIDE {} | 47 virtual void OnWindowDestroying() OVERRIDE {} |
47 virtual void OnWindowDestroyed() OVERRIDE {} | 48 virtual void OnWindowDestroyed() OVERRIDE {} |
48 | 49 |
49 private: | 50 private: |
50 DISALLOW_COPY_AND_ASSIGN(WindowDelegateImpl); | 51 DISALLOW_COPY_AND_ASSIGN(WindowDelegateImpl); |
51 }; | 52 }; |
52 | 53 |
53 // Used for verifying destruction methods are invoked. | 54 // Used for verifying destruction methods are invoked. |
54 class DestroyTrackingDelegateImpl : public WindowDelegateImpl { | 55 class DestroyTrackingDelegateImpl : public WindowDelegateImpl { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 EXPECT_TRUE(parent_delegate_->in_destroying()); | 100 EXPECT_TRUE(parent_delegate_->in_destroying()); |
100 DestroyTrackingDelegateImpl::OnWindowDestroying(); | 101 DestroyTrackingDelegateImpl::OnWindowDestroying(); |
101 } | 102 } |
102 | 103 |
103 private: | 104 private: |
104 DestroyTrackingDelegateImpl* parent_delegate_; | 105 DestroyTrackingDelegateImpl* parent_delegate_; |
105 | 106 |
106 DISALLOW_COPY_AND_ASSIGN(ChildWindowDelegateImpl); | 107 DISALLOW_COPY_AND_ASSIGN(ChildWindowDelegateImpl); |
107 }; | 108 }; |
108 | 109 |
| 110 // Used in verifying mouse capture. |
| 111 class CaptureWindowDelegateImpl : public WindowDelegateImpl { |
| 112 public: |
| 113 explicit CaptureWindowDelegateImpl() |
| 114 : capture_lost_count_(0), |
| 115 mouse_event_count_(0) { |
| 116 } |
| 117 |
| 118 int capture_lost_count() const { return capture_lost_count_; } |
| 119 void set_capture_lost_count(int value) { capture_lost_count_ = value; } |
| 120 int mouse_event_count() const { return mouse_event_count_; } |
| 121 void set_mouse_event_count(int value) { mouse_event_count_ = value; } |
| 122 |
| 123 virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { |
| 124 mouse_event_count_++; |
| 125 return false; |
| 126 } |
| 127 virtual void OnCaptureLost() OVERRIDE { |
| 128 capture_lost_count_++; |
| 129 } |
| 130 |
| 131 private: |
| 132 int capture_lost_count_; |
| 133 int mouse_event_count_; |
| 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(CaptureWindowDelegateImpl); |
| 136 }; |
| 137 |
109 // A simple WindowDelegate implementation for these tests. It owns itself | 138 // A simple WindowDelegate implementation for these tests. It owns itself |
110 // (deletes itself when the Window it is attached to is destroyed). | 139 // (deletes itself when the Window it is attached to is destroyed). |
111 class TestWindowDelegate : public WindowDelegateImpl { | 140 class TestWindowDelegate : public WindowDelegateImpl { |
112 public: | 141 public: |
113 TestWindowDelegate(SkColor color) | 142 TestWindowDelegate(SkColor color) |
114 : color_(color), | 143 : color_(color), |
115 last_key_code_(ui::VKEY_UNKNOWN) { | 144 last_key_code_(ui::VKEY_UNKNOWN) { |
116 } | 145 } |
117 virtual ~TestWindowDelegate() {} | 146 virtual ~TestWindowDelegate() {} |
118 | 147 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 327 |
299 parent.MoveChildToFront(&child1); | 328 parent.MoveChildToFront(&child1); |
300 ASSERT_EQ(2u, parent.children().size()); | 329 ASSERT_EQ(2u, parent.children().size()); |
301 EXPECT_EQ(&child1, parent.children()[1]); | 330 EXPECT_EQ(&child1, parent.children()[1]); |
302 EXPECT_EQ(&child2, parent.children()[0]); | 331 EXPECT_EQ(&child2, parent.children()[0]); |
303 ASSERT_EQ(2u, parent.layer()->children().size()); | 332 ASSERT_EQ(2u, parent.layer()->children().size()); |
304 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 333 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
305 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 334 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
306 } | 335 } |
307 | 336 |
| 337 // Various destruction assertions. |
| 338 TEST_F(WindowTest, CaptureTests) { |
| 339 Desktop* desktop = Desktop::GetInstance(); |
| 340 CaptureWindowDelegateImpl delegate; |
| 341 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
| 342 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
| 343 EXPECT_FALSE(window->HasCapture()); |
| 344 |
| 345 // Do a capture. |
| 346 window->SetCapture(); |
| 347 EXPECT_TRUE(window->HasCapture()); |
| 348 EXPECT_EQ(0, delegate.capture_lost_count()); |
| 349 |
| 350 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), |
| 351 ui::EF_LEFT_BUTTON_DOWN)); |
| 352 EXPECT_EQ(1, delegate.mouse_event_count()); |
| 353 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), |
| 354 ui::EF_LEFT_BUTTON_DOWN)); |
| 355 EXPECT_EQ(2, delegate.mouse_event_count()); |
| 356 delegate.set_mouse_event_count(0); |
| 357 |
| 358 window->ReleaseCapture(); |
| 359 EXPECT_FALSE(window->HasCapture()); |
| 360 EXPECT_EQ(1, delegate.capture_lost_count()); |
| 361 |
| 362 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), |
| 363 ui::EF_LEFT_BUTTON_DOWN)); |
| 364 EXPECT_EQ(0, delegate.mouse_event_count()); |
| 365 } |
| 366 |
| 367 // Verifies capture is reset when a window is destroyed. |
| 368 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { |
| 369 Desktop* desktop = Desktop::GetInstance(); |
| 370 RootWindow* root = static_cast<RootWindow*>(desktop->window()); |
| 371 CaptureWindowDelegateImpl delegate; |
| 372 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
| 373 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
| 374 EXPECT_FALSE(window->HasCapture()); |
| 375 |
| 376 // Do a capture. |
| 377 window->SetCapture(); |
| 378 EXPECT_TRUE(window->HasCapture()); |
| 379 |
| 380 // Destroy the window. |
| 381 window.reset(); |
| 382 |
| 383 // Make sure the root doesn't reference the window anymore. |
| 384 EXPECT_EQ(NULL, root->mouse_pressed_handler()); |
| 385 EXPECT_EQ(NULL, root->capture_window()); |
| 386 } |
| 387 |
308 } // namespace internal | 388 } // namespace internal |
309 } // namespace aura | 389 } // namespace aura |
310 | |
OLD | NEW |