Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/ui/initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 0 additions & 6 deletions lib/web_ui/lib/src/ui/test_embedding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
66 changes: 66 additions & 0 deletions lib/web_ui/test/engine/navigation_test.dart
Original file line number Diff line number Diff line change
@@ -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');
});
}