Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-11055] Android: WebView event JSON object conversion bug causing crash. (backport) #3174

Merged
merged 2 commits into from
Oct 11, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,23 @@ public static Object fromJSON(Object value) {
try {
if (value instanceof JSONObject) {
return new KrollDict((JSONObject)value);

} else if (value instanceof JSONArray) {
JSONArray array = (JSONArray)value;
Object[] values = new Object[array.length()];
for (int i = 0; i < array.length(); i++) {
values[i] = fromJSON(array.get(i));
}
return values;

} else if (value == JSONObject.NULL) {
return null;

}
} catch (JSONException e) {
Log.e(TAG, "Error parsing JSON", e);
}

return value;
}

Expand Down
21 changes: 21 additions & 0 deletions support/anvil/configSet/Resources/suites/ui/test-fire-event.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>test</title>
</head>
<body>
<script>
setTimeout(function() {
Ti.App.fireEvent('webViewEvent', {
object: {
string: "string",
number: 1,
nullObject: null,
array: [{}, "a", 1, null]
}
});
}, 250);
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions support/anvil/configSet/Resources/suites/ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = new function() {
{name: "webviewBindingUnavailable", timeout: 15000},
{name: "webviewBindingAvailable", timeout: 10000},
{name: "webviewBindingAvailableAfterSetHtml", timeout: 10000},
{name: "webviewFireEvent", timeout: 10000},
{name: "dotslashWindow"},
{name: "absoluteAndRelativeWinURLs", timeout: 10000},
{name: "appendRowWithHeader"},
Expand Down Expand Up @@ -93,6 +94,33 @@ module.exports = new function() {
wv.html = "<html><body>x</body></html>";
}

this.webviewFireEvent = function(testRun) {
var w = Ti.UI.createWindow();
w.open();

function onEventFired(e) {
valueOf(testRun, e.object).shouldBeObject();
valueOf(testRun, e.object.string).shouldBeString();
valueOf(testRun, e.object.number).shouldBeNumber();
valueOf(testRun, e.object.nullObject).shouldBeNull();
valueOf(testRun, e.object.array).shouldBeArray();

valueOf(testRun, e.object.array.length).shouldBe(4);
valueOf(testRun, e.object.array[0]).shouldBeObject();
valueOf(testRun, e.object.array[1]).shouldBeString();
valueOf(testRun, e.object.array[2]).shouldBeNumber();
valueOf(testRun, e.object.array[3]).shouldBeNull();

Ti.App.removeEventListener('webViewEvent', onEventFired);
finish(testRun);
}

Ti.App.addEventListener('webViewEvent', onEventFired);

var wv = Ti.UI.createWebView({url: 'test-fire-event.html'});
w.add(wv);
}

//https://appcelerator.lighthouseapp.com/projects/32238/tickets/2443-android-paths-beginning-with-are-not-recognised
this.dotslashWindow = function(testRun) {
var w = Ti.UI.createWindow({url:'./testwin.js'});
Expand Down