todo-app/test/desktop/browser_launcher_test.dart
Krzysztof kuhy Rudnicki 2bbfe0b663
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
Desktop: launch Chrome with --password-store=basic so a locked keyring cannot blank the window
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-25 16:31:08 +02:00

97 lines
2.5 KiB
Dart

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:todo/desktop/browser_launcher.dart';
void main() {
group('browserArgs', () {
final args = browserArgs('/h');
test('opens the wrapper as an app window in the fixed profile', () {
expect(args, contains('--app=http://localhost:$kWrapperPort'));
expect(
args,
contains('--user-data-dir=/h/.local/share/todo-desktop/profile'),
);
expect(args, contains('--class=todo'));
});
test('keeps Chrome off the keyring, whose lock blanks the window', () {
expect(args, contains('--password-store=basic'));
});
});
group('findBrowser', () {
test('an override that exists wins', () {
expect(findBrowser(override: '/x/b', exists: (_) => true), '/x/b');
});
test('falls through to the first installed candidate', () {
expect(
findBrowser(
override: '',
exists: (p) => p == '/usr/bin/google-chrome-stable',
),
'/usr/bin/google-chrome-stable',
);
});
test("returns '' when nothing is installed", () {
expect(findBrowser(override: '', exists: (_) => false), '');
});
test(r'defaults to $TODO_BROWSER and real files', () {
expect(findBrowser(), isA<String>());
});
});
group('launchBrowser', () {
test('defaults to the browser findBrowser picks', () async {
final expected = findBrowser();
String? exe;
await launchBrowser(
'/h',
start: (e, _) {
exe = e;
return Process.start('true', []);
},
);
expect(exe, expected.isEmpty ? isNull : expected);
});
test('without a browser it reports false and starts nothing', () async {
var started = false;
final ok = await launchBrowser(
'/h',
browser: '',
start: (_, _) async {
started = true;
return Process.start('true', []);
},
);
expect(ok, isFalse);
expect(started, isFalse);
});
test(
'starts the browser with browserArgs; a quick exit is false',
() async {
String? exe;
List<String>? passed;
final ok = await launchBrowser(
'/h',
browser: '/x/chrome',
start: (e, a) {
exe = e;
passed = a;
return Process.start('true', []);
},
);
expect(exe, '/x/chrome');
expect(passed, browserArgs('/h'));
expect(ok, isFalse, reason: 'ran under 5 s: did not own the session');
},
);
});
}