Skip to content

Commit dea6c73

Browse files
[webview_flutter_android] Add test that onReceivedHttpAuthRequest is cancelled by default (flutter#5723)
Added test in response to feedback from flutter/packages#5454 (review) Also regenerates mock files.
1 parent 6abb0dd commit dea6c73

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66

77
import 'package:flutter_test/flutter_test.dart';
88
import 'package:mockito/annotations.dart';
9+
import 'package:mockito/mockito.dart';
910
import 'package:webview_flutter_android/src/android_proxy.dart';
1011
import 'package:webview_flutter_android/src/android_webview.dart'
1112
as android_webview;
@@ -15,7 +16,10 @@ import 'package:webview_flutter_platform_interface/webview_flutter_platform_inte
1516
import 'android_navigation_delegate_test.mocks.dart';
1617
import 'test_android_webview.g.dart';
1718

18-
@GenerateMocks(<Type>[TestInstanceManagerHostApi])
19+
@GenerateMocks(<Type>[
20+
TestInstanceManagerHostApi,
21+
android_webview.HttpAuthHandler,
22+
])
1923
void main() {
2024
TestWidgetsFlutterBinding.ensureInitialized();
2125

@@ -492,6 +496,21 @@ void main() {
492496
expect(callbackHost, expectedHost);
493497
expect(callbackRealm, expectedRealm);
494498
});
499+
500+
test('onReceivedHttpAuthRequest calls cancel by default', () {
501+
AndroidNavigationDelegate(_buildCreationParams());
502+
503+
final MockHttpAuthHandler mockAuthHandler = MockHttpAuthHandler();
504+
505+
CapturingWebViewClient.lastCreatedDelegate.onReceivedHttpAuthRequest!(
506+
android_webview.WebView.detached(),
507+
mockAuthHandler,
508+
'host',
509+
'realm',
510+
);
511+
512+
verify(mockAuthHandler.cancel());
513+
});
495514
});
496515
}
497516

packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
// Do not manually edit this file.
44

55
// ignore_for_file: no_leading_underscores_for_library_prefixes
6+
import 'dart:async' as _i4;
7+
68
import 'package:mockito/mockito.dart' as _i1;
9+
import 'package:webview_flutter_android/src/android_webview.dart' as _i2;
710

8-
import 'test_android_webview.g.dart' as _i2;
11+
import 'test_android_webview.g.dart' as _i3;
912

1013
// ignore_for_file: type=lint
1114
// ignore_for_file: avoid_redundant_argument_values
@@ -20,11 +23,21 @@ import 'test_android_webview.g.dart' as _i2;
2023
// ignore_for_file: camel_case_types
2124
// ignore_for_file: subtype_of_sealed_class
2225

26+
class _FakeJavaObject_0 extends _i1.SmartFake implements _i2.JavaObject {
27+
_FakeJavaObject_0(
28+
Object parent,
29+
Invocation parentInvocation,
30+
) : super(
31+
parent,
32+
parentInvocation,
33+
);
34+
}
35+
2336
/// A class which mocks [TestInstanceManagerHostApi].
2437
///
2538
/// See the documentation for Mockito's code generation for more information.
2639
class MockTestInstanceManagerHostApi extends _i1.Mock
27-
implements _i2.TestInstanceManagerHostApi {
40+
implements _i3.TestInstanceManagerHostApi {
2841
MockTestInstanceManagerHostApi() {
2942
_i1.throwOnMissingStub(this);
3043
}
@@ -38,3 +51,63 @@ class MockTestInstanceManagerHostApi extends _i1.Mock
3851
returnValueForMissingStub: null,
3952
);
4053
}
54+
55+
/// A class which mocks [HttpAuthHandler].
56+
///
57+
/// See the documentation for Mockito's code generation for more information.
58+
class MockHttpAuthHandler extends _i1.Mock implements _i2.HttpAuthHandler {
59+
MockHttpAuthHandler() {
60+
_i1.throwOnMissingStub(this);
61+
}
62+
63+
@override
64+
_i4.Future<void> cancel() => (super.noSuchMethod(
65+
Invocation.method(
66+
#cancel,
67+
[],
68+
),
69+
returnValue: _i4.Future<void>.value(),
70+
returnValueForMissingStub: _i4.Future<void>.value(),
71+
) as _i4.Future<void>);
72+
73+
@override
74+
_i4.Future<void> proceed(
75+
String? username,
76+
String? password,
77+
) =>
78+
(super.noSuchMethod(
79+
Invocation.method(
80+
#proceed,
81+
[
82+
username,
83+
password,
84+
],
85+
),
86+
returnValue: _i4.Future<void>.value(),
87+
returnValueForMissingStub: _i4.Future<void>.value(),
88+
) as _i4.Future<void>);
89+
90+
@override
91+
_i4.Future<bool> useHttpAuthUsernamePassword() => (super.noSuchMethod(
92+
Invocation.method(
93+
#useHttpAuthUsernamePassword,
94+
[],
95+
),
96+
returnValue: _i4.Future<bool>.value(false),
97+
) as _i4.Future<bool>);
98+
99+
@override
100+
_i2.JavaObject copy() => (super.noSuchMethod(
101+
Invocation.method(
102+
#copy,
103+
[],
104+
),
105+
returnValue: _FakeJavaObject_0(
106+
this,
107+
Invocation.method(
108+
#copy,
109+
[],
110+
),
111+
),
112+
) as _i2.JavaObject);
113+
}

0 commit comments

Comments
 (0)