You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/08/19 03:06:12 UTC

[5/6] git commit: merged with renamed tests dir

merged with renamed tests dir


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/commit/6ec6016a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/6ec6016a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/6ec6016a

Branch: refs/heads/master
Commit: 6ec6016a67e8f83ea8cb5022920e49e6c14c0418
Parents: 183e871 cf06008
Author: Edna Morales <ed...@ednas-mbp-2.raleigh.ibm.com>
Authored: Wed Aug 13 12:53:01 2014 -0400
Committer: Edna Morales <ed...@ednas-mbp-2.raleigh.ibm.com>
Committed: Wed Aug 13 12:53:01 2014 -0400

----------------------------------------------------------------------
 RELEASENOTES.md                |   6 +
 doc/pl/index.md                |  42 +++---
 plugin.xml                     |   2 +-
 src/firefoxos/accelerometer.js |   2 +-
 test/tests.js                  | 294 ------------------------------------
 tests/plugin.xml               |  29 ++++
 tests/tests.js                 | 294 ++++++++++++++++++++++++++++++++++++
 7 files changed, 352 insertions(+), 317 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/6ec6016a/tests/tests.js
----------------------------------------------------------------------
diff --cc tests/tests.js
index 0000000,1deb0c4..6bcd61c
mode 000000,100644..100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@@ -1,0 -1,287 +1,294 @@@
+ /*
+  *
+  * 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.
+  *
+ */
+ 
+ exports.defineAutoTests = function () {
 -    describe('Accelerometer (navigator.accelerometer)', function () {
 -        var fail = function (done) {
 -            expect(true).toBe(false);
 -            done();
++  describe('Accelerometer (navigator.accelerometer)', function () {
++    var fail = function(done) {
++      expect(true).toBe(false);
++      done();
++    };
++
++    it("accelerometer.spec.1 should exist", function () {
++      expect(navigator.accelerometer).toBeDefined();
++    });
++
++    describe("getCurrentAcceleration", function() {
++      it("accelerometer.spec.2 should exist", function() {
++        expect(typeof navigator.accelerometer.getCurrentAcceleration).toBeDefined();
++        expect(typeof navigator.accelerometer.getCurrentAcceleration == 'function').toBe(true);
++      });
++
++      it("accelerometer.spec.3 success callback should be called with an Acceleration object", function(done) {
++        var win = function(a) {
++          expect(a).toBeDefined();
++          expect(a.x).toBeDefined();
++          expect(typeof a.x == 'number').toBe(true);
++          expect(a.y).toBeDefined();
++          expect(typeof a.y == 'number').toBe(true);
++          expect(a.z).toBeDefined();
++          expect(typeof a.z == 'number').toBe(true);
++          expect(a.timestamp).toBeDefined();
++          expect(typeof a.timestamp).toBe('number');
++          done();
+         };
+ 
 -        it("accelerometer.spec.1 should exist", function () {
 -            expect(navigator.accelerometer).toBeDefined();
 -        });
++        navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null, done));
++      });
++
++      it("accelerometer.spec.4 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function(done) {
++        var reasonableThreshold = 15;
++        var win = function(a) {
++          expect(a.x).toBeLessThan(reasonableThreshold);
++          expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
++          expect(a.y).toBeLessThan(reasonableThreshold);
++          expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
++          expect(a.z).toBeLessThan(reasonableThreshold);
++          expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
++          done()
++        };
+ 
 -        describe("getCurrentAcceleration", function () {
 -            it("accelerometer.spec.2 should exist", function () {
 -                expect(typeof navigator.accelerometer.getCurrentAcceleration).toBeDefined();
 -                expect(typeof navigator.accelerometer.getCurrentAcceleration == 'function').toBe(true);
 -            });
 -
 -            it("accelerometer.spec.3 success callback should be called with an Acceleration object", function (done) {
 -                var win = function (a) {
 -                    expect(a).toBeDefined();
 -                    expect(a.x).toBeDefined();
 -                    expect(typeof a.x == 'number').toBe(true);
 -                    expect(a.y).toBeDefined();
 -                    expect(typeof a.y == 'number').toBe(true);
 -                    expect(a.z).toBeDefined();
 -                    expect(typeof a.z == 'number').toBe(true);
 -                    expect(a.timestamp).toBeDefined();
 -                    expect(typeof a.timestamp).toBe('number');
 -                    done();
 -                };
 -
 -                navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null, done));
 -            });
 -
 -            it("accelerometer.spec.4 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function (done) {
 -                var reasonableThreshold = 15;
 -                var win = function (a) {
 -                    expect(a.x).toBeLessThan(reasonableThreshold);
 -                    expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
 -                    expect(a.y).toBeLessThan(reasonableThreshold);
 -                    expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
 -                    expect(a.z).toBeLessThan(reasonableThreshold);
 -                    expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
 -                    done()
 -                };
 -
 -                navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null, done));
 -            });
 -
 -            it("accelerometer.spec.5 success callback Acceleration object should return a recent timestamp", function (done) {
 -                var veryRecently = (new Date()).getTime();
 -                // Need to check that dates returned are not vastly greater than a recent time stamp.
 -                // In case the timestamps returned are ridiculously high
 -                var reasonableTimeLimit = veryRecently + 5000; // 5 seconds from now
 -                var win = function (a) {
 -                    expect(a.timestamp).toBeGreaterThan(veryRecently);
 -                    expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
 -                    done();
 -                };
 -
 -                navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null, done));
 -            });
 -        });
