forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webview_flutter_android] Adds support for use of old hybrid composit…
…ion (flutter#6063)
- Loading branch information
1 parent
69deb8f
commit 81f6ab8
Showing
4 changed files
with
171 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/webview_flutter/webview_flutter_android/test/surface_android_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:webview_flutter_android/webview_surface_android.dart'; | ||
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group('SurfaceAndroidWebView', () { | ||
late List<MethodCall> log; | ||
|
||
setUpAll(() { | ||
SystemChannels.platform_views.setMockMethodCallHandler( | ||
(MethodCall call) async { | ||
log.add(call); | ||
if (call.method == 'resize') { | ||
return <String, Object?>{ | ||
'width': call.arguments['width'], | ||
'height': call.arguments['height'], | ||
}; | ||
} | ||
}, | ||
); | ||
}); | ||
|
||
tearDownAll(() { | ||
SystemChannels.platform_views.setMockMethodCallHandler(null); | ||
}); | ||
|
||
setUp(() { | ||
log = <MethodCall>[]; | ||
}); | ||
|
||
testWidgets( | ||
'uses hybrid composition when background color is not 100% opaque', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget(Builder(builder: (BuildContext context) { | ||
return SurfaceAndroidWebView().build( | ||
context: context, | ||
creationParams: CreationParams( | ||
backgroundColor: Colors.transparent, | ||
webSettings: WebSettings( | ||
userAgent: const WebSetting<String?>.absent(), | ||
hasNavigationDelegate: false, | ||
)), | ||
javascriptChannelRegistry: JavascriptChannelRegistry(null), | ||
webViewPlatformCallbacksHandler: | ||
TestWebViewPlatformCallbacksHandler(), | ||
); | ||
})); | ||
await tester.pumpAndSettle(); | ||
|
||
final MethodCall createMethodCall = log[0]; | ||
expect(createMethodCall.method, 'create'); | ||
expect(createMethodCall.arguments, containsPair('hybrid', true)); | ||
}); | ||
|
||
testWidgets('default text direction is ltr', (WidgetTester tester) async { | ||
await tester.pumpWidget(Builder(builder: (BuildContext context) { | ||
return SurfaceAndroidWebView().build( | ||
context: context, | ||
creationParams: CreationParams( | ||
webSettings: WebSettings( | ||
userAgent: const WebSetting<String?>.absent(), | ||
hasNavigationDelegate: false, | ||
)), | ||
javascriptChannelRegistry: JavascriptChannelRegistry(null), | ||
webViewPlatformCallbacksHandler: | ||
TestWebViewPlatformCallbacksHandler(), | ||
); | ||
})); | ||
await tester.pumpAndSettle(); | ||
|
||
final MethodCall createMethodCall = log[0]; | ||
expect(createMethodCall.method, 'create'); | ||
expect( | ||
createMethodCall.arguments, | ||
containsPair( | ||
'direction', | ||
AndroidViewController.kAndroidLayoutDirectionLtr, | ||
), | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
class TestWebViewPlatformCallbacksHandler | ||
implements WebViewPlatformCallbacksHandler { | ||
@override | ||
FutureOr<bool> onNavigationRequest({ | ||
required String url, | ||
required bool isForMainFrame, | ||
}) { | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
void onPageFinished(String url) {} | ||
|
||
@override | ||
void onPageStarted(String url) {} | ||
|
||
@override | ||
void onProgress(int progress) {} | ||
|
||
@override | ||
void onWebResourceError(WebResourceError error) {} | ||
} |