/* * * 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. * */ /* jshint jasmine: true */ exports.defineAutoTests = function () { describe('Vibration (navigator.notification.vibrate)', function () { it("navigator.notification should exist with vibrate function", function () { expect(navigator.notification).toBeDefined(); expect(typeof navigator.notification.vibrate).toBeDefined(); expect(typeof navigator.notification.vibrate).toBe("function"); if (cordova.platformId == "browser") expect(navigator.notification.vibrate(0)).toBe(false); }); }); }; exports.defineManualTests = function (contentEl, createActionButton) { 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([1000, 3000, 2000, 5000]); logMessage("navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000])", "green"); }; //old vibrate with pattern with repeat call var vibrateWithPatternOldWithRepeat = function(){ clearLog(); navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000], 2); logMessage("navigator.notification.vibrateWithPattern([1000, 3000, 2000, 5000], 2)", "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([1000, 2000, 3000, 2000, 5000]); logMessage("navigator.vibrate([1000, 2000, 3000, 2000, 5000])", "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"); }; //reference to the timeout variable var timeout; //check whether there is an ongoing vibration var vibrateOn = false; //special long vibrate used to test cancel var longVibrate = function() { clearLog(); navigator.vibrate(60000); vibrateOn = true; logMessage("navigator.vibrate(60000)", "green"); timeout = setTimeout(resetVibrateOn, 60000); //if user doesn't cancel vibrate, reset vibrateOn var after 60 seconds }; //special long vibrate with pattern used to test cancel var longVibrateWithPattern = function() { clearLog(); navigator.vibrate([1000, 2000, 3000, 2000, 5000, 2000, 30000]); vibrateOn = true; logMessage("navigator.vibrate([1000, 2000, 3000, 2000, 5000, 2000, 30000])", "green"); timeout = setTimeout(resetVibrateOn, 45000); //if user doesn't cancel vibrate, reset vibrateOn var after 45 seconds }; //initiate two vibrations to test cancel var multipleVibrations = function() { clearLog(); navigator.vibrate(20000); navigator.vibrate(45000); vibrateOn = true; logMessage("navigator.vibrate(15000)\nnavigator.vibrate(45000)", "green"); timeout = setTimeout(resetVibrateOn, 45000); //if user doesn't cancel vibrate, reset vibrateOn var after 45 seconds }; function resetVibrateOn() { vibrateOn = false; } var vibrate_tests = '