++        navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null,done));
++      });
++
++      it("accelerometer.spec.5 success callback Acceleration object should return a recent timestamp", function(done) {
++        var veryRecently = (new Date()).getTime();
++        // Need to check that dates returned are not vastly greater than a recent time stamp.
++        // In case the timestamps returned are ridiculously high
++        var reasonableTimeLimit = veryRecently + 5000; // 5 seconds from now
++        var win = function(a) {
++          expect(a.timestamp).toBeGreaterThan(veryRecently);
++          expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
++          done();
++        };
++
++        navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null,done));
++      });
++    });
++
++    describe("watchAcceleration", function() {
++      var id;
++
++      afterEach(function() {
++          navigator.accelerometer.clearWatch(id);
++      });
++
++      it("accelerometer.spec.6 should exist", function() {
++          expect(navigator.accelerometer.watchAcceleration).toBeDefined();
++          expect(typeof navigator.accelerometer.watchAcceleration == 'function').toBe(true);
++      });
++
++      it("accelerometer.spec.7 success callback should be called with an Acceleration object", function(done) {
++        var win = function(a) {
++          expect(a).toBeDefined();
++          expect(a.x).toBeDefined();
++          expect(typeof a.x == 'number').toBe(true);
++          expect(a.y).toBeDefined();
++          expect(typeof a.y == 'number').toBe(true);
++          expect(a.z).toBeDefined();
++          expect(typeof a.z == 'number').toBe(true);
++          expect(a.timestamp).toBeDefined();
++          expect(typeof a.timestamp).toBe('number');
++          done();
++        };
++
++        id = navigator.accelerometer.watchAcceleration(win, fail.bind(null,done), {frequency:100});
++      });
++
++        it("accelerometer.spec.8 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function(done) {
++          var reasonableThreshold = 15;
++          var win = function(a) {
++            expect(a.x).toBeLessThan(reasonableThreshold);
++            expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
++            expect(a.y).toBeLessThan(reasonableThreshold);
++            expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
++            expect(a.z).toBeLessThan(reasonableThreshold);
++            expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
++            done();
++          };
+ 
 -        describe("watchAcceleration", function () {
 -            var id;
 -
 -            afterEach(function () {
 -                navigator.accelerometer.clearWatch(id);
 -            });
 -
 -            it("accelerometer.spec.6 should exist", function () {
 -                expect(navigator.accelerometer.watchAcceleration).toBeDefined();
 -                expect(typeof navigator.accelerometer.watchAcceleration == 'function').toBe(true);
 -            });
 -
 -            it("accelerometer.spec.7 success callback should be called with an Acceleration object", function (done) {
 -                var win = function (a) {
 -                    expect(a).toBeDefined();
 -                    expect(a.x).toBeDefined();
 -                    expect(typeof a.x == 'number').toBe(true);
 -                    expect(a.y).toBeDefined();
 -                    expect(typeof a.y == 'number').toBe(true);
 -                    expect(a.z).toBeDefined();
 -                    expect(typeof a.z == 'number').toBe(true);
 -                    expect(a.timestamp).toBeDefined();
 -                    expect(typeof a.timestamp).toBe('number');
 -                    done();
 -                };
 -
 -                id = navigator.accelerometer.watchAcceleration(win, fail.bind(null, done), { frequency: 100 });
 -            });
 -
 -            it("accelerometer.spec.8 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function (done) {
 -                var reasonableThreshold = 15;
 -                var win = function (a) {
 -                    expect(a.x).toBeLessThan(reasonableThreshold);
 -                    expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
 -                    expect(a.y).toBeLessThan(reasonableThreshold);
 -                    expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
 -                    expect(a.z).toBeLessThan(reasonableThreshold);
 -                    expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
 -                    done();
 -                };
 -
 -                id = navigator.accelerometer.watchAcceleration(win, fail.bind(null, done), { frequency: 100 });
 -            });
 -
 -            it("accelerometer.spec.9 success callback Acceleration object should return a recent timestamp", function (done) {
 -                var veryRecently = (new Date()).getTime();
 -                // Need to check that dates returned are not vastly greater than a recent time stamp.
 -                // In case the timestamps returned are ridiculously high
 -                var reasonableTimeLimit = veryRecently + 5000; // 5 seconds from now
 -                var win = function (a) {
 -                    expect(a.timestamp).toBeGreaterThan(veryRecently);
 -                    expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
 -                    done();
 -                };
 -
 -                id = navigator.accelerometer.watchAcceleration(win, fail.bind(null, done), { frequency: 100 });
 -            });
++          id = navigator.accelerometer.watchAcceleration(win, fail.bind(null,done), {frequency:100});
+         });
+ 
 -        describe("clearWatch", function () {
 -            it("accelerometer.spec.10 should exist", function () {
 -                expect(navigator.accelerometer.clearWatch).toBeDefined();
 -                expect(typeof navigator.accelerometer.clearWatch == 'function').toBe(true);
 -            });
 -
 -            it("accelerometer.spec.11 should clear an existing watch", function (done) {
 -                var id;
 -
 -                // expect win to get called exactly once
 -                var win = function (a) {
 -                    // clear watch on first call
 -                    navigator.accelerometer.clearWatch(id);
 -                    // if win isn't called again in 201 ms we assume success
 -                    var tid = setTimeout(function () {
 -                        expect(true).toBe(true);
 -                        done();
 -                    }, 101);
 -                    // if win is called again, clear the timeout and fail the test
 -                    win = function () {
 -                        clearTimeout(tid);
 -                        fail(done);
 -                    }
 -                };
 -
 -                // wrap the success call in a closure since the value of win changes between calls
 -                id = navigator.accelerometer.watchAcceleration(function () { win(); }, fail.bind(null, done), { frequency: 100 });
 -            });
++        it("accelerometer.spec.9 success callback Acceleration object should return a recent timestamp", function(done) {
++          var veryRecently = (new Date()).getTime();
++          // Need to check that dates returned are not vastly greater than a recent time stamp.
++          // In case the timestamps returned are ridiculously high
++          var reasonableTimeLimit = veryRecently + 5000; // 5 seconds from now
++          var win = function(a) {
++            expect(a.timestamp).toBeGreaterThan(veryRecently);
++            expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
++            done();
++          };
++
++          id = navigator.accelerometer.watchAcceleration(win, fail.bind(null,done), {frequency:100});
+         });
+     });
++
++    describe("clearWatch", function() {
++      it("accelerometer.spec.10 should exist", function() {
++          expect(navigator.accelerometer.clearWatch).toBeDefined();
++          expect(typeof navigator.accelerometer.clearWatch == 'function').toBe(true);
++      });
++
++      it("accelerometer.spec.11 should clear an existing watch", function(done) {
++          var id;
++
++          // expect win to get called exactly once
++          var win = function(a) {
++            // clear watch on first call
++            navigator.accelerometer.clearWatch(id);
++            // if win isn't called again in 201 ms we assume success
++            var tid = setTimeout(function() {
++              expect(true).toBe(true);
++              done();
++            }, 101);
++            // if win is called again, clear the timeout and fail the test
++            win = function() {
++              clearTimeout(tid);
++              fail(done);
++            }
++          };
++
++          // wrap the success call in a closure since the value of win changes between calls
++          id = navigator.accelerometer.watchAcceleration(function() { win(); }, fail.bind(null, done), {frequency:100});
++      });
++    });
++  });
+ };
+ 
+ /******************************************************************************/
+ /******************************************************************************/
+ /******************************************************************************/
+ 
+ exports.defineManualTests = function (contentEl, createActionButton) {
+     function roundNumber(num) {
+         var dec = 3;
+         var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
+         return result;
+     }
+ 
+     var watchAccelId = null;
+ 
+     /**
+      * Start watching acceleration
+      */
+     var watchAccel = function () {
+         console.log("watchAccel()");
+ 
+         // Success callback
+         var success = function (a) {
+             document.getElementById('x').innerHTML = roundNumber(a.x);
+             document.getElementById('y').innerHTML = roundNumber(a.y);
+             document.getElementById('z').innerHTML = roundNumber(a.z);
+         };
+ 
+         // Fail callback
+         var fail = function (e) {
+             console.log("watchAccel fail callback with error code " + e);
+             stopAccel();
+             setAccelStatus(Accelerometer.ERROR_MSG[e]);
+         };
+ 
+         // Update acceleration every 1 sec
+         var opt = {};
+         opt.frequency = 1000;
+         watchAccelId = navigator.accelerometer.watchAcceleration(success, fail, opt);
+ 
+         setAccelStatus("Running");
+     };
+ 
+     /**
+      * Stop watching the acceleration
+      */
+     var stopAccel = function () {
+         console.log("stopAccel()");
+         setAccelStatus("Stopped");
+         if (watchAccelId) {
+             navigator.accelerometer.clearWatch(watchAccelId);
+             watchAccelId = null;
+         }
+     };
+ 
+     /**
+      * Get current acceleration
+      */
+     var getAccel = function () {
+         console.log("getAccel()");
+ 
+         // Stop accel if running
+         stopAccel();
+ 
+         // Success callback
+         var success = function (a) {
+             document.getElementById('x').innerHTML = roundNumber(a.x);
+             document.getElementById('y').innerHTML = roundNumber(a.y);
+             document.getElementById('z').innerHTML = roundNumber(a.z);
+             console.log("getAccel success callback");
+         };
+ 
+         // Fail callback
+         var fail = function (e) {
+             console.log("getAccel fail callback with error code " + e);
+             setAccelStatus(Accelerometer.ERROR_MSG[e]);
+         };
+ 
+         // Make call
+         var opt = {};
+         navigator.accelerometer.getCurrentAcceleration(success, fail, opt);
+     };
+ 
+     /**
+      * Set accelerometer status
+      */
+     var setAccelStatus = function (status) {
+         document.getElementById('accel_status').innerHTML = status;
+     };
+ 
+     /******************************************************************************/
+ 
++    var accelerometer_tests = '<div id="getAcceleration"></div>' +
++        'Expected result: Will update the status box with X, Y, and Z values when pressed. Status will read "Stopped"' +
++        '<p/> <div id="watchAcceleration"></div>' +
++        'Expected result: When pressed, will start a watch on the accelerometer and update X,Y,Z values when movement is sensed. Status will read "Running"' +
++        '<p/> <div id="clearAcceleration"></div>' +
++        'Expected result: Will clear the accelerometer watch, so X,Y,Z values will no longer be updated. Status will read "Stopped"';
++
+     contentEl.innerHTML = '<div id="info">' +
+         'Status: <span id="accel_status">Stopped</span>' +
+         '<table width="100%">' +
+         '<tr><td width="20%">X:</td><td id="x"> </td></tr>' +
+         '<tr><td width="20%">Y:</td><td id="y"> </td></tr>' +
+         '<tr><td width="20%">Z:</td><td id="z"> </td></tr>' +
+         '</table></div>' +
 -        '<div id="actions"></div>';
++        accelerometer_tests;
+ 
+     createActionButton('Get Acceleration', function () {
+         getAccel();
 -    }, 'actions');
++    }, 'getAcceleration');
+ 
+     createActionButton('Start Watch', function () {
+         watchAccel();
 -    }, 'actions');
++    }, 'watchAcceleration');
+ 
+     createActionButton('Clear Watch', function () {
+         stopAccel();
 -    }, 'actions');
++    }, 'clearAcceleration');
+ };