diff --git a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart index 3b407a8d65f..c9a7e8ddcbe 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart @@ -6,6 +6,7 @@ import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; import 'package:webview_flutter_android/src/android_proxy.dart'; import 'package:webview_flutter_android/src/android_webview.dart' as android_webview; @@ -15,7 +16,10 @@ import 'package:webview_flutter_platform_interface/webview_flutter_platform_inte import 'android_navigation_delegate_test.mocks.dart'; import 'test_android_webview.g.dart'; -@GenerateMocks([TestInstanceManagerHostApi]) +@GenerateMocks([ + TestInstanceManagerHostApi, + android_webview.HttpAuthHandler, +]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -492,6 +496,21 @@ void main() { expect(callbackHost, expectedHost); expect(callbackRealm, expectedRealm); }); + + test('onReceivedHttpAuthRequest calls cancel by default', () { + AndroidNavigationDelegate(_buildCreationParams()); + + final MockHttpAuthHandler mockAuthHandler = MockHttpAuthHandler(); + + CapturingWebViewClient.lastCreatedDelegate.onReceivedHttpAuthRequest!( + android_webview.WebView.detached(), + mockAuthHandler, + 'host', + 'realm', + ); + + verify(mockAuthHandler.cancel()); + }); }); } diff --git a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart index a02c47065a4..ee783f3777c 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart @@ -3,9 +3,12 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i4; + import 'package:mockito/mockito.dart' as _i1; +import 'package:webview_flutter_android/src/android_webview.dart' as _i2; -import 'test_android_webview.g.dart' as _i2; +import 'test_android_webview.g.dart' as _i3; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -20,11 +23,21 @@ import 'test_android_webview.g.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +class _FakeJavaObject_0 extends _i1.SmartFake implements _i2.JavaObject { + _FakeJavaObject_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + /// A class which mocks [TestInstanceManagerHostApi]. /// /// See the documentation for Mockito's code generation for more information. class MockTestInstanceManagerHostApi extends _i1.Mock - implements _i2.TestInstanceManagerHostApi { + implements _i3.TestInstanceManagerHostApi { MockTestInstanceManagerHostApi() { _i1.throwOnMissingStub(this); } @@ -38,3 +51,63 @@ class MockTestInstanceManagerHostApi extends _i1.Mock returnValueForMissingStub: null, ); } + +/// A class which mocks [HttpAuthHandler]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockHttpAuthHandler extends _i1.Mock implements _i2.HttpAuthHandler { + MockHttpAuthHandler() { + _i1.throwOnMissingStub(this); + } + + @override + _i4.Future cancel() => (super.noSuchMethod( + Invocation.method( + #cancel, + [], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + + @override + _i4.Future proceed( + String? username, + String? password, + ) => + (super.noSuchMethod( + Invocation.method( + #proceed, + [ + username, + password, + ], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + + @override + _i4.Future useHttpAuthUsernamePassword() => (super.noSuchMethod( + Invocation.method( + #useHttpAuthUsernamePassword, + [], + ), + returnValue: _i4.Future.value(false), + ) as _i4.Future); + + @override + _i2.JavaObject copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeJavaObject_0( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.JavaObject); +}