未验证 提交 cd920398 编写于 作者: M Mouad Debbar 提交者: GitHub

Handle new navigation platform messages (#11880)

上级 898480fe
......@@ -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;
......
// 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');
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册