Files
pipelines/app/test/application/clipboard_failures_test.dart
T
alan 3d739c3bfc Copy and paste: the desktop's universal copy key works; Ctrl+C at the terminal login keeps the terminal
Omarchy's Super+C sends Ctrl+C by setting the modifier state with no Ctrl key
event while Super is held. Flutter's web engine only presses a modifier on its
own key event, so the app saw a plain "c": the chat selection was not copied
and the terminal typed the letter. A key modifier sync in front of the
framework's key handler now presses the modifiers the browser event's flags
hold (and outside Apple platforms lets go of a held Meta for Ctrl+C/V/X/A/
Insert), installed by the app's binding.

The terminal copies a selection on Ctrl+C without sending ^C, treats the
injected copy key as copy only, and pastes on Shift+Insert. A refused
clipboard write or read now shows a message instead of failing silently.

Server: before the login completes, Ctrl+C and Ctrl+\ erase the typed
password (Ctrl+U) and Ctrl+Z is dropped, so su is not killed and the terminal
no longer ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 17:57:28 +00:00

108 lines
3.0 KiB
Dart

import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/clipboard_failures.dart';
/// A platform side that answers every platform-channel call with [reply].
class _Platform implements BinaryMessenger {
_Platform(this.reply);
final ByteData? Function(MethodCall call) reply;
static const codec = JSONMethodCodec();
@override
Future<ByteData?>? send(String channel, ByteData? message) async =>
reply(codec.decodeMethodCall(message));
@override
Future<void> handlePlatformMessage(
String channel,
ByteData? data,
ui.PlatformMessageResponseCallback? callback,
) async {}
@override
void setMessageHandler(String channel, MessageHandler? handler) {}
}
void main() {
const codec = JSONMethodCodec();
final refused = codec.encodeErrorEnvelope(
code: 'copy_fail',
message: 'Clipboard.setData failed.',
);
Future<(List<String>, Object?)> call(
String method,
ByteData? Function(MethodCall) reply,
) async {
final reports = <String>[];
final messenger = ClipboardReportingMessenger(
_Platform(reply),
report: reports.add,
);
final channel = MethodChannel(
SystemChannels.platform.name,
codec,
messenger,
);
Object? error;
try {
await channel.invokeMethod<void>(method, {'text': 'x'});
} on PlatformException catch (e) {
error = e;
}
return (reports, error);
}
test(
'a refused clipboard write is reported and still reaches the caller',
() async {
final (reports, error) = await call('Clipboard.setData', (_) => refused);
expect(reports, [
'Could not copy: the browser refused access to the clipboard',
]);
expect(error, isA<PlatformException>());
},
);
test('an insecure page says why; a refused read is reported too', () async {
final (reports, _) = await call(
'Clipboard.getData',
(_) => codec.encodeErrorEnvelope(
code: 'paste_fail',
message: 'Clipboard is not available in the context.',
),
);
expect(reports, [
'Could not paste: Clipboard is not available in the context.',
]);
});
test('successes and passive checks are not reported', () async {
final (ok, _) = await call(
'Clipboard.setData',
(_) => codec.encodeSuccessEnvelope(null),
);
expect(ok, isEmpty);
final (checks, _) = await call(
'Clipboard.hasStrings',
(_) => codec.encodeErrorEnvelope(code: 'has_strings_fail'),
);
expect(checks, isEmpty);
});
testWidgets('the message shows in the app', (tester) async {
await tester.pumpWidget(
MaterialApp(
scaffoldMessengerKey: appScaffoldMessengerKey,
home: const Scaffold(),
),
);
expect(showAppMessage('Could not copy: denied'), isTrue);
await tester.pump();
expect(find.text('Could not copy: denied'), findsOneWidget);
});
}