From c56c8d935476da006669cc9c637a51bf04315bbd Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Fri, 24 Mar 2023 13:12:13 -0700 Subject: [PATCH] =?UTF-8?q?Added=20additional=20uri=20field=20to=20routeIn?= =?UTF-8?q?formationUpdated=20to=20accept=20entir=E2=80=A6=20(flutter/engi?= =?UTF-8?q?ne#40250)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added additional uri field to routeInformationUpdated to accept entir… --- .../lib/web_ui/lib/src/engine/window.dart | 17 ++++++++++++- .../flutter/lib/web_ui/test/window_test.dart | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart index 11af5ef1bb..f48f7909a0 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart @@ -191,8 +191,23 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { return true; case 'routeInformationUpdated': assert(arguments != null); + final String? uriString = arguments!.tryString('uri'); + final String path; + if (uriString != null) { + final Uri uri = Uri.parse(uriString); + // Need to remove scheme and authority. + path = Uri.decodeComponent( + Uri( + path: uri.path.isEmpty ? '/' : uri.path, + queryParameters: uri.queryParametersAll.isEmpty ? null : uri.queryParametersAll, + fragment: uri.fragment.isEmpty ? null : uri.fragment, + ).toString(), + ); + } else { + path = arguments.tryString('location')!; + } browserHistory.setRouteName( - arguments!.tryString('location'), + path, state: arguments['state'], replace: arguments.tryBool('replace') ?? false, ); diff --git a/engine/src/flutter/lib/web_ui/test/window_test.dart b/engine/src/flutter/lib/web_ui/test/window_test.dart index b356b6fba1..d37bdbdc2b 100644 --- a/engine/src/flutter/lib/web_ui/test/window_test.dart +++ b/engine/src/flutter/lib/web_ui/test/window_test.dart @@ -301,6 +301,30 @@ void testMain() { expect(actualState['state4']['substate2'], 'string2'); }); + test('routeInformationUpdated can handle uri', + () async { + await window.debugInitializeHistory(TestUrlStrategy.fromEntry( + const TestHistoryEntry('initial state', null, '/initial'), + ), useSingle: false); + expect(window.browserHistory, isA()); + + // routeInformationUpdated does not + final Completer callback = Completer(); + window.sendPlatformMessage( + 'flutter/navigation', + const JSONMethodCodec().encodeMethodCall(const MethodCall( + 'routeInformationUpdated', + { + 'uri': 'http://myhostname.com/baz?abc=def#fragment', + }, + )), + (_) { callback.complete(); }, + ); + await callback.future; + expect(window.browserHistory, isA()); + expect(window.browserHistory.urlStrategy!.getPath(), '/baz?abc=def#fragment'); + }); + test('can replace in MultiEntriesBrowserHistory', () async { await window.debugInitializeHistory(TestUrlStrategy.fromEntry(