From 625f1d77678c479f9c61764aedf2eecca7a026b1 Mon Sep 17 00:00:00 2001 From: Pawel Andruszkiewicz Date: Tue, 1 Dec 2015 15:45:21 +0100 Subject: [PATCH] [Events] Added manual unit tests. [Verification] Manual test for supported events pass. Change-Id: Ibc79411607f177f63cd2a06e7f56a978f847b6d0 Signed-off-by: Pawel Andruszkiewicz --- test/index.html | 1 + test/unittest/all.html | 1 + test/unittest/tests/events.tests.js | 112 ++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 test/unittest/tests/events.tests.js diff --git a/test/index.html b/test/index.html index 2f2b670..5c0cbe7 100644 --- a/test/index.html +++ b/test/index.html @@ -58,6 +58,7 @@ Device Tests Dialogs Tests + Events Tests File Tests FileTransfer Tests Geolocation Tests diff --git a/test/unittest/all.html b/test/unittest/all.html index bb32834..5ca390f 100644 --- a/test/unittest/all.html +++ b/test/unittest/all.html @@ -97,6 +97,7 @@ contacts: 'contacts', // datauri: 'datauri', // test code was not updated device: 'device', + events: 'events', file: 'file', filetransfer: 'filetransfer', geolocation: 'geolocation', diff --git a/test/unittest/tests/events.tests.js b/test/unittest/tests/events.tests.js new file mode 100644 index 0000000..4f6968d --- /dev/null +++ b/test/unittest/tests/events.tests.js @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed 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. + */ + +exports.defineAutoTests = function () { +}; + +exports.defineManualTests = function (content, createActionButton) { + var logMessage = function (message) { + var log = document.getElementById('info'); + var logLine = document.createElement('div'); + logLine.innerHTML = message; + log.appendChild(logLine); + console.log(message); + }; + + var clearLog = function () { + var log = document.getElementById('info'); + log.innerHTML = ''; + }; + + var callback; + var current_event; + + var prepareTest = function (e) { + clearLog(); + if (current_event) { + document.removeEventListener(current_event, callback); + } + current_event = e; + var i = 0; + callback = function () { + logMessage('Event \"' + e + '\" has been fired ' + (++i) + ' time(s).'); + }; + document.addEventListener(current_event, callback); + } + + var events_tests = '

' + + 'Expected result: \"deviceready\" event should be fired exactly once.' + + '

' + + 'Expected result: \"pause\" event should be fired each time application is hidden (i.e. device is locked when application is running).' + + '

' + + 'Expected result: \"resume\" event should be fired each time application is shown (i.e. device is unlocked when application is running in foreground).' + + '

' + + 'Expected result: \"backbutton\" event should be fired each time \"Back\" key is pressed.' + + '

' + + 'Expected result: \"menubutton\" event should be fired each time \"Menu\" key is pressed.' + + '

' + + 'Expected result: \"searchbutton\" event should be fired each time \"Search\" key is pressed.' + + '

' + + 'Expected result: \"startcallbutton\" event should be fired each time \"Start call\" key is pressed.' + + '

' + + 'Expected result: \"endcallbutton\" event should be fired each time \"End call\" key is pressed.' + + '

' + + 'Expected result: \"volumedownbutton\" event should be fired each time \"Volume down\" key is pressed.' + + '

' + + 'Expected result: \"volumeupbutton\" event should be fired each time \"Volume up\" key is pressed.'; + + content.innerHTML = '
' + events_tests; + + createActionButton('Event: deviceready', function () { + prepareTest('deviceready'); + }, 'deviceready'); + + createActionButton('Event: pause', function () { + prepareTest('pause'); + }, 'pause'); + + createActionButton('Event: resume', function () { + prepareTest('resume'); + }, 'resume'); + + createActionButton('Event: backbutton', function () { + prepareTest('backbutton'); + }, 'backbutton'); + + createActionButton('Event: menubutton', function () { + prepareTest('menubutton'); + }, 'menubutton'); + + createActionButton('Event: searchbutton', function () { + prepareTest('searchbutton'); + }, 'searchbutton'); + + createActionButton('Event: startcallbutton', function () { + prepareTest('startcallbutton'); + }, 'startcallbutton'); + + createActionButton('Event: endcallbutton', function () { + prepareTest('endcallbutton'); + }, 'endcallbutton'); + + createActionButton('Event: volumedownbutton', function () { + prepareTest('volumedownbutton'); + }, 'volumedownbutton'); + + createActionButton('Event: volumeupbutton', function () { + prepareTest('volumeupbutton'); + }, 'volumeupbutton'); +}; -- 2.7.4