Lightpanda: the headless browser designed for AI and automation
cdp: add Input.setInterceptDrags and Input.dispatchDragEvent
Jay Hemnanid2bd39ee049e
diff --git a/src/browser/Page.zig b/src/browser/Page.zigindex 7283e44c6..7a3e972da 100644--- a/src/browser/Page.zig+++ b/src/browser/Page.zig@@ -208,6 +208,10 @@ input_touch: @import("frame/user_input.zig").TouchInput = .{},// user_input.PointerButtons.input_pointer: @import("frame/user_input.zig").PointerButtons = .{},+// A drag from outside the page a CDP client is driving; see+// user_input.DragInput.+input_drag: @import("frame/user_input.zig").DragInput = .{},+// Popup Frames opened by window.open. They are top-level browsing contexts// (parent == null, no iframe element) but share this Page's factory, arena,// and identity map.diff --git a/src/browser/frame/user_input.zig b/src/browser/frame/user_input.zigindex d5d5ac5bc..8f6646912 100644--- a/src/browser/frame/user_input.zig+++ b/src/browser/frame/user_input.zig@@ -42,6 +42,8 @@ const TouchEvent = @import("../webapi/event/TouchEvent.zig");const WheelEvent = @import("../webapi/event/WheelEvent.zig");const PointerEvent = @import("../webapi/event/PointerEvent.zig");const KeyboardEvent = @import("../webapi/event/KeyboardEvent.zig");+const DragEvent = @import("../webapi/event/DragEvent.zig");+const DataTransfer = @import("../webapi/DataTransfer.zig");const log = lp.log;@@ -816,6 +818,176 @@ fn deltaToScroll(d: f64) i32 {return @trunc(std.math.clamp(d, std.math.minInt(i32), std.math.maxInt(i32)));}+/// One string of a drag's data, for one MIME type (CDP Input.DragDataItem).+pub const DragItem = struct {+ mimeType: []const u8,+ data: []const u8,+};++/// What a drag from outside the page carries: its items, and the operations+/// its source allows, as Chrome's mask (copy 1, link 2, move 16).+pub const DragData = struct {+ items: []const DragItem,+ dragOperationsMask: u32,+};++pub const DragType = enum { enter, over, drop, cancel };++/// A drag from outside the page, driven message by message (CDP+/// Input.dispatchDragEvent). Mouse input never starts a drag, so there is no+/// source element and no dragstart, drag or dragend.+pub const DragInput = struct {+ /// Set by dragEnter. A drop or dragCancel ends the drag, and dragOver and+ /// drop do nothing until the next dragEnter.+ active: bool = false,+ /// The element the drag is over (the spec's current target element).+ target: ?*Element = null,+};++const drag_copy: u32 = 1;+const drag_link: u32 = 2;+const drag_move: u32 = 16;+const drag_every = drag_copy | drag_link | drag_move;++fn dragEffectAllowed(mask: u32) []const u8 {+ return switch (mask & drag_every) {+ 0 => "none",+ drag_copy => "copy",+ drag_link => "link",+ drag_move => "move",+ drag_copy | drag_link => "copyLink",+ drag_copy | drag_move => "copyMove",+ drag_link | drag_move => "linkMove",+ else => "all",+ };+}++/// The dropEffect a dragenter or dragover starts with, picked as Blink does.+fn dragDefaultDropEffect(mask: u32) []const u8 {+ const ops = mask & drag_every;+ if (ops == drag_every) return "copy";+ if (ops & drag_move != 0) return "move";+ if (ops & drag_copy != 0) return "copy";+ if (ops & drag_link != 0) return "link";+ return "none";+}++fn dragAllows(mask: u32, effect: []const u8) bool {+ const bit: u32 = if (std.mem.eql(u8, effect, "copy"))+ drag_copy+ else if (std.mem.eql(u8, effect, "link"))+ drag_link+ else if (std.mem.eql(u8, effect, "move"))+ drag_move+ else+ 0;+ return mask & bit != 0;+}++/// Moves, drops or cancels a drag from outside the page, as Chrome does for+/// Input.dispatchDragEvent. dragEnter, dragOver and drop each run one step: a+/// new target gets dragenter, then the old one dragleave; the same target gets+/// dragover. A drop then goes to the target if that step accepted the drag+/// with an operation the source allows. If not, the target gets dragleave only+/// when a listener called preventDefault(). dragCancel fires nothing.+pub fn triggerDrag(frame: *Frame, typ: DragType, x: f64, y: f64, data: DragData, modifiers: Modifiers) !void {+ const drag = &frame.page.input_drag;+ switch (typ) {+ .cancel => {+ drag.* = .{};+ return;+ },+ .enter => drag.active = true,+ .over, .drop => if (!drag.active) return,+ }++ const d: DragDispatch = .{ .x = x, .y = y, .data = data, .modifiers = modifiers };+ const drop_effect = dragDefaultDropEffect(data.dragOperationsMask);+ const hit = try mouseHitTest(frame, x, y);+ var result: DragResult = .{ .cancelled = false, .drop_effect = "none" };+ if (hit.target != drag.target) {+ const old = drag.target;+ drag.target = hit.target;+ if (hit.target) |target| {+ result = try emitDrag(frame, target, "dragenter", old, d, .protected, drop_effect);+ }+ if (old) |target| {+ _ = try emitDrag(frame, target, "dragleave", hit.target, d, .protected, "none");+ }+ } else if (drag.target) |target| {+ result = try emitDrag(frame, target, "dragover", null, d, .protected, drop_effect);+ }+ // A listener may have discarded the target's frame and reset us.+ if (drag.target != hit.target) return;+ if (typ != .drop) return;++ drag.* = .{};+ const target = hit.target orelse return;+ if (result.cancelled and dragAllows(data.dragOperationsMask, result.drop_effect)) {+ _ = try emitDrag(frame, target, "drop", null, d, .read_only, result.drop_effect);+ } else if (result.cancelled) {+ _ = try emitDrag(frame, target, "dragleave", null, d, .protected, "none");+ }+}++const DragDispatch = struct {+ x: f64,+ y: f64,+ data: DragData,+ modifiers: Modifiers,+};++const DragResult = struct {+ cancelled: bool,+ /// dataTransfer.dropEffect once the listeners ran.+ drop_effect: []const u8,+};++/// Dispatches a trusted DragEvent whose dataTransfer holds the drag's items.+/// Each event gets its own DataTransfer, as in Blink.+fn emitDrag(+ frame: *Frame,+ target: *Element,+ comptime typ: []const u8,+ related: ?*Element,+ d: DragDispatch,+ mode: DataTransfer.Mode,+ drop_effect: []const u8,+) !DragResult {+ const owner = target.ownerFrame(frame) orelse frame;+ if (owner.window._closed) return .{ .cancelled = true, .drop_effect = "none" };++ const data_transfer = try DataTransfer.init(owner);+ data_transfer.acquireRef();+ defer data_transfer.releaseRef(owner.page);+ for (d.data.items) |item| {+ try data_transfer.setData(item.mimeType, item.data);+ }+ data_transfer._mode = mode;+ data_transfer._drop_effect = drop_effect;+ data_transfer._effect_allowed = dragEffectAllowed(d.data.dragOperationsMask);++ // No relatedTarget from another document.+ const same_document = if (related) |el| el.ownerFrame(frame) == owner else false;+ const related_target = if (same_document) related.?.asEventTarget() else null;+ const point = pointInFrame(frame, owner, d.x, d.y);+ const event: *DragEvent = try .initTrusted(typ, .{+ .bubbles = true,+ .cancelable = comptime !std.mem.eql(u8, typ, "dragleave"),+ .composed = true,+ .clientX = point.x,+ .clientY = point.y,+ .relatedTarget = related_target,+ .ctrlKey = d.modifiers.ctrl,+ .shiftKey = d.modifiers.shift,+ .altKey = d.modifiers.alt,+ .metaKey = d.modifiers.meta,+ .dataTransfer = data_transfer,+ }, owner);+ const cancelled = try owner._event_manager.dispatchCancelable(target.asEventTarget(), event.asEvent());+ return .{ .cancelled = cancelled, .drop_effect = data_transfer._drop_effect };+}+// pointerId 1 is the mouse.pub const first_touch_pointer_id: i32 = 2;// Chrome's touch slop, also the tap slop: inside it touchmove is suppressed.@@ -1127,6 +1299,11 @@ pub fn forgetFrame(frame: *Frame) void {page.input_pointer.reset();}}+ if (page.input_drag.target) |el| {+ if (el.ownerFrame(frame) == frame) {+ page.input_drag = .{};+ }+ }const touch = &page.input_touch;if (touch.contact) |contact| {if (contact.target.ownerFrame(frame) == frame) {diff --git a/src/browser/webapi/DataTransfer.zig b/src/browser/webapi/DataTransfer.zigindex d8ce98c09..48cd1c2ae 100644--- a/src/browser/webapi/DataTransfer.zig+++ b/src/browser/webapi/DataTransfer.zig@@ -58,6 +58,16 @@ _item_list: *DataTransferItemList,_files: *FileList,_drop_effect: []const u8 = "none",_effect_allowed: []const u8 = "none",+_mode: Mode = .read_write,++// https://html.spec.whatwg.org/multipage/dnd.html#drag-data-store-mode+// A drag's dragenter/dragover/dragleave see the item types but not their data,+// and only a dragstart may change the items.+pub const Mode = enum {+ read_write,+ read_only,+ protected,+};pub fn init(frame: *Frame) !*DataTransfer {const arena = try frame.getArena(.medium, "DataTransfer");@@ -102,6 +112,9 @@ fn normalizeFormat(arena: Allocator, format: []const u8) ![]const u8 {}pub fn getData(self: *const DataTransfer, format: []const u8, frame: *Frame) ![]const u8 {+ if (self._mode == .protected) {+ return "";+ }const norm = try normalizeFormat(frame.local_arena, format);for (self._items.items) |it| {if (it._kind == .string and std.mem.eql(u8, it._type, norm)) {@@ -112,6 +125,9 @@ pub fn getData(self: *const DataTransfer, format: []const u8, frame: *Frame) ![]}pub fn setData(self: *DataTransfer, format: []const u8, data: []const u8) !void {+ if (self._mode != .read_write) {+ return;+ }const norm = try normalizeFormat(self._arena.allocator(), format);const owned_data = try self._arena.dupe(u8, data);for (self._items.items) |it| {@@ -126,6 +142,9 @@ pub fn setData(self: *DataTransfer, format: []const u8, data: []const u8) !void}fn clearData(self: *DataTransfer, format_: ?[]const u8, frame: *Frame) !void {+ if (self._mode != .read_write) {+ return;+ }if (format_) |format| {const norm = try normalizeFormat(frame.local_arena, format);var i: usize = 0;@@ -154,6 +173,9 @@ fn clearData(self: *DataTransfer, format_: ?[]const u8, frame: *Frame) !void {// add(File) -> file item ; add(DOMString, DOMString) -> string item.pub fn addItem(self: *DataTransfer, data: js.Value, type_: ?[]const u8, frame: *Frame) !?*DataTransferItem {+ if (self._mode != .read_write) {+ return null;+ }if (data.toZig(*File)) |file| {return try self.addFileItem(file, frame);} else |_| {}@@ -176,7 +198,7 @@ fn addFileItem(self: *DataTransfer, file: *File, frame: *Frame) !*DataTransferIt}pub fn removeItem(self: *DataTransfer, index: u32, frame: *Frame) !void {- if (index >= self._items.items.len) {+ if (self._mode != .read_write or index >= self._items.items.len) {return;}const it = self._items.orderedRemove(index);@@ -187,6 +209,9 @@ pub fn removeItem(self: *DataTransfer, index: u32, frame: *Frame) !void {}pub fn clearItems(self: *DataTransfer, frame: *Frame) !void {+ if (self._mode != .read_write) {+ return;+ }for (self._items.items) |it| {if (it._kind == .file) {it._payload.file._proto.releaseRef(frame.page);diff --git a/src/browser/webapi/DataTransferItem.zig b/src/browser/webapi/DataTransferItem.zigindex 6d5d70b4c..6f0ba7cd4 100644--- a/src/browser/webapi/DataTransferItem.zig+++ b/src/browser/webapi/DataTransferItem.zig@@ -76,6 +76,10 @@ fn getAsFile(self: *const DataTransferItem) ?*File {// The callback runs in a queued task.pub fn getAsString(self: *DataTransferItem, cb_: ?js.Function.Global, exec: *js.Execution) !void {const cb = cb_ orelse return;+ if (self._data_transfer._mode == .protected) {+ cb.release();+ return;+ }errdefer cb.release();const value = switch (self._payload) {diff --git a/src/server/cdp/CDP.zig b/src/server/cdp/CDP.zigindex 1ae7eacc9..7fa422e50 100644--- a/src/server/cdp/CDP.zig+++ b/src/server/cdp/CDP.zig@@ -501,6 +501,10 @@ pub const BrowserContext = struct {// (chromedp's keyDown/char/keyUp split), as Chrome does.suppress_next_char: bool = false,+ // Input.setInterceptDrags. Nothing starts a drag from mouse input yet, so+ // no Input.dragIntercepted is ever due.+ intercept_drags: bool = false,+security_origin: []const u8,page_life_cycle_events: bool,secure_context_type: []const u8,diff --git a/src/server/cdp/domains/input.zig b/src/server/cdp/domains/input.zigindex 34d8aa1e6..80c1991c3 100644--- a/src/server/cdp/domains/input.zig+++ b/src/server/cdp/domains/input.zig@@ -25,17 +25,21 @@ const dom_button = Frame.user_input.mouse_button;pub fn processMessage(cmd: *CDP.Command) !void {const action = std.meta.stringToEnum(enum {+ dispatchDragEvent,dispatchKeyEvent,dispatchMouseEvent,dispatchTouchEvent,insertText,+ setInterceptDrags,}, cmd.input.action) orelse return error.UnknownMethod;switch (action) {+ .dispatchDragEvent => return dispatchDragEvent(cmd),.dispatchKeyEvent => return dispatchKeyEvent(cmd),.dispatchMouseEvent => return dispatchMouseEvent(cmd),.dispatchTouchEvent => return dispatchTouchEvent(cmd),.insertText => return insertText(cmd),+ .setInterceptDrags => return setInterceptDrags(cmd),}}@@ -220,6 +224,55 @@ fn dispatchTouchEvent(cmd: *CDP.Command) !void {}}+// https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchDragEvent+//+// A drag from outside the page. DragData.files is not implemented.+fn dispatchDragEvent(cmd: *CDP.Command) !void {+ const params = (try cmd.params(struct {+ type: Type,+ x: f64,+ y: f64,+ data: Frame.user_input.DragData,+ modifiers: u4 = 0,++ const Type = enum {+ dragEnter,+ dragOver,+ drop,+ dragCancel,+ };+ })) orelse return error.InvalidParams;++ try cmd.sendResult(null, .{});++ const bc = cmd.browser_context orelse return;+ const frame = bc.mainFrame() orelse return;++ const typ: Frame.user_input.DragType = switch (params.type) {+ .dragEnter => .enter,+ .dragOver => .over,+ .drop => .drop,+ .dragCancel => .cancel,+ };+ try Frame.user_input.triggerDrag(frame, typ, params.x, params.y, params.data, cdpModifiers(params.modifiers));+}++// https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-setInterceptDrags+//+// Playwright enables this around every mouse move with the left button down.+// Mouse input never starts a drag here, so there is no Input.dragIntercepted+// to send, as in Chrome when the press is not on a draggable element.+fn setInterceptDrags(cmd: *CDP.Command) !void {+ const params = (try cmd.params(struct {+ enabled: bool,+ })) orelse return error.InvalidParams;++ if (cmd.browser_context) |bc| {+ bc.intercept_drags = params.enabled;+ }+ try cmd.sendResult(null, .{});+}+fn cdpModifiers(bits: u4) Frame.user_input.Modifiers {return .{.alt = bits & 1 != 0,@@ -3848,3 +3901,202 @@ test "cdp.input: typing into a non-editable focused element inserts nothing" {\\host.innerHTML === 'ab' && window.types() === 'keypress:host');}++test "cdp.input: setInterceptDrags keeps a held-button mouse move a plain mouse move" {+ var ctx = try testing.context();+ defer ctx.deinit();++ const bc = try ctx.loadBrowserContext(.{});+ const page = try bc.session.createPage();+ const frame = page.frame().?;+ try frame.navigate("http://localhost:9582/src/browser/tests/mcp_actions.html", .{ .reason = .address_bar, .kind = .{ .push = null } });+ try testing.waitForPage(bc);++ var ls: lp.js.Local.Scope = undefined;+ frame.js.localScope(&ls);+ defer ls.deinit();++ _ = try ls.local.compileAndRun(+ \\window.moves = [];+ \\for (const t of ['pointermove', 'mousemove', 'dragstart']) document.addEventListener(t, e => moves.push(e.type + ':' + e.buttons));+ , null);+ const x = try (try ls.local.compileAndRun("document.getElementById('hoverTarget').getBoundingClientRect().x + 1", null)).toF64();+ const y = try (try ls.local.compileAndRun("document.getElementById('hoverTarget').getBoundingClientRect().y + 1", null)).toF64();++ // Playwright's sequence for page.mouse.down() then page.mouse.move().+ try ctx.processMessage(.{ .id = 1, .method = "Input.dispatchMouseEvent", .params = .{ .type = "mousePressed", .x = x, .y = y, .button = "left", .clickCount = 1 } });+ try ctx.processMessage(.{ .id = 2, .method = "Input.setInterceptDrags", .params = .{ .enabled = true } });+ try ctx.expectSentResult(null, .{ .id = 2 });+ try testing.expect(bc.intercept_drags);+ try ctx.processMessage(.{ .id = 3, .method = "Input.dispatchMouseEvent", .params = .{ .type = "mouseMoved", .x = x + 5, .y = y, .button = "left" } });+ try ctx.processMessage(.{ .id = 4, .method = "Input.setInterceptDrags", .params = .{ .enabled = false } });+ try ctx.expectSentResult(null, .{ .id = 4 });+ try testing.expect(!bc.intercept_drags);+ try ctx.processMessage(.{ .id = 5, .method = "Input.dispatchMouseEvent", .params = .{ .type = "mouseReleased", .x = x + 5, .y = y, .button = "left", .clickCount = 1 } });++ try testing.expect((try ls.local.compileAndRun("moves.join(',') === 'pointermove:1,mousemove:1'", null)).isTrue());+ for (ctx.received_raw.items) |msg| {+ try testing.expect(std.mem.indexOf(u8, msg, "dragIntercepted") == null);+ }+}++const DragStep = struct {+ type: []const u8,+ over: enum { a, b, outside } = .b,+ mask: u32 = 1,+ modifiers: u4 = 0,+};++/// Dispatches `steps` as Input.dispatchDragEvent, carrying text/plain "hello"+/// and a text/uri-list, over #a or #b, and checks the drag events that+/// reached the document (each `type|target|relatedTarget|cancelable|isTrusted|+/// shiftKey|types|getData('text/plain')|dropEffect|effectAllowed`) against+/// `expected`. `accept` is the id whose dragenter/dragover/drop listeners+/// call preventDefault().+fn expectDragSequence(accept: []const u8, steps: []const DragStep, comptime expected: []const u8) !void {+ var ctx = try testing.context();+ defer ctx.deinit();++ const bc = try ctx.loadBrowserContext(.{});+ const page = try bc.session.createPage();+ const frame = page.frame().?;+ try frame.navigate("http://localhost:9582/src/browser/tests/mcp_actions.html", .{ .reason = .address_bar, .kind = .{ .push = null } });+ try testing.waitForPage(bc);++ var ls: lp.js.Local.Scope = undefined;+ frame.js.localScope(&ls);+ defer ls.deinit();++ _ = try ls.local.compileAndRun(+ \\document.body.innerHTML = '<div id="a">A</div><div id="b">B</div>';+ \\window.drags = [];+ \\for (const t of ['dragenter', 'dragover', 'dragleave', 'drop']) document.addEventListener(t, e => {+ \\ const dt = e.dataTransfer;+ \\ // Only a dragstart may change the items.+ \\ dt.setData('text/x-added', 'x');+ \\ drags.push([e.type, e.target.id, e.relatedTarget?.id ?? '-', e.cancelable, e.isTrusted, e.shiftKey,+ \\ dt.types.join('+'), dt.getData('text/plain'), dt.dropEffect, dt.effectAllowed].join('|'));+ \\ if (e.type !== 'dragleave' && e.target.id === window.accept) e.preventDefault();+ \\}, true);+ , null);+ const accept_js = try std.fmt.allocPrint(testing.arena_allocator, "window.accept = '{s}'", .{accept});+ _ = try ls.local.compileAndRun(accept_js, null);++ const ax = try (try ls.local.compileAndRun("document.getElementById('a').getBoundingClientRect().x + 1", null)).toF64();+ const ay = try (try ls.local.compileAndRun("document.getElementById('a').getBoundingClientRect().y + 1", null)).toF64();+ const bx = try (try ls.local.compileAndRun("document.getElementById('b').getBoundingClientRect().x + 1", null)).toF64();+ const by = try (try ls.local.compileAndRun("document.getElementById('b').getBoundingClientRect().y + 1", null)).toF64();++ for (steps, 1..) |step, id| {+ const x: f64, const y: f64 = switch (step.over) {+ .a => .{ ax, ay },+ .b => .{ bx, by },+ .outside => .{ -1000, -1000 },+ };+ try ctx.processMessage(.{+ .id = @as(i32, @intCast(id)),+ .method = "Input.dispatchDragEvent",+ .params = .{+ .type = step.type,+ .x = x,+ .y = y,+ .modifiers = step.modifiers,+ .data = .{+ .items = &.{+ .{ .mimeType = "text/plain", .data = "hello" },+ .{ .mimeType = "text/uri-list", .data = "http://example.com/" },+ },+ .dragOperationsMask = step.mask,+ },+ },+ });+ try ctx.expectSentResult(null, .{ .id = id });+ }++ const result = try ls.local.compileAndRun("JSON.stringify(drags) === JSON.stringify([" ++ expected ++ "])", null);+ if (!result.isTrue()) {+ const actual = try ls.local.compileAndRun("JSON.stringify(drags)", null);+ std.debug.print("drag events: {s}\n", .{try actual.toStringSlice()});+ }+ try testing.expect(result.isTrue());+}++test "cdp.input: dispatchDragEvent enters, moves between targets and drops" {+ try expectDragSequence("b", &.{+ .{ .type = "dragEnter", .over = .a },+ .{ .type = "dragEnter", .over = .a },+ .{ .type = "dragOver", .over = .a },+ .{ .type = "dragOver", .over = .b },+ .{ .type = "drop", .over = .b },+ },+ \\'dragenter|a|-|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'dragover|a|-|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'dragover|a|-|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'dragenter|b|a|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'dragleave|a|b|false|true|false|text/plain+text/uri-list||none|copy',+ \\'dragover|b|-|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'drop|b|-|true|true|false|text/plain+text/uri-list|hello|copy|copy'+ );+}++test "cdp.input: dispatchDragEvent drop runs a dragover at the target first" {+ try expectDragSequence("b", &.{+ .{ .type = "dragEnter", .mask = 17, .modifiers = 8 },+ .{ .type = "drop", .mask = 17, .modifiers = 8 },+ },+ \\'dragenter|b|-|true|true|true|text/plain+text/uri-list||move|copyMove',+ \\'dragover|b|-|true|true|true|text/plain+text/uri-list||move|copyMove',+ \\'drop|b|-|true|true|true|text/plain+text/uri-list|hello|move|copyMove'+ );+ // Dropped on a new target: its dragenter decides.+ try expectDragSequence("b", &.{+ .{ .type = "dragEnter", .over = .a },+ .{ .type = "drop", .over = .b },+ },+ \\'dragenter|a|-|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'dragenter|b|a|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'dragleave|a|b|false|true|false|text/plain+text/uri-list||none|copy',+ \\'drop|b|-|true|true|false|text/plain+text/uri-list|hello|copy|copy'+ );+}++test "cdp.input: dispatchDragEvent a drop nobody accepted" {+ // Ignored by the page: nothing fires.+ try expectDragSequence("a", &.{+ .{ .type = "dragEnter", .over = .a },+ .{ .type = "dragOver", .over = .b },+ .{ .type = "drop", .over = .b },+ },+ \\'dragenter|a|-|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'dragenter|b|a|true|true|false|text/plain+text/uri-list||copy|copy',+ \\'dragleave|a|b|false|true|false|text/plain+text/uri-list||none|copy',+ \\'dragover|b|-|true|true|false|text/plain+text/uri-list||copy|copy'+ );+ // Accepted, but with no operation the source allows: dragleave.+ try expectDragSequence("b", &.{+ .{ .type = "dragEnter", .mask = 0 },+ .{ .type = "drop", .mask = 0 },+ },+ \\'dragenter|b|-|true|true|false|text/plain+text/uri-list||none|none',+ \\'dragover|b|-|true|true|false|text/plain+text/uri-list||none|none',+ \\'dragleave|b|-|false|true|false|text/plain+text/uri-list||none|none'+ );+}++test "cdp.input: dispatchDragEvent dragCancel ends the drag without events" {+ try expectDragSequence("b", &.{+ .{ .type = "dragEnter", .mask = 65535 },+ .{ .type = "dragCancel", .mask = 65535 },+ .{ .type = "dragOver", .mask = 65535 },+ .{ .type = "drop", .mask = 65535 },+ .{ .type = "dragCancel", .mask = 65535 },+ .{ .type = "dragEnter", .over = .a, .mask = 2 },+ .{ .type = "dragOver", .over = .outside, .mask = 2 },+ .{ .type = "drop", .over = .outside, .mask = 2 },+ .{ .type = "dragOver", .over = .a, .mask = 2 },+ },+ \\'dragenter|b|-|true|true|false|text/plain+text/uri-list||copy|all',+ \\'dragenter|a|-|true|true|false|text/plain+text/uri-list||link|link',+ \\'dragleave|a|-|false|true|false|text/plain+text/uri-list||none|link'+ );+}