diff --git a/packages/url_launcher/url_launcher/test/link_test.dart b/packages/url_launcher/url_launcher/test/link_test.dart index 6a598298bdf0..819f6a370e30 100644 --- a/packages/url_launcher/url_launcher/test/link_test.dart +++ b/packages/url_launcher/url_launcher/test/link_test.dart @@ -2,11 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui'; - import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; import 'package:flutter/services.dart'; import 'package:url_launcher/link.dart'; import 'package:url_launcher/src/link.dart'; @@ -14,19 +11,12 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface. import 'mock_url_launcher_platform.dart'; -final MethodCodec _codec = const JSONMethodCodec(); - void main() { late MockUrlLauncher mock; - PlatformMessageCallback? realOnPlatformMessage; setUp(() { mock = MockUrlLauncher(); UrlLauncherPlatform.instance = mock; - realOnPlatformMessage = window.onPlatformMessage; - }); - tearDown(() { - window.onPlatformMessage = realOnPlatformMessage; }); group('$Link', () { @@ -147,99 +137,5 @@ void main() { // Restore the original function. pushRouteToFrameworkFunction = originalPushFunction; }); - - testWidgets('sends router platform messages for internal route names', - (WidgetTester tester) async { - // Intercept messages sent to the engine. - final List engineCalls = []; - SystemChannels.navigation.setMockMethodCallHandler((MethodCall call) { - engineCalls.add(call); - return Future.value(); - }); - - // Intercept messages sent to the framework. - final List frameworkCalls = []; - window.onPlatformMessage = ( - String name, - ByteData? data, - PlatformMessageResponseCallback? callback, - ) { - frameworkCalls.add(_codec.decodeMethodCall(data)); - realOnPlatformMessage!(name, data, callback); - }; - - final Uri uri = Uri.parse('/foo/bar'); - FollowLink? followLink; - - final Link link = Link( - uri: uri, - builder: (BuildContext context, FollowLink? followLink2) { - followLink = followLink2; - return Container(); - }, - ); - await tester.pumpWidget(MaterialApp.router( - routeInformationParser: MockRouteInformationParser(), - routerDelegate: MockRouterDelegate( - builder: (BuildContext context) => link, - ), - )); - - engineCalls.clear(); - frameworkCalls.clear(); - await followLink!(); - - // Shouldn't use url_launcher when uri is an internal route name. - expect(mock.canLaunchCalled, isFalse); - expect(mock.launchCalled, isFalse); - - // Sends route information update to the engine. - expect(engineCalls, hasLength(1)); - expect( - engineCalls.single, - isMethodCall('routeInformationUpdated', arguments: { - 'location': '/foo/bar', - 'state': null - }), - ); - - // Also pushes route information update to the Router. - expect(frameworkCalls, hasLength(1)); - expect( - frameworkCalls.single, - isMethodCall( - 'pushRouteInformation', - arguments: { - 'location': '/foo/bar', - 'state': null, - }, - ), - ); - }); }); } - -class MockRouteInformationParser extends Mock - implements RouteInformationParser { - @override - Future parseRouteInformation(RouteInformation routeInformation) { - return Future.value(true); - } -} - -class MockRouterDelegate extends Mock implements RouterDelegate { - MockRouterDelegate({required this.builder}); - - final WidgetBuilder builder; - - @override - Widget build(BuildContext context) { - return builder(context); - } - - @override - Future setInitialRoutePath(Object configuration) async {} - - @override - Future setNewRoutePath(Object configuration) async {} -} diff --git a/packages/url_launcher/url_launcher_platform_interface/test/link_test.dart b/packages/url_launcher/url_launcher_platform_interface/test/link_test.dart index 1f45b594a349..75a14b2e11a6 100644 --- a/packages/url_launcher/url_launcher_platform_interface/test/link_test.dart +++ b/packages/url_launcher/url_launcher_platform_interface/test/link_test.dart @@ -20,7 +20,7 @@ void main() { )); expect(find.byKey(Key('home')), findsOneWidget); expect(find.byKey(Key('a')), findsNothing); - await pushRouteNameToFramework(null, '/a'); + await tester.runAsync(() => pushRouteNameToFramework(null, '/a')); // start animation await tester.pump(); // skip past animation (5s is arbitrary, just needs to be long enough) @@ -36,7 +36,7 @@ void main() { )); expect(find.byKey(Key('/')), findsOneWidget); expect(find.byKey(Key('/a')), findsNothing); - await pushRouteNameToFramework(null, '/a'); + await tester.runAsync(() => pushRouteNameToFramework(null, '/a')); // start animation await tester.pump(); // skip past animation (5s is arbitrary, just needs to be long enough)