Chromium Code Reviews| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 997 // Send a mouse event to the RootWindow associated with |widget1|. Even though | 997 // Send a mouse event to the RootWindow associated with |widget1|. Even though |
| 998 // |widget2| has capture, |widget1| should still get the event. | 998 // |widget2| has capture, |widget1| should still get the event. |
| 999 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 999 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), |
| 1000 ui::EF_NONE, ui::EF_NONE); | 1000 ui::EF_NONE, ui::EF_NONE); |
| 1001 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1001 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 1002 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1002 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 1003 ASSERT_FALSE(details.dispatcher_destroyed); | 1003 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1004 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1004 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 1005 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1005 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 1006 } | 1006 } |
| 1007 | |
| 1008 // Widget observer which grabs capture when the widget is activated. | |
| 1009 class CaptureOnActivationObserver : public WidgetObserver { | |
| 1010 public: | |
| 1011 CaptureOnActivationObserver() { | |
| 1012 } | |
| 1013 virtual ~CaptureOnActivationObserver() { | |
| 1014 } | |
| 1015 | |
| 1016 virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE { | |
|
sadrul
2014/07/14 16:58:00
// WidgetObserver:
| |
| 1017 if (active) | |
| 1018 widget->SetCapture(NULL); | |
| 1019 } | |
| 1020 | |
| 1021 private: | |
| 1022 DISALLOW_COPY_AND_ASSIGN(CaptureOnActivationObserver); | |
| 1023 }; | |
| 1024 | |
| 1025 // Test that setting capture on widget activation of a non-toplevel widget | |
| 1026 // (e.g. a bubble on Linux) succeeds. | |
| 1027 TEST_F(WidgetCaptureTest, SetCaptureToNonToplevel) { | |
| 1028 Widget toplevel; | |
| 1029 Widget::InitParams toplevel_params = | |
| 1030 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 1031 toplevel_params.native_widget = new DesktopNativeWidgetAura(&toplevel); | |
| 1032 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 1033 toplevel.Init(toplevel_params); | |
| 1034 toplevel.Show(); | |
| 1035 | |
| 1036 Widget* child = new Widget; | |
| 1037 Widget::InitParams child_params = | |
| 1038 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 1039 child_params.parent = toplevel.GetNativeView(); | |
| 1040 child_params.context = toplevel.GetNativeView(); | |
| 1041 child->Init(child_params); | |
| 1042 | |
| 1043 CaptureOnActivationObserver observer; | |
| 1044 child->AddObserver(&observer); | |
| 1045 child->Show(); | |
| 1046 | |
| 1047 EXPECT_TRUE(child->HasCapture()); | |
| 1048 } | |
| 1007 #endif | 1049 #endif |
| 1008 | 1050 |
| 1009 } // namespace test | 1051 } // namespace test |
| 1010 } // namespace views | 1052 } // namespace views |
| OLD | NEW |