You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2013/07/23 00:09:54 UTC

[1/2] spec commit: [CB-4279] Bridge test now generic and tests available modes

Updated Branches:
  refs/heads/master e064f5037 -> f5c0a54d0


[CB-4279] Bridge test now generic and tests available modes


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/94f1514d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/94f1514d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/94f1514d

Branch: refs/heads/master
Commit: 94f1514de65144eabb135dcb0dd85e12dda1866c
Parents: e064f50
Author: David Kemp <dr...@chromium.org>
Authored: Wed Jul 17 09:35:34 2013 -0400
Committer: Max Woghiren <ma...@gmail.com>
Committed: Mon Jul 22 18:07:55 2013 -0400

----------------------------------------------------------------------
 autotest/tests/bridge.tests.js | 55 +++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/94f1514d/autotest/tests/bridge.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/bridge.tests.js b/autotest/tests/bridge.tests.js
index ec363d7..b549745 100644
--- a/autotest/tests/bridge.tests.js
+++ b/autotest/tests/bridge.tests.js
@@ -74,14 +74,14 @@ var fail = function() {
 };
 
 function createTestCase(jsToNativeModeName, nativeToJsModeName, testAsyncEcho) {
-    it(jsToNativeModeName + '+' + nativeToJsModeName, function() {
-        expect(exec.jsToNativeModes[jsToNativeModeName]).toBeDefined();
-        expect(exec.nativeToJsModes[nativeToJsModeName]).toBeDefined();
+    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;
-        exec.setJsToNativeBridgeMode(exec.jsToNativeModes[jsToNativeModeName]);
-        exec.setNativeToJsBridgeMode(exec.nativeToJsModes[nativeToJsModeName]);
+        if(jsToNativeModeName) exec.setJsToNativeBridgeMode(exec.jsToNativeModes[jsToNativeModeName]);
+        if(nativeToJsModeName) exec.setNativeToJsBridgeMode(exec.nativeToJsModes[nativeToJsModeName]);
 
         waits(300);
         runs(function() {
@@ -92,7 +92,7 @@ function createTestCase(jsToNativeModeName, nativeToJsModeName, testAsyncEcho) {
         runs(function() {
             var elapsedMs = endTime - startTime,
                 callsPerSecond = callCount * 1000 / elapsedMs;
-            expect(callsPerSecond).toBeGreaterThan(FENCEPOST);
+            expect(callsPerSecond).toBeLessThan(FENCEPOST);
         });
     });
 };
@@ -107,22 +107,29 @@ describe('Wait for page to load.', function() {
 // Before running on Android, set the following constants in NativeToJsMessagingBridge:
 // - ENABLE_LOCATION_CHANGE_EXEC_MODE = true
 // - DISABLE_EXEC_CHAINING = true
-describe('Android bridge with', function() {
-    var testAsyncEcho = false;
-    createTestCase('PROMPT', 'POLLING', testAsyncEcho);
-    createTestCase('JS_OBJECT', 'POLLING', testAsyncEcho);
-    createTestCase('LOCATION_CHANGE', 'ONLINE_EVENT', testAsyncEcho);
-
-    testAsyncEcho = true;
-    createTestCase('PROMPT', 'POLLING', testAsyncEcho);
-    createTestCase('PROMPT', 'HANGING_GET', testAsyncEcho);
-    createTestCase('PROMPT', 'LOAD_URL', testAsyncEcho);
-    createTestCase('PROMPT', 'ONLINE_EVENT', testAsyncEcho);
-    createTestCase('PROMPT', 'PRIVATE_API', testAsyncEcho);
-
-    createTestCase('JS_OBJECT', 'POLLING', testAsyncEcho);
-    createTestCase('JS_OBJECT', 'HANGING_GET', testAsyncEcho);
-    createTestCase('JS_OBJECT', 'LOAD_URL', testAsyncEcho);
-    createTestCase('JS_OBJECT', 'ONLINE_EVENT', testAsyncEcho);
-    createTestCase('JS_OBJECT', 'PRIVATE_API', testAsyncEcho);
+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);
+            }
+        }
+    }
 });


[2/2] spec commit: [CB-4281] Adding echo plugin after breakout

Posted by ma...@apache.org.
[CB-4281] Adding echo plugin after breakout


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/f5c0a54d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/f5c0a54d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/f5c0a54d

Branch: refs/heads/master
Commit: f5c0a54d056c6e9b76f59eac2b2908ddbfed3e65
Parents: 94f1514
Author: David Kemp <dr...@chromium.org>
Authored: Mon Jul 22 18:04:31 2013 -0400
Committer: Max Woghiren <ma...@gmail.com>
Committed: Mon Jul 22 18:09:12 2013 -0400

----------------------------------------------------------------------
 cordova-plugin-echo/README.md             |  5 ++
 cordova-plugin-echo/docs/echo.md          | 50 +++++++++++++++++
 cordova-plugin-echo/plugin.xml            | 35 ++++++++++++
 cordova-plugin-echo/src/android/Echo.java | 74 ++++++++++++++++++++++++++
 cordova-plugin-echo/src/ios/CDVEcho.h     | 23 ++++++++
 cordova-plugin-echo/src/ios/CDVEcho.m     | 61 +++++++++++++++++++++
 cordova-plugin-echo/www/echo.js           | 53 ++++++++++++++++++
 dependencies-plugin/plugin.xml            |  1 +
 8 files changed, 302 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f5c0a54d/cordova-plugin-echo/README.md
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/README.md b/cordova-plugin-echo/README.md
new file mode 100644
index 0000000..a4237af
--- /dev/null
+++ b/cordova-plugin-echo/README.md
@@ -0,0 +1,5 @@
+cordova-plugin-echo
+------------------------
+
+This is a plugin implementation of the Echo function to test the bridge. It is currently used by Mobile Spec to test and benchmark the bridge.
+

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f5c0a54d/cordova-plugin-echo/docs/echo.md
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/docs/echo.md b/cordova-plugin-echo/docs/echo.md
new file mode 100644
index 0000000..6fe0f8f
--- /dev/null
+++ b/cordova-plugin-echo/docs/echo.md
@@ -0,0 +1,50 @@
+---
+ license: Licensed to the Apache Software Foundation (ASF) under one
+         or more contributor license agreements.  See the NOTICE file
+         distributed with this work for additional information
+         regarding copyright ownership.  The ASF licenses this file
+         to you under the Apache License, Version 2.0 (the
+         "License"); you may not use this file except in compliance
+         with the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+         Unless required by applicable law or agreed to in writing,
+         software distributed under the License is distributed on an
+         "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+         KIND, either express or implied.  See the License for the
+         specific language governing permissions and limitations
+         under the License.
+---
+
+Echo
+=========
+
+> The `echo` object provides an interface for testing the bridge. It
+> sends any data received back across the bridge unmodifed. This 
+> allows the bridge modes to be tested and benchmarked.
+
+Methods
+-------
+
+- cordova.echo.echo
+- cordova.echo.echoAsync
+- cordova.echo.echoArrayBuffer
+- cordova.echo.echoMultiPart
+
+### cordova.echo.echo
+
+Echos string data in the same thread.
+
+### cordova.echo.echoAsync
+
+Echos string data in a new UI thread.
+
+### cordova.echo.echoArrayBuffer
+
+Echos base64 encoded data in the same thread.
+
+### cordova.echo.echoMultiPart
+
+Echos a multipart message in the same thread.
+

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f5c0a54d/cordova-plugin-echo/plugin.xml
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/plugin.xml b/cordova-plugin-echo/plugin.xml
new file mode 100644
index 0000000..816d77b
--- /dev/null
+++ b/cordova-plugin-echo/plugin.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
+           id="org.apache.cordova.test.echo"
+      version="0.1.0">
+    <name>Echo</name>
+
+    <js-module src="www/echo.js" name="echo">
+        <clobbers target="cordova.echo" />
+    </js-module>
+
+    <!-- android -->
+    <platform name="android">
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="Echo" >
+                <param name="android-package" value="org.apache.cordova.test.Echo"/>
+            </feature>
+        </config-file>
+
+        <source-file src="src/android/Echo.java" target-dir="src/org/apache/cordova/test" />
+    </platform>
+
+    <!-- ios -->
+    <platform name="ios">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Echo">
+                <param name="ios-package" value="CDVEcho"/>
+            </feature>
+        </config-file>
+        
+        <header-file src="src/ios/CDVEcho.h" />
+        <source-file src="src/ios/CDVEcho.m" />
+    </platform>
+
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f5c0a54d/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
new file mode 100644
index 0000000..0bd2e31
--- /dev/null
+++ b/cordova-plugin-echo/src/android/Echo.java
@@ -0,0 +1,74 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package org.apache.cordova.test;
+
+import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.PluginResult;
+import org.apache.cordova.PluginResult.Status;
+import org.json.JSONArray;
+import org.json.JSONException;
+
+import android.annotation.SuppressLint;
+import android.util.Base64;
+
+/**
+* This class exposes methods in Cordova that can be called from JavaScript.
+*/
+public class Echo extends CordovaPlugin {
+
+	   /**
+     * Executes the request and returns PluginResult.
+     *
+     * @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("echoMultiPart")) {
+            	callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, args.getJSONObject(0)));
+                return true;
+            }
+            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
+            return false;
+        } catch (JSONException e) {
+            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+            return false;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f5c0a54d/cordova-plugin-echo/src/ios/CDVEcho.h
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/src/ios/CDVEcho.h b/cordova-plugin-echo/src/ios/CDVEcho.h
new file mode 100644
index 0000000..785524e
--- /dev/null
+++ b/cordova-plugin-echo/src/ios/CDVEcho.h
@@ -0,0 +1,23 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Cordova/CDVPlugin.h>
+
+@interface CDVEcho : CDVPlugin
+@end

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f5c0a54d/cordova-plugin-echo/src/ios/CDVEcho.m
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/src/ios/CDVEcho.m b/cordova-plugin-echo/src/ios/CDVEcho.m
new file mode 100644
index 0000000..a5dc325
--- /dev/null
+++ b/cordova-plugin-echo/src/ios/CDVEcho.m
@@ -0,0 +1,61 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVEcho.h"
+#import <Cordova/CDV.h>
+
+@implementation CDVEcho
+
+- (void)echo:(CDVInvokedUrlCommand*)command
+{
+    id message = [command.arguments objectAtIndex:0];
+    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
+
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+- (void)echoAsyncHelper:(NSArray*)args
+{
+    [self.commandDelegate sendPluginResult:[args objectAtIndex:0] callbackId:[args objectAtIndex:1]];
+}
+
+- (void)echoAsync:(CDVInvokedUrlCommand*)command
+{
+    id message = [command.arguments objectAtIndex:0];
+    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
+
+    [self performSelector:@selector(echoAsyncHelper:) withObject:[NSArray arrayWithObjects:pluginResult, command.callbackId, nil] afterDelay:0];
+}
+
+- (void)echoArrayBuffer:(CDVInvokedUrlCommand*)command
+{
+    id message = [command.arguments objectAtIndex:0];
+    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArrayBuffer:message];
+
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+- (void)echoMultiPart:(CDVInvokedUrlCommand*)command
+{
+    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsMultipart:command.arguments];
+
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f5c0a54d/cordova-plugin-echo/www/echo.js
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/www/echo.js b/cordova-plugin-echo/www/echo.js
new file mode 100644
index 0000000..76fe3f0
--- /dev/null
+++ b/cordova-plugin-echo/www/echo.js
@@ -0,0 +1,53 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var exec = require('cordova/exec'),
+    utils = require('cordova/utils');
+
+/**
+ * Sends the given message through exec() to the Echo plugin, which sends it back to the successCallback.
+ * @param successCallback  invoked with a FileSystem object
+ * @param errorCallback  invoked if error occurs retrieving file system
+ * @param message  The string to be echoed.
+ * @param forceAsync  Whether to force an async return value (for testing native->js bridge).
+ */
+module.exports = function(successCallback, errorCallback, message, forceAsync) {
+    var action = 'echo';
+    var messageIsMultipart = (utils.typeName(message) == "Array");
+    var args = messageIsMultipart ? message : [message];
+
+    if (utils.typeName(message) == 'ArrayBuffer') {
+        if (forceAsync) {
+            console.warn('Cannot echo ArrayBuffer with forced async, falling back to sync.');
+        }
+        action += 'ArrayBuffer';
+    } else if (messageIsMultipart) {
+        if (forceAsync) {
+            console.warn('Cannot echo MultiPart Array with forced async, falling back to sync.');
+        }
+        action += 'MultiPart';
+    } else if (forceAsync) {
+        action += 'Async';
+    }
+
+    exec(successCallback, errorCallback, "Echo", action, args);
+};
+

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/f5c0a54d/dependencies-plugin/plugin.xml
----------------------------------------------------------------------
diff --git a/dependencies-plugin/plugin.xml b/dependencies-plugin/plugin.xml
index 70c15a9..7fb6ebc 100644
--- a/dependencies-plugin/plugin.xml
+++ b/dependencies-plugin/plugin.xml
@@ -46,4 +46,5 @@
   <dependency id="org.apache.cordova.core.splashscreen" url="." subdir="../cordova-plugin-splashscreen" />
   <dependency id="org.apache.cordova.core.vibration" url="." subdir="../cordova-plugin-vibration" />
   <dependency id="org.apache.cordova.test.whitelist" url="." subdir="cordova-plugin-whitelist" />
+  <dependency id="org.apache.cordova.test.echo" url="." subdir="cordova-plugin-echo" />
 </plugin>