75 lines
3.8 KiB
Dart
75 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:jj_mkvmaker/app/download_manager.dart';
|
|
import 'package:jj_mkvmaker/app/settings.dart';
|
|
import 'package:jj_mkvmaker/core/download_detect.dart';
|
|
import 'package:jj_mkvmaker/services/downloader.dart';
|
|
import 'package:jj_mkvmaker/ui/downloads_page.dart';
|
|
|
|
class _Backend implements DownloadBackend {
|
|
@override
|
|
final DownloadKind kind;
|
|
_Backend(this.kind);
|
|
final started = <String>[];
|
|
@override
|
|
Future<(String, List<PlaylistEntry>)?> expandPlaylist(String url) async => null;
|
|
@override
|
|
Future<void> start(DownloadTask t, void Function() changed) async {
|
|
started.add(t.source);
|
|
t.state = DownloadState.downloading;
|
|
}
|
|
|
|
@override
|
|
Future<void> pause(DownloadTask t) async {}
|
|
@override
|
|
Future<void> cancel(DownloadTask t) async {}
|
|
@override
|
|
Future<void> shutdown() async {}
|
|
}
|
|
|
|
/// 184 · 185: 직접 파일 주소는 일반 받기 · 다운로드 취소 창의 [계속 받기]
|
|
void main() {
|
|
test('184: 직접 파일 주소 알아보기 (동영상 · 소리 · 웹 페이지는 아님)', () {
|
|
expect(isDirectFileUrl('http://speedtest.tele2.net/100MB.zip'), isTrue);
|
|
expect(isDirectFileUrl('https://example.com/files/setup.EXE?v=2'), isTrue);
|
|
expect(isDirectFileUrl('https://example.com/doc.pdf#page=3'), isTrue);
|
|
expect(isDirectFileUrl('https://example.com/movie.mp4'), isFalse, reason: '동영상은 동영상 받기로');
|
|
expect(isDirectFileUrl('https://www.youtube.com/watch?v=abc'), isFalse);
|
|
expect(isDirectFileUrl('https://example.com/page'), isFalse);
|
|
expect(isDirectFileUrl('https://example.com/download.php?file=a.zip'), isFalse, reason: '경로가 .zip 으로 끝나지 않으면 모름 (동영상 받기 그대로)');
|
|
expect(detectLinks('http://speedtest.tele2.net/100MB.zip'), isEmpty, reason: '클립보드 자동 감지에는 쓰지 않음');
|
|
});
|
|
|
|
test('184: 직접 파일 주소는 일반 파일 받기 (aria2) 로 · 원래 이름 · aria2 폴더', () {
|
|
final s = AppSettings();
|
|
final video = _Backend(DownloadKind.video), files = _Backend(DownloadKind.torrent);
|
|
final d = DownloadManager(backends: [video, files], settings: () => s, readClipboard: () async => null);
|
|
addTearDown(d.dispose);
|
|
final t = d.addPage('http://speedtest.tele2.net/100MB.zip')!;
|
|
expect(t.kind, DownloadKind.torrent);
|
|
expect(t.title, '100MB.zip');
|
|
expect(t.dir, s.aria2Dir);
|
|
final page = d.addPage('https://example.com/some/page')!;
|
|
expect(page.kind, DownloadKind.video, reason: '그 밖의 웹 페이지는 지금처럼 동영상 받기');
|
|
});
|
|
|
|
testWidgets('185: 다운로드 취소 창 - 취소하지 않는 쪽은 [계속 받기] (옆의 [다운로드 취소] 와 헷갈리지 않게)', (tester) async {
|
|
tester.view.physicalSize = const Size(1500, 900);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
final s = AppSettings();
|
|
final d = DownloadManager(backends: [_Backend(DownloadKind.video)], settings: () => s, readClipboard: () async => null);
|
|
addTearDown(d.dispose);
|
|
final t = d.addPage('https://example.com/some/page')!;
|
|
d.toggle(t);
|
|
await tester.pumpWidget(MaterialApp(home: DownloadsPage(d: d)));
|
|
await tester.pump();
|
|
await tester.tap(find.widgetWithText(OutlinedButton, '다운로드 취소'));
|
|
await tester.pump(const Duration(milliseconds: 500)); // 받는 중 진행 막대가 움직여 pumpAndSettle 은 끝나지 않는다
|
|
expect(find.widgetWithText(TextButton, '계속 받기'), findsOneWidget);
|
|
await tester.tap(find.widgetWithText(TextButton, '계속 받기'));
|
|
await tester.pump(const Duration(milliseconds: 500)); // 받는 중 진행 막대가 움직여 pumpAndSettle 은 끝나지 않는다
|
|
expect(t.state, isNot(DownloadState.cancelled));
|
|
});
|
|
}
|