fix(KAN-71): use interactive WebKit navigation gestures
CI/CD / preconditions (pull_request) Successful in 1s
Native JavaScript checks / Native launcher and release tests (pull_request) Successful in 1m13s
macOS checks / Native Rust tests and unsigned build (pull_request) Successful in 1m44s
CI/CD / test_and_check_app (pull_request) Successful in 7m4s
CI/CD / Publish immutable image (pull_request) Skipped

This commit is contained in:
2026-09-29 08:02:10 +02:00
parent 386b25858b
commit 1cf7524a7b
16 changed files with 110 additions and 499 deletions
+8 -65
View File
@@ -25,74 +25,17 @@ await page.addInitScript(script);
const root = `http://127.0.0.1:${server.address().port}`;
try {
await page.goto(root);
const length = await page.evaluate(() => history.length);
for (const path of ['/board', '/ticket', '/settings']) {
await page.evaluate(
(path) =>
history.pushState(
{
page: { url: path },
rememberedState: { draft: 'retained' },
},
'',
path,
),
path,
);
}
await page.evaluate(() => {
window.steps = 0;
addEventListener('popstate', () => window.steps++);
});
await page.evaluate(() => window.__kanbanNavigation.step(-1));
await page.waitForFunction(() => location.pathname === '/ticket');
assert.equal(await page.evaluate(() => window.steps), 1);
await page.evaluate(() => window.__kanbanNavigation.step(-1));
await page.waitForFunction(() => location.pathname === '/board');
await page.evaluate(() => window.__kanbanNavigation.step(1));
await page.waitForFunction(() => location.pathname === '/ticket');
assert.equal(await page.evaluate(() => window.steps), 3);
assert.equal(await page.evaluate(() => history.length), length + 3);
assert.equal(await page.locator('#draft').inputValue(), 'retained');
assert.equal(
await page.evaluate(() => history.state.rememberedState.draft),
'retained',
await page.evaluate(() => typeof window.__kanbanNavigation),
'undefined',
);
await page.goto(`${root}/full-page`);
await page.evaluate(() => window.__kanbanNavigation.step(-1));
await page.waitForURL(`${root}/ticket`);
await page.evaluate(() => window.__kanbanNavigation.step(1));
await page.goBack();
await page.waitForURL(`${root}/`);
await page.goForward();
await page.waitForURL(`${root}/full-page`);
await page.locator('dialog').evaluate((dialog) => dialog.showModal());
assert.equal(
await page.evaluate(() => window.__kanbanNavigation.canSwipe(1, 1)),
false,
);
await page.locator('dialog').evaluate((dialog) => dialog.close());
for (const selector of ['#board', '#draft']) {
const point = await page.locator(selector).boundingBox();
assert.equal(
await page.evaluate(
({ x, y }) => window.__kanbanNavigation.canSwipe(x + 5, y + 5),
point,
),
false,
);
}
assert.equal(
await page.evaluate(() => window.__kanbanNavigation.canSwipe(1, 1)),
true,
);
await page.dispatchEvent('#board', 'dragstart');
assert.equal(
await page.evaluate(() => window.__kanbanNavigation.canSwipe(1, 1)),
false,
);
await page.dispatchEvent('#board', 'dragend');
assert.equal(
await page.evaluate(() => window.__kanbanNavigation.canSwipe(1, 1)),
true,
);
await page.locator('#draft').fill('unsaved draft');
assert.equal(await page.locator('#draft').inputValue(), 'unsaved draft');
assert.equal(
await page.evaluate(
() =>
@@ -143,7 +86,7 @@ try {
() => document.querySelector('dialog').scrollTop > 0,
);
console.log(
'PASS: SPA/full-page history, forward history, overlays, short/long scroll bounds, horizontal board, drag and input guards',
'PASS: browser-owned history, editable input, short/long scroll bounds, horizontal board and dialog scrolling',
);
} finally {
await browser.close();
+59 -127
View File
@@ -1,142 +1,74 @@
#import <AppKit/AppKit.h>
#import <WebKit/WebKit.h>
#import "../src-tauri/src/navigation.m"
// Exercise the AppKit event adapter deterministically; macos_smoke separately
// runs the shared history script against a real WKWebView.
@interface TestWindow : NSWindow
@end
@implementation TestWindow
- (BOOL)isKeyWindow { return YES; }
@end
@interface TestWebView : WKWebView
@property(nonatomic, strong) NSWindow *testWindow;
@property(nonatomic, strong) NSURL *testURL;
@property(nonatomic) BOOL back;
@property(nonatomic) BOOL forward;
@property(nonatomic) BOOL allowsSwipe;
@property(nonatomic) BOOL deferPermission;
@property(nonatomic, copy) void (^permission)(id, NSError *);
@property(nonatomic, strong) NSMutableArray<NSString *> *steps;
@end
@implementation TestWebView
- (NSWindow *)window { return self.testWindow; }
- (NSURL *)URL { return self.testURL; }
- (BOOL)canGoBack { return self.back; }
- (BOOL)canGoForward { return self.forward; }
- (NSPoint)convertPoint:(NSPoint)point fromView:(NSView *)view { return point; }
- (void)evaluateJavaScript:(NSString *)script completionHandler:(void (^)(id, NSError *))handler {
if ([script containsString:@".step("]) [self.steps addObject:script];
else if (self.deferPermission) self.permission = handler;
else handler(@(self.allowsSwipe), nil);
static void check(BOOL condition, NSString *message) {
if (!condition) {
fprintf(stderr, "FAIL: %s\n", message.UTF8String);
exit(1);
}
}
@end
@interface TestEvent : NSEvent
@property(nonatomic, strong) NSWindow *testWindow;
@property(nonatomic) NSEventPhase testPhase;
@property(nonatomic) NSEventPhase testMomentum;
@property(nonatomic) CGFloat dx;
@property(nonatomic) CGFloat dy;
@property(nonatomic) BOOL precise;
@property(nonatomic) NSInteger trackCount;
@property(nonatomic, copy) void (^tracking)(CGFloat, NSEventPhase, BOOL, BOOL *);
@end
@implementation TestEvent
- (NSWindow *)window { return self.testWindow; }
- (NSEventPhase)phase { return self.testPhase; }
- (NSEventPhase)momentumPhase { return self.testMomentum; }
- (CGFloat)scrollingDeltaX { return self.dx; }
- (CGFloat)scrollingDeltaY { return self.dy; }
- (BOOL)hasPreciseScrollingDeltas { return self.precise; }
- (NSPoint)locationInWindow { return NSMakePoint(20, 20); }
- (void)trackSwipeEventWithOptions:(NSEventSwipeTrackingOptions)options dampenAmountThresholdMin:(CGFloat)minimum max:(CGFloat)maximum usingHandler:(void (^)(CGFloat, NSEventPhase, BOOL, BOOL *))handler {
NSCAssert(options & NSEventSwipeTrackingLockDirection, @"Direction must be locked");
self.trackCount++;
self.tracking = handler;
static void waitUntil(BOOL (^condition)(void), NSString *message) {
NSDate *deadline = [NSDate dateWithTimeIntervalSinceNow:10];
while (!condition() && deadline.timeIntervalSinceNow > 0) {
[NSRunLoop.currentRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
check(condition(), message);
}
@interface WorkspacePages : NSObject <WKURLSchemeHandler, WKNavigationDelegate>
@property(nonatomic) NSUInteger finished;
@end
@interface TestNavigation : KanbanNavigation
@property(nonatomic) BOOL enabled;
@end
@implementation TestNavigation
- (BOOL)swipeTrackingEnabled { return self.enabled; }
@implementation WorkspacePages
- (void)webView:(WKWebView *)webView startURLSchemeTask:(id<WKURLSchemeTask>)task {
NSData *body = [[NSString stringWithFormat:@"<html><body>%@<input value='draft'></body></html>", task.request.URL.path]
dataUsingEncoding:NSUTF8StringEncoding];
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html"
expectedContentLength:body.length textEncodingName:@"utf-8"];
[task didReceiveResponse:response];
[task didReceiveData:body];
[task didFinish];
}
- (void)webView:(WKWebView *)webView stopURLSchemeTask:(id<WKURLSchemeTask>)task {}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
self.finished++;
}
@end
int main(void) {
@autoreleasepool {
[NSApplication sharedApplication];
TestWindow *window = [[TestWindow alloc] initWithContentRect:NSMakeRect(0, 0, 600, 400) styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO];
TestWebView *webview = [[TestWebView alloc] initWithFrame:NSMakeRect(0, 0, 600, 400)];
webview.testWindow = window;
webview.testURL = [NSURL URLWithString:@"https://example.com/board"];
webview.back = YES;
webview.forward = YES;
webview.allowsSwipe = YES;
webview.steps = [NSMutableArray new];
TestNavigation *navigation = [TestNavigation new];
navigation.webview = webview;
navigation.enabled = YES;
TestEvent *(^event)(void) = ^{
TestEvent *value = [TestEvent new];
value.testWindow = window;
value.testPhase = NSEventPhaseBegan;
value.precise = YES;
value.dx = 15;
return value;
};
BOOL stop = NO;
TestEvent *back = event();
[navigation handleEvent:back];
NSCAssert(back.trackCount == 1, @"A horizontal gesture must use AppKit tracking");
back.tracking(0.5, NSEventPhaseChanged, NO, &stop);
NSCAssert(webview.steps.count == 0, @"A partial swipe must not navigate");
back.tracking(1, NSEventPhaseNone, YES, &stop);
NSCAssert(webview.steps.count == 1 && [webview.steps.lastObject containsString:@"step(-1)"], @"Back must request exactly one step");
TestEvent *forward = event();
forward.dx = -15;
[navigation handleEvent:forward];
forward.tracking(-1, NSEventPhaseNone, YES, &stop);
NSCAssert(webview.steps.count == 2 && [webview.steps.lastObject containsString:@"step(1)"], @"Forward must request exactly one step");
TestEvent *cancelled = event();
[navigation handleEvent:cancelled];
cancelled.tracking(0, NSEventPhaseCancelled, YES, &stop);
NSCAssert(webview.steps.count == 2, @"Cancelled swipes must not navigate");
TestEvent *interrupted = event();
[navigation handleEvent:interrupted];
webview.allowsSwipe = NO;
[navigation handleEvent:event()];
interrupted.tracking(1, NSEventPhaseNone, YES, &stop);
NSCAssert(webview.steps.count == 2, @"A new gesture must cancel the previous gesture's animation callback");
WorkspacePages *pages = [WorkspacePages new];
WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
configuration.websiteDataStore = WKWebsiteDataStore.nonPersistentDataStore;
[configuration setURLSchemeHandler:pages forURLScheme:@"kanban-test"];
WKWebView *webview = [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration];
webview.navigationDelegate = pages;
check(!webview.allowsBackForwardNavigationGestures, @"WebKit defaults to disabled gestures");
install_workspace_navigation((__bridge void *)webview);
install_workspace_navigation((__bridge void *)webview);
check(webview.allowsBackForwardNavigationGestures, @"The workspace must enable WebKit's interactive gestures");
check(webview.configuration.userContentController.userScripts.count == 0, @"Enabling gestures must not inject a history adapter");
check([webview goBack] == nil && [webview goForward] == nil, @"Empty history must not navigate");
for (NSInteger test = 0; test < 7; test++) {
TestEvent *ignored = event();
navigation.enabled = test != 0;
webview.allowsSwipe = test != 1;
webview.back = webview.forward = test != 2;
if (test == 3) ignored.precise = NO;
if (test == 4) ignored.dy = 30;
if (test == 5) ignored.testMomentum = NSEventPhaseChanged;
if (test == 6) ignored.testWindow = nil;
NSCAssert([navigation handleEvent:ignored] == ignored && ignored.trackCount == 0, @"Non-navigation events must remain available for scrolling");
}
navigation.enabled = YES;
webview.allowsSwipe = YES;
webview.back = YES;
webview.deferPermission = YES;
TestEvent *stale = event();
[navigation handleEvent:stale];
TestEvent *ended = event();
ended.testPhase = NSEventPhaseEnded;
[navigation handleEvent:ended];
webview.permission(@YES, nil);
NSCAssert(stale.trackCount == 0, @"Late hit tests must not resurrect ended gestures");
TestEvent *changedPage = event();
[navigation handleEvent:changedPage];
webview.testURL = [NSURL URLWithString:@"https://example.com/settings"];
webview.permission(@YES, nil);
NSCAssert(changedPage.trackCount == 0, @"Page changes must invalidate a pending gesture");
puts("PASS: AppKit back/forward, cancelled/partial swipes, system preference, nested scroll ownership, empty history, mouse/vertical/momentum events, stale callbacks");
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"kanban-test://workspace/first"]]];
waitUntil(^BOOL { return pages.finished == 1; }, @"First page must load");
check(!webview.canGoBack && !webview.canGoForward, @"The first page must have no navigation target");
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"kanban-test://workspace/second"]]];
waitUntil(^BOOL { return pages.finished == 2; }, @"Second page must load");
check(webview.canGoBack && !webview.canGoForward, @"Native history must retain the first page");
check([webview goBack] != nil, @"Native back navigation must start");
waitUntil(^BOOL { return pages.finished == 3; }, @"Native back navigation must complete");
check([webview.URL.path isEqualToString:@"/first"] && !webview.canGoBack && webview.canGoForward,
@"Back must restore the first page and retain forward history");
check([webview goBack] == nil, @"Back at the first page must leave it in place");
check([webview goForward] != nil, @"Native forward navigation must start");
waitUntil(^BOOL { return pages.finished == 4; }, @"Native forward navigation must complete");
check([webview.URL.path isEqualToString:@"/second"] && webview.canGoBack && !webview.canGoForward,
@"Forward must restore the second page");
check(webview.allowsBackForwardNavigationGestures, @"Native gestures must remain enabled across page navigation");
puts("PASS: WebKit interactive gesture configuration, full-page back/forward and empty history");
}
return 0;
}
+2 -2
View File
@@ -8,7 +8,7 @@ import test from 'node:test';
import { fileURLToPath } from 'node:url';
test(
'AppKit gestures preserve single steps, cancellation, system preferences and scroll ownership',
'WebKit owns interactive navigation and preserves native back/forward history',
{ skip: process.platform !== 'darwin' },
() => {
const directory = mkdtempSync(join(tmpdir(), 'kanbangit-navigation-'));
@@ -50,7 +50,7 @@ test(
0,
result.stderr || result.error?.message,
);
assert.match(result.stdout, /PASS: AppKit/);
assert.match(result.stdout, /PASS: WebKit/);
} finally {
rmSync(directory, { recursive: true, force: true });
}