Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: ui/views/cocoa/bridged_native_widget_interactive_uitest.mm

Issue 2475173002: MacViews: Fix window dragging on Sierra. (Closed)
Patch Set: Tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/cocoa/bridged_native_widget_interactive_uitest.mm
diff --git a/ui/views/cocoa/bridged_native_widget_interactive_uitest.mm b/ui/views/cocoa/bridged_native_widget_interactive_uitest.mm
index 9dc032a2ffe76b19538048e2c244138cf16c16fa..bce3cf2b021f22f380872048ed6ac3796dd6a2da 100644
--- a/ui/views/cocoa/bridged_native_widget_interactive_uitest.mm
+++ b/ui/views/cocoa/bridged_native_widget_interactive_uitest.mm
@@ -198,9 +198,8 @@ class HitTestBridgedNativeWidget : public BridgedNativeWidget {
: BridgedNativeWidget(widget) {}
// BridgedNativeWidget:
- bool ShouldRepostPendingLeftMouseDown(NSPoint location_in_window) override {
- did_repost_ = BridgedNativeWidget::ShouldRepostPendingLeftMouseDown(
- location_in_window);
+ bool ShouldRepostPendingLeftMouseDown(NSEvent* event) override {
+ did_repost_ = BridgedNativeWidget::ShouldRepostPendingLeftMouseDown(event);
if (run_loop_)
run_loop_->Quit();
@@ -323,15 +322,28 @@ TEST_F(BridgedNativeWidgetUITest, HitTest) {
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.bounds = gfx::Rect(100, 200, 400, 300);
widget.Init(init_params);
+
+ WidgetActivationWaiter activation_waiter(&widget, true);
widget.Show();
+ activation_waiter.Wait();
// Points inside the resize area.
const NSPoint bottom_right_point = {398, 2};
const NSPoint right_of_bottom_right = {398 + 10, 2};
NSWindow* window = widget.GetNativeWindow();
+
+ // This is required since BridgedNativeWidget::SetVisibilityState initially
+ // suppresses visibility and ignores mouse events for opaque non modal
+ // dialogs. For the test, undo these changes.
+ [window setIgnoresMouseEvents:NO];
karandeepb 2016/11/08 02:59:03 What would be a good workaround to avoid this, sin
tapted 2016/11/08 05:03:17 I think if WindowResizeHelperMac::Get()->task_runn
karandeepb 2016/11/09 04:44:20 Weirdly, even after commenting this out, I can't s
tapted 2016/11/09 05:06:56 yah - OSX uses the alpha channel of the window for
karandeepb 2016/11/09 06:33:22 Yeah, you are correct. CALayer's alpha is also inf
tapted 2016/11/10 00:43:20 No task runner means no GPU process, which could h
karandeepb 2016/11/10 02:44:43 Acknowledged. Also, updated the comment regarding
+ [window setAlphaValue:1.0];
+
HitTestBridgedNativeWidget* bridge = native_widget->bridge();
+ const bool using_drag_event_monitor =
+ BridgedNativeWidget::ShouldUseDragEventMonitor();
+
// Dragging the window should work.
frame_view->set_hit_test_result(HTCAPTION);
{
@@ -341,12 +353,16 @@ TEST_F(BridgedNativeWidgetUITest, HitTest) {
NSMakePoint(20, 20), window);
EXPECT_FALSE(bridge->IsDraggable());
CGEventPost(kCGSessionEventTap, [mouse_down CGEvent]);
- bridge->WaitForShouldRepost();
- EXPECT_TRUE(bridge->did_repost());
- EXPECT_TRUE(bridge->IsDraggable());
- bridge->WaitForShouldRepost();
- EXPECT_FALSE(bridge->did_repost());
- EXPECT_FALSE(bridge->IsDraggable());
+ if (using_drag_event_monitor) {
+ bridge->WaitForShouldRepost();
+ EXPECT_TRUE(bridge->did_repost());
+ EXPECT_TRUE(bridge->IsDraggable());
+ bridge->WaitForShouldRepost();
+ EXPECT_FALSE(bridge->did_repost());
+ EXPECT_FALSE(bridge->IsDraggable());
+ } else {
+ WaitForEvent(NSLeftMouseDownMask);
+ }
base::scoped_nsobject<WindowedNSNotificationObserver> ns_observer(
tapted 2016/11/08 05:03:17 maybe we want to rename this to, e.g., move_observ
karandeepb 2016/11/09 04:44:20 Done.
[[WindowedNSNotificationObserver alloc]
@@ -354,7 +370,7 @@ TEST_F(BridgedNativeWidgetUITest, HitTest) {
NSEvent* mouse_drag = cocoa_test_event_utils::MouseEventAtPointInWindow(
NSMakePoint(30, 30), NSLeftMouseDragged, window, 0);
CGEventPost(kCGSessionEventTap, [mouse_drag CGEvent]);
- [ns_observer wait];
+ EXPECT_TRUE([ns_observer wait]);
EXPECT_EQ(110, [window frame].origin.x);
NSEvent* mouse_up = cocoa_test_event_utils::MouseEventAtPointInWindow(
@@ -372,12 +388,16 @@ TEST_F(BridgedNativeWidgetUITest, HitTest) {
bottom_right_point, window);
EXPECT_FALSE(bridge->IsDraggable());
CGEventPost(kCGSessionEventTap, [mouse_down CGEvent]);
- bridge->WaitForShouldRepost();
- EXPECT_TRUE(bridge->did_repost());
- EXPECT_TRUE(bridge->IsDraggable());
- bridge->WaitForShouldRepost();
- EXPECT_FALSE(bridge->did_repost());
- EXPECT_FALSE(bridge->IsDraggable());
+ if (using_drag_event_monitor) {
+ bridge->WaitForShouldRepost();
+ EXPECT_TRUE(bridge->did_repost());
+ EXPECT_TRUE(bridge->IsDraggable());
+ bridge->WaitForShouldRepost();
+ EXPECT_FALSE(bridge->did_repost());
+ EXPECT_FALSE(bridge->IsDraggable());
+ } else {
+ WaitForEvent(NSLeftMouseDownMask);
+ }
base::scoped_nsobject<WindowedNSNotificationObserver> ns_observer(
[[WindowedNSNotificationObserver alloc]
@@ -385,7 +405,7 @@ TEST_F(BridgedNativeWidgetUITest, HitTest) {
NSEvent* mouse_drag = cocoa_test_event_utils::MouseEventAtPointInWindow(
right_of_bottom_right, NSLeftMouseDragged, window, 0);
CGEventPost(kCGSessionEventTap, [mouse_drag CGEvent]);
- [ns_observer wait];
+ EXPECT_TRUE([ns_observer wait]);
EXPECT_EQ(120, [window frame].origin.x);
NSEvent* mouse_up = cocoa_test_event_utils::MouseEventAtPointInWindow(
@@ -412,6 +432,9 @@ TEST_F(BridgedNativeWidgetUITest, HitTest) {
EXPECT_FALSE(bridge->IsDraggable());
CGEventPost(kCGSessionEventTap, [mouse_down CGEvent]);
+ base::scoped_nsobject<WindowedNSNotificationObserver> ns_observer(
+ [[WindowedNSNotificationObserver alloc]
+ initForNotification:NSWindowDidResizeNotification]);
NSEvent* mouse_drag = cocoa_test_event_utils::MouseEventAtPoint(
NSMakePoint(x + 408, y + 2), NSLeftMouseDragged, 0);
CGEventPost(kCGSessionEventTap, [mouse_drag CGEvent]);
@@ -420,11 +443,15 @@ TEST_F(BridgedNativeWidgetUITest, HitTest) {
NSMakePoint(x + 408, y + 2), NSLeftMouseUp, 0);
CGEventPost(kCGSessionEventTap, [mouse_up CGEvent]);
- // The only event observed by us is the original mouse-down. It should not
- // be reposted.
- bridge->WaitForShouldRepost();
- EXPECT_FALSE(bridge->did_repost());
- EXPECT_FALSE(bridge->IsDraggable());
+ if (using_drag_event_monitor) {
+ // The only event observed by us is the original mouse-down. It should not
+ // be reposted.
+ bridge->WaitForShouldRepost();
+ EXPECT_FALSE(bridge->did_repost());
+ EXPECT_FALSE(bridge->IsDraggable());
+ }
+
+ EXPECT_TRUE([ns_observer wait]);
EXPECT_EQ(410, [window frame].size.width);
// Origin is unchanged.
@@ -467,10 +494,13 @@ TEST_F(BridgedNativeWidgetUITest, HitTest) {
CGEventPost(kCGSessionEventTap, [mouse_down CGEvent]);
WaitForEvent(NSLeftMouseDownMask);
+ base::scoped_nsobject<WindowedNSNotificationObserver> ns_observer(
+ [[WindowedNSNotificationObserver alloc]
+ initForNotification:NSWindowDidMoveNotification]);
NSEvent* mouse_drag = cocoa_test_event_utils::MouseEventAtPointInWindow(
NSMakePoint(30, 30), NSLeftMouseDragged, window, 0);
CGEventPost(kCGSessionEventTap, [mouse_drag CGEvent]);
- WaitForEvent(NSLeftMouseDraggedMask);
+ EXPECT_FALSE([ns_observer wait]);
karandeepb 2016/11/08 02:59:03 This causes a RunLoop to run till the timeout. Can
tapted 2016/11/08 05:03:17 Hrm. Doesn't that make this effectively ::sleep(te
karandeepb 2016/11/09 04:44:20 Yeah it does.
EXPECT_EQ(120, [window frame].origin.x);
NSEvent* mouse_up = cocoa_test_event_utils::MouseEventAtPointInWindow(

Powered by Google App Engine
This is Rietveld 408576698