cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [06/11] git commit: on/off button for cancel tests, add results box and msgs
Date Thu, 07 Aug 2014 20:48:33 GMT
on/off button for cancel tests, add results box and msgs


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/commit/90c6335c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/tree/90c6335c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/diff/90c6335c

Branch: refs/heads/master
Commit: 90c6335c59775fb5ee94ccf8aa027e5bfc98e9fd
Parents: e0723e2
Author: Edna Morales <ednamorales@ednas-mbp-2.raleigh.ibm.com>
Authored: Fri Jul 18 15:02:34 2014 -0400
Committer: Edna Morales <ednamorales@ednas-mbp-2.raleigh.ibm.com>
Committed: Fri Jul 18 15:02:34 2014 -0400

----------------------------------------------------------------------
 test/tests.js | 235 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 156 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/90c6335c/test/tests.js
----------------------------------------------------------------------
diff --git a/test/tests.js b/test/tests.js
index d152818..86fa7b9 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -34,106 +34,183 @@ exports.defineAutoTests = function () {
 };
 
 exports.defineManualTests = function (contentEl, createActionButton) {
-//-------------------------------------------------------------------------
-// Vibrations
-//-------------------------------------------------------------------------
-
-//old vibrate call
-var vibrateOld = function(){
-  navigator.notification.vibrate(2500);
-};
-
-//old vibrate with pattern call
-var vibrateWithPatternOld = function(){
-  navigator.notification.vibrateWithPattern([100, 200, 300]);
-};
-
-//old cancel vibrate call
-var cancelOld = function(){
-    navigator.notification.cancelVibration();
-};
-
-//new standard vibrate call that aligns to w3c spec with param long
-var vibrateWithInt = function() {
-    navigator.vibrate(3000);
-};
-
-//new standard vibrate call that aligns to w3c spec with param array
-var vibrateWithArray = function() {
-    navigator.vibrate([3000]);
-};
-
-//vibrate with a pattern using w3c spec
-var vibrateWithPattern = function() {
-    navigator.vibrate([100, 200, 300]);
-};
-
-//cancel existing vibration using w3c spec navigator.vibrate(0)
-var cancelWithZero = function() {
-    navigator.vibrate(0);
-};
-
-//cancel existing vibration using w3c spec navigator.vibrate([])
-var cancelWithEmpty = function() {
-    navigator.vibrate([]);
-};
-
-//special long vibrate used to test cancel
-var longVibrate = function() {
-    navigator.vibrate(60000);
-};
-
-//check whether there is an ongoing vibration
-var vibrateOn = false;
+    var logMessage = function (message, color) {
+        var log = document.getElementById('info');
+        var logLine = document.createElement('div');
+        if (color) {
+            logLine.style.color = color;
+        }
+        logLine.innerHTML = message;
+        log.appendChild(logLine);
+    }
+
+    var clearLog = function () {
+        var log = document.getElementById('info');
+        log.innerHTML = '';
+    }
+
+    //-------------------------------------------------------------------------
+    // Vibrations
+    //-------------------------------------------------------------------------
+
+    //old vibrate call
+    var vibrateOld = function(){
+        clearLog();
+        navigator.notification.vibrate(2500);
+        logMessage("navigator.notification.vibrate(2500)", "green");
+    };
+
+    //old vibrate with pattern call
+    var vibrateWithPatternOld = function(){
+        clearLog();
+        navigator.notification.vibrateWithPattern([100, 200, 300]);
+        logMessage("navigator.notification.vibrateWithPattern([100, 200, 300])", "green");
+    };
+
+    //old cancel vibrate call
+    var cancelOld = function(){
+        clearLog();
+        navigator.notification.cancelVibration();
+        logMessage("navigator.notification.cancelVibration()", "green");
+    };
+
+    //new standard vibrate call that aligns to w3c spec with param long
+    var vibrateWithInt = function() {
+        clearLog();
+        navigator.vibrate(3000);
+        logMessage("navigator.vibrate(3000)", "green");
+    };
+
+    //new standard vibrate call that aligns to w3c spec with param array
+    var vibrateWithArray = function() {
+        clearLog();
+        navigator.vibrate([3000]);
+        logMessage("navigator.vibrate([3000])", "green");
+    };
+
+    //vibrate with a pattern using w3c spec
+    var vibrateWithPattern = function() {
+        clearLog();
+        navigator.vibrate([100, 200, 300]);
+        logMessage("navigator.vibrate([100, 200, 300])", "green");
+    };
+
+    //cancel existing vibration using w3c spec navigator.vibrate(0)
+    var cancelWithZero = function() {
+        clearLog();
+        navigator.vibrate(0);
+        logMessage("navigator.vibrate(0)", "green");
+    };
+
+    //cancel existing vibration using w3c spec navigator.vibrate([])
+    var cancelWithEmpty = function() {
+        clearLog();
+        navigator.vibrate([]);
+        logMessage("navigator.vibrate([])", "green");
+    };
+
+    //special long vibrate used to test cancel
+    var longVibrate = function() {
+        clearLog();
+        navigator.vibrate(60000);
+        logMessage("navigator.vibrate(60000)", "green");
+    };
+
+    //check whether there is an ongoing vibration
+    var vibrateOn = false;
+
+
+
+
+    var vibrate_tests = '<h1>Vibrate Tests</h1>' +
+        '<h3>Starred tests only work for Android. </h3>' +
+        '<div id="vibrate_old"></div>' +
+        'Expected result: Vibrate once for 2.5 seconds.' +
+        '<p/> <div id="vibrateWithPattern_old"></div>' +
+        'Expected result: Vibrate for 100ms, pause for 200ms, then vibrate for 300ms.' +
+        '<p/> <div id="cancelVibrate_old"></div>' +
+        'Expected result: First press will begin vibration for 60 seconds. Pressing again
will cancel immediately.' +
+        '<p/> <div id="vibrate_int"></div>' +
+        'Expected result: Vibrate once for 3 seconds.' +
+        '<p/> <div id="vibrate_array"></div>' +
+        'Expected result: Vibrate once for 3 seconds.' +
+        '<p/> <div id="vibrate_with_pattern"></div>' +
+        'Expected result: Vibrate for 100ms, pause for 200ms, then vibrate for 300ms.' +
+        '<p/> <div id="cancel_zero"></div>' +
+        'Expected result: First press will begin vibration for 60 seconds. Pressing again
will cancel immediately.' +
+        '<p/><div id="cancel_array"></div>' +
+        'Expected result: First press will begin vibration for 60 seconds. Pressing again
will cancel immediately.';
+
+
+    contentEl.innerHTML = '<div id="info"></div>' + vibrate_tests;
 
     //standard vibrate with old call
     createActionButton('Vibrate (Old)', function () {
         vibrateOld();
-        console.log("navigator.notification.vibrate(2500)");
-    });
+    }, 'vibrate_old');
 
     //vibrate with pattern with old call
