@@ -128,6 +128,59 @@ void testMain() {
128128 expect (window.browserHistory.urlStrategy.getPath (), '/baz' );
129129 });
130130
131+ test ('initialize browser history with default url strategy (single)' , () async {
132+ // On purpose, we don't initialize history on the window. We want to let the
133+ // window to self-initialize when it receives a navigation message.
134+
135+ // Without initializing history, the default route name should be
136+ // initialized to "/" in tests.
137+ expect (window.defaultRouteName, '/' );
138+
139+ Completer <void > callback = Completer <void >();
140+ window.sendPlatformMessage (
141+ 'flutter/navigation' ,
142+ JSONMethodCodec ().encodeMethodCall (MethodCall (
143+ 'routeUpdated' ,
144+ < String , dynamic > {'routeName' : '/bar' },
145+ )),
146+ (_) { callback.complete (); },
147+ );
148+ await callback.future;
149+ expect (window.browserHistory is SingleEntryBrowserHistory , true );
150+ // The url strategy should've been set to the default, and the path
151+ // should've been correctly set to "/bar".
152+ expect (window.browserHistory.urlStrategy, isNot (isNull));
153+ expect (window.browserHistory.urlStrategy.getPath (), '/bar' );
154+ }, skip: browserEngine == BrowserEngine .webkit); // https://github.com/flutter/flutter/issues/50836
155+
156+ test ('initialize browser history with default url strategy (multiple)' , () async {
157+ // On purpose, we don't initialize history on the window. We want to let the
158+ // window to self-initialize when it receives a navigation message.
159+
160+ // Without initializing history, the default route name should be
161+ // initialized to "/" in tests.
162+ expect (window.defaultRouteName, '/' );
163+
164+ Completer <void > callback = Completer <void >();
165+ window.sendPlatformMessage (
166+ 'flutter/navigation' ,
167+ JSONMethodCodec ().encodeMethodCall (MethodCall (
168+ 'routeInformationUpdated' ,
169+ < String , dynamic > {
170+ 'location' : '/baz' ,
171+ 'state' : null ,
172+ },
173+ )),
174+ (_) { callback.complete (); },
175+ );
176+ await callback.future;
177+ expect (window.browserHistory is MultiEntriesBrowserHistory , true );
178+ // The url strategy should've been set to the default, and the path
179+ // should've been correctly set to "/baz".
180+ expect (window.browserHistory.urlStrategy, isNot (isNull));
181+ expect (window.browserHistory.urlStrategy.getPath (), '/baz' );
182+ }, skip: browserEngine == BrowserEngine .webkit); // https://github.com/flutter/flutter/issues/50836
183+
131184 test ('can disable location strategy' , () async {
132185 // Disable URL strategy.
133186 expect (() => jsSetUrlStrategy (null ), returnsNormally);
0 commit comments