You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/04/18 23:49:53 UTC

[34/37] spec commit: converted accel tests

converted accel tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/commit/7785df52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/tree/7785df52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/diff/7785df52

Branch: refs/heads/master
Commit: 7785df52e8f133f242e2a0751194fbd26126c68a
Parents: 57b79a8
Author: Gord Tanner <gt...@gmail.com>
Authored: Mon Apr 2 22:33:51 2012 -0400
Committer: Fil Maj <ma...@gmail.com>
Committed: Mon Apr 16 16:05:09 2012 -0700

----------------------------------------------------------------------
 autotest/pages/accelerometer.html     |   47 +++++++++++++
 autotest/tests/accelerometer.tests.js |  103 ++++++++++++++-------------
 2 files changed, 100 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/7785df52/autotest/pages/accelerometer.html
----------------------------------------------------------------------
diff --git a/autotest/pages/accelerometer.html b/autotest/pages/accelerometer.html
index af0ae42..01b0970 100644
--- a/autotest/pages/accelerometer.html
+++ b/autotest/pages/accelerometer.html
@@ -1,5 +1,6 @@
 <!DOCTYPE html>
 <html>
+<<<<<<< HEAD
   <head>
     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
     <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=1.0;" />
@@ -48,6 +49,52 @@
             <!-- Populated by tests -->
         </div>
     </body>
