How to use callback method in elementium

Best Python code snippet using elementium_python

FileLoaderPluginTest.js

Source:FileLoaderPluginTest.js Github

copy

Full Screen

1/*2 * Copyright 2009 Google Inc.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not5 * use this file except in compliance with the License. You may obtain a copy of6 * the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13 * License for the specific language governing permissions and limitations under14 * the License.15 */16var FileLoaderPluginCallbackTests = ConditionalTestCase(17 'FileLoaderPluginCallbackTests',18 function() {19 return !jstestdriver.jQuery.browser.opera;20});21FileLoaderPluginCallbackTests.prototype.createScriptLoader = function(win, dom) {22 return new jstestdriver.plugins.ScriptLoader(win, dom, {23 updateLatestTestCase: function() {},24 removeTestCaseForFilename: function() {}25 }, jstestdriver.now);26};27FileLoaderPluginCallbackTests.prototype.testFileOnLoadJs = function() {28 var mockDOM = new jstestdriver.MockDOM();29 var head = mockDOM.createElement('head');30 var scriptLoader = this.createScriptLoader({}, mockDOM);31 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);32 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,33 stylesheetLoader,34 jstestdriver.now);35 var file = new jstestdriver.FileSource('file.js', 12);36 var callbackCalled = false;37 var callbackFileResult = null;38 var callback = function(fileResult) {39 callbackCalled = true;40 callbackFileResult = fileResult;41 };42 fileLoaderPlugin.loadSource(file, callback);43 assertEquals(1, head.childNodes.length);44 var script = head.childNodes[0];45 script.onload();46 assertEquals('script', script.nodeName);47 assertEquals('text/javascript', script.type);48 assertEquals('file.js', script.src);49 assertTrue(callbackCalled);50 assertNotNull(callbackFileResult);51 assertTrue(callbackFileResult.success);52 assertEquals('', callbackFileResult.message);53 assertNotNull(callbackFileResult.file);54 assertEquals('file.js', callbackFileResult.file.fileSrc);55 assertEquals(12, callbackFileResult.file.timestamp);56};57FileLoaderPluginCallbackTests.prototype.testFileOnLoadJsError = function() {58 var mockDOM = new jstestdriver.MockDOM();59 var head = mockDOM.createElement('head');60 var scriptLoader = this.createScriptLoader({}, mockDOM);61 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);62 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,63 stylesheetLoader);64 var file = new jstestdriver.FileSource('file.js', 42);65 var callbackCalled = false;66 var callbackFileResult = null;67 var callback = function(fileResult) {68 callbackCalled = true;69 callbackFileResult = fileResult;70 };71 fileLoaderPlugin.loadSource(file, callback);72 assertEquals(1, head.childNodes.length);73 var script = head.childNodes[0];74 script.onerror('msg', 'url', 42);75 script.onload();76 assertEquals('script', script.nodeName);77 assertEquals('text/javascript', script.type);78 assertEquals('file.js', script.src);79 assertTrue(callbackCalled);80 assertNotNull(callbackFileResult);81 assertFalse(callbackFileResult.success);82 assertEquals('error loading file: file.js:42: msg', callbackFileResult.message);83 assertNotNull(callbackFileResult.file);84 assertEquals('file.js', callbackFileResult.file.fileSrc);85 assertEquals(42, callbackFileResult.file.timestamp);86};87FileLoaderPluginCallbackTests.prototype.testFileOnLoadJsWindowError = function() {88 var mockDOM = new jstestdriver.MockDOM();89 var head = mockDOM.createElement('head');90 var win = {};91 var scriptLoader = this.createScriptLoader(win, mockDOM);92 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader(win, mockDOM, false);93 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,94 stylesheetLoader);95 var file = new jstestdriver.FileSource('file.js', 42);96 var callbackCalled = false;97 var callbackFileResult = null;98 var callback = function(fileResult) {99 callbackCalled = true;100 callbackFileResult = fileResult;101 };102 fileLoaderPlugin.loadSource(file, callback);103 assertNotNull(win.onerror);104 assertEquals(1, head.childNodes.length);105 var script = head.childNodes[0];106 win.onerror('msg', 'url', 42);107 script.onload();108 assertSame(jstestdriver.EMPTY_FUNC, win.onerror);109 assertEquals('script', script.nodeName);110 assertEquals('text/javascript', script.type);111 assertEquals('file.js', script.src);112 assertTrue(callbackCalled);113 assertNotNull(callbackFileResult);114 assertFalse(callbackFileResult.success);115 assertEquals('error loading file: file.js:42: msg', callbackFileResult.message);116 assertNotNull(callbackFileResult.file);117 assertEquals('file.js', callbackFileResult.file.fileSrc);118 assertEquals(42, callbackFileResult.file.timestamp);119};120FileLoaderPluginCallbackTests.prototype.testFileOnLoadCss = function() {121 var mockDOM = new jstestdriver.MockDOM();122 var head = mockDOM.createElement('head');123 var scriptLoader = this.createScriptLoader({}, mockDOM);124 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);125 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,126 stylesheetLoader);127 var file = new jstestdriver.FileSource('file.css', 24);128 var callbackCalled = false;129 var callbackFileResult = null;130 var callback = function(fileResult) {131 callbackCalled = true;132 callbackFileResult = fileResult;133 };134 fileLoaderPlugin.loadSource(file, callback);135 assertEquals(1, head.childNodes.length);136 var link = head.childNodes[0];137 link.onload();138 assertEquals('link', link.nodeName);139 assertEquals('text/css', link.type);140 assertEquals('stylesheet', link.rel);141 assertEquals('file.css', link.href);142 assertTrue(callbackCalled);143 assertNotNull(callbackFileResult);144 assertTrue(callbackFileResult.success);145 assertEquals('', callbackFileResult.message);146 assertNotNull(callbackFileResult.file);147 assertEquals('file.css', callbackFileResult.file.fileSrc);148 assertEquals(24, callbackFileResult.file.timestamp);149};150FileLoaderPluginCallbackTests.prototype.testFileOnLoadCssError = function() {151 var mockDOM = new jstestdriver.MockDOM();152 var head = mockDOM.createElement('head');153 var scriptLoader = this.createScriptLoader({}, mockDOM);154 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);155 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,156 stylesheetLoader);157 var file = new jstestdriver.FileSource('file.css', 84);158 var callbackCalled = false;159 var callbackFileResult = null;160 var callback = function(fileResult) {161 callbackCalled = true;162 callbackFileResult = fileResult;163 };164 fileLoaderPlugin.loadSource(file, callback);165 assertEquals(1, head.childNodes.length);166 var link = head.childNodes[0];167 link.onerror('it sucks', 'url', 90);168 link.onload();169 assertEquals('link', link.nodeName);170 assertEquals('text/css', link.type);171 assertEquals('stylesheet', link.rel);172 assertEquals('file.css', link.href);173 assertTrue(callbackCalled);174 assertNotNull(callbackFileResult);175 assertFalse(callbackFileResult.success);176 assertEquals('error loading file: file.css:90: it sucks', callbackFileResult.message);177 assertNotNull(callbackFileResult.file);178 assertEquals('file.css', callbackFileResult.file.fileSrc);179 assertEquals(84, callbackFileResult.file.timestamp);180};181FileLoaderPluginCallbackTests.prototype.testFileOnLoadCssWindowError = function() {182 var mockDOM = new jstestdriver.MockDOM();183 var head = mockDOM.createElement('head');184 var win = {};185 var scriptLoader = this.createScriptLoader(win, mockDOM);186 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader(win, mockDOM, false);187 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader,188 stylesheetLoader);189 var file = new jstestdriver.FileSource('file.css', 84);190 var callbackCalled = false;191 var callbackFileResult = null;192 var callback = function(fileResult) {193 callbackCalled = true;194 callbackFileResult = fileResult;195 };196 fileLoaderPlugin.loadSource(file, callback);197 assertNotNull(win.onerror);198 assertEquals(1, head.childNodes.length);199 var link = head.childNodes[0];200 win.onerror('it sucks', 'url', 90);201 link.onload();202 assertSame(jstestdriver.EMPTY_FUNC, win.onerror);203 assertEquals('link', link.nodeName);204 assertEquals('text/css', link.type);205 assertEquals('stylesheet', link.rel);206 assertEquals('file.css', link.href);207 assertTrue(callbackCalled);208 assertNotNull(callbackFileResult);209 assertFalse(callbackFileResult.success);210 assertEquals('error loading file: file.css:90: it sucks', callbackFileResult.message);211 assertNotNull(callbackFileResult.file);212 assertEquals('file.css', callbackFileResult.file.fileSrc);213 assertEquals(84, callbackFileResult.file.timestamp);214};215var FileLoaderPluginTest = TestCase('FileLoaderPluginTest');216FileLoaderPluginTest.prototype.createScriptLoader = function(win, dom) {217 return new jstestdriver.plugins.ScriptLoader(win, dom, {218 updateLatestTestCase: function() {},219 removeTestCaseForFilename: function() {}220 }, jstestdriver.now);221};222FileLoaderPluginTest.prototype.testFileOnReadyStateChangeJs = function() {223 var mockDOM = new jstestdriver.MockDOM();224 var head = mockDOM.createElement('head');225 var scriptLoader = this.createScriptLoader({}, mockDOM);226 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);227 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);228 var file = new jstestdriver.FileSource('file.js', 12);229 var callbackCalled = false;230 var callbackFileResult = null;231 var callback = function(fileResult) {232 callbackCalled = true;233 callbackFileResult = fileResult;234 };235 fileLoaderPlugin.loadSource(file, callback);236 assertEquals(1, head.childNodes.length);237 var script = head.childNodes[0];238 script.readyState = 'loaded';239 script.onreadystatechange();240 assertEquals('script', script.nodeName);241 assertEquals('text/javascript', script.type);242 assertEquals('file.js', script.src);243 assertTrue(callbackCalled);244 assertNotNull(callbackFileResult);245 assertTrue(callbackFileResult.success);246 assertEquals('', callbackFileResult.message);247 assertNotNull(callbackFileResult.file);248 assertEquals('file.js', callbackFileResult.file.fileSrc);249 assertEquals(12, callbackFileResult.file.timestamp);250};251FileLoaderPluginTest.prototype.testFileOnReadyStateChangeJsError = function() {252 var mockDOM = new jstestdriver.MockDOM();253 var head = mockDOM.createElement('head');254 var scriptLoader = this.createScriptLoader({}, mockDOM);255 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);256 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);257 var file = new jstestdriver.FileSource('file.js', 42);258 var callbackCalled = false;259 var callbackFileResult = null;260 var callback = function(fileResult) {261 callbackCalled = true;262 callbackFileResult = fileResult;263 };264 fileLoaderPlugin.loadSource(file, callback);265 assertEquals(1, head.childNodes.length);266 var script = head.childNodes[0];267 script.onerror('msg', 'url', 42);268 script.readyState = 'loaded';269 script.onreadystatechange();270 assertEquals('script', script.nodeName);271 assertEquals('text/javascript', script.type);272 assertEquals('file.js', script.src);273 assertTrue(callbackCalled);274 assertNotNull(callbackFileResult);275 assertFalse(callbackFileResult.success);276 assertEquals('error loading file: file.js:42: msg', callbackFileResult.message);277 assertNotNull(callbackFileResult.file);278 assertEquals('file.js', callbackFileResult.file.fileSrc);279 assertEquals(42, callbackFileResult.file.timestamp);280};281FileLoaderPluginTest.prototype.testFileOnReadyStateChangeJsWindowError = function() {282 var mockDOM = new jstestdriver.MockDOM();283 var head = mockDOM.createElement('head');284 var win = {};285 var scriptLoader = this.createScriptLoader(win, mockDOM);286 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader(win, mockDOM, false);287 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);288 var file = new jstestdriver.FileSource('file.js', 42);289 var callbackCalled = false;290 var callbackFileResult = null;291 var callback = function(fileResult) {292 callbackCalled = true;293 callbackFileResult = fileResult;294 };295 fileLoaderPlugin.loadSource(file, callback);296 assertNotNull(win.onerror);297 assertEquals(1, head.childNodes.length);298 var script = head.childNodes[0];299 win.onerror('msg', 'url', 42);300 script.readyState = 'loaded';301 script.onreadystatechange();302 assertSame(jstestdriver.EMPTY_FUNC, win.onerror);303 assertEquals('script', script.nodeName);304 assertEquals('text/javascript', script.type);305 assertEquals('file.js', script.src);306 assertTrue(callbackCalled);307 assertNotNull(callbackFileResult);308 assertFalse(callbackFileResult.success);309 assertEquals('error loading file: file.js:42: msg', callbackFileResult.message);310 assertNotNull(callbackFileResult.file);311 assertEquals('file.js', callbackFileResult.file.fileSrc);312 assertEquals(42, callbackFileResult.file.timestamp);313};314FileLoaderPluginTest.prototype.testFileOnReadyStateChangeCss = function() {315 var mockDOM = new jstestdriver.MockDOM();316 var head = mockDOM.createElement('head');317 var scriptLoader = this.createScriptLoader({}, mockDOM);318 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);319 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);320 var file = new jstestdriver.FileSource('file.css', 24);321 var callbackCalled = false;322 var callbackFileResult = null;323 var callback = function(fileResult) {324 callbackCalled = true;325 callbackFileResult = fileResult;326 };327 fileLoaderPlugin.loadSource(file, callback);328 assertEquals(1, head.childNodes.length);329 var link = head.childNodes[0];330 link.readyState = 'loaded';331 link.onreadystatechange();332 assertEquals('link', link.nodeName);333 assertEquals('text/css', link.type);334 assertEquals('stylesheet', link.rel);335 assertEquals('file.css', link.href);336 assertTrue(callbackCalled);337 assertNotNull(callbackFileResult);338 assertTrue(callbackFileResult.success);339 assertEquals('', callbackFileResult.message);340 assertNotNull(callbackFileResult.file);341 assertEquals('file.css', callbackFileResult.file.fileSrc);342 assertEquals(24, callbackFileResult.file.timestamp);343};344FileLoaderPluginTest.prototype.testFileLoadCssOnLoadHack = function() {345 var mockDOM = new jstestdriver.MockDOM();346 var head = mockDOM.createElement('head');347 var scriptLoader = this.createScriptLoader({}, mockDOM);348 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, true);349 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);350 var file = new jstestdriver.FileSource('file.css', 24);351 var callbackCalled = 0;352 var callbackFileResult = null;353 var callback = function(fileResult) {354 callbackCalled++;355 callbackFileResult = fileResult;356 };357 fileLoaderPlugin.loadSource(file, callback);358 assertEquals(1, head.childNodes.length);359 var link = head.childNodes[0];360 assertEquals('link', link.nodeName);361 assertEquals('text/css', link.type);362 assertEquals('stylesheet', link.rel);363 assertEquals('file.css', link.href);364 assertEquals(1, callbackCalled);365 assertNotNull(callbackFileResult);366 assertTrue(callbackFileResult.success);367 assertEquals('', callbackFileResult.message);368 assertNotNull(callbackFileResult.file);369 assertEquals('file.css', callbackFileResult.file.fileSrc);370 assertEquals(24, callbackFileResult.file.timestamp);371};372FileLoaderPluginTest.prototype.testFileOnReadyStateChangeCssError = function() {373 var mockDOM = new jstestdriver.MockDOM();374 var head = mockDOM.createElement('head');375 var scriptLoader = this.createScriptLoader({}, mockDOM);376 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader({}, mockDOM, false);377 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);378 var file = new jstestdriver.FileSource('file.css', 84);379 var callbackCalled = false;380 var callbackFileResult = null;381 var callback = function(fileResult) {382 callbackCalled = true;383 callbackFileResult = fileResult;384 };385 fileLoaderPlugin.loadSource(file, callback);386 assertEquals(1, head.childNodes.length);387 var link = head.childNodes[0];388 link.onerror('it sucks', 'url', 90);389 link.readyState = 'loaded';390 link.onreadystatechange();391 assertEquals('link', link.nodeName);392 assertEquals('text/css', link.type);393 assertEquals('stylesheet', link.rel);394 assertEquals('file.css', link.href);395 assertTrue(callbackCalled);396 assertNotNull(callbackFileResult);397 assertFalse(callbackFileResult.success);398 assertEquals('error loading file: file.css:90: it sucks', callbackFileResult.message);399 assertNotNull(callbackFileResult.file);400 assertEquals('file.css', callbackFileResult.file.fileSrc);401 assertEquals(84, callbackFileResult.file.timestamp);402};403FileLoaderPluginTest.prototype.testFileOnReadyStateChangeCssWindowError = function() {404 var mockDOM = new jstestdriver.MockDOM();405 var head = mockDOM.createElement('head');406 var win = {};407 var scriptLoader = this.createScriptLoader(win, mockDOM);408 var stylesheetLoader = new jstestdriver.plugins.StylesheetLoader(win, mockDOM, false);409 var fileLoaderPlugin = new jstestdriver.plugins.FileLoaderPlugin(scriptLoader, stylesheetLoader);410 var file = new jstestdriver.FileSource('file.css', 84);411 var callbackCalled = false;412 var callbackFileResult = null;413 var callback = function(fileResult) {414 callbackCalled = true;415 callbackFileResult = fileResult;416 };417 fileLoaderPlugin.loadSource(file, callback);418 assertNotNull(win.onerror);419 assertEquals(1, head.childNodes.length);420 var link = head.childNodes[0];421 win.onerror('it sucks', 'url', 90);422 link.readyState = 'loaded';423 link.onreadystatechange();424 assertSame(jstestdriver.EMPTY_FUNC, win.onerror);425 assertEquals('link', link.nodeName);426 assertEquals('text/css', link.type);427 assertEquals('stylesheet', link.rel);428 assertEquals('file.css', link.href);429 assertTrue(callbackCalled);430 assertNotNull(callbackFileResult);431 assertFalse(callbackFileResult.success);432 assertEquals('error loading file: file.css:90: it sucks', callbackFileResult.message);433 assertNotNull(callbackFileResult.file);434 assertEquals('file.css', callbackFileResult.file.fileSrc);435 assertEquals(84, callbackFileResult.file.timestamp);...

Full Screen

Full Screen

local-notification-core.js

Source:local-notification-core.js Github

copy

Full Screen

1/*2 * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.3 *4 * @APPPLANT_LICENSE_HEADER_START@5 *6 * This file contains Original Code and/or Modifications of Original Code7 * as defined in and that are subject to the Apache License8 * Version 2.0 (the 'License'). You may not use this file except in9 * compliance with the License. Please obtain a copy of the License at10 * http://opensource.org/licenses/Apache-2.0/ and read it before using this11 * file.12 *13 * The Original Code and all software distributed under the License are14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.18 * Please see the License for the specific language governing rights and19 * limitations under the License.20 *21 * @APPPLANT_LICENSE_HEADER_END@22 */23var exec = require('cordova/exec');24/********25 * CORE *26 ********/27/**28 * Returns the default settings.29 *30 * @return {Object}31 */32exports.getDefaults = function () {33 return this._defaults;34};35/**36 * Overwrite default settings.37 *38 * @param {Object} defaults39 */40exports.setDefaults = function (newDefaults) {41 var defaults = this.getDefaults();42 for (var key in defaults) {43 if (newDefaults.hasOwnProperty(key)) {44 defaults[key] = newDefaults[key];45 }46 }47};48/**49 * Schedule a new local notification.50 *51 * @param {Object} msgs52 * The notification properties53 * @param {Function} callback54 * A function to be called after the notification has been canceled55 * @param {Object?} scope56 * The scope for the callback function57 * @param {Object?} args58 * skipPermission:true schedules the notifications immediatly without59 * registering or checking for permission60 */61exports.schedule = function (msgs, callback, scope, args) {62 var fn = function(granted) {63 if (!granted) return;64 var notifications = Array.isArray(msgs) ? msgs : [msgs];65 for (var i = 0; i < notifications.length; i++) {66 var notification = notifications[i];67 this.mergeWithDefaults(notification);68 this.convertProperties(notification);69 }70 this.exec('schedule', notifications, callback, scope);71 };72 if (args && args.skipPermission) {73 fn.call(this, true);74 } else {75 this.registerPermission(fn, this);76 }77};78/**79 * Update existing notifications specified by IDs in options.80 *81 * @param {Object} notifications82 * The notification properties to update83 * @param {Function} callback84 * A function to be called after the notification has been updated85 * @param {Object?} scope86 * The scope for the callback function87 * @param {Object?} args88 * skipPermission:true schedules the notifications immediatly without89 * registering or checking for permission90 */91exports.update = function (msgs, callback, scope, args) {92 var fn = function(granted) {93 if (!granted) return;94 var notifications = Array.isArray(msgs) ? msgs : [msgs];95 for (var i = 0; i < notifications.length; i++) {96 var notification = notifications[i];97 this.convertProperties(notification);98 }99 this.exec('update', notifications, callback, scope);100 };101 if (args && args.skipPermission) {102 fn.call(this, true);103 } else {104 this.registerPermission(fn, this);105 }106};107/**108 * Clear the specified notification.109 *110 * @param {String} id111 * The ID of the notification112 * @param {Function} callback113 * A function to be called after the notification has been cleared114 * @param {Object?} scope115 * The scope for the callback function116 */117exports.clear = function (ids, callback, scope) {118 ids = Array.isArray(ids) ? ids : [ids];119 ids = this.convertIds(ids);120 this.exec('clear', ids, callback, scope);121};122/**123 * Clear all previously sheduled notifications.124 *125 * @param {Function} callback126 * A function to be called after all notifications have been cleared127 * @param {Object?} scope128 * The scope for the callback function129 */130exports.clearAll = function (callback, scope) {131 this.exec('clearAll', null, callback, scope);132};133/**134 * Cancel the specified notifications.135 *136 * @param {String[]} ids137 * The IDs of the notifications138 * @param {Function} callback139 * A function to be called after the notifications has been canceled140 * @param {Object?} scope141 * The scope for the callback function142 */143exports.cancel = function (ids, callback, scope) {144 ids = Array.isArray(ids) ? ids : [ids];145 ids = this.convertIds(ids);146 this.exec('cancel', ids, callback, scope);147};148/**149 * Remove all previously registered notifications.150 *151 * @param {Function} callback152 * A function to be called after all notifications have been canceled153 * @param {Object?} scope154 * The scope for the callback function155 */156exports.cancelAll = function (callback, scope) {157 this.exec('cancelAll', null, callback, scope);158};159/**160 * Check if a notification with an ID is present.161 *162 * @param {String} id163 * The ID of the notification164 * @param {Function} callback165 * A callback function to be called with the list166 * @param {Object?} scope167 * The scope for the callback function168 */169exports.isPresent = function (id, callback, scope) {170 this.exec('isPresent', id || 0, callback, scope);171};172/**173 * Check if a notification with an ID is scheduled.174 *175 * @param {String} id176 * The ID of the notification177 * @param {Function} callback178 * A callback function to be called with the list179 * @param {Object?} scope180 * The scope for the callback function181 */182exports.isScheduled = function (id, callback, scope) {183 this.exec('isScheduled', id || 0, callback, scope);184};185/**186 * Check if a notification with an ID was triggered.187 *188 * @param {String} id189 * The ID of the notification190 * @param {Function} callback191 * A callback function to be called with the list192 * @param {Object?} scope193 * The scope for the callback function194 */195exports.isTriggered = function (id, callback, scope) {196 this.exec('isTriggered', id || 0, callback, scope);197};198/**199 * List all local notification IDs.200 *201 * @param {Function} callback202 * A callback function to be called with the list203 * @param {Object?} scope204 * The scope for the callback function205 */206exports.getAllIds = function (callback, scope) {207 this.exec('getAllIds', null, callback, scope);208};209/**210 * Alias for `getAllIds`.211 */212exports.getIds = function () {213 this.getAllIds.apply(this, arguments);214};215/**216 * List all scheduled notification IDs.217 *218 * @param {Function} callback219 * A callback function to be called with the list220 * @param {Object?} scope221 * The scope for the callback function222 */223exports.getScheduledIds = function (callback, scope) {224 this.exec('getScheduledIds', null, callback, scope);225};226/**227 * List all triggered notification IDs.228 *229 * @param {Function} callback230 * A callback function to be called with the list231 * @param {Object?} scope232 * The scope for the callback function233 */234exports.getTriggeredIds = function (callback, scope) {235 this.exec('getTriggeredIds', null, callback, scope);236};237/**238 * Property list for given local notifications.239 * If called without IDs, all notification will be returned.240 *241 * @param {Number[]?} ids242 * Set of notification IDs243 * @param {Function} callback244 * A callback function to be called with the list245 * @param {Object?} scope246 * The scope for the callback function247 */248exports.get = function () {249 var args = Array.apply(null, arguments);250 if (typeof args[0] == 'function') {251 args.unshift([]);252 }253 var ids = args[0],254 callback = args[1],255 scope = args[2];256 if (!Array.isArray(ids)) {257 this.exec('getSingle', Number(ids), callback, scope);258 return;259 }260 ids = this.convertIds(ids);261 this.exec('getAll', ids, callback, scope);262};263/**264 * Property list for all local notifications.265 *266 * @param {Function} callback267 * A callback function to be called with the list268 * @param {Object?} scope269 * The scope for the callback function270 */271exports.getAll = function (callback, scope) {272 this.exec('getAll', null, callback, scope);273};274/**275 * Property list for given scheduled notifications.276 * If called without IDs, all notification will be returned.277 *278 * @param {Number[]?} ids279 * Set of notification IDs280 * @param {Function} callback281 * A callback function to be called with the list282 * @param {Object?} scope283 * The scope for the callback function284 */285exports.getScheduled = function () {286 var args = Array.apply(null, arguments);287 if (typeof args[0] == 'function') {288 args.unshift([]);289 }290 var ids = args[0],291 callback = args[1],292 scope = args[2];293 if (!Array.isArray(ids)) {294 ids = [ids];295 }296 if (!Array.isArray(ids)) {297 this.exec('getSingleScheduled', Number(ids), callback, scope);298 return;299 }300 ids = this.convertIds(ids);301 this.exec('getScheduled', ids, callback, scope);302};303/**304 * Property list for all scheduled notifications.305 *306 * @param {Function} callback307 * A callback function to be called with the list308 * @param {Object?} scope309 * The scope for the callback function310 */311exports.getAllScheduled = function (callback, scope) {312 this.exec('getScheduled', null, callback, scope);313};314/**315 * Property list for given triggered notifications.316 * If called without IDs, all notification will be returned.317 *318 * @param {Number[]?} ids319 * Set of notification IDs320 * @param {Function} callback321 * A callback function to be called with the list322 * @param {Object?} scope323 * The scope for the callback function324 */325exports.getTriggered = function () {326 var args = Array.apply(null, arguments);327 if (typeof args[0] == 'function') {328 args.unshift([]);329 }330 var ids = args[0],331 callback = args[1],332 scope = args[2];333 if (!Array.isArray(ids)) {334 ids = [ids];335 }336 if (!Array.isArray(ids)) {337 this.exec('getSingleTriggered', Number(ids), callback, scope);338 return;339 }340 ids = this.convertIds(ids);341 this.exec('getTriggered', ids, callback, scope);342};343/**344 * Property list for all triggered notifications.345 *346 * @param {Function} callback347 * A callback function to be called with the list348 * @param {Object?} scope349 * The scope for the callback function350 */351exports.getAllTriggered = function (callback, scope) {352 this.exec('getTriggered', null, callback, scope);353};354/**355 * Informs if the app has the permission to show notifications.356 *357 * @param {Function} callback358 * The function to be exec as the callback359 * @param {Object?} scope360 * The callback function's scope361 */362exports.hasPermission = function (callback, scope) {363 var fn = this.createCallbackFn(callback, scope);364 if (device.platform != 'iOS') {365 fn(true);366 return;367 }368 exec(fn, null, 'LocalNotification', 'hasPermission', []);369};370/**371 * Register permission to show notifications if not already granted.372 *373 * @param {Function} callback374 * The function to be exec as the callback375 * @param {Object?} scope376 * The callback function's scope377 */378exports.registerPermission = function (callback, scope) {379 if (this._registered) {380 return this.hasPermission(callback, scope);381 } else {382 this._registered = true;383 }384 var fn = this.createCallbackFn(callback, scope);385 if (device.platform != 'iOS') {386 fn(true);387 return;388 }389 exec(fn, null, 'LocalNotification', 'registerPermission', []);390};391/**********392 * EVENTS *393 **********/394/**395 * Register callback for given event.396 *397 * @param {String} event398 * The event's name399 * @param {Function} callback400 * The function to be exec as callback401 * @param {Object?} scope402 * The callback function's scope403 */404exports.on = function (event, callback, scope) {405 if (typeof callback !== "function")406 return;407 if (!this._listener[event]) {408 this._listener[event] = [];409 }410 var item = [callback, scope || window];411 this._listener[event].push(item);412};413/**414 * Unregister callback for given event.415 *416 * @param {String} event417 * The event's name418 * @param {Function} callback419 * The function to be exec as callback420 */421exports.un = function (event, callback) {422 var listener = this._listener[event];423 if (!listener)424 return;425 for (var i = 0; i < listener.length; i++) {426 var fn = listener[i][0];427 if (fn == callback) {428 listener.splice(i, 1);429 break;430 }431 }...

Full Screen

Full Screen

Element.anim.js

Source:Element.anim.js Github

copy

Full Screen

1xdescribe("Ext.Element.anim", function() {2 var el,3 todoIt = Ext.isSafari4 ? xit : it;4 5 beforeEach(function() {6 el = Ext.getBody().createChild({7 id: 'testElement'8 });9 });10 11 afterEach(function() {12 el.destroy();13 });14 15 describe("callbacks", function() {16 var callback, called, scope, actualScope;17 18 beforeEach(function() {19 called = false;20 scope = {};21 callback = jasmine.createSpy('callback').andCallFake(function() {22 called = true;23 actualScope = this;24 });25 });26 27 afterEach(function() {28 actualScope = undefined;29 });30 describe("slideIn()", function() {31 beforeEach(function() {32 el.slideIn('t', {33 duration: 10,34 callback: callback,35 scope: scope36 });37 });38 39 todoIt("should run callback", function() {40 waitsFor(function() { return called; }, 1000, 'Callback to fire');41 42 runs(function() {43 expect(called).toBeTruthy();44 });45 });46 47 todoIt("should run callback in correct scope", function() {48 waitsFor(function() { return called; }, 1000, 'Callback to fire');49 50 runs(function() {51 expect(actualScope).toBe(scope);52 });53 });54 });55 56 describe("slideOut()", function() {57 beforeEach(function() {58 el.slideOut('t', {59 duration: 10,60 callback: callback,61 scope: scope62 });63 });64 65 todoIt("should run callback", function() {66 waitsFor(function() { return called; }, 1000, 'Callback to fire');67 68 runs(function() {69 expect(called).toBeTruthy();70 });71 });72 73 todoIt("should run callback in correct scope", function() {74 waitsFor(function() { return called; }, 1000, 'Callback to fire');75 76 runs(function() {77 expect(actualScope).toBe(scope);78 });79 });80 });81 82 describe("puff()", function() {83 beforeEach(function() {84 el.slideIn('t', {85 duration: 10,86 callback: callback,87 scope: scope88 });89 });90 91 todoIt("should run callback", function() {92 waitsFor(function() { return called; }, 1000, 'Callback to fire');93 94 runs(function() {95 expect(called).toBeTruthy();96 });97 });98 99 todoIt("should run callback in correct scope", function() {100 waitsFor(function() { return called; }, 1000, 'Callback to fire');101 102 runs(function() {103 expect(actualScope).toBe(scope);104 });105 });106 });107 108 describe("switchOff()", function() {109 beforeEach(function() {110 el.switchOff({111 duration: 10,112 callback: callback,113 scope: scope114 });115 });116 117 todoIt("should run callback", function() {118 waitsFor(function() { return called; }, 1000, 'Callback to fire');119 120 runs(function() {121 expect(called).toBeTruthy();122 });123 });124 125 todoIt("should run callback in correct scope", function() {126 waitsFor(function() { return called; }, 1000, 'Callback to fire');127 128 runs(function() {129 expect(actualScope).toBe(scope);130 });131 });132 });133 describe("frame()", function() {134 beforeEach(function() {135 el.frame('#ff0000', 1, {136 duration: 10,137 callback: callback,138 scope: scope139 });140 });141 142 todoIt("should run callback", function() {143 waitsFor(function() { return called; }, 1000, 'Callback to fire');144 145 runs(function() {146 expect(called).toBeTruthy();147 });148 });149 150 todoIt("should run callback in correct scope", function() {151 waitsFor(function() { return called; }, 1000, 'Callback to fire');152 153 runs(function() {154 expect(actualScope).toBe(scope);155 });156 });157 });158 159 describe("ghost()", function() {160 beforeEach(function() {161 el.ghost('b', {162 duration: 10,163 callback: callback,164 scope: scope165 });166 });167 168 todoIt("should run callback", function() {169 waitsFor(function() { return called; }, 1000, 'Callback to fire');170 171 runs(function() {172 expect(called).toBeTruthy();173 });174 });175 176 todoIt("should run callback in correct scope", function() {177 waitsFor(function() { return called; }, 1000, 'Callback to fire');178 179 runs(function() {180 expect(actualScope).toBe(scope);181 });182 });183 });184 185 describe("highlight()", function() {186 beforeEach(function() {187 el.highlight('#0000ff', {188 duration: 10,189 callback: callback,190 scope: scope191 });192 });193 194 todoIt("should run callback", function() {195 waitsFor(function() { return called; }, 1000, 'Callback to fire');196 197 runs(function() {198 expect(called).toBeTruthy();199 });200 });201 202 todoIt("should run callback in correct scope", function() {203 waitsFor(function() { return called; }, 1000, 'Callback to fire');204 205 runs(function() {206 expect(actualScope).toBe(scope);207 });208 });209 });210 211 describe("fadeIn()", function() {212 beforeEach(function() {213 el.fadeIn({214 duration: 10,215 callback: callback,216 scope: scope217 });218 });219 220 todoIt("should run callback", function() {221 waitsFor(function() { return called; }, 1000, 'Callback to fire');222 223 runs(function() {224 expect(called).toBeTruthy();225 });226 });227 228 todoIt("should run callback in correct scope", function() {229 waitsFor(function() { return called; }, 1000, 'Callback to fire');230 231 runs(function() {232 expect(actualScope).toBe(scope);233 });234 });235 });236 237 describe("fadeOut()", function() {238 beforeEach(function() {239 el.fadeOut({240 duration: 10,241 callback: callback,242 scope: scope243 });244 });245 246 todoIt("should run callback", function() {247 waitsFor(function() { return called; }, 1000, 'Callback to fire');248 249 runs(function() {250 expect(called).toBeTruthy();251 });252 });253 254 todoIt("should run callback in correct scope", function() {255 waitsFor(function() { return called; }, 1000, 'Callback to fire');256 257 runs(function() {258 expect(actualScope).toBe(scope);259 });260 });261 });262 263 describe("scale()", function() {264 beforeEach(function() {265 el.scale(100, 100, {266 duration: 10,267 callback: callback,268 scope: scope269 });270 });271 272 todoIt("should run callback", function() {273 waitsFor(function() { return called; }, 1000, 'Callback to fire');274 275 runs(function() {276 expect(called).toBeTruthy();277 });278 });279 280 todoIt("should run callback in correct scope", function() {281 waitsFor(function() { return called; }, 1000, 'Callback to fire');282 283 runs(function() {284 expect(actualScope).toBe(scope);285 });286 });287 });288 289 describe("shift()", function() {290 beforeEach(function() {291 el.shift({292 x: 200,293 y: 200,294 duration: 10,295 callback: callback,296 scope: scope297 });298 });299 300 todoIt("should run callback", function() {301 waitsFor(function() { return called; }, 1000, 'Callback to fire');302 303 runs(function() {304 expect(called).toBeTruthy();305 });306 });307 308 todoIt("should run callback in correct scope", function() {309 waitsFor(function() { return called; }, 1000, 'Callback to fire');310 311 runs(function() {312 expect(actualScope).toBe(scope);313 });314 });315 });316 });...

Full Screen

Full Screen

local-notification.js

Source:local-notification.js Github

copy

Full Screen

1/*2 * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.3 *4 * @APPPLANT_LICENSE_HEADER_START@5 *6 * This file contains Original Code and/or Modifications of Original Code7 * as defined in and that are subject to the Apache License8 * Version 2.0 (the 'License'). You may not use this file except in9 * compliance with the License. Please obtain a copy of the License at10 * http://opensource.org/licenses/Apache-2.0/ and read it before using this11 * file.12 *13 * The Original Code and all software distributed under the License are14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.18 * Please see the License for the specific language governing rights and19 * limitations under the License.20 *21 * @APPPLANT_LICENSE_HEADER_END@22 */23/*************24 * INTERFACE *25 *************/26/**27 * Returns the default settings.28 *29 * @return {Object}30 */31exports.getDefaults = function () {32 return this.core.getDefaults();33};34/**35 * Overwrite default settings.36 *37 * @param {Object} defaults38 */39exports.setDefaults = function (defaults) {40 this.core.setDefaults(defaults);41};42/**43 * Schedule a new local notification.44 *45 * @param {Object} notifications46 * The notification properties47 * @param {Function} callback48 * A function to be called after the notification has been canceled49 * @param {Object?} scope50 * The scope for the callback function51 * @param {Object?} args52 * skipPermission:true schedules the notifications immediatly without53 * registering or checking for permission54 */55exports.schedule = function (notifications, callback, scope, args) {56 this.core.schedule(notifications, callback, scope, args);57};58/**59 * Update existing notifications specified by IDs in options.60 *61 * @param {Object} notifications62 * The notification properties to update63 * @param {Function} callback64 * A function to be called after the notification has been updated65 * @param {Object?} scope66 * The scope for the callback function67 * @param {Object?} args68 * skipPermission:true schedules the notifications immediatly without69 * registering or checking for permission70 */71exports.update = function (notifications, callback, scope, args) {72 this.core.update(notifications, callback, scope, args);73};74/**75 * Clear the specified notification.76 *77 * @param {String} id78 * The ID of the notification79 * @param {Function} callback80 * A function to be called after the notification has been cleared81 * @param {Object?} scope82 * The scope for the callback function83 */84exports.clear = function (ids, callback, scope) {85 this.core.clear(ids, callback, scope);86};87/**88 * Clear all previously sheduled notifications.89 *90 * @param {Function} callback91 * A function to be called after all notifications have been cleared92 * @param {Object?} scope93 * The scope for the callback function94 */95exports.clearAll = function (callback, scope) {96 this.core.clearAll(callback, scope);97};98/**99 * Cancel the specified notifications.100 *101 * @param {String[]} ids102 * The IDs of the notifications103 * @param {Function} callback104 * A function to be called after the notifications has been canceled105 * @param {Object?} scope106 * The scope for the callback function107 */108exports.cancel = function (ids, callback, scope) {109 this.core.cancel(ids, callback, scope);110};111/**112 * Remove all previously registered notifications.113 *114 * @param {Function} callback115 * A function to be called after all notifications have been canceled116 * @param {Object?} scope117 * The scope for the callback function118 */119exports.cancelAll = function (callback, scope) {120 this.core.cancelAll(callback, scope);121};122/**123 * Check if a notification with an ID is present.124 *125 * @param {String} id126 * The ID of the notification127 * @param {Function} callback128 * A callback function to be called with the list129 * @param {Object?} scope130 * The scope for the callback function131 */132exports.isPresent = function (id, callback, scope) {133 this.core.isPresent(id, callback, scope);134};135/**136 * Check if a notification with an ID is scheduled.137 *138 * @param {String} id139 * The ID of the notification140 * @param {Function} callback141 * A callback function to be called with the list142 * @param {Object?} scope143 * The scope for the callback function144 */145exports.isScheduled = function (id, callback, scope) {146 this.core.isScheduled(id, callback, scope);147};148/**149 * Check if a notification with an ID was triggered.150 *151 * @param {String} id152 * The ID of the notification153 * @param {Function} callback154 * A callback function to be called with the list155 * @param {Object?} scope156 * The scope for the callback function157 */158exports.isTriggered = function (id, callback, scope) {159 this.core.isTriggered(id, callback, scope);160};161/**162 * List all local notification IDs.163 *164 * @param {Function} callback165 * A callback function to be called with the list166 * @param {Object?} scope167 * The scope for the callback function168 */169exports.getAllIds = function (callback, scope) {170 this.core.getAllIds(callback, scope);171};172/**173 * Alias for `getAllIds`.174 */175exports.getIds = function () {176 this.getAllIds.apply(this, arguments);177};178/**179 * List all scheduled notification IDs.180 *181 * @param {Function} callback182 * A callback function to be called with the list183 * @param {Object?} scope184 * The scope for the callback function185 */186exports.getScheduledIds = function (callback, scope) {187 this.core.getScheduledIds(callback, scope);188};189/**190 * List all triggered notification IDs.191 *192 * @param {Function} callback193 * A callback function to be called with the list194 * @param {Object?} scope195 * The scope for the callback function196 */197exports.getTriggeredIds = function (callback, scope) {198 this.core.getTriggeredIds(callback, scope);199};200/**201 * Property list for given local notifications.202 * If called without IDs, all notification will be returned.203 *204 * @param {Number[]?} ids205 * Set of notification IDs206 * @param {Function} callback207 * A callback function to be called with the list208 * @param {Object?} scope209 * The scope for the callback function210 */211exports.get = function () {212 this.core.get.apply(this.core, arguments);213};214/**215 * Property list for all local notifications.216 *217 * @param {Function} callback218 * A callback function to be called with the list219 * @param {Object?} scope220 * The scope for the callback function221 */222exports.getAll = function (callback, scope) {223 this.core.getAll(callback, scope);224};225/**226 * Property list for given scheduled notifications.227 * If called without IDs, all notification will be returned.228 *229 * @param {Number[]?} ids230 * Set of notification IDs231 * @param {Function} callback232 * A callback function to be called with the list233 * @param {Object?} scope234 * The scope for the callback function235 */236exports.getScheduled = function () {237 this.core.getScheduled.apply(this.core, arguments);238};239/**240 * Property list for all scheduled notifications.241 *242 * @param {Function} callback243 * A callback function to be called with the list244 * @param {Object?} scope245 * The scope for the callback function246 */247exports.getAllScheduled = function (callback, scope) {248 this.core.getAllScheduled(callback, scope);249};250/**251 * Property list for given triggered notifications.252 * If called without IDs, all notification will be returned.253 *254 * @param {Number[]?} ids255 * Set of notification IDs256 * @param {Function} callback257 * A callback function to be called with the list258 * @param {Object?} scope259 * The scope for the callback function260 */261exports.getTriggered = function () {262 this.core.getTriggered.apply(this.core, arguments);263};264/**265 * Property list for all triggered notifications.266 *267 * @param {Function} callback268 * A callback function to be called with the list269 * @param {Object?} scope270 * The scope for the callback function271 */272exports.getAllTriggered = function (callback, scope) {273 this.core.getAllTriggered(callback, scope);274};275/**276 * Informs if the app has the permission to show notifications.277 *278 * @param {Function} callback279 * The function to be exec as the callback280 * @param {Object?} scope281 * The callback function's scope282 */283exports.hasPermission = function (callback, scope) {284 this.core.hasPermission(callback, scope);285};286/**287 * Register permission to show notifications if not already granted.288 *289 * @param {Function} callback290 * The function to be exec as the callback291 * @param {Object?} scope292 * The callback function's scope293 */294exports.registerPermission = function (callback, scope) {295 this.core.registerPermission(callback, scope);296};297/****************298 * DEPRECATIONS *299 ****************/300/**301 * Schedule a new local notification.302 */303exports.add = function () {304 console.warn('Depreated: Please use `notification.local.schedule` instead.');305 this.schedule.apply(this, arguments);306};307/**308 * Register permission to show notifications309 * if not already granted.310 */311exports.promptForPermission = function () {312 console.warn('Depreated: Please use `notification.local.registerPermission` instead.');313 this.registerPermission.apply(this, arguments);314};315/**********316 * EVENTS *317 **********/318/**319 * Register callback for given event.320 *321 * @param {String} event322 * The event's name323 * @param {Function} callback324 * The function to be exec as callback325 * @param {Object?} scope326 * The callback function's scope327 */328exports.on = function (event, callback, scope) {329 this.core.on(event, callback, scope);330};331/**332 * Unregister callback for given event.333 *334 * @param {String} event335 * The event's name336 * @param {Function} callback337 * The function to be exec as callback338 */339exports.un = function (event, callback) {340 this.core.un(event, callback, scope);...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run elementium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful