LifeMate — Personal, Family & Learning Companion
feat/weekly-planner-android
chore/phase1-repository-cleanup
deploy/stable-web-apk
deployment-static
design/mobile-accessibility-v2
design/mobile-navigation-review
docs/child-education-access-decision
docs/offline-data-rescue-options
docs/owner-guide-and-delivery-plan
docs/phase1-policy-options
docs/public-review-live-2026-10-15
feat/aparat-learning-library
feat/child-device-safety
feat/child-identity-schema
feat/flutter-mobile-navigation
feat/learning-content-operations
feat/local-signing-preflight
feat/online-family-stage0
feat/personal-encrypted-recovery
feat/private-planner-series-api
feat/public-review-page
feat/standalone-weekly-planner
feat/weekly-planner-android
final-feature-1/iran-family-school
fix/auth-abuse-expiry-safety
fix/auth-expiry-after-lock
fix/backend-request-safety
fix/lifeguide-bootstrap-naming-ci
fix/lifeguide-pages-qa-base-preflight
fix/lifeguide-qa-pages-env-deployment
fix/local-task-persistence
fix/managed-child-session-boundary
fix/personal-jalali-dates
fix/personal-notification-controls
fix/personal-upgrade-delivery-guard
fix/sms-approval-gates
fix/study-duration-display
infra/cloudflare-neon-migration
infra/lifeguide-cloudflare-qa
infra/lifeguide-github-pages-qa
infra/lifeguide-supabase-qa
main
phase-1/foundation-completion
phase-2/product-foundation-identity
phase-3/planner-school-family-core
phase-4/ai-learning-wellbeing
phase-5/hardening-observability-release
test/android-reminder-acceptance
test/personal-notification-settings
test/personal-recovery-acceptance
test/role-entry-apk
| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | import 'package:lifemate/aparat_player.dart'; |
| 4 | |
| 5 | class _PlayerPort implements AparatPlayerPort { |
| 6 | final List<Uri> frames = []; |
| 7 | ValueChanged<String>? fail; |
| 8 | |
| 9 | @override |
| 10 | bool get isSupported => true; |
| 11 | |
| 12 | @override |
| 13 | Widget buildFrame(BuildContext context, |
| 14 | {required Uri uri, |
| 15 | required String title, |
| 16 | required VoidCallback onFrameReady, |
| 17 | required ValueChanged<String> onError}) { |
| 18 | frames.add(uri); |
| 19 | fail = onError; |
| 20 | return const ColoredBox( |
| 21 | key: ValueKey('fixture-frame'), color: Colors.black); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | Widget _app(_PlayerPort port, {String hash = 'rod03i6'}) => MaterialApp( |
| 26 | home: Scaffold( |
| 27 | body: AparatPlayerPortScope( |
| 28 | port: port, |
| 29 | child: AparatPlayer(videoHash: hash, title: 'درس نمونه')))); |
| 30 | |
| 31 | void main() { |
| 32 | test('hash policy rejects URLs, escaped paths and unbounded identifiers', () { |
| 33 | for (final hash in [ |
| 34 | '', |
| 35 | 'abcd', |
| 36 | 'a' * 65, |
| 37 | 'rod03i6?autoplay=true', |
| 38 | 'rod03i6/other', |
| 39 | '%72od03i6', |
| 40 | 'رود۳', |
| 41 | 'https://www.aparat.com/v/rod03i6', |
| 42 | ' rod03i6', |
| 43 | 'rod03i6\n' |
| 44 | ]) { |
| 45 | expect(aparatEmbedUri(hash), isNull, reason: hash); |
| 46 | } |
| 47 | expect(aparatEmbedUri('rOd03i6').toString(), |
| 48 | 'https://www.aparat.com/video/video/embed/videohash/rOd03i6/vt/frame'); |
| 49 | }); |
| 50 | |
| 51 | test('native navigation allows only the selected canonical HTTPS frame', () { |
| 52 | final canonical = aparatEmbedUri('rod03i6')!; |
| 53 | expect(isAllowedAparatNavigation(canonical.toString(), 'rod03i6'), isTrue); |
| 54 | expect( |
| 55 | isAllowedAparatNavigation( |
| 56 | canonical.replace(host: 'aparat.com').toString(), 'rod03i6'), |
| 57 | isTrue); |
| 58 | for (final url in [ |
| 59 | 'http://www.aparat.com${canonical.path}', |
| 60 | 'https://www.aparat.com.evil.test${canonical.path}', |
| 61 | 'https://evil.test${canonical.path}', |
| 62 | 'https://user@www.aparat.com${canonical.path}', |
| 63 | 'https://www.aparat.com:444${canonical.path}', |
| 64 | 'https://www.aparat.com/video/video/embed/videohash/%72od03i6/vt/frame', |
| 65 | '${canonical.toString()}?autoplay=true', |
| 66 | '${canonical.toString()}#other', |
| 67 | 'https://www.aparat.com/v/rod03i6', |
| 68 | 'https://www.aparat.com/video/video/embed/videohash/other01/vt/frame', |
| 69 | 'javascript:alert(1)', |
| 70 | 'intent://www.aparat.com', |
| 71 | 'about:blank' |
| 72 | ]) { |
| 73 | expect(isAllowedAparatNavigation(url, 'rod03i6'), isFalse, reason: url); |
| 74 | } |
| 75 | }); |
| 76 | |
| 77 | testWidgets('no provider frame exists until the explicit load click', |
| 78 | (tester) async { |
| 79 | final port = _PlayerPort(); |
| 80 | await tester.pumpWidget(_app(port)); |
| 81 | expect(port.frames, isEmpty); |
| 82 | expect(find.textContaining('حریم خصوصی'), findsOneWidget); |
| 83 | await tester.tap(find.text('بارگذاری ویدئو از آپارات')); |
| 84 | await tester.pump(); |
| 85 | expect(find.byKey(const ValueKey('fixture-frame')), findsOneWidget); |
| 86 | expect(port.frames.single.toString(), |
| 87 | 'https://www.aparat.com/video/video/embed/videohash/rod03i6/vt/frame'); |
| 88 | expect(port.frames.single.hasQuery, isFalse); |
| 89 | expect(port.frames.single.hasFragment, isFalse); |
| 90 | expect(find.textContaining('اثبات مطالعه'), findsOneWidget); |
| 91 | }); |
| 92 | |
| 93 | testWidgets('invalid identifier cannot load a remote player', (tester) async { |
| 94 | final port = _PlayerPort(); |
| 95 | await tester.pumpWidget(_app(port, hash: 'rod03i6?autoplay=true')); |
| 96 | expect(find.textContaining('شناسهٔ ویدئو معتبر نیست'), findsOneWidget); |
| 97 | expect(find.text('بارگذاری ویدئو از آپارات'), findsNothing); |
| 98 | expect(port.frames, isEmpty); |
| 99 | }); |
| 100 | |
| 101 | testWidgets('load failure removes the frame and offers an explicit retry', |
| 102 | (tester) async { |
| 103 | final port = _PlayerPort(); |
| 104 | await tester.pumpWidget(_app(port)); |
| 105 | await tester.tap(find.text('بارگذاری ویدئو از آپارات')); |
| 106 | await tester.pump(); |
| 107 | port.fail!('network'); |
| 108 | await tester.pump(); |
| 109 | expect(find.byKey(const ValueKey('fixture-frame')), findsNothing); |
| 110 | expect(find.textContaining('بارگذاری آپارات انجام نشد'), findsOneWidget); |
| 111 | await tester.tap(find.text('تلاش دوباره')); |
| 112 | await tester.pump(); |
| 113 | expect(find.byKey(const ValueKey('fixture-frame')), findsOneWidget); |
| 114 | expect(port.frames, hasLength(2)); |
| 115 | }); |
| 116 | |
| 117 | testWidgets( |
| 118 | 'new selection requires consent again and stale errors are ignored', |
| 119 | (tester) async { |
| 120 | final port = _PlayerPort(); |
| 121 | await tester.pumpWidget(_app(port)); |
| 122 | await tester.tap(find.text('بارگذاری ویدئو از آپارات')); |
| 123 | await tester.pump(); |
| 124 | final oldFailure = port.fail!; |
| 125 | await tester.pumpWidget(_app(port, hash: 'new0123')); |
| 126 | await tester.pump(); |
| 127 | expect(find.byKey(const ValueKey('fixture-frame')), findsNothing); |
| 128 | oldFailure('late failure'); |
| 129 | await tester.pump(); |
| 130 | expect(find.textContaining('بارگذاری آپارات انجام نشد'), findsNothing); |
| 131 | expect(find.text('بارگذاری ویدئو از آپارات'), findsOneWidget); |
| 132 | expect(port.frames, hasLength(1)); |
| 133 | }); |
| 134 | |
| 135 | testWidgets('closing the player removes remote content', (tester) async { |
| 136 | final port = _PlayerPort(); |
| 137 | await tester.pumpWidget(_app(port)); |
| 138 | await tester.tap(find.text('بارگذاری ویدئو از آپارات')); |
| 139 | await tester.pump(); |
| 140 | await tester.tap(find.text('بستن پخشکننده')); |
| 141 | await tester.pump(); |
| 142 | expect(find.byKey(const ValueKey('fixture-frame')), findsNothing); |
| 143 | expect(find.text('بارگذاری ویدئو از آپارات'), findsOneWidget); |
| 144 | }); |
| 145 | |
| 146 | testWidgets('backgrounding removes provider content and requires a new click', |
| 147 | (tester) async { |
| 148 | final port = _PlayerPort(); |
| 149 | await tester.pumpWidget(_app(port)); |
| 150 | await tester.tap(find.text('بارگذاری ویدئو از آپارات')); |
| 151 | await tester.pump(); |
| 152 | tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden); |
| 153 | await tester.pump(); |
| 154 | expect(find.byKey(const ValueKey('fixture-frame')), findsNothing); |
| 155 | tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed); |
| 156 | await tester.pump(); |
| 157 | expect(find.text('بارگذاری ویدئو از آپارات'), findsOneWidget); |
| 158 | expect(port.frames, hasLength(1)); |
| 159 | }); |
| 160 | |
| 161 | testWidgets('unsupported desktop explains the in-page limitation', |
| 162 | (tester) async { |
| 163 | await tester.pumpWidget(const MaterialApp( |
| 164 | home: Scaffold( |
| 165 | body: AparatPlayer(videoHash: 'rod03i6', title: 'درس نمونه')))); |
| 166 | await tester.tap(find.text('بارگذاری ویدئو از آپارات')); |
| 167 | await tester.pump(); |
| 168 | expect(find.textContaining('پخش در این نسخه پشتیبانی نمیشود'), |
| 169 | findsOneWidget); |
| 170 | }, variant: TargetPlatformVariant.only(TargetPlatform.linux)); |
| 171 | |
| 172 | testWidgets('fullscreen Back returns the native view once', (tester) async { |
| 173 | final navigator = GlobalKey<NavigatorState>(); |
| 174 | await tester.pumpWidget(MaterialApp( |
| 175 | navigatorKey: navigator, home: const Text('underlying app'))); |
| 176 | final presenter = |
| 177 | AparatFullscreenPresenter(navigator: navigator.currentState!); |
| 178 | var returned = 0; |
| 179 | presenter.show(const Text('native fullscreen'), () { |
| 180 | returned++; |
| 181 | presenter |
| 182 | .hide(); // Native custom-view hide can follow the close callback. |
| 183 | }); |
| 184 | await tester.pumpAndSettle(); |
| 185 | expect(find.text('native fullscreen'), findsOneWidget); |
| 186 | await tester.binding.handlePopRoute(); |
| 187 | await tester.pumpAndSettle(); |
| 188 | expect(returned, 1); |
| 189 | presenter.hide(); |
| 190 | await tester.pumpAndSettle(); |
| 191 | expect(find.text('underlying app'), findsOneWidget); |
| 192 | expect(returned, 1); |
| 193 | presenter.dispose(); |
| 194 | }); |
| 195 | |
| 196 | testWidgets('native fullscreen hide removes its route without popping others', |
| 197 | (tester) async { |
| 198 | final navigator = GlobalKey<NavigatorState>(); |
| 199 | await tester.pumpWidget(MaterialApp( |
| 200 | navigatorKey: navigator, home: const Text('underlying app'))); |
| 201 | final presenter = |
| 202 | AparatFullscreenPresenter(navigator: navigator.currentState!); |
| 203 | var returned = 0; |
| 204 | presenter.show(const Text('native fullscreen'), () => returned++); |
| 205 | await tester.pumpAndSettle(); |
| 206 | navigator.currentState!.push(MaterialPageRoute<void>( |
| 207 | builder: (_) => const Scaffold(body: Text('another app route')))); |
| 208 | await tester.pumpAndSettle(); |
| 209 | presenter.hide(); |
| 210 | presenter.hide(); |
| 211 | await tester.pumpAndSettle(); |
| 212 | expect(find.text('another app route'), findsOneWidget); |
| 213 | expect(returned, 0); |
| 214 | navigator.currentState!.pop(); |
| 215 | await tester.pumpAndSettle(); |
| 216 | expect(find.text('underlying app'), findsOneWidget); |
| 217 | presenter.dispose(); |
| 218 | }); |
| 219 | |
| 220 | testWidgets('fullscreen close and disposal notify native only once', |
| 221 | (tester) async { |
| 222 | final navigator = GlobalKey<NavigatorState>(); |
| 223 | await tester.pumpWidget(MaterialApp( |
| 224 | navigatorKey: navigator, home: const Text('underlying app'))); |
| 225 | final presenter = |
| 226 | AparatFullscreenPresenter(navigator: navigator.currentState!); |
| 227 | var returned = 0; |
| 228 | presenter.show(const Text('native fullscreen'), () => returned++); |
| 229 | await tester.pumpAndSettle(); |
| 230 | await tester.tap(find.byTooltip('خروج از تمامصفحه')); |
| 231 | await tester.pumpAndSettle(); |
| 232 | expect(returned, 1); |
| 233 | presenter.show(const Text('native fullscreen again'), () => returned++); |
| 234 | await tester.pumpAndSettle(); |
| 235 | presenter.dispose(); |
| 236 | presenter.hide(); |
| 237 | await tester.pumpAndSettle(); |
| 238 | expect(returned, 2); |
| 239 | expect(find.text('underlying app'), findsOneWidget); |
| 240 | }); |
| 241 | } |