okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-split-int (a3024ed10) into f-split-qa1: qa2's s3237-s3238 kept, my 21 strings renumbered s3260-s32808667a3dbf

main
2.0 KiB29 linesraw
1// Linux file drop (found on z440 under Xvfb with a real GTK drag, WebKitGTK 2.52): the page gets no files and WebKit never raises the drop signal,
2// so the shell reads the file:// addresses from the drag data, accepts the drag itself, takes the "leave" with every button up as the drop and
3// hands the paths to the host. The behaviour itself is checked on a real X display (scripts in phaseA-tests); these keep the pieces in place.
4import test from 'node:test';
5import assert from 'node:assert/strict';
6import { readFile } from 'node:fs/promises';
7
8const read = path => readFile(new URL(path, import.meta.url), 'utf8').then(s => s.replace(/\r\n/g, '\n'));
9
10test('the Linux shell hooks the drag signals of the page and keeps Windows and macOS on their own paths', async () => {
11  const rust = await read('../../desktop/src-tauri/src/main.rs');
12  assert.match(rust, /#\[cfg\(target_os = "linux"\)\]\s+hook_linux_drops\(&window, port, shell_token\);/);
13  assert.match(rust, /view\.connect_drag_data_received\(/); assert.match(rust, /file_uri_to_path\(u\.as_str\(\)\)/);
14  assert.match(rust, /ctx\.drag_status\(gtk::gdk::DragAction::COPY, time\)/);
15  assert.match(rust, /pointer_buttons_up\(widget\)/);
16  assert.match(rust, /hand_over_drop\(target\.clone\(\), port, token\.clone\(\), list\)/);
17  assert.match(rust, /fn file_uri_to_path\(uri: &str\) -> Option<String>/);
18  assert.match(rust, /#\[cfg\(windows\)\]\s+let builder = builder\.disable_drag_drop_handler\(\);/);
19  const toml = await read('../../desktop/src-tauri/Cargo.toml');
20  assert.match(toml, /\[target\.'cfg\(target_os = "linux"\)'\.dependencies\]\ngtk = "0\.18"\nwebkit2gtk = "2\.0"/);
21});
22
23test('only file:// addresses reach the host, which applies the same limits as for every drop', async () => {
24  const rust = await read('../../desktop/src-tauri/src/main.rs');
25  assert.match(rust, /strip_prefix\("file:\/\/"\)\?/);
26  const host = await read('../server/native-drop.mjs');
27  assert.match(host, /MAX_FILES = 10, MAX_BYTES = 25 \* 1024 \* 1024/);
28  assert.match(host, /!isAbsolute\(path\)/);
29});