iosWebViewFix/example/integration_test/cookie_manager/set_get_delete.dart

73 lines
2.4 KiB
Dart
Raw Normal View History

part of 'main.dart';
2022-04-28 21:23:38 +00:00
void setGetDelete() {
2022-04-29 00:07:01 +00:00
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
2022-04-28 21:23:38 +00:00
skippableTestWidgets('set, get, delete', (WidgetTester tester) async {
2022-04-28 21:23:38 +00:00
CookieManager cookieManager = CookieManager.instance();
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 21:23:38 +00:00
final Completer<String> pageLoaded = Completer<String>();
var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) async {
pageLoaded.complete(url!.toString());
});
if (defaultTargetPlatform == TargetPlatform.macOS) {
await headlessWebView.run();
} else {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
initialSettings: InAppWebViewSettings(
clearCache: true,
),
onLoadStop: (controller, url) {
pageLoaded.complete(url!.toString());
},
2022-04-29 00:07:01 +00:00
),
2022-04-28 21:23:38 +00:00
),
);
}
2022-04-28 21:23:38 +00:00
final url = WebUri(await pageLoaded.future);
2022-04-28 21:23:38 +00:00
2022-04-29 00:07:01 +00:00
await cookieManager.setCookie(url: url, name: "myCookie", value: "myValue");
2022-04-28 21:23:38 +00:00
List<Cookie> cookies = await cookieManager.getCookies(url: url);
expect(cookies, isNotEmpty);
2022-04-29 00:07:01 +00:00
Cookie? cookie = await cookieManager.getCookie(url: url, name: "myCookie");
2022-04-28 21:23:38 +00:00
expect(cookie?.value.toString(), "myValue");
await cookieManager.deleteCookie(url: url, name: "myCookie");
cookie = await cookieManager.getCookie(url: url, name: "myCookie");
expect(cookie, isNull);
2022-10-14 00:28:23 +00:00
await cookieManager.deleteCookies(
url: url, domain: ".${TEST_CROSS_PLATFORM_URL_1.host}");
2022-04-28 21:23:38 +00:00
cookies = await cookieManager.getCookies(url: url);
expect(cookies, isEmpty);
if (defaultTargetPlatform == TargetPlatform.macOS) {
headlessWebView.dispose();
}
2022-04-28 21:23:38 +00:00
}, skip: shouldSkip);
}