| Index: ui/aura/window_unittest.cc
|
| diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
|
| index 2c8918f2ce5e9fde1fbfe2ec0505068c8470fe11..8dbd5312451ec5efe958e52ff83f397123a1fadb 100644
|
| --- a/ui/aura/window_unittest.cc
|
| +++ b/ui/aura/window_unittest.cc
|
| @@ -42,6 +42,8 @@ class WindowDelegateImpl : public WindowDelegate {
|
| return HTCLIENT;
|
| }
|
| virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { return false; }
|
| + virtual void OnCaptureGained() OVERRIDE {}
|
| + virtual void OnCaptureLost() OVERRIDE {}
|
| virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {}
|
| virtual void OnWindowDestroying() OVERRIDE {}
|
| virtual void OnWindowDestroyed() OVERRIDE {}
|
| @@ -106,6 +108,41 @@ class ChildWindowDelegateImpl : public DestroyTrackingDelegateImpl {
|
| DISALLOW_COPY_AND_ASSIGN(ChildWindowDelegateImpl);
|
| };
|
|
|
| +// Used in verifying mouse capture.
|
| +class CaptureWindowDelegateImpl : public WindowDelegateImpl {
|
| + public:
|
| + explicit CaptureWindowDelegateImpl()
|
| + : capture_gained_count_(0),
|
| + capture_lost_count_(0),
|
| + mouse_event_count_(0) {
|
| + }
|
| +
|
| + int capture_gained_count() const { return capture_gained_count_; }
|
| + void set_capture_gained_count(int value) { capture_gained_count_ = value; }
|
| + int capture_lost_count() const { return capture_lost_count_; }
|
| + void set_capture_lost_count(int value) { capture_lost_count_ = value; }
|
| + int mouse_event_count() const { return mouse_event_count_; }
|
| + void set_mouse_event_count(int value) { mouse_event_count_ = value; }
|
| +
|
| + virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE {
|
| + mouse_event_count_++;
|
| + return false;
|
| + }
|
| + virtual void OnCaptureGained() OVERRIDE {
|
| + capture_gained_count_++;
|
| + }
|
| + virtual void OnCaptureLost() OVERRIDE {
|
| + capture_lost_count_++;
|
| + }
|
| +
|
| + private:
|
| + int capture_gained_count_;
|
| + int capture_lost_count_;
|
| + int mouse_event_count_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CaptureWindowDelegateImpl);
|
| +};
|
| +
|
| // A simple WindowDelegate implementation for these tests. It owns itself
|
| // (deletes itself when the Window it is attached to is destroyed).
|
| class TestWindowDelegate : public WindowDelegateImpl {
|
| @@ -305,6 +342,58 @@ TEST_F(WindowTest, MoveChildToFront) {
|
| EXPECT_EQ(child2.layer(), parent.layer()->children()[0]);
|
| }
|
|
|
| +// Various destruction assertions.
|
| +TEST_F(WindowTest, CaptureTests) {
|
| + Desktop* desktop = Desktop::GetInstance();
|
| + CaptureWindowDelegateImpl delegate;
|
| + scoped_ptr<Window> window(CreateTestWindowWithDelegate(
|
| + &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
|
| + EXPECT_FALSE(window->HasCapture());
|
| +
|
| + // Do a capture.
|
| + window->SetCapture();
|
| + EXPECT_TRUE(window->HasCapture());
|
| + EXPECT_EQ(1, delegate.capture_gained_count());
|
| + EXPECT_EQ(0, delegate.capture_lost_count());
|
| +
|
| + desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50),
|
| + ui::EF_LEFT_BUTTON_DOWN));
|
| + EXPECT_EQ(1, delegate.mouse_event_count());
|
| + desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50),
|
| + ui::EF_LEFT_BUTTON_DOWN));
|
| + EXPECT_EQ(2, delegate.mouse_event_count());
|
| + delegate.set_mouse_event_count(0);
|
| +
|
| + window->ReleaseCapture();
|
| + EXPECT_FALSE(window->HasCapture());
|
| + EXPECT_EQ(1, delegate.capture_gained_count());
|
| + EXPECT_EQ(1, delegate.capture_lost_count());
|
| +
|
| + desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50),
|
| + ui::EF_LEFT_BUTTON_DOWN));
|
| + EXPECT_EQ(0, delegate.mouse_event_count());
|
| +}
|
| +
|
| +// Various destruction assertions.
|
| +TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
|
| + Desktop* desktop = Desktop::GetInstance();
|
| + RootWindow* root = static_cast<RootWindow*>(desktop->window());
|
| + CaptureWindowDelegateImpl delegate;
|
| + scoped_ptr<Window> window(CreateTestWindowWithDelegate(
|
| + &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
|
| + EXPECT_FALSE(window->HasCapture());
|
| +
|
| + // Do a capture.
|
| + window->SetCapture();
|
| + EXPECT_TRUE(window->HasCapture());
|
| +
|
| + // Destroy the window.
|
| + window.reset();
|
| +
|
| + // Make sure the root doesn't reference the window anymore.
|
| + EXPECT_EQ(NULL, root->mouse_pressed_handler());
|
| + EXPECT_EQ(NULL, root->capture_window());
|
| +}
|
| +
|
| } // namespace internal
|
| } // namespace aura
|
| -
|
|
|