initial bunch of tests that don't interact with page visibility
authorRobin Berjon <robin@berjon.com>
Fri, 27 Jan 2012 15:35:36 +0100
changeset 42 c48f5c8036e8
parent 41 1397be1f02f4
child 43 56526227e580
initial bunch of tests that don't interact with page visibility
tests/vibration/approved/.hgkeep
tests/vibration/submissions/robin/TODO.txt
tests/vibration/submissions/robin/api-is-present.html
tests/vibration/submissions/robin/cancel-with-0.html
tests/vibration/submissions/robin/cancel-with-[].html
tests/vibration/submissions/robin/cancel-with-new.html
tests/vibration/submissions/robin/pattern-array-extra.html
tests/vibration/submissions/robin/pattern-array.html
tests/vibration/submissions/robin/silent-ignore.html
tests/vibration/submissions/robin/simple-array.html
tests/vibration/submissions/robin/simple-scalar.html
tests/vibration/support/feature-detection.js
tests/vibration/support/helpers.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/TODO.txt	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,29 @@
+
+TESTS:
+    ✓ API presence
+    ✓ silent ignore (requires a device that does not support vibration)
+    ✓ simple value
+    ✓ array of values
+    ✓ array with extra parameter (even array)
+    ✓ cancel with 0
+    ✓ cancel with []
+    ✓ cancel with new vibration
+    - do nothing when hidden
+    - cancel when dynamically hidden
+    - reinstate when dynamically shown
+
+
+NOTES:
+• Test using vendor prefix as in
+ http://dvcs.w3.org/hg/webperf/file/25712d0f6bd5/tests/submission/Microsoft/PageVisibility/support/featuredetection.js
+
+• Testing transitions as in
+http://dvcs.w3.org/hg/webperf/file/25712d0f6bd5/tests/submission/Microsoft/PageVisibility/test_tab_switch.htm
+
+• When the visibilitychange event [PAGE-VISIBILITY] is dispatched at the Document, the user agent must run the following steps
+    - If the hidden attribute [PAGE-VISIBILITY] is set to true, the user agent must 
+      suppress the vibration produced by running the pre-existing instance of the processing 
+      vibration patterns algorithm, if any.
+    - If the hidden attribute [PAGE-VISIBILITY] is set to false, the user agent must 
+      restore the vibration produced by running the pre-existing instance of the 
+      processing vibration patterns algorithm, if any.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/api-is-present.html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: test that the vibrate() method is present (with or without vendor prefix)</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom'/>
+    <meta name='assert' content='Check that the vibrate() method is present.'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      This test checks for the presence of the <code>vibrate()</code> method, taking
+      vendor prefixes into account.
+    </p>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script>
+      test(function () {
+          assert_true(undefined !== BrowserHasFeature(navigator, "vibrate"), "navigator.vibrate exists");
+      }, "vibrate() is present on navigator");
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/cancel-with-0.html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: cancel ongoing vibrate() with 0</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom, interact'/>
+    <meta name='assert' content='If pattern is 0, cancel the pre-existing instance of the processing vibration patterns algorithm'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      After hitting the button below, your device must vibrate for a short period of time (roughly one
+      second). If it vibrates for a longer time (roughly five seconds, it should feel somewhat long) then
+      the test has failed.
+    </p>
+    <buton id='vib'>Vibrate!</buton>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script src='../../support/helpers.js'></script>
+    <script>
+      if (supportsVibration()) {
+          document.getElementById("vib").onclick = function () {
+              navigator.vibrate(5000);
+              setTimeout(function () {
+                  navigator.vibrate(0);
+              }, 1000);
+          };
+      }
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/cancel-with-[].html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: cancel ongoing vibrate() with []</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom, interact'/>
+    <meta name='assert' content='If pattern is an empty list, cancel the pre-existing instance of the processing vibration patterns algorithm'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      After hitting the button below, your device must vibrate for a short period of time (roughly one
+      second). If it vibrates for a longer time (roughly five seconds, it should feel somewhat long) then
+      the test has failed.
+    </p>
+    <buton id='vib'>Vibrate!</buton>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script src='../../support/helpers.js'></script>
+    <script>
+      if (supportsVibration()) {
+          document.getElementById("vib").onclick = function () {
+              navigator.vibrate(5000);
+              setTimeout(function () {
+                  navigator.vibrate([]);
+              }, 1000);
+          };
+      }
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/cancel-with-new.html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: cancel ongoing vibrate() with a new call to vibrate</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom, interact'/>
+    <meta name='assert' content='Cancel the pre-existing instance of the processing vibration patterns algorithm, if any.'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      After hitting the button below, your device must vibrate continuously for a short period of time (roughly one
+      second), then vibrate a series of short bursts. If the initial continuously vibration is longer (roughly five
+      seconds, it should feel somewhat long) or if there is no series of short vibration bursts then the test has
+      failed.
+    </p>
+    <buton id='vib'>Vibrate!</buton>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script src='../../support/helpers.js'></script>
+    <script>
+      if (supportsVibration()) {
+          document.getElementById("vib").onclick = function () {
+              navigator.vibrate(5000);
+              setTimeout(function () {
+                  navigator.vibrate([200, 200, 200, 200, 200, 200, 200, 200, 200]);
+              }, 1000);
+          };
+      }
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/pattern-array-extra.html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: test a pattern array parameter to vibrate() with an extra (even) item</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom, interact'/>
+    <meta name='assert' content='If the length of pattern is even, then remove the last entry in pattern.'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      After hitting the button below, your device must vibrate three times for one second, separated
+      by one second intervals.
+    </p>
+    <buton id='vib'>Vibrate!</buton>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script src='../../support/helpers.js'></script>
+    <script>
+      if (supportsVibration()) {
+          document.getElementById("vib").onclick = function () {
+              navigator.vibrate([1000, 1000, 1000, 1000, 1000, 1000]);
+          };
+      }
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/pattern-array.html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: test a pattern array parameter to vibrate()</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom, interact'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      After hitting the button below, your device must vibrate three times for one second, separated
+      by one second intervals.
+    </p>
+    <buton id='vib'>Vibrate!</buton>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script src='../../support/helpers.js'></script>
+    <script>
+      if (supportsVibration()) {
+          document.getElementById("vib").onclick = function () {
+              navigator.vibrate([1000, 1000, 1000, 1000, 1000]);
+          };
+      }
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/silent-ignore.html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: test that calls to vibrate() are silently ignored when the device cannot vibrate</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom, no-vibrator'/>
+    <meta name='assert' content='If the device does not provide a vibration mechanism, or it is disabled, the user agent must silently ignore any invocations of the vibrate() method.'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      <strong>This test is only useful on devices that do not have vibration capability</strong>.
+      If your device supports vibration, then <strong>skip</strong> this test. An implementation
+      supporting this API but running on a device that cannot vibrate must silently ignore the
+      call (we test that it doesn't throw).
+    </p>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script src='../../support/helpers.js'></script>
+    <script>
+      if (supportsVibration()) {
+          test(function () {
+              var ok = false;
+              try {
+                  navigator.vibrate(1000);
+                  ok = true;
+              }
+              catch (e) {
+                  ok = false;
+              }
+              assert_true(ok, "vibrate() should not throw");
+          }, "Calling vibrate does not throw.");
+      }
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/simple-array.html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: test a simple array parameter to vibrate()</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom, interact'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      After hitting the button below, your device must vibrate continuously for about two seconds, once.
+    </p>
+    <buton id='vib'>Vibrate!</buton>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script src='../../support/helpers.js'></script>
+    <script>
+      if (supportsVibration()) {
+          document.getElementById("vib").onclick = function () {
+              navigator.vibrate([2000]);
+          };
+      }
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/submissions/robin/simple-scalar.html	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html xmlns='http://www.w3.org/1999/xhtml' lang='en'>
+  <head>
+    <meta charset='utf-8'/>
+    <title>Vibration API: test a simple scalar parameter to vibrate()</title>
+    <link rel='author' title='Robin Berjon' href='mailto:robin@berjon.com'/>
+    <link rel='help' href='http://www.w3.org/TR/vibration/#methods' media='all'/>
+    <meta name='flags' content='vendor-prefix, dom, interact'/>
+    <!-- 
+      When you review this test, please add
+      <link rel='reviewer' title='Your Name' href='mailto:your-email-address'/>
+    -->
+    <link rel='stylesheet' href='http://w3c-test.org/resources/testharness.css' media='all'/>
+  </head>
+  <body>
+    <h1>Description</h1>
+    <p>
+      After hitting the button below, your device must vibrate continuously for about two seconds, once.
+    </p>
+    <buton id='vib'>Vibrate!</buton>
+    <div id='log'></div>
+    <script src='http://w3c-test.org/resources/testharness.js'></script>
+    <!-- When this test gets approved, remove a "../" below -->
+    <script src='../../support/feature-detection.js'></script>
+    <script src='../../support/helpers.js'></script>
+    <script>
+      if (supportsVibration()) {
+          document.getElementById("vib").onclick = function () {
+              navigator.vibrate(2000);
+          };
+      }
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/support/feature-detection.js	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,94 @@
+
+// 2012-01-27
+//  The code below has been stolen from Microsoft's submission tests to the Page Visibility
+//  specification. Thanks!
+
+
+// This function returns the value of an API feature if it is defined with one of
+// the known ventor prefixes. 
+//
+// Parameters:
+//  parent: the object containing the API feature
+//  feature: the name of the API feature, this should be a string value
+//  isAttribute: set this to true to indicate that this is a constant attribute
+//               as opposed to a variable
+function BrowserHasFeature(parent, feature, isAttribute)
+{
+    if (parent[feature] !== undefined)
+    {
+        //feature is defined without a vendor prefix, no further checks necessary
+        return parent[feature];
+    }
+
+    // the feature is not defined without a vendor prefix, so find the vendor prefix, if any,
+    // that it is defined with
+    var prefix = GetVendorPrefix(parent, feature, isAttribute);
+    
+    // if prefix is not undefined, then the feature has been found to exist with this prefix
+    if (prefix !== undefined)
+    {
+        var prefixedFeatureName = AppendPrefix(prefix, feature, isAttribute);
+        return parent[prefixedFeatureName];
+    }
+
+    //The feature does not exist.
+    //Callers should check for !==undefined as the feature itself could return
+    //a Bool which would fail a typical if(feature) check
+    return undefined;
+}
+
+// This function returns the vendor prefix found if a certain feature is defined with it.
+// It takes the same parameters at BrowserHasFeature().
+function GetVendorPrefix(parent, feature, isAttribute)
+{
+    //Known vendor prefixes
+    var VendorPrefixes = ["moz", "ms", "o", "webkit"];
+    for (vendor in VendorPrefixes)
+    {
+        //Build up the new feature name with the vendor prefix
+        var prefixedFeatureName = AppendPrefix(VendorPrefixes[vendor], feature, isAttribute);
+        if (parent[prefixedFeatureName] !== undefined)
+        {
+            //Vendor prefix version exists, return a pointer to the feature
+            return VendorPrefixes[vendor];
+        }
+    }
+    
+    // if no version of the feature with a vendor prefix has been found, return undefined
+    return undefined;
+}
+
+// This will properly capitalize the feature name and then return the feature name preceded
+// with the provided vendor prefix. If the prefix given is undefined, this function will
+// return the feature name given as is. The output of this function should not be used
+// as an indicator of whether or not a feature exists as it will return the same thing if
+// the inputted feature is undefined or is defined without a vendor prefix. It takes the 
+// same parameters at BrowserHasFeature().
+function AppendPrefix(prefix, feature, isAttribute)
+{
+    if (prefix !== undefined)
+    {
+        if (isAttribute)
+        {
+            // if a certain feature is an attribute, then it follows a different naming standard
+            // where it must be completely capitalized and have words split with an underscore
+            return prefix.toUpperCase() + "_" + feature.toUpperCase();
+        }
+        else
+        {
+            //Vendor prefixing should follow the standard convention: vendorprefixFeature
+            //Note that the feature is capitalized after the vendor prefix
+            //Therefore if the feature is window.feature, the vendor prefix version is:
+            //window.[vp]Feature where vp is the vendor prefix: 
+            //window.msFeature, window.webkitFeature, window.mozFeature, window.oFeature
+            var newFeature = feature[0].toUpperCase() + feature.substr(1, feature.length);
+
+            //Build up the new feature name with the vendor prefix
+            return prefix + newFeature;
+        }
+    }
+    else
+    {
+        return feature;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/vibration/support/helpers.js	Fri Jan 27 15:35:36 2012 +0100
@@ -0,0 +1,13 @@
+
+function supportsVibration () {
+    if (undefined !== BrowserHasFeature(navigator, "vibrate")) {
+        return true;
+    }
+    else {
+        test(function () {
+            assert_true(false, "Vibration API not found");
+        }, "Your user agent does not support the Vibration API.");
+        return false;
+    }
+}
+