26e68140fd
The native video player requests media itself, without the session cookie the app's file fetches send, so a video shown with show_file (or opened from Files) behind the web login was refused in the phone and Mac apps. Pass ServerSession.headersFor(uri) as the player's HTTP headers.
102 lines
3.3 KiB
Dart
102 lines
3.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:pipelines_app/core/session/server_session.dart';
|
|
import 'package:pipelines_app/features/artifacts/domain/artifact_preview.dart';
|
|
import 'package:pipelines_app/features/artifacts/domain/artifact_url.dart';
|
|
import 'package:pipelines_app/features/artifacts/ui/artifact_video_player.dart';
|
|
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_content.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
/// A controller whose platform work is scripted: [initialize] completes or
|
|
/// fails only when the test says so, and nothing reaches a video plugin.
|
|
class _ScriptedController extends VideoPlayerController {
|
|
_ScriptedController(super.uri) : super.networkUrl();
|
|
|
|
final ready = Completer<void>();
|
|
int plays = 0;
|
|
|
|
@override
|
|
Future<void> initialize() => ready.future;
|
|
|
|
@override
|
|
Future<void> play() async => plays++;
|
|
}
|
|
|
|
Widget _body(ArtifactVideoControllerFactory factory) => MaterialApp(
|
|
home: Scaffold(
|
|
body: ArtifactPreviewBody(
|
|
plan: ArtifactPreviewPlan(
|
|
kind: ArtifactPreviewKind.video,
|
|
resolved: ResolvedArtifactUrl(
|
|
uri: Uri.parse('http://127.0.0.1:8080/artifacts/7/clip.mp4'),
|
|
external: false,
|
|
),
|
|
message: '',
|
|
),
|
|
loading: false,
|
|
markdownBuilder: defaultArtifactMarkdown,
|
|
videoControllerFactory: factory,
|
|
),
|
|
),
|
|
);
|
|
|
|
void main() {
|
|
test(
|
|
'the default player sends the sign-in only to the signed-in server',
|
|
() async {
|
|
SharedPreferences.setMockInitialValues({
|
|
'pipelines.session.v2.${Uri.encodeComponent('a')}.cookie': 'session=a',
|
|
});
|
|
await ServerSession.load();
|
|
await ServerSession.activateServer(
|
|
id: 'a',
|
|
endpoints: [Uri.parse('wss://primary.example/connect')],
|
|
migrateLegacy: false,
|
|
);
|
|
addTearDown(ServerSession.clearSelection);
|
|
|
|
final own = defaultArtifactVideoController(
|
|
Uri.parse('https://primary.example/files/view?path=/a.mp4'),
|
|
);
|
|
addTearDown(own.dispose);
|
|
expect(own.httpHeaders, {'Cookie': 'session=a'});
|
|
|
|
final other = defaultArtifactVideoController(
|
|
Uri.parse('https://external.example/a.mp4'),
|
|
);
|
|
addTearDown(other.dispose);
|
|
expect(other.httpHeaders, isEmpty);
|
|
},
|
|
);
|
|
|
|
testWidgets('a video preview streams its resolved url and never autoplays', (
|
|
tester,
|
|
) async {
|
|
final opened = <Uri>[];
|
|
late _ScriptedController controller;
|
|
await tester.pumpWidget(
|
|
_body((uri) {
|
|
opened.add(uri);
|
|
return controller = _ScriptedController(uri);
|
|
}),
|
|
);
|
|
expect(find.byType(ArtifactVideoPlayer), findsOneWidget);
|
|
expect(opened.single.path, '/artifacts/7/clip.mp4');
|
|
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
|
expect(controller.plays, 0);
|
|
});
|
|
|
|
testWidgets('a video that cannot be opened says so', (tester) async {
|
|
late _ScriptedController controller;
|
|
await tester.pumpWidget(
|
|
_body((uri) => controller = _ScriptedController(uri)),
|
|
);
|
|
controller.ready.completeError(StateError('unsupported codec'));
|
|
await tester.pump();
|
|
expect(find.text(artifactVideoError), findsOneWidget);
|
|
});
|
|
}
|