michael@0: /* michael@0: * michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * michael@0: */ michael@0: michael@0: exports.defineAutoTests = function () { michael@0: michael@0: describe('Vibration (navigator.notification.vibrate)', function () { michael@0: it("navigator.notification should exist", function () { michael@0: expect(navigator.notification).toBeDefined(); michael@0: }); michael@0: michael@0: it("should contain a vibrate function", function () { michael@0: expect(typeof navigator.notification.vibrate).toBeDefined(); michael@0: expect(typeof navigator.notification.vibrate).toBe("function"); michael@0: }); michael@0: }); michael@0: }; michael@0: michael@0: exports.defineManualTests = function (contentEl, createActionButton) { michael@0: var logMessage = function (message, color) { michael@0: var log = document.getElementById('info'); michael@0: var logLine = document.createElement('div'); michael@0: if (color) { michael@0: logLine.style.color = color; michael@0: } michael@0: logLine.innerHTML = message; michael@0: log.appendChild(logLine); michael@0: } michael@0: michael@0: var clearLog = function () { michael@0: var log = document.getElementById('info'); michael@0: log.innerHTML = ''; michael@0: } michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // Vibrations michael@0: //------------------------------------------------------------------------- michael@0: michael@0: //old vibrate call michael@0: var vibrateOld = function(){ michael@0: clearLog(); michael@0: navigator.notification.vibrate(2500); michael@0: logMessage("navigator.notification.vibrate(2500)", "green"); michael@0: }; michael@0: michael@0: //old vibrate with pattern call michael@0: var vibrateWithPatternOld = function(){ michael@0: clearLog(); michael@0: navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000]); michael@0: logMessage("navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000])", "green"); michael@0: }; michael@0: michael@0: //old cancel vibrate call michael@0: var cancelOld = function(){ michael@0: clearLog(); michael@0: navigator.notification.cancelVibration(); michael@0: logMessage("navigator.notification.cancelVibration()", "green"); michael@0: }; michael@0: michael@0: //new standard vibrate call that aligns to w3c spec with param long michael@0: var vibrateWithInt = function() { michael@0: clearLog(); michael@0: navigator.vibrate(3000); michael@0: logMessage("navigator.vibrate(3000)", "green"); michael@0: }; michael@0: michael@0: //new standard vibrate call that aligns to w3c spec with param array michael@0: var vibrateWithArray = function() { michael@0: clearLog(); michael@0: navigator.vibrate([3000]); michael@0: logMessage("navigator.vibrate([3000])", "green"); michael@0: }; michael@0: michael@0: //vibrate with a pattern using w3c spec michael@0: var vibrateWithPattern = function() { michael@0: clearLog(); michael@0: navigator.vibrate([1000, 2000, 3000, 2000, 5000]); michael@0: logMessage("navigator.vibrate([1000, 2000, 3000, 2000, 5000])", "green"); michael@0: }; michael@0: michael@0: //cancel existing vibration using w3c spec navigator.vibrate(0) michael@0: var cancelWithZero = function() { michael@0: clearLog(); michael@0: navigator.vibrate(0); michael@0: logMessage("navigator.vibrate(0)", "green"); michael@0: }; michael@0: michael@0: //cancel existing vibration using w3c spec navigator.vibrate([]) michael@0: var cancelWithEmpty = function() { michael@0: clearLog(); michael@0: navigator.vibrate([]); michael@0: logMessage("navigator.vibrate([])", "green"); michael@0: }; michael@0: michael@0: //reference to the timeout variable michael@0: var timeout; michael@0: michael@0: //special long vibrate used to test cancel michael@0: var longVibrate = function() { michael@0: clearLog(); michael@0: navigator.vibrate(60000); michael@0: vibrateOn = true; michael@0: logMessage("navigator.vibrate(60000)", "green"); michael@0: timeout = setTimeout(resetVibrateOn, 60000); //if user doesn't cancel vibrate, reset vibrateOn var after 60 seconds michael@0: }; michael@0: michael@0: //special long vibrate with pattern used to test cancel michael@0: var longVibrateWithPattern = function() { michael@0: clearLog(); michael@0: navigator.vibrate([1000, 2000, 3000, 2000, 5000, 2000, 30000]); michael@0: vibrateOn = true; michael@0: logMessage("navigator.vibrate([1000, 2000, 3000, 2000, 5000, 2000, 30000])", "green"); michael@0: timeout = setTimeout(resetVibrateOn, 45000); //if user doesn't cancel vibrate, reset vibrateOn var after 45 seconds michael@0: }; michael@0: michael@0: //initiate two vibrations to test cancel michael@0: var multipleVibrations = function() { michael@0: clearLog(); michael@0: navigator.vibrate(20000); michael@0: navigator.vibrate(45000); michael@0: vibrateOn = true; michael@0: logMessage("navigator.vibrate(15000)\nnavigator.vibrate(45000)", "green"); michael@0: timeout = setTimeout(resetVibrateOn, 45000); //if user doesn't cancel vibrate, reset vibrateOn var after 45 seconds michael@0: } michael@0: michael@0: function resetVibrateOn() { michael@0: vibrateOn = false; michael@0: } michael@0: michael@0: //check whether there is an ongoing vibration michael@0: var vibrateOn = false; michael@0: michael@0: michael@0: michael@0: michael@0: var vibrate_tests = '