Files
sync_replay_project/apps/desktop/test/volume_readout_test.dart
T
foxyzandClaude Opus 5.5 25b19f2d6a Restructure step 5: one media pipeline on a player host
- PlayerHost port (MediaKitHost): players by role, pins, hwdec policy,
  render probe, log routing, disposal order; the only media_kit user.
- MediaPipeline: plan (one pure switch over state, origin, caps,
  presence) -> resolve -> open (prepared player promoted, else fresh)
  -> ready; commands queued during a switch apply once (P15); viewers
  play the buffer and wait for a dropped source without seek loops (D6).
- Every web page resolved by our yt-dlp into an EDL with headers and
  cookies (danmaku excluded); mpv's ytdl_hook no longer used (ytdl=no).
- D11: sign-in errors say which cookies were used and whether they hold
  any for the site.
- Relay: 256 KiB slices read as they fill, superseded pulls released
  (seek-to-play ~4.2 s -> ~2.8 s, P29); own Jellyfin relay channel only
  when someone needs it (P28).
- STARSYNC_SMOKE run and a Windows CI smoke step after the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 01:08:54 +03:00

102 lines
4.2 KiB
Dart

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart' show VideoState;
import 'package:starsync/src/controls/model/controls_prefs.dart';
import 'package:starsync/src/controls/frame.dart';
import 'package:starsync/src/shell/session_player.dart';
import 'package:starsync/src/state/settings.dart';
import 'test_graph.dart';
/// This file's composition root (see test_graph.dart).
final _graph = testGraph();
// The wheel anywhere on the full player flashes the volume readout, in
// both skins, windowed and fullscreen, with the controls up or hidden.
// The picture is a black box with the session's controls on it (never a
// media_kit `Video`).
void main() {
final coord = _graph.coordinator;
final s = AppSettings.instance;
// A real player for the volume steps to go to. Never disposed: the
// steps' mpv calls start in the test's fake time and never finish, so a
// dispose would wait on them for ever; the test process ending ends it.
setUpAll(() async {
MediaKit.ensureInitialized();
await coord.media.start();
});
testWidgets('wheel over the video: readout for about a second', (tester) async {
addTearDown(() => s.controlsSkin.value = ControlsSkin.standard);
tester.view.physicalSize = const Size(1280, 720);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final readout = find.byKey(const ValueKey('volume-readout'));
double opacity() => readout.evaluate().isEmpty
? 0
: tester.widget<AnimatedOpacity>(find.ancestor(of: readout, matching: find.byType(AnimatedOpacity)).first).opacity;
Future<void> wheel() async {
await tester.sendEventToBinding(
PointerScrollEvent(kind: PointerDeviceKind.mouse, position: const Offset(640, 300), scrollDelta: const Offset(0, -60)));
await tester.pump();
}
for (final skin in ControlsSkin.values) {
for (final fullscreen in [false, true]) {
final what = '${skin.name}, ${fullscreen ? 'fullscreen' : 'windowed'}';
s.controlsSkin.value = skin;
await tester.pumpWidget(scoped(_graph, MaterialApp(
theme: ThemeData.dark(),
home: Scaffold(
body: SessionPlayer(
key: ValueKey(what),
mode: PlayerMode.full,
fullscreen: fullscreen,
onExpand: () {},
onCollapse: () {},
onClose: () {},
onToggleFullscreen: () {},
onToggleChat: () {},
onChangeVideo: () {},
onOpenIntegrations: () {},
onLeave: () {},
windowControls: false,
videoBuilder: (context, controls) => Stack(fit: StackFit.expand, children: [
const ColoredBox(color: Colors.black),
if (controls != null) controls(VideoState()),
]),
),
),
)));
await tester.pump();
expect(opacity(), 0, reason: '$what: nothing before a step');
// Controls up.
expect(tester.state<ControlsFrameState>(find.byType(ControlsFrame)).visible, isTrue, reason: what);
await wheel();
expect(opacity(), 1, reason: '$what, controls up: shown');
await tester.pump(const Duration(milliseconds: 900));
expect(opacity(), 1, reason: '$what: still up within the second');
await tester.pump(const Duration(milliseconds: 300));
expect(opacity(), 0, reason: '$what: gone after the second');
// Controls hidden (no mouse movement past the hide delay).
await tester.pump(Duration(seconds: s.controlsHideSecs.value + 1));
await tester.pump(const Duration(milliseconds: 500));
expect(tester.state<ControlsFrameState>(find.byType(ControlsFrame)).visible, isFalse, reason: what);
await wheel();
expect(opacity(), 1, reason: '$what, controls hidden: shown');
await tester.pump(const Duration(milliseconds: 1200));
expect(opacity(), 0, reason: '$what: gone after the second');
}
}
await tester.pumpWidget(scoped(_graph, const SizedBox()));
await tester.pump(const Duration(seconds: 5));
});
}