[web] Freeze window.defaultRouteName (flutter/engine#15565)
This commit is contained in:
committed by
Flutter GitHub Bot
parent
117972971f
commit
8f125958e2
@@ -99,8 +99,14 @@ class EngineWindow extends ui.Window {
|
||||
/// Simulates clicking the browser's back button.
|
||||
Future<void> webOnlyBack() => _browserHistory.back();
|
||||
|
||||
/// Lazily initialized when the `defaultRouteName` getter is invoked.
|
||||
///
|
||||
/// The reason for the lazy initialization is to give enough time for the app to set [locationStrategy]
|
||||
/// in `lib/src/ui/initialization.dart`.
|
||||
String _defaultRouteName;
|
||||
|
||||
@override
|
||||
String get defaultRouteName => _browserHistory.currentPath;
|
||||
String get defaultRouteName => _defaultRouteName ??= _browserHistory.currentPath;
|
||||
|
||||
/// Change the strategy to use for handling browser history location.
|
||||
/// Setting this member will automatically update [_browserHistory].
|
||||
|
||||
22
engine/src/flutter/lib/web_ui/test/window_test.dart
Normal file
22
engine/src/flutter/lib/web_ui/test/window_test.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
|
||||
TestLocationStrategy _strategy;
|
||||
TestLocationStrategy get strategy => _strategy;
|
||||
set strategy(TestLocationStrategy newStrategy) {
|
||||
window.locationStrategy = _strategy = newStrategy;
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('window.defaultRouteName should not change', () {
|
||||
strategy = TestLocationStrategy.fromEntry(TestHistoryEntry('initial state', null, '/initial'));
|
||||
expect(window.defaultRouteName, '/initial');
|
||||
|
||||
strategy.replaceState(null, null, '/newpath');
|
||||
expect(window.defaultRouteName, '/initial');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user