-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TIMOB-25862] Parity: Support async Ti.UI.Webview.evalJS call on Andr…
…oid & iOS (#9889) * Add an async variant of Ti.UI.WebView.evalJS * Update docs to include async variant * Handle evalJS in async fashion when not invoked from UI thread - stick the request into a static map keyed by a globally incrementing int and then post/handleMessage to pull it out and run it in the UI
- Loading branch information
1 parent
de57da3
commit 2909c0e
Showing
4 changed files
with
196 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2011-Present by Appcelerator, 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 */ | ||
/* global Ti */ | ||
/* eslint no-unused-expressions: "off" */ | ||
'use strict'; | ||
var should = require('./utilities/assertions'), | ||
utilities = require('./utilities/utilities'); | ||
|
||
describe('Ti.UI.WebView', function () { | ||
var win, | ||
didFocus = false; | ||
this.slow(2000); | ||
this.timeout(10000); | ||
|
||
beforeEach(function () { | ||
didFocus = false; | ||
}); | ||
|
||
afterEach(function () { | ||
if (win) { | ||
win.close(); | ||
} | ||
win = null; | ||
}); | ||
|
||
it('#evalJS(string, function) - async variant', function (finish) { | ||
var webview, | ||
hadError = false; | ||
win = Ti.UI.createWindow({ | ||
backgroundColor: 'blue' | ||
}); | ||
|
||
webview = Ti.UI.createWebView(); | ||
|
||
webview.addEventListener('load', function () { | ||
if (hadError) { | ||
return; | ||
} | ||
|
||
// FIXME: Android is dumb and assumes no trailing semicolon! | ||
webview.evalJS('Ti.API.info("Hello, World!");"WebView.evalJS.TEST"', function (result) { | ||
try { | ||
if (utilities.isAndroid()) { | ||
should(result).be.eql('"WebView.evalJS.TEST"'); // FIXME: Why the double-quoting? | ||
} else { | ||
should(result).be.eql('WebView.evalJS.TEST'); | ||
} | ||
|
||
finish(); | ||
} catch (err) { | ||
finish(err); | ||
} | ||
}); | ||
}); | ||
win.addEventListener('focus', function () { | ||
if (didFocus) { | ||
return; | ||
} | ||
didFocus = true; | ||
|
||
try { | ||
webview.url = 'ti.ui.webview.test.html'; | ||
} catch (err) { | ||
hadError = true; | ||
finish(err); | ||
} | ||
}); | ||
|
||
win.add(webview); | ||
win.open(); | ||
}); | ||
}); |