Skip to content
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

[webview_flutter_android] Add test that onReceivedHttpAuthRequest is cancelled by default #5723

Merged
merged 2 commits into from
Jan 13, 2024
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
Expand Up @@ -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;
Expand All @@ -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(<Type>[TestInstanceManagerHostApi])
@GenerateMocks(<Type>[
TestInstanceManagerHostApi,
android_webview.HttpAuthHandler,
])
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -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());
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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<void> cancel() => (super.noSuchMethod(
Invocation.method(
#cancel,
[],
),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);

@override
_i4.Future<void> proceed(
String? username,
String? password,
) =>
(super.noSuchMethod(
Invocation.method(
#proceed,
[
username,
password,
],
),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);

@override
_i4.Future<bool> useHttpAuthUsernamePassword() => (super.noSuchMethod(
Invocation.method(
#useHttpAuthUsernamePassword,
[],
),
returnValue: _i4.Future<bool>.value(false),
) as _i4.Future<bool>);

@override
_i2.JavaObject copy() => (super.noSuchMethod(
Invocation.method(
#copy,
[],
),
returnValue: _FakeJavaObject_0(
this,
Invocation.method(
#copy,
[],
),
),
) as _i2.JavaObject);
}