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 2012/09/28 21:07:03 UTC

[1/2] js commit: [android] Added unit tests for exec.processMessages()

Updated Branches:
  refs/heads/master 01a2683ad -> fe6f8c618


[android] Added unit tests for exec.processMessages()


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/fe6f8c61
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/fe6f8c61
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/fe6f8c61

Branch: refs/heads/master
Commit: fe6f8c6182a1a211433389c6212b6c4836b0011f
Parents: b56626f
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Sep 28 15:05:58 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Sep 28 15:05:58 2012 -0400

----------------------------------------------------------------------
 lib/test/plugin/android/nativeapiprovider.js    |    1 +
 lib/test/plugin/android/promptbasednativeapi.js |    1 +
 test/android/test.exec.js                       |   30 ++++++++++++++++--
 3 files changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/fe6f8c61/lib/test/plugin/android/nativeapiprovider.js
----------------------------------------------------------------------
diff --git a/lib/test/plugin/android/nativeapiprovider.js b/lib/test/plugin/android/nativeapiprovider.js
new file mode 120000
index 0000000..70a680d
--- /dev/null
+++ b/lib/test/plugin/android/nativeapiprovider.js
@@ -0,0 +1 @@
+../../../android/plugin/android/nativeapiprovider.js
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/fe6f8c61/lib/test/plugin/android/promptbasednativeapi.js
----------------------------------------------------------------------
diff --git a/lib/test/plugin/android/promptbasednativeapi.js b/lib/test/plugin/android/promptbasednativeapi.js
new file mode 120000
index 0000000..9fe7b2f
--- /dev/null
+++ b/lib/test/plugin/android/promptbasednativeapi.js
@@ -0,0 +1 @@
+../../../android/plugin/android/promptbasednativeapi.js
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/fe6f8c61/test/android/test.exec.js
----------------------------------------------------------------------
diff --git a/test/android/test.exec.js b/test/android/test.exec.js
index 797fb12..14360bd 100644
--- a/test/android/test.exec.js
+++ b/test/android/test.exec.js
@@ -23,6 +23,7 @@ describe('exec.processMessages', function () {
     var cordova = require('cordova'),
         exec = require('cordova/androidexec'),
         callbackSpy = jasmine.createSpy('callbackFromNative'),
+        origPrompt = typeof prompt == 'undefined' ? null : prompt,
         origCallbackFromNative = cordova.callbackFromNative;
 
     beforeEach(function() {
@@ -32,13 +33,14 @@ describe('exec.processMessages', function () {
 
     afterEach(function() {
         cordova.callbackFromNative = origCallbackFromNative;
+        prompt = origPrompt;
     });
 
     function createCallbackMessage(success, keepCallback, status, callbackId, encodedPayload) {
         var ret = '';
         ret += success ? 'S' : 'F';
         ret += keepCallback ? '1' : '0';
-        ret += ' ' + status;
+        ret += status;
         ret += ' ' + callbackId;
         ret += ' ' + encodedPayload;
         ret = ret.length + ' ' + ret;
@@ -67,7 +69,7 @@ describe('exec.processMessages', function () {
             expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, 'Hello world', true);
         });
         it('should handle payloads of JSON objects', function() {
-            var messages = createCallbackMessage(true, true, 1, 'id', '{a:1}');
+            var messages = createCallbackMessage(true, true, 1, 'id', '{"a":1}');
             exec.processMessages(messages);
             expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, {a:1}, true);
         });
@@ -81,6 +83,28 @@ describe('exec.processMessages', function () {
             exec.processMessages(messages);
             expect(callbackSpy).toHaveBeenCalledWith('id', false, 3, 'foo', false);
         });
-
+        it('should handle multiple messages', function() {
+            var message1 = createCallbackMessage(false, false, 3, 'id', 'sfoo');
+            var message2 = createCallbackMessage(true, true, 1, 'id', 'f');
+            var messages = message1 + message2;
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', false, 3, 'foo', false);
+            expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, false, true);
+        });
+        it('should poll for more messages when hitting an *', function() {
+            var message1 = createCallbackMessage(false, false, 3, 'id', 'sfoo');
+            var message2 = createCallbackMessage(true, true, 1, 'id', 'f');
+            prompt = jasmine.createSpy('prompt').andCallFake(function() {
+                callbackSpy.reset();
+                return message2;
+            });
+            var messages = message1 + '*';
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', false, 3, 'foo', false);
+            waitsFor(function() { return prompt.wasCalled }, 500);
+            runs(function() {
+                expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, false, true);
+            });
+        });
     });
 });