diff --git a/iphone/Classes/TiUIWebView.m b/iphone/Classes/TiUIWebView.m index ad0c65aed71..38585281615 100644 --- a/iphone/Classes/TiUIWebView.m +++ b/iphone/Classes/TiUIWebView.m @@ -276,7 +276,7 @@ - (void)setHtml_:(id)args NSString *baseURL = options[@"baseURL"]; NSString *mimeType = options[@"mimeType"]; - NSURL *url = [baseURL hasPrefix:@"file:"] ? [NSURL URLWithString:baseURL] : [NSURL fileURLWithPath:baseURL]; + NSURL *url = [baseURL hasPrefix:@"file:"] ? [NSURL fileURLWithPath:baseURL] : [NSURL URLWithString:baseURL]; [[self webView] loadData:[content dataUsingEncoding:NSUTF8StringEncoding] MIMEType:mimeType diff --git a/tests/Resources/ti.ui.webview.addontest.js b/tests/Resources/ti.ui.webview.addontest.js new file mode 100644 index 00000000000..8bceb68372c --- /dev/null +++ b/tests/Resources/ti.ui.webview.addontest.js @@ -0,0 +1,33 @@ +/* + * Appcelerator Titanium Mobile + * Copyright (c) 2015-Present by Axway, Inc. All Rights Reserved. + * Licensed under the terms of the Apache Public License + * Please see the LICENSE included with this distribution for details. + */ +/* eslint-env mocha */ +/* eslint no-unused-expressions: "off" */ +'use strict'; +const should = require('./utilities/assertions'); + +describe('Titanium.UI.WebView', function () { + it('baseURL should be accessible via window.location', (done) => { + const win = Ti.UI.createWindow(); + const baseURL = 'https://www.google.com/'; + const webView = Ti.UI.createWebView(); + webView.setHtml( + '', + { + baseURL + } + ); + webView.addEventListener('load', () => { + webView.evalJS('window.location.href', result => { + should(result).be.eql(baseURL); + win.close(); + done(); + }); + }); + win.add(webView); + win.open(); + }); +});