mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Handle new navigation platform messages (flutter/engine#11880)
This commit is contained in:
parent
a4cb86d72d
commit
04095305ed
@ -77,7 +77,7 @@ class EngineWindow extends ui.Window {
|
||||
/// Setting this member will automatically update [_browserHistory].
|
||||
///
|
||||
/// By setting this to null, the browser history will be disabled.
|
||||
set webOnlyLocationStrategy(LocationStrategy strategy) {
|
||||
set locationStrategy(LocationStrategy strategy) {
|
||||
_browserHistory.locationStrategy = strategy;
|
||||
}
|
||||
|
||||
@ -147,6 +147,20 @@ class EngineWindow extends ui.Window {
|
||||
// In widget tests we want to bypass processing of platform messages.
|
||||
accessibilityAnnouncements.handleMessage(data);
|
||||
return;
|
||||
|
||||
case 'flutter/navigation':
|
||||
const MethodCodec codec = JSONMethodCodec();
|
||||
final MethodCall decoded = codec.decodeMethodCall(data);
|
||||
final Map<String, dynamic> message = decoded.arguments;
|
||||
switch (decoded.method) {
|
||||
case 'routePushed':
|
||||
_browserHistory.setRouteName(message['routeName']);
|
||||
break;
|
||||
case 'routePopped':
|
||||
_browserHistory.setRouteName(message['previousRouteName']);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (pluginMessageCallHandler != null) {
|
||||
|
||||
@ -9,7 +9,7 @@ Future<void> webOnlyInitializePlatform({
|
||||
engine.AssetManager assetManager,
|
||||
}) async {
|
||||
if (!debugEmulateFlutterTesterEnvironment) {
|
||||
engine.window.webOnlyLocationStrategy = const engine.HashLocationStrategy();
|
||||
engine.window.locationStrategy = const engine.HashLocationStrategy();
|
||||
}
|
||||
|
||||
engine.webOnlyInitializeEngine();
|
||||
|
||||
@ -24,12 +24,6 @@ Future<dynamic> ensureTestPlatformInitializedThenRunTest(
|
||||
return _testPlatformInitializedFuture.then<dynamic>((_) => body());
|
||||
}
|
||||
|
||||
/// This setter is used by [WebNavigatorObserver] to update the url to
|
||||
/// reflect the [Navigator]'s current route name.
|
||||
set webOnlyRouteName(String routeName) {
|
||||
engine.window.webOnlyRouteName = routeName;
|
||||
}
|
||||
|
||||
/// Used to track when the platform is initialized. This ensures the test fonts
|
||||
/// are available.
|
||||
Future<void> _platformInitializedFuture;
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart' as engine;
|
||||
|
||||
engine.TestLocationStrategy _strategy;
|
||||
|
||||
const engine.MethodCodec codec = engine.JSONMethodCodec();
|
||||
|
||||
void emptyCallback(ByteData date) {}
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
engine.window.locationStrategy = _strategy = engine.TestLocationStrategy();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
engine.window.locationStrategy = _strategy = null;
|
||||
});
|
||||
|
||||
test('Tracks pushed and popped routes', () {
|
||||
engine.window.sendPlatformMessage(
|
||||
'flutter/navigation',
|
||||
codec.encodeMethodCall(const engine.MethodCall(
|
||||
'routePushed',
|
||||
<String, dynamic>{'previousRouteName': '/', 'routeName': '/foo'},
|
||||
)),
|
||||
emptyCallback,
|
||||
);
|
||||
expect(_strategy.path, '/foo');
|
||||
|
||||
engine.window.sendPlatformMessage(
|
||||
'flutter/navigation',
|
||||
codec.encodeMethodCall(const engine.MethodCall(
|
||||
'routePushed',
|
||||
<String, dynamic>{'previousRouteName': '/foo', 'routeName': '/bar'},
|
||||
)),
|
||||
emptyCallback,
|
||||
);
|
||||
expect(_strategy.path, '/bar');
|
||||
|
||||
engine.window.sendPlatformMessage(
|
||||
'flutter/navigation',
|
||||
codec.encodeMethodCall(const engine.MethodCall(
|
||||
'routePopped',
|
||||
<String, dynamic>{'previousRouteName': '/foo', 'routeName': '/bar'},
|
||||
)),
|
||||
emptyCallback,
|
||||
);
|
||||
expect(_strategy.path, '/foo');
|
||||
|
||||
engine.window.sendPlatformMessage(
|
||||
'flutter/navigation',
|
||||
codec.encodeMethodCall(const engine.MethodCall(
|
||||
'routePushed',
|
||||
<String, dynamic>{'previousRouteName': '/foo', 'routeName': '/bar/baz'},
|
||||
)),
|
||||
emptyCallback,
|
||||
);
|
||||
expect(_strategy.path, '/bar/baz');
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user