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
30 changes: 7 additions & 23 deletions lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
/// button, etc.
@visibleForTesting
BrowserHistory get browserHistory {
return _browserHistory ??=
MultiEntriesBrowserHistory(urlStrategy: _urlStrategyForInitialization);
}

UrlStrategy? get _urlStrategyForInitialization {
final UrlStrategy? urlStrategy = _isUrlStrategySet
? _customUrlStrategy
: _createDefaultUrlStrategy();
// Prevent any further customization of URL strategy.
_isUrlStrategySet = true;
return urlStrategy;
return _browserHistory ??=
MultiEntriesBrowserHistory(urlStrategy: urlStrategy);
}

BrowserHistory? _browserHistory;
Expand All @@ -63,29 +59,17 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
if (_browserHistory is SingleEntryBrowserHistory) {
return;
}

final UrlStrategy? strategy;
if (_browserHistory == null) {
strategy = _urlStrategyForInitialization;
} else {
strategy = _browserHistory?.urlStrategy;
await _browserHistory?.tearDown();
}
final UrlStrategy? strategy = _browserHistory?.urlStrategy;
await _browserHistory?.tearDown();
_browserHistory = SingleEntryBrowserHistory(urlStrategy: strategy);
}

Future<void> _useMultiEntryBrowserHistory() async {
if (_browserHistory is MultiEntriesBrowserHistory) {
return;
}

final UrlStrategy? strategy;
if (_browserHistory == null) {
strategy = _urlStrategyForInitialization;
} else {
strategy = _browserHistory?.urlStrategy;
await _browserHistory?.tearDown();
}
final UrlStrategy? strategy = _browserHistory?.urlStrategy;
await _browserHistory?.tearDown();
_browserHistory = MultiEntriesBrowserHistory(urlStrategy: strategy);
}

Expand Down Expand Up @@ -277,7 +261,7 @@ external set _jsSetUrlStrategy(_JsSetUrlStrategy? newJsSetUrlStrategy);

UrlStrategy? _createDefaultUrlStrategy() {
return ui.debugEmulateFlutterTesterEnvironment
? TestUrlStrategy.fromEntry(TestHistoryEntry('default', null, '/default'))
? null
: const HashUrlStrategy();
}

Expand Down
45 changes: 0 additions & 45 deletions lib/web_ui/test/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,51 +128,6 @@ void testMain() {
expect(window.browserHistory.urlStrategy.getPath(), '/baz');
});

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.

Completer<void> callback = Completer<void>();
window.sendPlatformMessage(
'flutter/navigation',
JSONMethodCodec().encodeMethodCall(MethodCall(
'routeUpdated',
<String, dynamic>{'routeName': '/bar'},
)),
(_) { callback.complete(); },
);
await callback.future;
expect(window.browserHistory is SingleEntryBrowserHistory, true);
// The url strategy should've been set to the default, and the path
// should've been correctly set to "/bar".
expect(window.browserHistory.urlStrategy, isNot(isNull));
expect(window.browserHistory.urlStrategy.getPath(), '/bar');
}, skip: browserEngine == BrowserEngine.webkit); // 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.

Completer<void> callback = Completer<void>();
window.sendPlatformMessage(
'flutter/navigation',
JSONMethodCodec().encodeMethodCall(MethodCall(
'routeInformationUpdated',
<String, dynamic>{
'location': '/baz',
'state': null,
},
)),
(_) { callback.complete(); },
);
await callback.future;
expect(window.browserHistory is MultiEntriesBrowserHistory, true);
// The url strategy should've been set to the default, and the path
// should've been correctly set to "/baz".
expect(window.browserHistory.urlStrategy, isNot(isNull));
expect(window.browserHistory.urlStrategy.getPath(), '/baz');
}, skip: browserEngine == BrowserEngine.webkit); // https://github.com/flutter/flutter/issues/50836

test('can disable location strategy', () async {
// Disable URL strategy.
expect(() => jsSetUrlStrategy(null), returnsNormally);
Expand Down