+=======
+<head>
+  <title>Cordova: Accelerometer API Specs</title>
+
+  <!-- Load jasmine -->
+  <link href="../jasmine.css" rel="stylesheet"/>
+  <script type="text/javascript" src="../jasmine.js"></script>
+  <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
+  <script type="text/javascript" src="../html/HtmlReporter.js"></script>
+  <script type="text/javascript" src="../html/ReporterView.js"></script>
+  <script type="text/javascript" src="../html/SpecView.js"></script>
+  <script type="text/javascript" src="../html/SuiteView.js"></script>
+  <script type="text/javascript" src="../html/TrivialReporter.js"></script>
+
+  <!-- Source -->
+  <script type="text/javascript" src="../../phonegap.js"></script>
+
+  <!-- Load Test Runner -->
+  <script type="text/javascript" src="../test-runner.js"></script>
+
+  <!-- Tests -->
+  <script type="text/javascript" src="../tests/accelerometer.tests.js"></script>
+
+  <script type="text/javascript">
+    document.addEventListener('deviceready', function () {
+      var jasmineEnv = jasmine.getEnv();
+      jasmineEnv.updateInterval = 1000;
+
+      var htmlReporter = new jasmine.HtmlReporter();
+
+      jasmineEnv.addReporter(htmlReporter);
+
+      jasmineEnv.specFilter = function(spec) {
+        return htmlReporter.specFilter(spec);
+      };
+
+      jasmineEnv.execute();
+    }, false);
+  </script>
+</head>
+
+<body>
+  <a href="javascript:" class="backBtn" onclick="backHome();">Back</a>
+</body>
+>>>>>>> converted accel tests
 </html>
 
 
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-mobile-spec/blob/7785df52/autotest/tests/accelerometer.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/accelerometer.tests.js b/autotest/tests/accelerometer.tests.js
index a99d459..c9a2745 100644
--- a/autotest/tests/accelerometer.tests.js
+++ b/autotest/tests/accelerometer.tests.js
@@ -1,55 +1,58 @@
-Tests.prototype.AccelerometerTests = function() {
-	module('Accelerometer (navigator.accelerometer)');
-	test("should exist", function() {
-  		expect(1);
-  		ok(navigator.accelerometer != null, "navigator.accelerometer should not be null.");
+describe('Accelerometer (navigator.accelerometer)', function () {
+	it("should exist", function () {
+        expect(navigator.accelerometer).toBeDefined();
 	});
-	test("should contain a getCurrentAcceleration function", function() {
-		expect(2);
-		ok(typeof navigator.accelerometer.getCurrentAcceleration != 'undefined' && navigator.accelerometer.getCurrentAcceleration != null, "navigator.accelerometer.getCurrentAcceleration should not be null.");
-		ok(typeof navigator.accelerometer.getCurrentAcceleration == 'function', "navigator.accelerometer.getCurrentAcceleration should be a function.");
+
+	it("should contain a getCurrentAcceleration function", function() {
+		expect(typeof navigator.accelerometer.getCurrentAcceleration).toBeDefined();
+		expect(typeof navigator.accelerometer.getCurrentAcceleration == 'function').toBe(true);
 	});
-	test("getCurrentAcceleration success callback should be called with an Acceleration object", function() {
-		expect(7);
-		QUnit.stop(Tests.TEST_TIMEOUT);
-		var win = function(a) {
-			ok(typeof a == 'object', "Acceleration object returned in getCurrentAcceleration success callback should be of type 'object'.");
-			ok(a.x != null, "Acceleration object returned in getCurrentAcceleration success callback should have an 'x' property.");
-			ok(typeof a.x == 'number', "Acceleration object's 'x' property returned in getCurrentAcceleration success callback should be of type 'number'.");
-			ok(a.y != null, "Acceleration object returned in getCurrentAcceleration success callback should have a 'y' property.");
-			ok(typeof a.y == 'number', "Acceleration object's 'y' property returned in getCurrentAcceleration success callback should be of type 'number'.");
-			ok(a.z != null, "Acceleration object returned in getCurrentAcceleration success callback should have a 'z' property.");
-			ok(typeof a.z == 'number', "Acceleration object's 'z' property returned in getCurrentAcceleration success callback should be of type 'number'.");
-			start();
-		};
-		var fail = function() { start(); };
-		navigator.accelerometer.getCurrentAcceleration(win, fail);
+
+	it("getCurrentAcceleration success callback should be called with an Acceleration object", function() {
+
+		var win = jasmine.createSpy().andCallFake(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);
+            }),
+            fail = jasmine.createSpy();
+
+        runs(function () {
+		    navigator.accelerometer.getCurrentAcceleration(win, fail);
+        });
+
+        waitsFor(function () { return win.wasCalled; }, "win never called", Tests.TEST_TIMEOUT);
+
+        runs(function () {
+            expect(fail).not.toHaveBeenCalled();
+        });
 	});
-	test("should contain a watchAcceleration function", function() {
-		expect(2);
-		ok(typeof navigator.accelerometer.watchAcceleration != 'undefined' && navigator.accelerometer.watchAcceleration != null, "navigator.accelerometer.watchAcceleration should not be null.");
-		ok(typeof navigator.accelerometer.watchAcceleration == 'function', "navigator.accelerometer.watchAcceleration should be a function.");
+
+	it("should contain a watchAcceleration function", function() {
+		expect(navigator.accelerometer.watchAcceleration).toBeDefined();
+		expect(typeof navigator.accelerometer.watchAcceleration == 'function').toBe(true);
 	});
-	test("should contain a clearWatch function", function() {
-		expect(2);
-		ok(typeof navigator.accelerometer.clearWatch != 'undefined' && navigator.accelerometer.clearWatch != null, "navigator.accelerometer.clearWatch should not be null.");
-		ok(typeof navigator.accelerometer.clearWatch == 'function', "navigator.accelerometer.clearWatch should be a function!");
+
+	it("should contain a clearWatch function", function() {
+		expect(navigator.accelerometer.clearWatch).toBeDefined();
+		expect(typeof navigator.accelerometer.clearWatch == 'function').toBe(true);
 	});
-	module('Acceleration model');
-	test("should be able to define a new Acceleration object with x, y, z and timestamp properties.", function () {
-		expect(9);
-		var x = 1;
-		var y = 2;
-		var z = 3;
-		var a = new Acceleration(x, y, z);
-		ok(a != null, "new Acceleration object should not be null.");
-		ok(typeof a == 'object', "new Acceleration object should be of type 'object'.");
-		ok(a.x != null, "new Acceleration object should have an 'x' property.");
-		equals(a.x, x, "new Acceleration object should have 'x' property equal to first parameter passed in Acceleration constructor.");
-		ok(a.y != null, "new Acceleration object should have a 'y' property.");
-		equals(a.y, y, "new Acceleration object should have 'y' property equal to second parameter passed in Acceleration constructor.");
-		ok(a.z != null, "new Acceleration object should have a 'z' property.");
-		equals(a.z, z, "new Acceleration object should have 'z' property equal to third parameter passed in Acceleration constructor.");
-		ok(a.timestamp != null, "new Acceleration object should have a 'timestamp' property.");
-	});
-};
\ No newline at end of file
+
+	describe('Acceleration model', function () { 
+        it("should be able to define a new Acceleration object with x, y, z and timestamp properties.", function () {
+            var x = 1;
+            var y = 2;
+            var z = 3;
+            var a = new Acceleration(x, y, z);
+            expect(a).toBeDefined();
+            expect(a.x).toBe(x);
+            expect(a.y).toBe(y);
+            expect(a.z).toBe(z);
+            expect(a.timestamp).toBeDefined();
+        });
+    });
+});