@@ -960,54 +960,51 @@ void main() {
960
960
961
961
final WebViewController controller = await controllerCompleter.future;
962
962
await pageLoaded.future;
963
-
964
- final String viewportRectJSON = await controller.evaluateJavascript (
965
- 'JSON.stringify(viewport.getBoundingClientRect())' );
963
+ final String viewportRectJSON = await _evaluateJavascript (
964
+ controller, 'JSON.stringify(viewport.getBoundingClientRect())' );
966
965
final Map <String , dynamic > viewportRectRelativeToViewport =
967
- jsonDecode (jsonDecode ( viewportRectJSON) );
966
+ jsonDecode (viewportRectJSON);
968
967
969
968
// Check that the input is originally outside of the viewport.
970
- {
971
- final String inputClientRectJSON = await controller.evaluateJavascript (
972
- 'JSON.stringify(inputEl.getBoundingClientRect())' );
973
- final Map <String , dynamic > inputClientRectRelativeToViewport =
974
- jsonDecode (jsonDecode (inputClientRectJSON));
975
-
976
- expect (
977
- inputClientRectRelativeToViewport['bottom' ] <=
978
- viewportRectRelativeToViewport['bottom' ],
979
- isFalse);
980
- }
969
+
970
+ final String initialInputClientRectJSON = await _evaluateJavascript (
971
+ controller, 'JSON.stringify(inputEl.getBoundingClientRect())' );
972
+ final Map <String , dynamic > initialInputClientRectRelativeToViewport =
973
+ jsonDecode (initialInputClientRectJSON);
974
+
975
+ expect (
976
+ initialInputClientRectRelativeToViewport['bottom' ] <=
977
+ viewportRectRelativeToViewport['bottom' ],
978
+ isFalse);
981
979
982
980
await controller.evaluateJavascript ('inputEl.focus()' );
983
981
984
982
// Check that focusing the input brought it into view.
985
- {
986
- final String inputClientRectJSON = await controller.evaluateJavascript (
987
- 'JSON.stringify(inputEl.getBoundingClientRect())' );
988
- final Map <String , dynamic > inputClientRectRelativeToViewport =
989
- jsonDecode (jsonDecode (inputClientRectJSON));
990
-
991
- expect (
992
- inputClientRectRelativeToViewport['top' ] >=
993
- viewportRectRelativeToViewport['top' ],
994
- isTrue);
995
- expect (
996
- inputClientRectRelativeToViewport['bottom' ] <=
997
- viewportRectRelativeToViewport['bottom' ],
998
- isTrue);
999
983
1000
- expect (
1001
- inputClientRectRelativeToViewport['left' ] >=
1002
- viewportRectRelativeToViewport['left' ],
1003
- isTrue);
1004
- expect (
1005
- inputClientRectRelativeToViewport['right' ] <=
1006
- viewportRectRelativeToViewport['right' ],
1007
- isTrue);
1008
- }
984
+ final String lastInputClientRectJSON = await _evaluateJavascript (
985
+ controller, 'JSON.stringify(inputEl.getBoundingClientRect())' );
986
+ final Map <String , dynamic > lastInputClientRectRelativeToViewport =
987
+ jsonDecode (lastInputClientRectJSON);
988
+
989
+ expect (
990
+ lastInputClientRectRelativeToViewport['top' ] >=
991
+ viewportRectRelativeToViewport['top' ],
992
+ isTrue);
993
+ expect (
994
+ lastInputClientRectRelativeToViewport['bottom' ] <=
995
+ viewportRectRelativeToViewport['bottom' ],
996
+ isTrue);
997
+
998
+ expect (
999
+ lastInputClientRectRelativeToViewport['left' ] >=
1000
+ viewportRectRelativeToViewport['left' ],
1001
+ isTrue);
1002
+ expect (
1003
+ lastInputClientRectRelativeToViewport['right' ] <=
1004
+ viewportRectRelativeToViewport['right' ],
1005
+ isTrue);
1009
1006
});
1010
- }, skip: defaultTargetPlatform != TargetPlatform .android );
1007
+ }, skip: ! Platform .isAndroid );
1011
1008
1012
1009
group ('NavigationDelegate' , () {
1013
1010
final String blankPage = "<!DOCTYPE html><head></head><body></body></html>" ;
@@ -1074,7 +1071,8 @@ void main() {
1074
1071
expect (error.failingUrl, isNull);
1075
1072
} else if (Platform .isAndroid) {
1076
1073
expect (error.errorType, isNotNull);
1077
- expect (error.failingUrl, 'https://www.notawebsite..com' );
1074
+ expect (error.failingUrl.startsWith ('https://www.notawebsite..com' ),
1075
+ isTrue);
1078
1076
}
1079
1077
});
1080
1078
@@ -1261,7 +1259,7 @@ void main() {
1261
1259
await controller.goBack ();
1262
1260
expect (controller.currentUrl (), completion ('https://www.flutter.dev' ));
1263
1261
},
1264
- skip: defaultTargetPlatform != TargetPlatform .android ,
1262
+ skip: ! Platform .isAndroid ,
1265
1263
);
1266
1264
1267
1265
testWidgets (
@@ -1329,7 +1327,7 @@ void main() {
1329
1327
completion ('null' ),
1330
1328
);
1331
1329
},
1332
- skip: defaultTargetPlatform != TargetPlatform .android ,
1330
+ skip: ! Platform .isAndroid ,
1333
1331
);
1334
1332
}
1335
1333
@@ -1344,9 +1342,13 @@ String _webviewBool(bool value) {
1344
1342
1345
1343
/// Returns the value used for the HTTP User-Agent: request header in subsequent HTTP requests.
1346
1344
Future <String > _getUserAgent (WebViewController controller) async {
1345
+ return _evaluateJavascript (controller, 'navigator.userAgent;' );
1346
+ }
1347
+
1348
+ Future <String > _evaluateJavascript (
1349
+ WebViewController controller, String js) async {
1347
1350
if (defaultTargetPlatform == TargetPlatform .iOS) {
1348
- return await controller.evaluateJavascript ('navigator.userAgent;' );
1351
+ return await controller.evaluateJavascript (js );
1349
1352
}
1350
- return jsonDecode (
1351
- await controller.evaluateJavascript ('navigator.userAgent;' ));
1353
+ return jsonDecode (await controller.evaluateJavascript (js));
1352
1354
}
0 commit comments