98 lines
2.4 KiB
Dart
98 lines
2.4 KiB
Dart
import 'dart:async';
|
|
import 'dart:collection';
|
|
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// Returns a matcher that matches the isNullOrEmpty property.
|
|
const Matcher isNullOrEmpty = _NullOrEmpty();
|
|
|
|
class _NullOrEmpty extends Matcher {
|
|
const _NullOrEmpty();
|
|
|
|
@override
|
|
bool matches(Object? item, Map matchState) =>
|
|
item == null || (item as dynamic).isEmpty;
|
|
|
|
@override
|
|
Description describe(Description description) =>
|
|
description.add('null or empty');
|
|
}
|
|
|
|
class Foo {
|
|
String? bar;
|
|
String? baz;
|
|
|
|
Foo({this.bar, this.baz});
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {'bar': this.bar, 'baz': this.baz};
|
|
}
|
|
}
|
|
|
|
class MyInAppBrowser extends InAppBrowser {
|
|
final Completer<void> browserCreated = Completer<void>();
|
|
final Completer<void> firstPageLoaded = Completer<void>();
|
|
|
|
MyInAppBrowser(
|
|
{int? windowId, UnmodifiableListView<UserScript>? initialUserScripts})
|
|
: super(windowId: windowId, initialUserScripts: initialUserScripts);
|
|
|
|
@override
|
|
Future onBrowserCreated() async {
|
|
browserCreated.complete();
|
|
}
|
|
|
|
@override
|
|
void onLoadStop(WebUri? url) {
|
|
super.onLoadStop(url);
|
|
|
|
if (!firstPageLoaded.isCompleted) {
|
|
firstPageLoaded.complete();
|
|
}
|
|
}
|
|
}
|
|
|
|
class MyChromeSafariBrowser extends ChromeSafariBrowser {
|
|
final Completer<void> serviceConnected = Completer<void>();
|
|
final Completer<void> opened = Completer<void>();
|
|
final Completer<bool?> firstPageLoaded = Completer<bool?>();
|
|
final Completer<void> closed = Completer<void>();
|
|
final Completer<CustomTabsNavigationEventType?> navigationEvent =
|
|
Completer<CustomTabsNavigationEventType?>();
|
|
final Completer<bool> relationshipValidationResult = Completer<bool>();
|
|
|
|
@override
|
|
void onServiceConnected() {
|
|
serviceConnected.complete();
|
|
}
|
|
|
|
@override
|
|
void onOpened() {
|
|
opened.complete();
|
|
}
|
|
|
|
@override
|
|
void onCompletedInitialLoad(didLoadSuccessfully) {
|
|
firstPageLoaded.complete(didLoadSuccessfully);
|
|
}
|
|
|
|
@override
|
|
void onNavigationEvent(CustomTabsNavigationEventType? type) {
|
|
if (!navigationEvent.isCompleted) {
|
|
navigationEvent.complete(type);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onRelationshipValidationResult(
|
|
CustomTabsRelationType? relation, Uri? requestedOrigin, bool result) {
|
|
relationshipValidationResult.complete(result);
|
|
}
|
|
|
|
@override
|
|
void onClosed() {
|
|
closed.complete();
|
|
}
|
|
}
|