mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-14 16:31:03 +03:00
test(cursor): reuse painting and web fixtures
This commit is contained in:
@@ -117,52 +117,49 @@ class _Canvas extends Fake implements Canvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<ImagePainter> _paintCursor(WidgetTester tester, CanvasModel canvas,
|
||||||
|
{double dpr = 2, bool zoom = true, (int, int) source = (48, 64)}) async {
|
||||||
|
final image = (await tester
|
||||||
|
.runAsync(() => createTestImage(width: source.$1, height: source.$2)))!;
|
||||||
|
addTearDown(image.dispose);
|
||||||
|
await tester.pumpWidget(MediaQuery(
|
||||||
|
data: MediaQueryData(devicePixelRatio: dpr),
|
||||||
|
child: MultiProvider(
|
||||||
|
providers: [
|
||||||
|
ChangeNotifierProvider<CursorModel>(create: (_) => _CursorModel(image)),
|
||||||
|
ChangeNotifierProvider<CanvasModel>(create: (_) => canvas),
|
||||||
|
],
|
||||||
|
child: CursorPaint(id: 'cursor-test', zoomCursor: zoom.obs),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
final painter = tester.widget<CustomPaint>(find.byType(CustomPaint)).painter!
|
||||||
|
as ImagePainter;
|
||||||
|
expect(painter.image, same(image));
|
||||||
|
return painter;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
final minimumScale = Platform.isWindows ? 1 / 3 : 2 / 3;
|
||||||
for (final (style, zoom, dpr, source, canvasScale, scale, texture) in [
|
for (final (style, zoom, dpr, source, canvasScale, scale, texture) in [
|
||||||
(kRemoteViewStyleAdaptive, false, 2.0, (48, 64), 0.375, 0.375, true),
|
(kRemoteViewStyleAdaptive, false, 2.0, (48, 64), 0.375, 0.375, true),
|
||||||
(kRemoteViewStyleOriginal, false, 2.0, (48, 64), 0.5, 0.5, true),
|
(kRemoteViewStyleOriginal, false, 2.0, (48, 64), 0.5, 0.5, true),
|
||||||
(kRemoteViewStyleCustom, false, 2.0, (48, 64), 0.25, 0.25, false),
|
(kRemoteViewStyleCustom, false, 2.0, (48, 64), 0.25, 0.25, false),
|
||||||
(kRemoteViewStyleCustom, true, 2.0, (48, 64), 2.0, 2.0, false),
|
(kRemoteViewStyleCustom, true, 2.0, (48, 64), 2.0, 2.0, false),
|
||||||
(kRemoteViewStyleAdaptive, false, 2.25, (48, 48), 0.375, 0.375, false),
|
(kRemoteViewStyleAdaptive, false, 2.25, (48, 48), 0.375, 0.375, false),
|
||||||
(
|
(kRemoteViewStyleAdaptive, true, 2.0, (9, 18), 0.1, minimumScale, true),
|
||||||
kRemoteViewStyleAdaptive,
|
|
||||||
true,
|
|
||||||
2.0,
|
|
||||||
(9, 18),
|
|
||||||
0.1,
|
|
||||||
Platform.isWindows ? 1 / 3 : 2 / 3,
|
|
||||||
true
|
|
||||||
),
|
|
||||||
]) {
|
]) {
|
||||||
testWidgets(
|
testWidgets(
|
||||||
'$style zoom=$zoom dpr=$dpr source=$source texture=$texture keeps remote geometry',
|
'$style zoom=$zoom dpr=$dpr source=$source texture=$texture keeps remote geometry',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
final image = (await tester.runAsync(
|
final painter = await _paintCursor(
|
||||||
() => createTestImage(width: source.$1, height: source.$2)))!;
|
tester, _CanvasModel(style, canvasScale, texture),
|
||||||
addTearDown(image.dispose);
|
dpr: dpr, zoom: zoom, source: source);
|
||||||
await tester.pumpWidget(MediaQuery(
|
|
||||||
data: MediaQueryData(devicePixelRatio: dpr),
|
|
||||||
child: MultiProvider(
|
|
||||||
providers: [
|
|
||||||
ChangeNotifierProvider<CursorModel>(
|
|
||||||
create: (_) => _CursorModel(image)),
|
|
||||||
ChangeNotifierProvider<CanvasModel>(
|
|
||||||
create: (_) => _CanvasModel(style, canvasScale, texture)),
|
|
||||||
],
|
|
||||||
child: CursorPaint(id: 'cursor-test', zoomCursor: zoom.obs),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
final painter = tester
|
|
||||||
.widget<CustomPaint>(find.byType(CustomPaint))
|
|
||||||
.painter! as ImagePainter;
|
|
||||||
|
|
||||||
expect(painter.image, same(image));
|
|
||||||
expect(painter.scale, scale);
|
expect(painter.scale, scale);
|
||||||
var imageOrigin = _canvasOffset;
|
var imageOrigin = _canvasOffset;
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
final background = _Canvas();
|
final background = _Canvas();
|
||||||
ImagePainter(
|
ImagePainter(
|
||||||
image: image,
|
image: painter.image,
|
||||||
x: _canvasOffset.dx / canvasScale,
|
x: _canvasOffset.dx / canvasScale,
|
||||||
y: _canvasOffset.dy / canvasScale,
|
y: _canvasOffset.dy / canvasScale,
|
||||||
scale: canvasScale,
|
scale: canvasScale,
|
||||||
@@ -181,28 +178,10 @@ void main() {
|
|||||||
for (final style in [kRemoteViewStyleOriginal, kRemoteViewStyleCustom]) {
|
for (final style in [kRemoteViewStyleOriginal, kRemoteViewStyleCustom]) {
|
||||||
testWidgets('$style painted cursor follows scrollbar position',
|
testWidgets('$style painted cursor follows scrollbar position',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
final image = (await tester.runAsync(
|
final painter = await _paintCursor(tester, _ScrollbarCanvasModel(style));
|
||||||
() => createTestImage(width: 48, height: 64)))!;
|
|
||||||
addTearDown(image.dispose);
|
|
||||||
await tester.pumpWidget(MediaQuery(
|
|
||||||
data: const MediaQueryData(devicePixelRatio: 2),
|
|
||||||
child: MultiProvider(
|
|
||||||
providers: [
|
|
||||||
ChangeNotifierProvider<CursorModel>(
|
|
||||||
create: (_) => _CursorModel(image)),
|
|
||||||
ChangeNotifierProvider<CanvasModel>(
|
|
||||||
create: (_) => _ScrollbarCanvasModel(style)),
|
|
||||||
],
|
|
||||||
child: CursorPaint(id: 'cursor-test', zoomCursor: true.obs),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
final painter = tester
|
|
||||||
.widget<CustomPaint>(find.byType(CustomPaint))
|
|
||||||
.painter! as ImagePainter;
|
|
||||||
final target = _remotePosition * 2 -
|
final target = _remotePosition * 2 -
|
||||||
Offset(_viewport.width * 2 * 0.1, _viewport.height * 2 * 0.2);
|
Offset(_viewport.width * 2 * 0.1, _viewport.height * 2 * 0.2);
|
||||||
expect(
|
expect((Offset(painter.x, painter.y) + _hotspot) * painter.scale, target);
|
||||||
(Offset(painter.x, painter.y) + _hotspot) * painter.scale, target);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,7 @@ void main() {
|
|||||||
registered = jsonDecode(value) as Map<String, dynamic>;
|
registered = jsonDecode(value) as Map<String, dynamic>;
|
||||||
});
|
});
|
||||||
addTearDown(() => js.context['setByName'] = original);
|
addTearDown(() => js.context['setByName'] = original);
|
||||||
final recorder = ui.PictureRecorder();
|
final nativeImage = await createTestImage(width: 48, height: 48);
|
||||||
ui.Canvas(recorder).drawColor(const ui.Color(0xffffffff), ui.BlendMode.src);
|
|
||||||
final picture = recorder.endRecording();
|
|
||||||
final nativeImage = await picture.toImage(48, 48);
|
|
||||||
picture.dispose();
|
|
||||||
addTearDown(nativeImage.dispose);
|
addTearDown(nativeImage.dispose);
|
||||||
for (final (hotspot, scale, side, expected) in [
|
for (final (hotspot, scale, side, expected) in [
|
||||||
((7.0, 7.0), 633 / 1600, 19, (3, 3)),
|
((7.0, 7.0), 633 / 1600, 19, (3, 3)),
|
||||||
|
|||||||
Reference in New Issue
Block a user