Skip to content

Commit c4bf640

Browse files
mdebbarksokolovskyi
authored andcommitted
[web] Cleanup usages of deprecated routeUpdated message (flutter#173782)
This is a follow up to flutter#173652 Closes flutter#50836
1 parent e4f2a91 commit c4bf640

File tree

4 files changed

+30
-71
lines changed

4 files changed

+30
-71
lines changed

engine/src/flutter/lib/web_ui/lib/src/engine/window.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,6 @@ final class EngineFlutterWindow extends EngineFlutterView implements ui.Singleto
625625
await _useSingleEntryBrowserHistory();
626626
return true;
627627
// the following cases assert that arguments are not null
628-
case 'routeUpdated': // deprecated
629-
assert(arguments != null);
630-
await _useSingleEntryBrowserHistory();
631-
browserHistory.setRouteName(arguments!.tryString('routeName'));
632-
return true;
633628
case 'routeInformationUpdated':
634629
assert(arguments != null);
635630
final String? uriString = arguments!.tryString('uri');

engine/src/flutter/lib/web_ui/test/engine/history_test.dart

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void testMain() {
186186
expect(strategy.history, hasLength(2));
187187
expect(strategy.currentEntry.state, flutterState);
188188
expect(strategy.currentEntry.url, '/home');
189-
await routeUpdated('/page1');
189+
await routeInformationUpdated('/page1', null);
190190
// The number of entries shouldn't change.
191191
expect(strategy.history, hasLength(2));
192192
expect(strategy.currentEntryIndex, 1);
@@ -204,7 +204,7 @@ void testMain() {
204204
expect(spy.messages[0].methodName, 'popRoute');
205205
expect(spy.messages[0].methodArguments, isNull);
206206
// The framework responds by updating to the most current route name.
207-
await routeUpdated('/home');
207+
await routeInformationUpdated('/home', null);
208208
// We still have 2 entries.
209209
expect(strategy.history, hasLength(2));
210210
expect(strategy.currentEntryIndex, 1);
@@ -219,8 +219,8 @@ void testMain() {
219219
);
220220
await implicitView.debugInitializeHistory(strategy, useSingle: true);
221221

222-
await routeUpdated('/page1');
223-
await routeUpdated('/page2');
222+
await routeInformationUpdated('/page1', null);
223+
await routeInformationUpdated('/page2', null);
224224

225225
// Make sure we are on page2.
226226
expect(strategy.history, hasLength(2));
@@ -237,7 +237,7 @@ void testMain() {
237237
expect(spy.messages[0].methodArguments, isNull);
238238
spy.messages.clear();
239239
// 2. The framework sends a `routePopped` platform message.
240-
await routeUpdated('/page1');
240+
await routeInformationUpdated('/page1', null);
241241
// 3. The history state should reflect that /page1 is currently active.
242242
expect(strategy.history, hasLength(2));
243243
expect(strategy.currentEntryIndex, 1);
@@ -253,7 +253,7 @@ void testMain() {
253253
expect(spy.messages[0].methodArguments, isNull);
254254
spy.messages.clear();
255255
// 2. The framework sends a `routePopped` platform message.
256-
await routeUpdated('/home');
256+
await routeInformationUpdated('/home', null);
257257
// 3. The history state should reflect that /page1 is currently active.
258258
expect(strategy.history, hasLength(2));
259259
expect(strategy.currentEntryIndex, 1);
@@ -296,7 +296,7 @@ void testMain() {
296296
expect(spy.messages[0].methodArguments, '/page3');
297297
spy.messages.clear();
298298
// 2. The framework sends a `routeUpdated` platform message.
299-
await routeUpdated('/page3');
299+
await routeInformationUpdated('/page3', null);
300300
// 3. The history state should reflect that /page3 is currently active.
301301
expect(strategy.history, hasLength(3));
302302
expect(strategy.currentEntryIndex, 1);
@@ -312,7 +312,7 @@ void testMain() {
312312
expect(spy.messages[0].methodArguments, isNull);
313313
spy.messages.clear();
314314
// 2. The framework sends a `routeUpdated` platform message.
315-
await routeUpdated('/home');
315+
await routeInformationUpdated('/home', null);
316316
// 3. The history state should reflect that /home is currently active.
317317
expect(strategy.history, hasLength(2));
318318
expect(strategy.currentEntryIndex, 1);
@@ -351,7 +351,7 @@ void testMain() {
351351
await implicitView.debugInitializeHistory(strategy, useSingle: true);
352352

353353
// Go to a named route.
354-
await routeUpdated('/named-route');
354+
await routeInformationUpdated('/named-route', null);
355355
expect(strategy.currentEntry.url, '/named-route');
356356

357357
// Now, push a nameless route. The url shouldn't change.
@@ -761,16 +761,6 @@ void testMain() {
761761
});
762762
}
763763

764-
Future<void> routeUpdated(String routeName) {
765-
final Completer<void> completer = Completer<void>();
766-
EnginePlatformDispatcher.instance.sendPlatformMessage(
767-
'flutter/navigation',
768-
codec.encodeMethodCall(MethodCall('routeUpdated', <String, dynamic>{'routeName': routeName})),
769-
(_) => completer.complete(),
770-
);
771-
return completer.future;
772-
}
773-
774764
Future<void> routeInformationUpdated(String location, dynamic state) {
775765
final Completer<void> completer = Completer<void>();
776766
EnginePlatformDispatcher.instance.sendPlatformMessage(

engine/src/flutter/lib/web_ui/test/engine/navigation_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void testMain() {
2929
ui.PlatformDispatcher.instance.sendPlatformMessage(
3030
'flutter/navigation',
3131
codec.encodeMethodCall(
32-
const MethodCall('routeUpdated', <String, dynamic>{'routeName': '/foo'}),
32+
const MethodCall('routeInformationUpdated', <String, dynamic>{'location': '/foo'}),
3333
),
3434
(ByteData? response) => completer.complete(response),
3535
);
@@ -53,7 +53,7 @@ void testMain() {
5353
ui.PlatformDispatcher.instance.sendPlatformMessage(
5454
'flutter/navigation',
5555
codec.encodeMethodCall(
56-
const MethodCall('routeUpdated', <String, dynamic>{'routeName': '/foo'}),
56+
const MethodCall('routeInformationUpdated', <String, dynamic>{'location': '/foo'}),
5757
),
5858
(_) => completer.complete(),
5959
);

engine/src/flutter/lib/web_ui/test/engine/routing_test.dart

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void testMain() {
7878
myWindow.sendPlatformMessage(
7979
'flutter/navigation',
8080
const JSONMethodCodec().encodeMethodCall(
81-
const MethodCall('routeUpdated', <String, dynamic>{'routeName': '/bar'}),
81+
const MethodCall('routeInformationUpdated', <String, dynamic>{'location': '/bar'}),
8282
),
8383
(_) {
8484
callback.complete();
@@ -125,30 +125,21 @@ void testMain() {
125125
'selectMultiEntryHistory',
126126
<String, dynamic>{},
127127
); // -> multi
128-
await check<SingleEntryBrowserHistory>('routeUpdated', <String, dynamic>{
129-
'routeName': '/bar',
130-
}); // -> single
131-
await check<SingleEntryBrowserHistory>('routeInformationUpdated', <String, dynamic>{
128+
await check<MultiEntriesBrowserHistory>('routeInformationUpdated', <String, dynamic>{
132129
'location': '/bar',
133130
}); // does not change mode
134-
await check<MultiEntriesBrowserHistory>(
135-
'selectMultiEntryHistory',
131+
await check<SingleEntryBrowserHistory>(
132+
'selectSingleEntryHistory',
136133
<String, dynamic>{},
137-
); // -> multi
138-
await check<MultiEntriesBrowserHistory>('routeInformationUpdated', <String, dynamic>{
134+
); // -> single
135+
await check<SingleEntryBrowserHistory>('routeInformationUpdated', <String, dynamic>{
139136
'location': '/bar',
140137
}); // does not change mode
141138
});
142139

143140
test(
144141
'handleNavigationMessage throws for route update methods called with null arguments',
145142
() async {
146-
expect(() async {
147-
await myWindow.handleNavigationMessage(
148-
const JSONMethodCodec().encodeMethodCall(const MethodCall('routeUpdated')),
149-
);
150-
}, throwsAssertionError);
151-
152143
expect(() async {
153144
await myWindow.handleNavigationMessage(
154145
const JSONMethodCodec().encodeMethodCall(const MethodCall('routeInformationUpdated')),
@@ -214,12 +205,21 @@ void testMain() {
214205
);
215206
expect(myWindow.browserHistory, isA<MultiEntriesBrowserHistory>());
216207

217-
// routeUpdated resets the history type
208+
// change the history type
218209
Completer<void> callback = Completer<void>();
210+
myWindow.sendPlatformMessage(
211+
'flutter/navigation',
212+
const JSONMethodCodec().encodeMethodCall(const MethodCall('selectSingleEntryHistory')),
213+
(_) {
214+
callback.complete();
215+
},
216+
);
217+
await callback.future;
218+
callback = Completer<void>();
219219
myWindow.sendPlatformMessage(
220220
'flutter/navigation',
221221
const JSONMethodCodec().encodeMethodCall(
222-
const MethodCall('routeUpdated', <String, dynamic>{'routeName': '/bar'}),
222+
const MethodCall('routeInformationUpdated', <String, dynamic>{'location': '/bar'}),
223223
),
224224
(_) {
225225
callback.complete();
@@ -250,7 +250,7 @@ void testMain() {
250250
// they can be interleaved safely
251251
await myWindow.handleNavigationMessage(
252252
const JSONMethodCodec().encodeMethodCall(
253-
const MethodCall('routeUpdated', <String, dynamic>{'routeName': '/foo'}),
253+
const MethodCall('routeInformationUpdated', <String, dynamic>{'location': '/foo'}),
254254
),
255255
);
256256
expect(myWindow.browserHistory, isA<SingleEntryBrowserHistory>());
@@ -390,32 +390,6 @@ void testMain() {
390390
expect(myWindow.browserHistory.urlStrategy!.getState(), _tagStateWithSerialCount('/state1', 1));
391391
});
392392

393-
test('initialize browser history with default url strategy (single)', () async {
394-
// On purpose, we don't initialize history on the window. We want to let the
395-
// window to self-initialize when it receives a navigation message.
396-
397-
// Without initializing history, the default route name should be
398-
// initialized to "/" in tests.
399-
expect(myWindow.defaultRouteName, '/');
400-
401-
final Completer<void> callback = Completer<void>();
402-
myWindow.sendPlatformMessage(
403-
'flutter/navigation',
404-
const JSONMethodCodec().encodeMethodCall(
405-
const MethodCall('routeUpdated', <String, dynamic>{'routeName': '/bar'}),
406-
),
407-
(_) {
408-
callback.complete();
409-
},
410-
);
411-
await callback.future;
412-
expect(myWindow.browserHistory, isA<SingleEntryBrowserHistory>());
413-
// The url strategy should've been set to the default, and the path
414-
// should've been correctly set to "/bar".
415-
expect(myWindow.browserHistory.urlStrategy, isNot(isNull));
416-
expect(myWindow.browserHistory.urlStrategy!.getPath(), '/bar');
417-
}, skip: isSafari); // https://github.com/flutter/flutter/issues/50836
418-
419393
test('initialize browser history with default url strategy (multiple)', () async {
420394
// On purpose, we don't initialize history on the window. We want to let the
421395
// window to self-initialize when it receives a navigation message.
@@ -443,7 +417,7 @@ void testMain() {
443417
// should've been correctly set to "/baz".
444418
expect(myWindow.browserHistory.urlStrategy, isNot(isNull));
445419
expect(myWindow.browserHistory.urlStrategy!.getPath(), '/baz');
446-
}, skip: isSafari); // https://github.com/flutter/flutter/issues/50836
420+
});
447421

448422
test('can disable location strategy', () async {
449423
// Disable URL strategy.

0 commit comments

Comments
 (0)