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: describe('Notification (navigator.notification)', function () { michael@0: it("should exist", function () { michael@0: expect(navigator.notification).toBeDefined(); michael@0: }); michael@0: michael@0: it("should contain a beep function", function () { michael@0: expect(typeof navigator.notification.beep).toBeDefined(); michael@0: expect(typeof navigator.notification.beep).toBe("function"); michael@0: }); michael@0: michael@0: it("should contain an alert function", function () { michael@0: expect(typeof navigator.notification.alert).toBeDefined(); michael@0: expect(typeof navigator.notification.alert).toBe("function"); michael@0: }); michael@0: michael@0: it("should contain a confirm function", function () { michael@0: expect(typeof navigator.notification.confirm).toBeDefined(); michael@0: expect(typeof navigator.notification.confirm).toBe("function"); michael@0: }); michael@0: michael@0: it("should contain a prompt function", function () { michael@0: expect(typeof navigator.notification.prompt).toBeDefined(); michael@0: expect(typeof navigator.notification.prompt).toBe("function"); michael@0: }); michael@0: }); michael@0: }; michael@0: michael@0: /******************************************************************************/ michael@0: /******************************************************************************/ michael@0: /******************************************************************************/ michael@0: michael@0: exports.defineManualTests = function (contentEl, createActionButton) { michael@0: var logMessage = function (message) { michael@0: var log = document.getElementById('info'); michael@0: var logLine = document.createElement('div'); 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: var beep = function () { michael@0: console.log("beep()"); michael@0: navigator.notification.beep(3); michael@0: }; michael@0: michael@0: var alertDialog = function (message, title, button) { michael@0: console.log("alertDialog()"); michael@0: navigator.notification.alert(message, michael@0: function () { michael@0: console.log("Alert dismissed."); michael@0: }, michael@0: title, button); michael@0: console.log("After alert"); michael@0: }; michael@0: michael@0: var confirmDialogA = function (message, title, buttons) { michael@0: clearLog(); michael@0: navigator.notification.confirm(message, michael@0: function (r) { michael@0: if (r === 0) { michael@0: logMessage("Dismissed dialog without making a selection."); michael@0: console.log("Dismissed dialog without making a selection."); michael@0: } else { michael@0: console.log("You selected " + r); michael@0: logMessage("You selected " + (buttons.split(","))[r - 1]); michael@0: } michael@0: }, michael@0: title, michael@0: buttons); michael@0: }; michael@0: michael@0: var confirmDialogB = function (message, title, buttons) { michael@0: clearLog(); michael@0: navigator.notification.confirm(message, michael@0: function (r) { michael@0: if (r === 0) { michael@0: logMessage("Dismissed dialog without making a selection."); michael@0: console.log("Dismissed dialog without making a selection."); michael@0: } else { michael@0: console.log("You selected " + r); michael@0: logMessage("You selected " + buttons[r - 1]); michael@0: } michael@0: }, michael@0: title, michael@0: buttons); michael@0: }; michael@0: michael@0: var promptDialog = function (message, title, buttons) { michael@0: clearLog(); michael@0: navigator.notification.prompt(message, michael@0: function (r) { michael@0: if (r && r.buttonIndex === 0) { michael@0: var msg = "Dismissed dialog"; michael@0: if (r.input1) { michael@0: msg += " with input: " + r.input1 michael@0: } michael@0: logMessage(msg); michael@0: console.log(msg); michael@0: } else { michael@0: console.log("You selected " + r.buttonIndex + " and entered: " + r.input1); michael@0: logMessage("You selected " + buttons[r.buttonIndex - 1] + " and entered: " + r.input1); michael@0: } michael@0: }, michael@0: title, michael@0: buttons); michael@0: }; michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: var dialogs_tests = '
' + michael@0: 'Expected result: Device will beep (unless device is on silent). Nothing will get updated in status box.' + michael@0: '

Dialog Tests

' + michael@0: '

Dialog boxes will pop up for each of the following tests

' + michael@0: '

' + michael@0: 'Expected result: Dialog will say "You pressed alert". Press continue to close dialog. Nothing will get updated in status box.' + michael@0: '

' + michael@0: 'Expected result: Dialog will say "You pressed confirm". Press Yes, No, or Maybe to close dialog. Status box will tell you what option you selected.' + michael@0: '

' + michael@0: 'Expected result: Dialog will say "You pressed confirm". Press Yes, No, or Maybe, Not Sure to close dialog. Status box will tell you what option you selected, and should use 1-based indexing.' + michael@0: '

' + michael@0: 'Expected result: Dialog will say "You pressed prompt". Enter any message and press Yes, No, or Maybe, Not Sure to close dialog. Status box will tell you what option you selected and message you entered, and should use 1-based indexing.' + michael@0: '

' + michael@0: 'Expected result: Dialog will have title "index.html" and say "You pressed alert" Press OK to close dialog. Nothing will get updated in status box.' + michael@0: '

' + michael@0: 'Expected result: Dialog will have title "index.html" and say "You selected confirm". Press Cancel or OK to close dialog. Nothing will get updated in status box.' + michael@0: '

' + michael@0: 'Expected result: Dialog will have title "index.html" and say "This is a prompt". "Default value" will be in text box. Press Cancel or OK to close dialog. Nothing will get updated in status box.'; michael@0: michael@0: contentEl.innerHTML = '
' + michael@0: dialogs_tests; michael@0: michael@0: createActionButton('Beep', function () { michael@0: beep(); michael@0: }, 'beep'); michael@0: michael@0: createActionButton('Alert Dialog', function () { michael@0: alertDialog('You pressed alert.', 'Alert Dialog', 'Continue'); michael@0: }, 'alert'); michael@0: michael@0: // WP8.1 detection is necessary since it doesn't support confirm dialogs with more than 2 buttons michael@0: var isRunningOnWP81 = cordova.platformId == "windows" && navigator.userAgent.indexOf('Windows Phone') > -1; michael@0: michael@0: createActionButton('Confirm Dialog - Deprecated', function () { michael@0: var buttons = isRunningOnWP81 ? 'Yes,No' : 'Yes,No,Maybe'; michael@0: confirmDialogA('You pressed confirm.', 'Confirm Dialog', buttons); michael@0: }, 'confirm_deprecated'); michael@0: michael@0: createActionButton('Confirm Dialog', function () { michael@0: var buttons = isRunningOnWP81 ? ['Yes', 'Actually, No'] : ['Yes', 'No', 'Maybe, Not Sure']; michael@0: confirmDialogB('You pressed confirm.', 'Confirm Dialog', buttons); michael@0: }, 'confirm'); michael@0: michael@0: createActionButton('Prompt Dialog', function () { michael@0: promptDialog('You pressed prompt.', 'Prompt Dialog', ['Yes', 'No', 'Maybe, Not Sure']); michael@0: }, 'prompt'); michael@0: michael@0: createActionButton('Built-in Alert Dialog', function () { michael@0: typeof alert === 'function' && alert('You pressed alert'); michael@0: }, 'built_in_alert'); michael@0: michael@0: createActionButton('Built-in Confirm Dialog', function () { michael@0: typeof confirm === 'function' && confirm('You selected confirm'); michael@0: }, 'built_in_confirm'); michael@0: michael@0: createActionButton('Built-in Prompt Dialog', function () { michael@0: typeof prompt === 'function' && prompt('This is a prompt', 'Default value'); michael@0: }, 'built_in_prompt'); michael@0: };