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

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

Issue 2337233004: MacViews: Fix sending mouse exit event and releasing capture on D&D. (Closed)
Patch Set: Created 4 years, 3 months 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/drag_drop_client_mac_unittest.mm
diff --git a/ui/views/cocoa/drag_drop_client_mac_unittest.mm b/ui/views/cocoa/drag_drop_client_mac_unittest.mm
index 0f9341305eb607ed359b72a4bf82188650123c9e..48875734c549ce54f476246d29c614bed7e34f3f 100644
--- a/ui/views/cocoa/drag_drop_client_mac_unittest.mm
+++ b/ui/views/cocoa/drag_drop_client_mac_unittest.mm
@@ -6,8 +6,11 @@
#import <Cocoa/Cocoa.h>
+#import "base/mac/scoped_objc_class_swizzler.h"
#include "base/mac/sdk_forward_declarations.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "ui/events/test/event_generator.h"
#import "ui/views/cocoa/bridged_native_widget.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/view.h"
@@ -16,6 +19,18 @@
using base::ASCIIToUTF16;
+@interface NSView (DragSessionTestingDonor)
+@end
+
+@implementation NSView (DragSessionTestingDonor)
+- (NSDraggingSession*)cr_beginDraggingSessionWithItems:(NSArray*)items
+ event:(NSEvent*)event
+ source:(id<NSDraggingSource>)
+ source {
+ return nil;
+}
+@end
+
// Mocks the NSDraggingInfo sent to the DragDropClientMac's DragUpdate() and
// Drop() methods. Out of the required methods of the protocol, only
// draggingLocation and draggingPasteboard are used.
@@ -209,6 +224,45 @@ TEST_F(DragDropClientMacTest, BasicDragDrop) {
EXPECT_EQ(Drop(), NSDragOperationMove);
}
+// Tests that widget releases mouse capture when drag'n'drop is started.
tapted 2016/09/21 10:07:05 Since StartDragAndDrop() spins the runloop, the te
snake 2016/09/21 12:29:52 Done.
+TEST_F(DragDropClientMacTest, ReleaseCapture) {
+ ui::test::EventGenerator event_generator(GetContext(),
+ widget_->GetNativeWindow());
+ // Generate mouse press to toggle dragging_ flag in BaseView.
tapted 2016/09/21 10:07:05 this comment is out of date
snake 2016/09/21 12:29:52 Done.
+ // StartDragAndDrop() should disable it.
+ event_generator.MoveMouseTo(gfx::Point(50, 50));
+ event_generator.PressLeftButton();
+
+ // DragDropView doesn't actually capture the mouse, so explicitly acquire it
+ // to test that StartDragAndDrop() actually releases it.
+ bridge_->AcquireCapture();
tapted 2016/09/21 10:07:05 Be aware that capture on Windows typically can't b
snake 2016/09/21 12:29:52 Done.
+ EXPECT_TRUE(bridge_->HasCapture());
+
+ // Create the drop data
+ OSExchangeData data;
+ const base::string16& text = ASCIIToUTF16("text");
+ data.SetString(text);
+ SetData(data);
+
+ // There's no way to cleanly stop NSDraggingSession inside unit tests, so just
+ // don't start it at all.
+ base::mac::ScopedObjCClassSwizzler swizzle(
+ [NSView class], @selector(beginDraggingSessionWithItems:event:source:),
+ @selector(cr_beginDraggingSessionWithItems:event:source:));
+
+ // Immediately quit drag'n'drop, or we'll hang.
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&DragDropClientMac::EndDrag,
+ base::Unretained(drag_drop_client())));
+
+ // It will call ReleaseCapture(), and BaseView will no longer think it's
tapted 2016/09/21 10:07:05 update comment.
snake 2016/09/21 12:29:52 Done.
+ // dragging.
+ drag_drop_client()->StartDragAndDrop(
+ target_, data, 0, ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
+
+ EXPECT_FALSE(bridge_->HasCapture());
+}
+
// Tests if the drag and drop target rejects the dropped data with the
// incorrect format.
TEST_F(DragDropClientMacTest, InvalidFormatDragDrop) {
« ui/views/cocoa/drag_drop_client_mac.mm ('K') | « ui/views/cocoa/drag_drop_client_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698