Commit dce31242 authored by 1/2's avatar 1/2 Committed by GitHub

Merge pull request #2 from pichillilorenzo/master

origin
parents fead4fb2 8894ae1b
This diff is collapsed.
......@@ -567,10 +567,17 @@ public class InAppWebViewClient extends WebViewClient {
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage());
return null;
} catch (URISyntaxException uriExpection) {
String[] urlSplitted = url.split(":");
String scheme = urlSplitted[0];
try {
URL tempUrl = new URL(url.replace(scheme, "https"));
uri = new URI(scheme, tempUrl.getUserInfo(), tempUrl.getHost(), tempUrl.getPort(), tempUrl.getPath(), tempUrl.getQuery(), tempUrl.getRef());
} catch (Exception e) {
e.printStackTrace();
Log.d(LOG_TAG, e.getMessage());
return null;
}
}
String scheme = uri.getScheme();
......
......@@ -25,9 +25,6 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
InAppWebViewController webView;
String url = "";
double progress = 0;
@override
void initState() {
......
......@@ -26,6 +26,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
ansicolor: 1.0.2
flutter_inappbrowser:
path: ../
......
import 'package:ansicolor/ansicolor.dart';
import 'package:flutter/widgets.dart';
class WidgetTest extends StatefulWidget {
final String name;
WidgetTest({this.name, Key key}): super(key: key) {
AnsiPen pen = new AnsiPen()..white()..rgb(r: 1.0, g: 0.8, b: 0.2);
print("\n");
print(pen("'" + this.name + "' test loading..."));
print("\n");
}
@override
State<StatefulWidget> createState() {
return null;
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
import 'util_test.dart';
import 'custom_widget_test.dart';
class InAppWebViewInitialFileTest extends WidgetTest {
InAppWebViewInitialFileTest(): super(name: "InAppWebViewInitialFileTest");
@override
_InAppWebViewInitialFileTestState createState() => new _InAppWebViewInitialFileTestState();
}
class _InAppWebViewInitialFileTestState extends State<InAppWebViewInitialFileTest> {
InAppWebViewController webView;
String initialUrl = "https://flutter.dev/";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('InAppWebViewInitialFileTest'),
),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialFile: "assets/index.html",
initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions(),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
},
onLoadStop: (InAppWebViewController controller, String url) {
customAssert(widget: widget, name: "initialFile", value: true);
nextTest(context: context);
},
),
),
),
])
)
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
import 'util_test.dart';
import 'custom_widget_test.dart';
class InAppWebViewInitialUrlTest extends WidgetTest {
InAppWebViewInitialUrlTest(): super(name: "InAppWebViewInitialUrlTest");
@override
_InAppWebViewInitialUrlTestState createState() => new _InAppWebViewInitialUrlTestState();
}
class _InAppWebViewInitialUrlTestState extends State<InAppWebViewInitialUrlTest> {
InAppWebViewController webView;
String initialUrl = "https://flutter.dev/";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('InAppWebViewInitialUrlTest'),
),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialUrl: initialUrl,
initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions(),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
},
onLoadStop: (InAppWebViewController controller, String url) {
customAssert(widget: widget, name: "initialUrl", value: url == initialUrl);
nextTest(context: context);
},
),
),
),
])
)
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
import 'util_test.dart';
import 'custom_widget_test.dart';
class InAppWebViewOnLoadResourceTest extends WidgetTest {
InAppWebViewOnLoadResourceTest(): super(name: "InAppWebViewOnLoadResourceTest");
@override
_InAppWebViewOnLoadResourceTestState createState() => new _InAppWebViewOnLoadResourceTestState();
}
class _InAppWebViewOnLoadResourceTestState extends State<InAppWebViewOnLoadResourceTest> {
InAppWebViewController webView;
List<String> resourceList = [
"http://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"
];
int countResources = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('InAppWebViewOnLoadResourceTest'),
),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialFile: "assets/index.html",
initialHeaders: {},
initialOptions: InAppWebViewWidgetOptions(
inAppWebViewOptions: InAppWebViewOptions(
clearCache: true,
useOnLoadResource: true
)
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
},
onLoadStop: (InAppWebViewController controller, String url) {
},
onLoadResource: (InAppWebViewController controller, LoadedResource response) {
customAssert(widget: widget, name: "onLoadResource", value: resourceList.contains(response.url));
countResources++;
if (countResources == resourceList.length) {
nextTest(context: context);
}
}
),
),
),
])
)
);
}
}
import 'dart:async';
import 'package:flutter/material.dart';
import 'in_app_webview_initial_file_test.dart';
import 'in_app_webview_initial_url_test.dart';
import 'in_app_webview_on_load_resource_test.dart';
Future main() async {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter_inappbrowser tests',
initialRoute: '/',
routes: {
'/': (context) => InAppWebViewInitialUrlTest(),
'/InAppWebViewInitialFileTest': (context) => InAppWebViewInitialFileTest(),
'/InAppWebViewOnLoadResourceTest': (context) => InAppWebViewOnLoadResourceTest()
}
);
}
}
\ No newline at end of file
import 'package:ansicolor/ansicolor.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'custom_widget_test.dart';
int countTestPassed = 0;
int countTestFailed = 0;
int currentTest = 0;
List<String> testRoutes = [
'/',
'/InAppWebViewInitialFileTest',
'/InAppWebViewOnLoadResourceTest'
];
void nextTest({@required BuildContext context}) {
if (currentTest + 1 < testRoutes.length) {
currentTest++;
String nextRoute = testRoutes[currentTest];
Navigator.pushReplacementNamed(context, nextRoute);
} else {
AnsiPen penError = new AnsiPen()..white()..rgb(r: 1.0, g: 0.0, b: 0.0);
AnsiPen penSuccess = new AnsiPen()..white()..rgb(r: 0.0, g: 1.0, b: 0.0);
if (countTestFailed > 0)
print("\n" + penError("Total tests failed $countTestFailed.") + "\n");
if (countTestPassed > 0)
print("\n" + penSuccess("Total tests passed $countTestPassed.") + "\n");
}
}
bool customAssert({WidgetTest widget, String name, @required bool value}) {
try {
assert(value);
} catch (e, stackTrace) {
String message = "${widget != null ? "'" + widget.name + "' - " : ""} ERROR - Failed assertion: ";
List<String> stakTraceSplitted = stackTrace.toString().split("\n");
String lineCallingAssert = stakTraceSplitted[3].trim().substring(2).trim();
AnsiPen penError = new AnsiPen()..white()..rgb(r: 1.0, g: 0.0, b: 0.0);
print("\n" + penError(message + lineCallingAssert) + "\n");
countTestFailed++;
return false;
}
countTestPassed++;
try {
throw Exception();
} on Exception catch(e, stackTrace) {
String message = "${widget != null ? "'" + widget.name + "' - " : ""} Test ";
message += (name != null) ? "'$name' " : "";
message += "passed!";
List<String> stakTraceSplitted = stackTrace.toString().split("\n");
String lineCallingAssert = stakTraceSplitted[1].trim().substring(2).trim();
message += " $lineCallingAssert";
AnsiPen pen = new AnsiPen()..white()..rgb(r: 1.0, g: 0.8, b: 0.2);
print("\n" + pen(message) + "\n");
}
return true;
}
\ No newline at end of file
......@@ -45,7 +45,7 @@ class InAppLocalhostServer {
var body = List<int>();
var path = request.requestedUri.path;
path = (path.startsWith('/')) ? path.substring(1) : path;
path += (path.endsWith('/')) ? 't-rex.html' : '';
path += (path.endsWith('/')) ? 'index.html' : '';
try {
body = (await rootBundle.load(path))
......@@ -85,4 +85,4 @@ class InAppLocalhostServer {
}
}
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment