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 d0ffdf7713d..5e2bf758bef 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 @@ -625,11 +625,6 @@ final class EngineFlutterWindow extends EngineFlutterView implements ui.Singleto await _useSingleEntryBrowserHistory(); return true; // the following cases assert that arguments are not null - case 'routeUpdated': // deprecated - assert(arguments != null); - await _useSingleEntryBrowserHistory(); - browserHistory.setRouteName(arguments!.tryString('routeName')); - return true; case 'routeInformationUpdated': assert(arguments != null); final String? uriString = arguments!.tryString('uri'); diff --git a/engine/src/flutter/lib/web_ui/test/engine/history_test.dart b/engine/src/flutter/lib/web_ui/test/engine/history_test.dart index 40af749fecc..402408cbced 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/history_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/history_test.dart @@ -186,7 +186,7 @@ void testMain() { expect(strategy.history, hasLength(2)); expect(strategy.currentEntry.state, flutterState); expect(strategy.currentEntry.url, '/home'); - await routeUpdated('/page1'); + await routeInformationUpdated('/page1', null); // The number of entries shouldn't change. expect(strategy.history, hasLength(2)); expect(strategy.currentEntryIndex, 1); @@ -204,7 +204,7 @@ void testMain() { expect(spy.messages[0].methodName, 'popRoute'); expect(spy.messages[0].methodArguments, isNull); // The framework responds by updating to the most current route name. - await routeUpdated('/home'); + await routeInformationUpdated('/home', null); // We still have 2 entries. expect(strategy.history, hasLength(2)); expect(strategy.currentEntryIndex, 1); @@ -219,8 +219,8 @@ void testMain() { ); await implicitView.debugInitializeHistory(strategy, useSingle: true); - await routeUpdated('/page1'); - await routeUpdated('/page2'); + await routeInformationUpdated('/page1', null); + await routeInformationUpdated('/page2', null); // Make sure we are on page2. expect(strategy.history, hasLength(2)); @@ -237,7 +237,7 @@ void testMain() { expect(spy.messages[0].methodArguments, isNull); spy.messages.clear(); // 2. The framework sends a `routePopped` platform message. - await routeUpdated('/page1'); + await routeInformationUpdated('/page1', null); // 3. The history state should reflect that /page1 is currently active. expect(strategy.history, hasLength(2)); expect(strategy.currentEntryIndex, 1); @@ -253,7 +253,7 @@ void testMain() { expect(spy.messages[0].methodArguments, isNull); spy.messages.clear(); // 2. The framework sends a `routePopped` platform message. - await routeUpdated('/home'); + await routeInformationUpdated('/home', null); // 3. The history state should reflect that /page1 is currently active. expect(strategy.history, hasLength(2)); expect(strategy.currentEntryIndex, 1); @@ -296,7 +296,7 @@ void testMain() { expect(spy.messages[0].methodArguments, '/page3'); spy.messages.clear(); // 2. The framework sends a `routeUpdated` platform message. - await routeUpdated('/page3'); + await routeInformationUpdated('/page3', null); // 3. The history state should reflect that /page3 is currently active. expect(strategy.history, hasLength(3)); expect(strategy.currentEntryIndex, 1); @@ -312,7 +312,7 @@ void testMain() { expect(spy.messages[0].methodArguments, isNull); spy.messages.clear(); // 2. The framework sends a `routeUpdated` platform message. - await routeUpdated('/home'); + await routeInformationUpdated('/home', null); // 3. The history state should reflect that /home is currently active. expect(strategy.history, hasLength(2)); expect(strategy.currentEntryIndex, 1); @@ -351,7 +351,7 @@ void testMain() { await implicitView.debugInitializeHistory(strategy, useSingle: true); // Go to a named route. - await routeUpdated('/named-route'); + await routeInformationUpdated('/named-route', null); expect(strategy.currentEntry.url, '/named-route'); // Now, push a nameless route. The url shouldn't change. @@ -761,16 +761,6 @@ void testMain() { }); } -Future routeUpdated(String routeName) { - final Completer completer = Completer(); - EnginePlatformDispatcher.instance.sendPlatformMessage( - 'flutter/navigation', - codec.encodeMethodCall(MethodCall('routeUpdated', {'routeName': routeName})), - (_) => completer.complete(), - ); - return completer.future; -} - Future routeInformationUpdated(String location, dynamic state) { final Completer completer = Completer(); EnginePlatformDispatcher.instance.sendPlatformMessage( diff --git a/engine/src/flutter/lib/web_ui/test/engine/navigation_test.dart b/engine/src/flutter/lib/web_ui/test/engine/navigation_test.dart index 1b602da8f35..d4b490b3190 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/navigation_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/navigation_test.dart @@ -29,7 +29,7 @@ void testMain() { ui.PlatformDispatcher.instance.sendPlatformMessage( 'flutter/navigation', codec.encodeMethodCall( - const MethodCall('routeUpdated', {'routeName': '/foo'}), + const MethodCall('routeInformationUpdated', {'location': '/foo'}), ), (ByteData? response) => completer.complete(response), ); @@ -53,7 +53,7 @@ void testMain() { ui.PlatformDispatcher.instance.sendPlatformMessage( 'flutter/navigation', codec.encodeMethodCall( - const MethodCall('routeUpdated', {'routeName': '/foo'}), + const MethodCall('routeInformationUpdated', {'location': '/foo'}), ), (_) => completer.complete(), ); diff --git a/engine/src/flutter/lib/web_ui/test/engine/routing_test.dart b/engine/src/flutter/lib/web_ui/test/engine/routing_test.dart index eb0afd8ed48..a76d0e4f70e 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/routing_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/routing_test.dart @@ -78,7 +78,7 @@ void testMain() { myWindow.sendPlatformMessage( 'flutter/navigation', const JSONMethodCodec().encodeMethodCall( - const MethodCall('routeUpdated', {'routeName': '/bar'}), + const MethodCall('routeInformationUpdated', {'location': '/bar'}), ), (_) { callback.complete(); @@ -125,17 +125,14 @@ void testMain() { 'selectMultiEntryHistory', {}, ); // -> multi - await check('routeUpdated', { - 'routeName': '/bar', - }); // -> single - await check('routeInformationUpdated', { + await check('routeInformationUpdated', { 'location': '/bar', }); // does not change mode - await check( - 'selectMultiEntryHistory', + await check( + 'selectSingleEntryHistory', {}, - ); // -> multi - await check('routeInformationUpdated', { + ); // -> single + await check('routeInformationUpdated', { 'location': '/bar', }); // does not change mode }); @@ -143,12 +140,6 @@ void testMain() { test( 'handleNavigationMessage throws for route update methods called with null arguments', () async { - expect(() async { - await myWindow.handleNavigationMessage( - const JSONMethodCodec().encodeMethodCall(const MethodCall('routeUpdated')), - ); - }, throwsAssertionError); - expect(() async { await myWindow.handleNavigationMessage( const JSONMethodCodec().encodeMethodCall(const MethodCall('routeInformationUpdated')), @@ -214,12 +205,21 @@ void testMain() { ); expect(myWindow.browserHistory, isA()); - // routeUpdated resets the history type + // change the history type Completer callback = Completer(); + myWindow.sendPlatformMessage( + 'flutter/navigation', + const JSONMethodCodec().encodeMethodCall(const MethodCall('selectSingleEntryHistory')), + (_) { + callback.complete(); + }, + ); + await callback.future; + callback = Completer(); myWindow.sendPlatformMessage( 'flutter/navigation', const JSONMethodCodec().encodeMethodCall( - const MethodCall('routeUpdated', {'routeName': '/bar'}), + const MethodCall('routeInformationUpdated', {'location': '/bar'}), ), (_) { callback.complete(); @@ -250,7 +250,7 @@ void testMain() { // they can be interleaved safely await myWindow.handleNavigationMessage( const JSONMethodCodec().encodeMethodCall( - const MethodCall('routeUpdated', {'routeName': '/foo'}), + const MethodCall('routeInformationUpdated', {'location': '/foo'}), ), ); expect(myWindow.browserHistory, isA()); @@ -390,32 +390,6 @@ void testMain() { expect(myWindow.browserHistory.urlStrategy!.getState(), _tagStateWithSerialCount('/state1', 1)); }); - test('initialize browser history with default url strategy (single)', () async { - // On purpose, we don't initialize history on the window. We want to let the - // window to self-initialize when it receives a navigation message. - - // Without initializing history, the default route name should be - // initialized to "/" in tests. - expect(myWindow.defaultRouteName, '/'); - - final Completer callback = Completer(); - myWindow.sendPlatformMessage( - 'flutter/navigation', - const JSONMethodCodec().encodeMethodCall( - const MethodCall('routeUpdated', {'routeName': '/bar'}), - ), - (_) { - callback.complete(); - }, - ); - await callback.future; - expect(myWindow.browserHistory, isA()); - // The url strategy should've been set to the default, and the path - // should've been correctly set to "/bar". - expect(myWindow.browserHistory.urlStrategy, isNot(isNull)); - expect(myWindow.browserHistory.urlStrategy!.getPath(), '/bar'); - }, skip: isSafari); // https://github.com/flutter/flutter/issues/50836 - test('initialize browser history with default url strategy (multiple)', () async { // On purpose, we don't initialize history on the window. We want to let the // window to self-initialize when it receives a navigation message. @@ -443,7 +417,7 @@ void testMain() { // should've been correctly set to "/baz". expect(myWindow.browserHistory.urlStrategy, isNot(isNull)); expect(myWindow.browserHistory.urlStrategy!.getPath(), '/baz'); - }, skip: isSafari); // https://github.com/flutter/flutter/issues/50836 + }); test('can disable location strategy', () async { // Disable URL strategy.