2019-11-16 11:41:30 +00:00
|
|
|
// Imports the Flutter Driver API.
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter_driver/flutter_driver.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
|
|
|
group('Flutter InAppBrowser', () {
|
|
|
|
FlutterDriver driver;
|
|
|
|
|
|
|
|
// Connect to the Flutter driver before running any tests.
|
|
|
|
setUpAll(() async {
|
|
|
|
driver = await FlutterDriver.connect();
|
2019-11-20 01:30:16 +00:00
|
|
|
await driver.setTextEntryEmulation(enabled: true);
|
2019-11-16 11:41:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Close the connection to the driver after the tests have completed.
|
|
|
|
tearDownAll(() async {
|
|
|
|
if (driver != null) {
|
|
|
|
driver.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//
|
|
|
|
// IMPORTANT NOTE!!!
|
|
|
|
// These tests need to follow the same order of "var routes" in "buildRoutes()" function
|
|
|
|
// defined in main_test.dart
|
|
|
|
//
|
|
|
|
|
2019-11-16 18:54:03 +00:00
|
|
|
test('InAppWebViewInitialUrlTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
2019-11-16 11:41:30 +00:00
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewInitialUrlTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = await driver.getText(appBarTitle);
|
|
|
|
expect(url, "https://flutter.dev/");
|
2019-11-16 18:54:03 +00:00
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
2019-11-16 11:41:30 +00:00
|
|
|
|
2019-11-16 18:54:03 +00:00
|
|
|
test('InAppWebViewInitialFileTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
2019-11-16 11:41:30 +00:00
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewInitialFileTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
expect(title, "true");
|
2019-11-16 18:54:03 +00:00
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
2019-11-16 11:41:30 +00:00
|
|
|
|
2019-11-16 18:54:03 +00:00
|
|
|
test('InAppWebViewOnLoadResourceTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
2019-11-16 11:41:30 +00:00
|
|
|
List<String> resourceList = [
|
|
|
|
"https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css",
|
|
|
|
"https://code.jquery.com/jquery-3.3.1.min.js",
|
|
|
|
"https://via.placeholder.com/100x50"
|
|
|
|
];
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewOnLoadResourceTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
for (String resource in resourceList) {
|
|
|
|
expect(true, title.contains(resource));
|
|
|
|
}
|
2019-11-16 18:54:03 +00:00
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
2019-11-16 11:41:30 +00:00
|
|
|
|
2019-11-16 18:54:03 +00:00
|
|
|
test('InAppWebViewJavaScriptHandlerTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
2019-11-16 11:41:30 +00:00
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewJavaScriptHandlerTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
expect(true, !title.contains("false"));
|
2019-11-16 18:54:03 +00:00
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
2019-11-16 11:41:30 +00:00
|
|
|
|
2019-11-16 18:54:03 +00:00
|
|
|
test('InAppWebViewAjaxTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
2019-11-16 11:41:30 +00:00
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewAjaxTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
expect(title, "Lorenzo Pichilli Lorenzo Pichilli");
|
2019-11-16 18:54:03 +00:00
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
|
|
|
test('InAppWebViewOnLoadResourceCustomSchemeTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewOnLoadResourceCustomSchemeTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
expect(title, "true");
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
|
|
|
test('InAppWebViewFetchTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewFetchTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
expect(true, title.contains("Lorenzo Pichilli") && title.contains("200"));
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
2019-11-17 17:31:31 +00:00
|
|
|
test('InAppWebViewShouldOverrideUrlLoadingTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewShouldOverrideUrlLoadingTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = await driver.getText(appBarTitle);
|
|
|
|
expect(url, "https://flutter.dev/");
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
|
|
|
test('InAppWebViewOnConsoleMessageTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewOnConsoleMessageTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
expect(title, "message LOG");
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
|
|
|
test('InAppWebViewOnDownloadStartTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewOnDownloadStartTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = await driver.getText(appBarTitle);
|
|
|
|
expect(url, "http://192.168.1.20:8082/test-download-file");
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
|
|
|
test('InAppWebViewOnTargetBlankTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewOnTargetBlankTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = await driver.getText(appBarTitle);
|
|
|
|
expect(url, "https://flutter.dev/");
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
2019-11-20 01:30:16 +00:00
|
|
|
test('InAppWebViewOnJsDialogTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
final alertButtonOk = find.byValueKey('AlertButtonOk');
|
|
|
|
final confirmButtonCancel = find.byValueKey('ConfirmButtonCancel');
|
|
|
|
final confirmButtonOk = find.byValueKey('ConfirmButtonOk');
|
|
|
|
final promptTextField = find.byValueKey('PromptTextField');
|
|
|
|
final promptButtonCancel = find.byValueKey('PromptButtonCancel');
|
|
|
|
final promptButtonOk = find.byValueKey('PromptButtonOk');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewOnJsDialogTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
await driver.tap(alertButtonOk);
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
expect(title, "alert");
|
|
|
|
|
|
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
|
|
|
|
|
|
await driver.tap(confirmButtonOk);
|
|
|
|
|
|
|
|
title = await driver.getText(appBarTitle);
|
|
|
|
expect(title, "confirm true");
|
|
|
|
|
|
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
|
|
|
|
|
|
await driver.tap(promptTextField);
|
|
|
|
await driver.enterText("new value");
|
|
|
|
await driver.waitFor(find.text("new value"));
|
|
|
|
|
|
|
|
await driver.tap(promptButtonOk);
|
|
|
|
|
|
|
|
title = await driver.getText(appBarTitle);
|
|
|
|
expect(title, "prompt new value");
|
|
|
|
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
2019-11-21 01:19:43 +00:00
|
|
|
test('InAppWebViewOnSafeBrowsingHitTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewOnSafeBrowsingHitTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = await driver.getText(appBarTitle);
|
|
|
|
expect(url, "chrome://safe-browsing/match?type=malware");
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
|
|
|
test('InAppWebViewOnReceivedHttpAuthRequestTest', () async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 2000));
|
|
|
|
final appBarTitle = find.byValueKey('AppBarTitle');
|
|
|
|
|
|
|
|
while((await driver.getText(appBarTitle)) == "InAppWebViewOnReceivedHttpAuthRequestTest") {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
String title = await driver.getText(appBarTitle);
|
|
|
|
expect(title, "Authorized");
|
|
|
|
}, timeout: new Timeout(new Duration(minutes: 5)));
|
|
|
|
|
2019-11-16 11:41:30 +00:00
|
|
|
});
|
|
|
|
}
|