-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[webview_flutter_platform_interface] Add support for getting cookie #11037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
| Future<List<WebViewCookie>> getCookies(Uri url) { | ||
| throw UnimplementedError( | ||
| 'getCookies is not implemented on the current platform', | ||
| ); | ||
| } | ||
|
Comment on lines
+70
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The repository's contribution guide requires that code changes are tested. Please add a unit test for the new References
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| 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(); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.