-    createActionButton('Vibrate with a pattern (Old - Android only)', function () {
+    createActionButton('* Vibrate with a pattern (Old)', function () {
         vibrateWithPatternOld();
-        console.log("navigator.notification.vibrate([100, 200, 300]): should vibrate for
100ms, pause for 200ms, then vibrate for 300ms");
-    });
+    }, 'vibrateWithPattern_old');
 
     //cancel vibrate with old call
-    createActionButton('Cancel vibration (Old - Android only)', function() {
-        console.log("navigator.notification.cancelVibration(): should should try to vibrate
for 60 seconds but will be canceled after 5");
-        longVibrate();
-        setTimeout(cancelOld(), 5000);
-    });
+    createActionButton('* Cancel vibration (Old)', function() {
+
+        if (!vibrateOn)
+        {
+            longVibrate();
+            vibrateOn = true;
+        }
+        else
+        {
+            cancelOld();
+            vibrateOn = false;
+        }
+    }, 'cancelVibrate_old');
 
     //standard vibrate with new call param int
     createActionButton('Vibrate with int', function() {
-        console.log("navigator.vibrate(3000): should vibrate once for 3 seconds");
         vibrateWithInt();
-    });
+    }, 'vibrate_int');
 
     //standard vibrate with new call param array
-    createActionButton('Vibrate with array', function() {
-        console.log("navigator.vibrate([3000]): should vibrate once for 3 seconds");
+    createActionButton('* Vibrate with array', function() {
         vibrateWithArray();
-    });
+    }, 'vibrate_array');
 
     //vibrate with a pattern
-    createActionButton('Vibrate with a pattern (Android only)', function() {
-        console.log("navigator.vibrate([100, 200, 300]): should vibrate for 100ms, pause
for 200ms, then vibrate for 300ms");
+    createActionButton('* Vibrate with a pattern', function() {
         vibrateWithPattern();
-    });
+    }, 'vibrate_with_pattern');
 
     //cancel any existing vibrations with param 0
-    createActionButton('Cancel vibration with 0 (Android only)', function() {
-        console.log("navigator.vibrate(0): should try to vibrate for 60 seconds but will
be canceled after 5");
-        longVibrate();
-        setTimeout(cancelWithZero(), 5000);
-    });
+    createActionButton('* Cancel vibration with 0', function() {
+
+        if (!vibrateOn)
+        {
+            longVibrate();
+            vibrateOn = true;
+        }
+        else
+        {
+            cancelWithZero();
+            vibrateOn = false;
+        }
+    }, 'cancel_zero');
 
     //cancel any existing vibrations with param []
-    createActionButton('Cancel vibration with [] (Android only)', function() {
-        console.log("navigator.vibrate([]): should should try to vibrate for 60 seconds but
will be canceled after 5");
-        longVibrate();
-        setTimeout(cancelWithEmpty(), 5000);
-    });
+    createActionButton('* Cancel vibration with []', function() {
+
+        if (!vibrateOn)
+        {
+            longVibrate();
+            vibrateOn = true;
+        }
+        else
+        {
+            cancelWithEmpty();
+            vibrateOn = false;
+        }
+    }, 'cancel_array');
 };


Mime
View raw message