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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 EXPECT_TRUE(window->HasCapture()); | 378 EXPECT_TRUE(window->HasCapture()); |
379 | 379 |
380 // Destroy the window. | 380 // Destroy the window. |
381 window.reset(); | 381 window.reset(); |
382 | 382 |
383 // Make sure the root doesn't reference the window anymore. | 383 // Make sure the root doesn't reference the window anymore. |
384 EXPECT_EQ(NULL, root->mouse_pressed_handler()); | 384 EXPECT_EQ(NULL, root->mouse_pressed_handler()); |
385 EXPECT_EQ(NULL, root->capture_window()); | 385 EXPECT_EQ(NULL, root->capture_window()); |
386 } | 386 } |
387 | 387 |
| 388 class MouseEnterExitWindowDelegate : public WindowDelegateImpl { |
| 389 public: |
| 390 MouseEnterExitWindowDelegate() : entered_(false), exited_(false) {} |
| 391 |
| 392 virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { |
| 393 switch (event->type()) { |
| 394 case ui::ET_MOUSE_ENTERED: |
| 395 entered_ = true; |
| 396 break; |
| 397 case ui::ET_MOUSE_EXITED: |
| 398 exited_ = true; |
| 399 break; |
| 400 default: |
| 401 break; |
| 402 } |
| 403 return false; |
| 404 } |
| 405 |
| 406 bool entered() const { return entered_; } |
| 407 bool exited() const { return exited_; } |
| 408 |
| 409 private: |
| 410 bool entered_; |
| 411 bool exited_; |
| 412 |
| 413 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); |
| 414 }; |
| 415 |
| 416 |
| 417 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for |
| 418 // mouse transitions from window to window. |
| 419 TEST_F(WindowTest, MouseEnterExit) { |
| 420 Desktop* desktop = Desktop::GetInstance(); |
| 421 |
| 422 MouseEnterExitWindowDelegate d1; |
| 423 scoped_ptr<Window> w1( |
| 424 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); |
| 425 MouseEnterExitWindowDelegate d2; |
| 426 scoped_ptr<Window> w2( |
| 427 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL)); |
| 428 |
| 429 gfx::Point move_point = w1->bounds().CenterPoint(); |
| 430 Window::ConvertPointToWindow(w1->parent(), desktop->window(), &move_point); |
| 431 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_MOVED, move_point, 0)); |
| 432 |
| 433 EXPECT_TRUE(d1.entered()); |
| 434 EXPECT_FALSE(d1.exited()); |
| 435 EXPECT_FALSE(d2.entered()); |
| 436 EXPECT_FALSE(d2.exited()); |
| 437 |
| 438 move_point = w2->bounds().CenterPoint(); |
| 439 Window::ConvertPointToWindow(w2->parent(), desktop->window(), &move_point); |
| 440 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_MOVED, move_point, 0)); |
| 441 |
| 442 EXPECT_TRUE(d1.entered()); |
| 443 EXPECT_TRUE(d1.exited()); |
| 444 EXPECT_TRUE(d2.entered()); |
| 445 EXPECT_FALSE(d2.exited()); |
| 446 } |
| 447 |
388 } // namespace internal | 448 } // namespace internal |
389 } // namespace aura | 449 } // namespace aura |
OLD | NEW |