@@ -867,6 +867,76 @@ testWidgets('ChildBackButtonDispatcher take priority recursively', (WidgetTester
867867 ]);
868868 });
869869
870+ testWidgets ('PlatformRouteInformationProvider does not push new entry if query parameters are semantically the same' , (WidgetTester tester) async {
871+ final List <MethodCall > log = < MethodCall > [];
872+ TestDefaultBinaryMessengerBinding
873+ .instance.defaultBinaryMessenger
874+ .setMockMethodCallHandler (
875+ SystemChannels .navigation,
876+ (MethodCall methodCall) async {
877+ log.add (methodCall);
878+ return null ;
879+ }
880+ );
881+ final RouteInformation initial = RouteInformation (
882+ uri: Uri .parse ('initial?a=ws/abcd' ),
883+ );
884+ final RouteInformationProvider provider = PlatformRouteInformationProvider (
885+ initialRouteInformation: initial
886+ );
887+ // Make sure engine is updated with initial route
888+ provider.routerReportsNewRouteInformation (initial);
889+ log.clear ();
890+
891+ provider.routerReportsNewRouteInformation (
892+ RouteInformation (
893+ uri: Uri (
894+ path: 'initial' ,
895+ queryParameters: < String , String > {'a' : 'ws/abcd' }, // This will be escaped.
896+ ),
897+ ),
898+ );
899+ expect (provider.value.uri.toString (), 'initial?a=ws%2Fabcd' );
900+ // should use `replace: true`
901+ expect (log, < Object > [
902+ isMethodCall ('selectMultiEntryHistory' , arguments: null ),
903+ isMethodCall ('routeInformationUpdated' , arguments: < String , dynamic > { 'uri' : 'initial?a=ws%2Fabcd' , 'state' : null , 'replace' : true }),
904+ ]);
905+ log.clear ();
906+
907+ provider.routerReportsNewRouteInformation (
908+ RouteInformation (uri: Uri .parse ('initial?a=1&b=2' )),
909+ );
910+ log.clear ();
911+
912+ // Change query parameters order
913+ provider.routerReportsNewRouteInformation (
914+ RouteInformation (uri: Uri .parse ('initial?b=2&a=1' )),
915+ );
916+ // should use `replace: true`
917+ expect (log, < Object > [
918+ isMethodCall ('selectMultiEntryHistory' , arguments: null ),
919+ isMethodCall ('routeInformationUpdated' , arguments: < String , dynamic > { 'uri' : 'initial?b=2&a=1' , 'state' : null , 'replace' : true }),
920+ ]);
921+ log.clear ();
922+
923+ provider.routerReportsNewRouteInformation (
924+ RouteInformation (uri: Uri .parse ('initial?a=1&a=2' )),
925+ );
926+ log.clear ();
927+
928+ // Change query parameters order for same key
929+ provider.routerReportsNewRouteInformation (
930+ RouteInformation (uri: Uri .parse ('initial?a=2&a=1' )),
931+ );
932+ // should use `replace: true`
933+ expect (log, < Object > [
934+ isMethodCall ('selectMultiEntryHistory' , arguments: null ),
935+ isMethodCall ('routeInformationUpdated' , arguments: < String , dynamic > { 'uri' : 'initial?a=2&a=1' , 'state' : null , 'replace' : true }),
936+ ]);
937+ log.clear ();
938+ });
939+
870940 testWidgets ('RootBackButtonDispatcher works' , (WidgetTester tester) async {
871941 final BackButtonDispatcher outerDispatcher = RootBackButtonDispatcher ();
872942 final RouteInformationProvider provider = PlatformRouteInformationProvider (
0 commit comments