[web] Use PlatformLocation from ui_web (#126851)
Remove the following APIs and export them directly from `dart:ui_web`: - `urlStrategy` getter and setter - `HashUrlStrategy` - `PlatformLocation` and `BrowserPlatformLocation` (keep the façades for non-web platforms) Depends on https://github.com/flutter/engine/pull/42043 Depends on https://github.com/flutter/engine/pull/42252 Part of https://github.com/flutter/flutter/issues/126831
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
|
||||
/// A mock implementation of [PlatformLocation] that doesn't access the browser.
|
||||
class TestPlatformLocation extends PlatformLocation {
|
||||
class TestPlatformLocation implements PlatformLocation {
|
||||
@override
|
||||
String pathname = '';
|
||||
|
||||
|
||||
@@ -11,60 +11,6 @@ import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
import 'common.dart';
|
||||
|
||||
void main() {
|
||||
group('$HashUrlStrategy', () {
|
||||
late TestPlatformLocation location;
|
||||
|
||||
setUp(() {
|
||||
location = TestPlatformLocation();
|
||||
});
|
||||
|
||||
test('allows null state', () {
|
||||
final HashUrlStrategy strategy = HashUrlStrategy(location);
|
||||
expect(() => strategy.pushState(null, '', '/'), returnsNormally);
|
||||
expect(() => strategy.replaceState(null, '', '/'), returnsNormally);
|
||||
});
|
||||
|
||||
test('leading slash is optional', () {
|
||||
final HashUrlStrategy strategy = HashUrlStrategy(location);
|
||||
|
||||
location.hash = '#/';
|
||||
expect(strategy.getPath(), '/');
|
||||
|
||||
location.hash = '#/foo';
|
||||
expect(strategy.getPath(), '/foo');
|
||||
|
||||
location.hash = '#foo';
|
||||
expect(strategy.getPath(), 'foo');
|
||||
});
|
||||
|
||||
test('path should not be empty', () {
|
||||
final HashUrlStrategy strategy = HashUrlStrategy(location);
|
||||
|
||||
location.hash = '';
|
||||
expect(strategy.getPath(), '/');
|
||||
|
||||
location.hash = '#';
|
||||
expect(strategy.getPath(), '/');
|
||||
});
|
||||
|
||||
test('allows location path/search before fragment', () {
|
||||
const String internalUrl = '/menu?foo=bar';
|
||||
final HashUrlStrategy strategy = HashUrlStrategy(location);
|
||||
|
||||
location.pathname = '/';
|
||||
expect(strategy.prepareExternalUrl(internalUrl), '/#/menu?foo=bar');
|
||||
|
||||
location.pathname = '/main';
|
||||
expect(strategy.prepareExternalUrl(internalUrl), '/main#/menu?foo=bar');
|
||||
|
||||
location.search = '?foo=bar';
|
||||
expect(
|
||||
strategy.prepareExternalUrl(internalUrl),
|
||||
'/main?foo=bar#/menu?foo=bar',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('$PathUrlStrategy', () {
|
||||
late TestPlatformLocation location;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user