Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.15.0

* Adds support to retrieve WebView cookies. See `PlatformWebViewCookieManager.getCookies`.
* Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.

## 2.14.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ abstract class PlatformWebViewCookieManager extends PlatformInterface {
'setCookie is not implemented on the current platform',
);
}

/// Returns a list of existing cookies for the specified domain from all
/// [WebView] instances of the application.
Comment thread
bparrishMines marked this conversation as resolved.
Future<List<WebViewCookie>> getCookies(Uri url) {
throw UnimplementedError(
'getCookies is not implemented on the current platform',
);
}
Comment on lines +70 to +74
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The repository's contribution guide requires that code changes are tested. Please add a unit test for the new getCookies method to verify that its default implementation throws an UnimplementedError.

References
  1. The style guide states that code should be tested. (link)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this in the original PR, but this is actually missing a test. Though it looks like test/platform_webview_cookie_manager_test.dart was never created, so you will need to create a new test file. You can follow the pattern of test/platform_webview_controller_test.dart.

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ class WebViewCookie {
/// Its value should match "path-value" in RFC6265bis:
/// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1
final String path;

@override
String toString() {
return 'WebViewCookie{name: $name, value: $value, domain: $domain, path: $path}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/webview_flutt
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.14.0
version: 2.15.0

environment:
sdk: ^3.9.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';

import 'webview_platform_test.mocks.dart';

void main() {
setUp(() {
WebViewPlatform.instance = MockWebViewPlatformWithMixin();
});

test('Cannot be implemented with `implements`', () {
when(
(WebViewPlatform.instance! as MockWebViewPlatform)
.createPlatformCookieManager(any),
).thenReturn(ImplementsPlatformWebViewCookieManager());

expect(() {
PlatformWebViewCookieManager(
const PlatformWebViewCookieManagerCreationParams(),
);
// In versions of `package:plugin_platform_interface` prior to fixing
// https://github.com/flutter/flutter/issues/109339, an attempt to
// implement a platform interface using `implements` would sometimes throw
// a `NoSuchMethodError` and other times throw an `AssertionError`. After
// the issue is fixed, an `AssertionError` will always be thrown. For the
// purpose of this test, we don't really care what exception is thrown, so
// just allow any exception.
}, throwsA(anything));
});

test('Can be extended', () {
const params = PlatformWebViewCookieManagerCreationParams();
when(
(WebViewPlatform.instance! as MockWebViewPlatform)
.createPlatformCookieManager(any),
).thenReturn(ExtendsPlatformWebViewCookieManager(params));

expect(PlatformWebViewCookieManager(params), isNotNull);
});

test('Can be mocked with `implements`', () {
when(
(WebViewPlatform.instance! as MockWebViewPlatform)
.createPlatformCookieManager(any),
).thenReturn(MockWebViewCookieManagerDelegate());

expect(
PlatformWebViewCookieManager(
const PlatformWebViewCookieManagerCreationParams(),
),
isNotNull,
);
});

test(
'Default implementation of clearCookies should throw unimplemented error',
() {
final PlatformWebViewCookieManager cookieManager =
ExtendsPlatformWebViewCookieManager(
const PlatformWebViewCookieManagerCreationParams(),
);

expect(() => cookieManager.clearCookies(), throwsUnimplementedError);
},
);

test(
'Default implementation of setCookie should throw unimplemented error',
() {
final PlatformWebViewCookieManager cookieManager =
ExtendsPlatformWebViewCookieManager(
const PlatformWebViewCookieManagerCreationParams(),
);

expect(
() => cookieManager.setCookie(
const WebViewCookie(name: 'foo', value: 'bar', domain: 'flutter.dev'),
),
throwsUnimplementedError,
);
},
);

test(
'Default implementation of getCookies should throw unimplemented error',
() {
final PlatformWebViewCookieManager cookieManager =
ExtendsPlatformWebViewCookieManager(
const PlatformWebViewCookieManagerCreationParams(),
);

expect(
() => cookieManager.getCookies(Uri.parse('https://flutter.dev')),
throwsUnimplementedError,
);
},
);
}

class MockWebViewPlatformWithMixin extends MockWebViewPlatform
with
// ignore: prefer_mixin
MockPlatformInterfaceMixin {}

class ImplementsPlatformWebViewCookieManager
implements PlatformWebViewCookieManager {
@override
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

class MockWebViewCookieManagerDelegate extends Mock
with
// ignore: prefer_mixin
MockPlatformInterfaceMixin
implements PlatformWebViewCookieManager {}

class ExtendsPlatformWebViewCookieManager extends PlatformWebViewCookieManager {
ExtendsPlatformWebViewCookieManager(super.params) : super.implementation();
}
Loading