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:
Jackson Gardner
2023-05-05 11:17:21 -07:00
committed by GitHub
parent 042eaf6b90
commit 201f7311f7
9 changed files with 174 additions and 270 deletions

View 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;
}

View File

@@ -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);
});
});
}

View File

@@ -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;
}