You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/07/04 04:10:56 UTC
[1/2] spec commit: android: Fix up double-callback of Echo plugin.
Repository: cordova-mobile-spec
Updated Branches:
refs/heads/master 15e6e6b3b -> e2ddbd366
android: Fix up double-callback of Echo plugin.
Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/9cf02457
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/9cf02457
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/9cf02457
Branch: refs/heads/master
Commit: 9cf02457f103234271a4e66c9395777c6d159952
Parents: 15e6e6b
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Jul 3 22:10:00 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Jul 3 22:10:00 2014 -0400
----------------------------------------------------------------------
cordova-plugin-echo/src/android/Echo.java | 99 ++++++++++++--------------
1 file changed, 44 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/9cf02457/cordova-plugin-echo/src/android/Echo.java
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/src/android/Echo.java b/cordova-plugin-echo/src/android/Echo.java
index 80e1ac7..91921ba 100644
--- a/cordova-plugin-echo/src/android/Echo.java
+++ b/cordova-plugin-echo/src/android/Echo.java
@@ -42,68 +42,57 @@ public class Echo extends CordovaPlugin {
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackContext The callback context from which we were invoked.
- * @return A PluginResult object with a status and message.
*/
@SuppressLint("NewApi")
- public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
- try {
- if (action.equals("echo")) {
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, args.getString(0)));
- return true;
- } else if(action.equals("echoAsync")) {
- cordova.getActivity().runOnUiThread(new Runnable() {
- public void run() {
- callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, args.optString(0)));
- }
- });
- return true;
- } else if(action.equals("echoArrayBuffer")) {
- String data = args.optString(0);
- byte[] rawData= Base64.decode(data, Base64.DEFAULT);
- callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, rawData));
- return true;
- } else if(action.equals("echoArrayBufferAsync")) {
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- String data = args.optString(0);
- byte[] rawData= Base64.decode(data, Base64.DEFAULT);
- callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, rawData));
- }
- });
- return true;
- } else if(action.equals("echoMultiPart")) {
- callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, args.getJSONObject(0)));
- return true;
- } else if(action.equals("stopEchoBulk")) {
- bulkEchoing = false;
- } else if(action.equals("echoBulk")) {
- if (bulkEchoing) {
- return true;
+ public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ if (action.equals("echo")) {
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, args.getString(0)));
+ } else if(action.equals("echoAsync")) {
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, args.optString(0)));
}
- final String payload = args.getString(0);
- final int delayMs = args.getInt(1);
- bulkEchoing = true;
- cordova.getThreadPool().execute(new Runnable() {
- public void run() {
- while (bulkEchoing) {
- try {
- Thread.sleep(delayMs);
- } catch (InterruptedException e) {}
- PluginResult pr = new PluginResult(PluginResult.Status.OK, payload);
- pr.setKeepCallback(true);
- callbackContext.sendPluginResult(pr);
- }
+ });
+ } else if(action.equals("echoArrayBuffer")) {
+ String data = args.optString(0);
+ byte[] rawData= Base64.decode(data, Base64.DEFAULT);
+ callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, rawData));
+ } else if(action.equals("echoArrayBufferAsync")) {
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ String data = args.optString(0);
+ byte[] rawData= Base64.decode(data, Base64.DEFAULT);
+ callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, rawData));
+ }
+ });
+ } else if(action.equals("echoMultiPart")) {
+ callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, args.getJSONObject(0)));
+ } else if(action.equals("stopEchoBulk")) {
+ bulkEchoing = false;
+ } else if(action.equals("echoBulk")) {
+ if (bulkEchoing) {
+ return true;
+ }
+ final String payload = args.getString(0);
+ final int delayMs = args.getInt(1);
+ bulkEchoing = true;
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ while (bulkEchoing) {
+ try {
+ Thread.sleep(delayMs);
+ } catch (InterruptedException e) {}
PluginResult pr = new PluginResult(PluginResult.Status.OK, payload);
+ pr.setKeepCallback(true);
callbackContext.sendPluginResult(pr);
}
- });
- return true;
- }
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
- return false;
- } catch (JSONException e) {
- callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ PluginResult pr = new PluginResult(PluginResult.Status.OK, payload);
+ callbackContext.sendPluginResult(pr);
+ }
+ });
+ } else {
return false;
}
+ return true;
}
}
[2/2] spec commit: CB-5988 Add unit test for android bridge being
blocked for data: URLs
Posted by ag...@apache.org.
CB-5988 Add unit test for android bridge being blocked for data: URLs
Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/e2ddbd36
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/e2ddbd36
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/e2ddbd36
Branch: refs/heads/master
Commit: e2ddbd366fcf7404775669add3c7806bd8ac89e9
Parents: 9cf0245
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Jul 3 22:10:19 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Jul 3 22:10:19 2014 -0400
----------------------------------------------------------------------
autotest/pages/all.html | 1 +
autotest/tests/bridge.tests.js | 124 ++++--------------------------------
2 files changed, 14 insertions(+), 111 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/e2ddbd36/autotest/pages/all.html
----------------------------------------------------------------------
diff --git a/autotest/pages/all.html b/autotest/pages/all.html
index e381ef4..c006db1 100644
--- a/autotest/pages/all.html
+++ b/autotest/pages/all.html
@@ -46,6 +46,7 @@
<!-- Tests -->
<script type="text/javascript" src="../tests/accelerometer.tests.js"></script>
<script type="text/javascript" src="../tests/battery.tests.js"></script>
+ <script type="text/javascript" src="../tests/bridge.tests.js"></script>
<script type="text/javascript" src="../tests/capture.tests.js"></script>
<script type="text/javascript" src="../tests/compass.tests.js"></script>
<script type="text/javascript" src="../tests/contacts.tests.js"></script>
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/e2ddbd36/autotest/tests/bridge.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/bridge.tests.js b/autotest/tests/bridge.tests.js
index b549745..28c44c2 100644
--- a/autotest/tests/bridge.tests.js
+++ b/autotest/tests/bridge.tests.js
@@ -19,117 +19,19 @@
*
*/
-/* This test requires some extra code to run, because we want benchmark results */
-
-/*
- It's never going to be OVER 9000
- http://youtu.be/SiMHTK15Pik
-*/
-var FENCEPOST = 9000;
-
-var exec = cordova.require('cordova/exec'),
- echo = cordova.require('cordova/plugin/echo'),
- startTime,
- endTime,
- callCount,
- durationMs = 1000,
- asyncEcho,
- useSetTimeout,
- payloadSize,
- payload;
-
-var vanillaWin = function(result) {
- callCount++;
- if (result != payload) {
- console.log('Wrong echo data!');
- }
- var elapsedMs = new Date - startTime;
- if (elapsedMs < durationMs) {
- if (useSetTimeout) {
- setTimeout(echoMessage, 0);
- } else {
- echoMessage();
- }
- } else {
- endTime = +new Date;
- }
-}
-
-var reset = function()
-{
- endTime = null;
- callCount = 0;
- useSetTimeout = false;
- payloadSize = 5;
- callsPerSecond = 0;
-}
-
-var echoMessage = function()
-{
- echo(vanillaWin, fail, payload, asyncEcho);
-}
-
-var fail = function() {
- expect(false).toBe(true);
-};
-
-function createTestCase(jsToNativeModeName, nativeToJsModeName, testAsyncEcho) {
- it(jsToNativeModeName + '+' + nativeToJsModeName + ': Async='+testAsyncEcho, function() {
- if(jsToNativeModeName) expect(exec.jsToNativeModes[jsToNativeModeName]).toBeDefined();
- if(nativeToJsModeName) expect(exec.nativeToJsModes[nativeToJsModeName]).toBeDefined();
- reset();
- payload = new Array(payloadSize * 10 + 1).join('012\n\n 6789');
- asyncEcho = testAsyncEcho;
- if(jsToNativeModeName) exec.setJsToNativeBridgeMode(exec.jsToNativeModes[jsToNativeModeName]);
- if(nativeToJsModeName) exec.setNativeToJsBridgeMode(exec.nativeToJsModes[nativeToJsModeName]);
-
- waits(300);
- runs(function() {
- startTime = +new Date,
- echoMessage();
+describe('Bridge', function() {
+ if (cordova.platformId == 'android') {
+ it("bridge.spec.1 should reject bridge from iframe with data: URL", function() {
+ var ifr = document.createElement('iframe');
+ var done = false;
+ ifr.src = 'data:text/html,';
+ ifr.onload = function() {
+ var stolenSecret = ifr.contentWindow.prompt('', 'gap_init:');
+ done = true;
+ expect(stolenSecret).toBe(null);
+ };
+ document.body.appendChild(ifr);
+ waitsFor(function() { return done; });
});
- waitsFor(function() { return endTime; }, "never completed", durationMs * 2);
- runs(function() {
- var elapsedMs = endTime - startTime,
- callsPerSecond = callCount * 1000 / elapsedMs;
- expect(callsPerSecond).toBeLessThan(FENCEPOST);
- });
- });
-};
-
-// Wait so that the first benchmark doesn't have contention.
-describe('Wait for page to load.', function() {
- it('waiting...', function() {
- waits(1000);
- });
-});
-
-// Before running on Android, set the following constants in NativeToJsMessagingBridge:
-// - ENABLE_LOCATION_CHANGE_EXEC_MODE = true
-// - DISABLE_EXEC_CHAINING = true
-describe('Bridge with', function() {
- var AsyncModes = [true,false];
- for(var asmode in AsyncModes){
- console.log("Bridge in Async: "+asmode);
- if (exec.jsToNativeModes) {
- for(var jnmode in exec.jsToNativeModes ) {
- console.log("Bridge js->native: "+ jnmode );
- if(exec.nativeToJsModes){
- for(var njmode in exec.nativeToJsModes ){
- console.log("Bridge native->: "+ njmode);
- createTestCase( jnmode, njmode, asmode);
- }
- } else {
- console.log("Bridge js->native: none");
- createTestCase(jnmode, '', asmode);
- }
- }
- } else {
- console.log("Bridge js->native: none");
- for(var njmode in exec.nativeToJsModes ){
- console.log("Bridge native->: "+ njmode);
- createTestCase('', njmode , asmode);
- }
- }
}
});