Use direct dart API from dart:ui_web rather than JS shim. (#123443)
This is based off (and dependent on) these changes in the web engine that expose web-specific APIs: https://github.com/flutter/engine/pull/40608
This commit is contained in:
47
packages/flutter_web_plugins/test/navigation/common.dart
Normal file
47
packages/flutter_web_plugins/test/navigation/common.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2014 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:flutter_web_plugins/url_strategy.dart';
|
||||
|
||||
/// A mock implementation of [PlatformLocation] that doesn't access the browser.
|
||||
class TestPlatformLocation extends PlatformLocation {
|
||||
@override
|
||||
String pathname = '';
|
||||
|
||||
@override
|
||||
String search = '';
|
||||
|
||||
@override
|
||||
String hash = '';
|
||||
|
||||
@override
|
||||
Object? get state => null;
|
||||
|
||||
/// Mocks the base href of the document.
|
||||
String baseHref = '';
|
||||
|
||||
@override
|
||||
void addPopStateListener(EventListener fn) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
void removePopStateListener(EventListener fn) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
void pushState(Object? state, String title, String url) {}
|
||||
|
||||
@override
|
||||
void replaceState(Object? state, String title, String url) {}
|
||||
|
||||
@override
|
||||
void go(int count) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
String getBaseHref() => baseHref;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
@TestOn('!chrome')
|
||||
library;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
void main() {
|
||||
group('Non-web UrlStrategy', () {
|
||||
late TestPlatformLocation location;
|
||||
|
||||
setUp(() {
|
||||
location = TestPlatformLocation();
|
||||
});
|
||||
|
||||
test('Can create and set a $HashUrlStrategy', () {
|
||||
expect(() {
|
||||
final HashUrlStrategy strategy = HashUrlStrategy(location);
|
||||
setUrlStrategy(strategy);
|
||||
}, returnsNormally);
|
||||
});
|
||||
|
||||
test('Can create and set a $PathUrlStrategy', () {
|
||||
expect(() {
|
||||
final PathUrlStrategy strategy = PathUrlStrategy(location);
|
||||
setUrlStrategy(strategy);
|
||||
}, returnsNormally);
|
||||
});
|
||||
|
||||
test('Can usePathUrlStrategy', () {
|
||||
expect(() {
|
||||
usePathUrlStrategy();
|
||||
}, returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -6,7 +6,9 @@
|
||||
library;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
void main() {
|
||||
group('$HashUrlStrategy', () {
|
||||
@@ -142,45 +144,3 @@ void main() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// A mock implementation of [PlatformLocation] that doesn't access the browser.
|
||||
class TestPlatformLocation extends PlatformLocation {
|
||||
@override
|
||||
String pathname = '';
|
||||
|
||||
@override
|
||||
String search = '';
|
||||
|
||||
@override
|
||||
String hash = '';
|
||||
|
||||
@override
|
||||
Object? get state => null;
|
||||
|
||||
/// Mocks the base href of the document.
|
||||
String baseHref = '';
|
||||
|
||||
@override
|
||||
void addPopStateListener(EventListener fn) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
void removePopStateListener(EventListener fn) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
void pushState(Object? state, String title, String url) {}
|
||||
|
||||
@override
|
||||
void replaceState(Object? state, String title, String url) {}
|
||||
|
||||
@override
|
||||
void go(int count) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
String getBaseHref() => baseHref;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user