Skip to content

Commit

Permalink
[webview_flutter_android] Add test that onReceivedHttpAuthRequest i…
Browse files Browse the repository at this point in the history
…s cancelled by default (flutter#5723)

Added test in response to feedback from flutter#5454 (review)

Also regenerates mock files.
  • Loading branch information
bparrishMines authored and arc-yong committed Jun 14, 2024
1 parent ecff1af commit 3aacdfa
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
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);
}

0 comments on commit 3aacdfa

Please sign in to comment.