OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/bind.h" | 6 #include "base/bind.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "ui/aura/client/activation_client.h" |
| 9 #include "ui/aura/client/focus_client.h" |
| 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_event_dispatcher.h" |
8 #include "ui/gfx/native_widget_types.h" | 13 #include "ui/gfx/native_widget_types.h" |
9 #include "ui/views/test/widget_test.h" | 14 #include "ui/views/test/widget_test.h" |
10 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
11 #include "ui/views/window/dialog_delegate.h" | 16 #include "ui/views/window/dialog_delegate.h" |
12 | 17 |
13 #if defined(USE_AURA) | 18 #if !defined(OS_CHROMEOS) |
14 #include "ui/aura/client/activation_client.h" | |
15 #include "ui/aura/client/focus_client.h" | |
16 #include "ui/aura/env.h" | |
17 #include "ui/aura/window.h" | |
18 #include "ui/aura/window_event_dispatcher.h" | |
19 #endif | |
20 | |
21 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | |
22 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 19 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
23 #endif | 20 #endif |
24 | 21 |
25 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
26 #include "ui/views/win/hwnd_util.h" | 23 #include "ui/views/win/hwnd_util.h" |
27 #endif | 24 #endif |
28 | 25 |
29 namespace views { | 26 namespace views { |
30 namespace test { | 27 namespace test { |
31 | 28 |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 DISALLOW_COPY_AND_ASSIGN(WidgetActivationTest); | 469 DISALLOW_COPY_AND_ASSIGN(WidgetActivationTest); |
473 }; | 470 }; |
474 | 471 |
475 // Tests whether the widget only becomes active when the underlying window | 472 // Tests whether the widget only becomes active when the underlying window |
476 // is really active. | 473 // is really active. |
477 TEST_F(WidgetTest, WidgetNotActivatedOnFakeActivationMessages) { | 474 TEST_F(WidgetTest, WidgetNotActivatedOnFakeActivationMessages) { |
478 WidgetActivationTest widget1; | 475 WidgetActivationTest widget1; |
479 Widget::InitParams init_params = | 476 Widget::InitParams init_params = |
480 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 477 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
481 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 478 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
482 #if defined(USE_AURA) | |
483 init_params.native_widget = new DesktopNativeWidgetAura(&widget1); | 479 init_params.native_widget = new DesktopNativeWidgetAura(&widget1); |
484 #endif | |
485 init_params.bounds = gfx::Rect(0, 0, 200, 200); | 480 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
486 widget1.Init(init_params); | 481 widget1.Init(init_params); |
487 widget1.Show(); | 482 widget1.Show(); |
488 EXPECT_EQ(true, widget1.active()); | 483 EXPECT_EQ(true, widget1.active()); |
489 | 484 |
490 WidgetActivationTest widget2; | 485 WidgetActivationTest widget2; |
491 #if defined(USE_AURA) | |
492 init_params.native_widget = new DesktopNativeWidgetAura(&widget2); | 486 init_params.native_widget = new DesktopNativeWidgetAura(&widget2); |
493 #endif | |
494 widget2.Init(init_params); | 487 widget2.Init(init_params); |
495 widget2.Show(); | 488 widget2.Show(); |
496 EXPECT_EQ(true, widget2.active()); | 489 EXPECT_EQ(true, widget2.active()); |
497 EXPECT_EQ(false, widget1.active()); | 490 EXPECT_EQ(false, widget1.active()); |
498 | 491 |
499 HWND win32_native_window1 = HWNDForWidget(&widget1); | 492 HWND win32_native_window1 = HWNDForWidget(&widget1); |
500 EXPECT_TRUE(::IsWindow(win32_native_window1)); | 493 EXPECT_TRUE(::IsWindow(win32_native_window1)); |
501 | 494 |
502 ::SendMessage(win32_native_window1, WM_NCACTIVATE, 1, 0); | 495 ::SendMessage(win32_native_window1, WM_NCACTIVATE, 1, 0); |
503 EXPECT_EQ(false, widget1.active()); | 496 EXPECT_EQ(false, widget1.active()); |
504 EXPECT_EQ(true, widget2.active()); | 497 EXPECT_EQ(true, widget2.active()); |
505 | 498 |
506 ::SetActiveWindow(win32_native_window1); | 499 ::SetActiveWindow(win32_native_window1); |
507 EXPECT_EQ(true, widget1.active()); | 500 EXPECT_EQ(true, widget1.active()); |
508 EXPECT_EQ(false, widget2.active()); | 501 EXPECT_EQ(false, widget2.active()); |
509 } | 502 } |
510 #endif | 503 #endif |
511 | 504 |
512 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 505 #if !defined(OS_CHROMEOS) |
513 // Provides functionality to create a window modal dialog. | 506 // Provides functionality to create a window modal dialog. |
514 class ModalDialogDelegate : public DialogDelegateView { | 507 class ModalDialogDelegate : public DialogDelegateView { |
515 public: | 508 public: |
516 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} | 509 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} |
517 virtual ~ModalDialogDelegate() {} | 510 virtual ~ModalDialogDelegate() {} |
518 | 511 |
519 // WidgetDelegate overrides. | 512 // WidgetDelegate overrides. |
520 virtual ui::ModalType GetModalType() const OVERRIDE { | 513 virtual ui::ModalType GetModalType() const OVERRIDE { |
521 return type_; | 514 return type_; |
522 } | 515 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 widget1.ReleaseCapture(); | 673 widget1.ReleaseCapture(); |
681 EXPECT_FALSE(widget1.HasCapture()); | 674 EXPECT_FALSE(widget1.HasCapture()); |
682 EXPECT_FALSE(widget2.HasCapture()); | 675 EXPECT_FALSE(widget2.HasCapture()); |
683 EXPECT_TRUE(widget1.GetAndClearGotCaptureLost()); | 676 EXPECT_TRUE(widget1.GetAndClearGotCaptureLost()); |
684 EXPECT_FALSE(widget2.GetAndClearGotCaptureLost()); | 677 EXPECT_FALSE(widget2.GetAndClearGotCaptureLost()); |
685 } | 678 } |
686 | 679 |
687 private: | 680 private: |
688 NativeWidget* CreateNativeWidget(bool create_desktop_native_widget, | 681 NativeWidget* CreateNativeWidget(bool create_desktop_native_widget, |
689 Widget* widget) { | 682 Widget* widget) { |
690 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 683 #if !defined(OS_CHROMEOS) |
691 if (create_desktop_native_widget) | 684 if (create_desktop_native_widget) |
692 return new DesktopNativeWidgetAura(widget); | 685 return new DesktopNativeWidgetAura(widget); |
693 #endif | 686 #endif |
694 return NULL; | 687 return NULL; |
695 } | 688 } |
696 | 689 |
697 DISALLOW_COPY_AND_ASSIGN(WidgetCaptureTest); | 690 DISALLOW_COPY_AND_ASSIGN(WidgetCaptureTest); |
698 }; | 691 }; |
699 | 692 |
700 // See description in TestCapture(). | 693 // See description in TestCapture(). |
701 TEST_F(WidgetCaptureTest, Capture) { | 694 TEST_F(WidgetCaptureTest, Capture) { |
702 TestCapture(false); | 695 TestCapture(false); |
703 } | 696 } |
704 | 697 |
705 #if defined(USE_AURA) && !defined(OS_LINUX) | 698 #if !defined(OS_LINUX) |
706 // See description in TestCapture(). Creates DesktopNativeWidget. | 699 // See description in TestCapture(). Creates DesktopNativeWidget. |
707 TEST_F(WidgetCaptureTest, CaptureDesktopNativeWidget) { | 700 TEST_F(WidgetCaptureTest, CaptureDesktopNativeWidget) { |
708 TestCapture(true); | 701 TestCapture(true); |
709 } | 702 } |
710 #endif | 703 #endif |
711 | 704 |
712 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 705 #if !defined(OS_CHROMEOS) |
713 namespace { | 706 namespace { |
714 | 707 |
715 // Used to veirfy OnMouseEvent() has been invoked. | 708 // Used to veirfy OnMouseEvent() has been invoked. |
716 class MouseEventTrackingWidget : public Widget { | 709 class MouseEventTrackingWidget : public Widget { |
717 public: | 710 public: |
718 MouseEventTrackingWidget() : got_mouse_event_(false) {} | 711 MouseEventTrackingWidget() : got_mouse_event_(false) {} |
719 virtual ~MouseEventTrackingWidget() {} | 712 virtual ~MouseEventTrackingWidget() {} |
720 | 713 |
721 bool GetAndClearGotMouseEvent() { | 714 bool GetAndClearGotMouseEvent() { |
722 bool value = got_mouse_event_; | 715 bool value = got_mouse_event_; |
723 got_mouse_event_ = false; | 716 got_mouse_event_ = false; |
724 return value; | 717 return value; |
725 } | 718 } |
726 | 719 |
727 // Widget: | 720 // Widget: |
728 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 721 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
729 got_mouse_event_ = true; | 722 got_mouse_event_ = true; |
730 Widget::OnMouseEvent(event); | 723 Widget::OnMouseEvent(event); |
731 } | 724 } |
732 | 725 |
733 private: | 726 private: |
734 bool got_mouse_event_; | 727 bool got_mouse_event_; |
735 | 728 |
736 DISALLOW_COPY_AND_ASSIGN(MouseEventTrackingWidget); | 729 DISALLOW_COPY_AND_ASSIGN(MouseEventTrackingWidget); |
737 }; | 730 }; |
738 | 731 |
739 } // namespace | 732 } // namespace |
740 | 733 |
741 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) | 734 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
742 // TODO(erg): linux_aura bringup: http://crbug.com/163931 | 735 // TODO(erg): linux_aura bringup: http://crbug.com/163931 |
743 #define MAYBE_MouseEventDispatchedToRightWindow \ | 736 #define MAYBE_MouseEventDispatchedToRightWindow \ |
744 DISABLED_MouseEventDispatchedToRightWindow | 737 DISABLED_MouseEventDispatchedToRightWindow |
745 #else | 738 #else |
746 #define MAYBE_MouseEventDispatchedToRightWindow \ | 739 #define MAYBE_MouseEventDispatchedToRightWindow \ |
747 MouseEventDispatchedToRightWindow | 740 MouseEventDispatchedToRightWindow |
748 #endif | 741 #endif |
749 | 742 |
750 // Verifies if a mouse event is received on a widget that doesn't have capture | 743 // Verifies if a mouse event is received on a widget that doesn't have capture |
751 // it is correctly processed by the widget that doesn't have capture. | 744 // it is correctly processed by the widget that doesn't have capture. |
(...skipping 28 matching lines...) Expand all Loading... |
780 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 773 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
781 GetHost()->dispatcher()->OnEventFromSource(&mouse_event); | 774 GetHost()->dispatcher()->OnEventFromSource(&mouse_event); |
782 ASSERT_FALSE(details.dispatcher_destroyed); | 775 ASSERT_FALSE(details.dispatcher_destroyed); |
783 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 776 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
784 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 777 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
785 } | 778 } |
786 #endif | 779 #endif |
787 | 780 |
788 } // namespace test | 781 } // namespace test |
789 } // namespace views | 782 } // namespace views |
OLD | NEW |