Support Element#drop for files and strings#316
Open
myabc wants to merge 3 commits into
Open
Conversation
`Node#drag_to` drove only real mouse events, which never fire the HTML5 drag sequence (dragstart/dragover/drop/dragend + DataTransfer), so suites exercising HTML5 drag-and-drop had to fall back to Selenium. Route drag_to between two paths after the initial mouse-down: a legacy path (real Ferrum mouse events, now applying held modifier keys via the public mouse modifier bitfield) and an HTML5 path (a JS emulation dispatching the drag events with a shared DataTransfer). Detection mirrors Capybara: a draggable source or ancestor takes the HTML5 path, otherwise legacy. The emulation is ported from Capybara's Selenium Html5Drag extension and lives in javascripts/drag.js. Un-skips the 15 Capybara shared drag specs (12 HTML5 + 3 mouse modifier). Uses only public Ferrum API. Element#drop (files/strings) remains out of scope. Closes rubycdp#314
There was a problem hiding this comment.
Pull request overview
Adds HTML5 drag-and-drop support required by Capybara shared specs by (1) routing Node#drag_to through a DataTransfer-backed JS emulation when appropriate and (2) implementing Node#drop/Browser#drop so Element#drop can drop files and strings, allowing previously force-skipped Capybara specs to run.
Changes:
- Un-skips Capybara shared specs for
#drag_toandElement#droppreviously filtered out inspec/spec_helper.rb. - Updates
Node#drag_toto pass drop modifier keys and options through to an updatedBrowser#drag, with an HTML5 emulation path vialib/.../javascripts/drag.js. - Implements
Node#dropandBrowser#drop, adding JS helpers inindex.jsto synthesize aDataTransferfor dropped strings/files.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/spec_helper.rb | Removes forced skips for drag/drop shared specs so the suite exercises the new behavior. |
| lib/capybara/cuprite/node.rb | Adds modifier aliasing for drag and forwards new drop command to the browser. |
| lib/capybara/cuprite/javascripts/index.js | Adds JS helpers for drag detection and DataTransfer-backed drop for strings/files. |
| lib/capybara/cuprite/javascripts/drag.js | Introduces the HTML5 drag/drop emulation script (ported from Capybara Selenium). |
| lib/capybara/cuprite/browser.rb | Implements updated drag API + HTML5 path and new drop implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Element#drop for files and strings
1de480e to
c4abb7e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements
Node#dropsoElement#dropcan drop files and strings onto an element, un-skipping the 5 CapybaraElement#dropshared specs.Why
Element#dropwas force-skipped inspec/spec_helper.rb— Cuprite had no way to dispatch an HTML5dropcarrying aDataTransfer. This is theElement#dropportion deferred from #315 (HTML5 drag-and-drop).How
Node#drop(*args)forwards toBrowser#drop(node, *args), mirroring Capybara's Seleniumhtml5_drop:<input type=file>is synthesized, files are attached through Cuprite's existingselect_file(CDPDOM.setFileInputFiles), then adropis dispatched carryingDataTransfer.files.{type => data}args) — aDataTransferis built viaitems.add/setDataand adropis dispatched.The three JS helpers (
dropString,attachDropInput,dropFile) are ported from Capybara's Seleniumhtml5_drag.rb(DROP_STRING/ATTACH_FILE/DROP_FILE) and carry provenance comments.Notes
command()or reach-ins (per Cuprite 1.0 #307).Node#dropis a single-line endless method to stay within the existingMetrics/ClassLengthbudget onnode.rb.Element#dropcommits once Support HTML5 drag-and-drop and drag modifier keys #315 lands.select_fileraised mid-drop the synthesized input would not be cleaned up. Kept faithful to the upstream port for now; can harden separately.Testing
Element#dropspecs (2 string + 3 file) now pass.#has_fieldvalidation-message failures are pre-existing — Chrome locale wording).bundle exec rubocopclean.Part of #307. Follow-up to #315.
🤖 Authored with agent assistance.