mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Ability to load local files in a WebView on iOS devices (#4444)
* Ability to load local files in a WebView on iOS devices * Ability to load local files in a WebView on iOS devices (removed doc-comments in test)
This commit is contained in:

committed by
Alexander Vakrilov

parent
1420fa8fcc
commit
f399f6c62b
10
tests/app/ui/web-view/test with spaces.html
Normal file
10
tests/app/ui/web-view/test with spaces.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>MyTitle</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<span style="color:red">TestÖ with Spaces</span>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -87,6 +87,40 @@ export class WebViewTest extends testModule.UITest<webViewModule.WebView> {
|
|||||||
// << webview-localfile
|
// << webview-localfile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public testLoadLocalFileWithSpaceInPath(done) {
|
||||||
|
let webView = this.testView;
|
||||||
|
|
||||||
|
webView.on(webViewModule.WebView.loadFinishedEvent, function (args: webViewModule.LoadEventData) {
|
||||||
|
let actual;
|
||||||
|
let expectedTitle = 'MyTitle';
|
||||||
|
let expectedHtml = '<span style="color:red">TestÖ with Spaces</span>';
|
||||||
|
|
||||||
|
if (webView.ios) {
|
||||||
|
actual = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
|
||||||
|
} else if (webView.android) {
|
||||||
|
actual = webView.android.getTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
TKUnit.assertNull(args.error, args.error);
|
||||||
|
TKUnit.assertEqual(actual, webView.ios ? expectedHtml : expectedTitle, "File ~/ui/web-view/test.html not loaded properly.");
|
||||||
|
done(null);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
let message;
|
||||||
|
if (!args.error) {
|
||||||
|
message = "WebView finished loading " + args.url;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message = "Error loading " + args.url + ": " + args.error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
webView.src = "~/ui/web-view/test with spaces.html";
|
||||||
|
}
|
||||||
|
|
||||||
public testLoadHTMLString(done) {
|
public testLoadHTMLString(done) {
|
||||||
let webView = this.testView;
|
let webView = this.testView;
|
||||||
|
|
||||||
|
@ -71,6 +71,11 @@ export abstract class WebViewBase extends View implements WebViewDefinition {
|
|||||||
src = "file://" + src;
|
src = "file://" + src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loading local files from paths with spaces may fail
|
||||||
|
if (src.toLowerCase().indexOf("file:///") === 0) {
|
||||||
|
src = encodeURI(src);
|
||||||
|
}
|
||||||
|
|
||||||
if (src.toLowerCase().indexOf("http://") === 0 ||
|
if (src.toLowerCase().indexOf("http://") === 0 ||
|
||||||
src.toLowerCase().indexOf("https://") === 0 ||
|
src.toLowerCase().indexOf("https://") === 0 ||
|
||||||
src.toLowerCase().indexOf("file:///") === 0) {
|
src.toLowerCase().indexOf("file:///") === 0) {
|
||||||
|
Reference in New Issue
Block a user