Best JavaScript code snippet using appium-android-driver
tab-content.js
Source:tab-content.js
1// *******************************************************************************2// Educational Online Test Delivery System3// Copyright (c) 2017 American Institutes for Research4//5// Distributed under the AIR Open Source License, Version 1.06// See accompanying file AIR-License-1_0.txt or at7// http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf8// *******************************************************************************9var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;10Cu.import("resource://gre/modules/XPCOMUtils.jsm");11Cu.import("resource://gre/modules/Services.jsm");12Cu.import("resource://gre/modules/ExtensionContent.jsm");13var BrowserDebug =14{15 log : function (aMsg)16 {17 Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(aMsg);18 },19 print : function ()20 {21 var msg = "TAB:FRAME: "+Array.join(arguments, ": ");22 BrowserDebug.log(msg);23 },24 error : function ()25 {26 BrowserDebug.log("ERROR", Array.join(arguments, ": "));27 }28};29addMessageListener("SecureBrowser:InsertTopLevelJS", function (aMsg)30{31 BrowserDebug.print("SecureBrowser:InsertTopLevelJS", "MESSAGE", aMsg.data.one, aMsg.data.two, content.location);32 // BrowserDebug.print("sendAsyncMessage", typeof(sendAsyncMessage));33});34var SecureBrowserFrame =35{36 // DOMBrower Observer37 DOMBrowserObserver :38 {39 _speakCallBack : null,40 _speakListenerAdded : false,41 _previousStatus : null,42 _window : null,43 observe : function (subject, topic, data)44 {45 /**46 * SECURITY QUIT47 */48 if (topic == "sb-dom-browser-quit")49 {50 BrowserDebug.print("QUIT");51 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-quit" });52 }53 /**54 * SECURITY RESTART55 */56 if (topic == "sb-dom-browser-restart")57 {58 BrowserDebug.print("OBSERVER", "RESTART");59 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-restart" });60 }61 /**62 * SECURITY GETMACADDRESS63 */64 if (topic == "sb-dom-browser-getMacAddress")65 {66 function cb (aMsg) 67 { 68 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.ma);69 removeMessageListener("SecureBrowser:GetMacAddress", cb);70 }71 addMessageListener("SecureBrowser:GetMacAddress", cb);72 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-getMacAddress" });73 }74 /**75 * TTS PAUSE76 */77 if (topic == "sb-dom-browser-tts-pause")78 {79 function cb (aMsg) 80 { 81 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.status);82 removeMessageListener("SecureBrowser:TTS:Pause", cb);83 }84 addMessageListener("SecureBrowser:TTS:Pause", cb);85 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-tts-pause" });86 }87 /**88 * TTS STOP89 */90 if (topic == "sb-dom-browser-tts-stop")91 {92 function cb (aMsg) 93 { 94 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.status);95 removeMessageListener("SecureBrowser:TTS:Stop", cb);96 }97 addMessageListener("SecureBrowser:TTS:Stop", cb);98 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-tts-stop" });99 }100 /**101 * TTS RESUME102 */103 if (topic == "sb-dom-browser-tts-resume")104 {105 function cb (aMsg) 106 { 107 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.status);108 removeMessageListener("SecureBrowser:TTS:Resume", cb);109 }110 addMessageListener("SecureBrowser:TTS:Resume", cb);111 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-tts-resume" });112 }113 /**114 * TTS PLAY115 */116 if (topic == "sb-dom-browser-tts-play")117 {118 SecureBrowserFrame.DOMBrowserObserver._speakCallBack = subject.wrappedJSObject.callback;119 SecureBrowserFrame.DOMBrowserObserver._window = subject.wrappedJSObject.window;120 function cb (aMsg) 121 { 122 let status = aMsg.data.o.status;123 let type = aMsg.data.o.type;124 try125 {126 if (typeof(SecureBrowserFrame.DOMBrowserObserver._speakCallBack == "function")) 127 {128 let e = 129 {130 type : null,131 charindex : aMsg.data.o.start,132 mark : null,133 length : aMsg.data.o.length,134 message : null135 };136 e.type = "word";137#ifdef XP_MACOSX138 if (aMsg.data.o.start == 0) e.type = "start";139#endif140 if (type == "Start") e.type = "start";141 if (type == "SentenceStart") e.type = "sentence";142 if (type == "Done") e.type = "end";143 if (type == "Sync") 144 {145 e.type = "sync";146 e.mark = true;147 }148 if (type == "Phoneme") e.type = "phoneme";149 if (status == "Paused") e.type = "pause";150 if (SecureBrowserFrame.DOMBrowserObserver.previousStatus == "Paused" && status == "Playing") e.type = "resumed"; 151 SecureBrowserFrame.DOMBrowserObserver._speakCallBack(Cu.cloneInto(e, SecureBrowserFrame.DOMBrowserObserver._window));152 SecureBrowserFrame.DOMBrowserObserver.previousStatus = status;153 }154 } 155 catch (e) { BrowserDebug.error(e); }156 }157 let o = 158 {159 options : subject.wrappedJSObject.options,160 txt : subject.wrappedJSObject.txt161 };162 try163 {164 // BrowserDebug.print("PLAY", "REMOVE MESSAGE LISTENER");165 removeMessageListener("SecureBrowser:TTS:Play", cb);166 } 167 catch (e) { BrowserDebug.error(e); }168 // BrowserDebug.print("PLAY", "ADD MESSAGE LISTENER");169 if (!SecureBrowserFrame.DOMBrowserObserver._speakListenerAdded)170 {171 addMessageListener("SecureBrowser:TTS:Play", cb);172 SecureBrowserFrame.DOMBrowserObserver._speakListenerAdded = true;173 }174 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-tts-play", o:o });175 }176 /**177 * TTS STATUS178 */179 if (topic == "sb-dom-browser-tts-status")180 {181 // BrowserDebug.print("STATUS");182 function cb (aMsg) 183 { 184 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.status);185 removeMessageListener("SecureBrowser:TTS:Status", cb);186 }187 addMessageListener("SecureBrowser:TTS:Status", cb);188 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-tts-status" });189 }190 /**191 * TTS VOICES192 */193 if (topic == "sb-dom-browser-tts-voices")194 {195 function cb (aMsg) 196 { 197 if (typeof(subject.wrappedJSObject.callback == "function")) 198 {199 let a = new Array;200 for (let el of aMsg.data.voices) 201 {202 // BrowserDebug.print("EL", el);203 let s = "new Object("+el+")";204 let o = eval(s);205 // BrowserDebug.print(typeof(o), o.name, o.gender, o.language);206 a.push(o);207 208 }209 subject.wrappedJSObject.callback(Cu.cloneInto(a, subject.wrappedJSObject.window));210 }211 removeMessageListener("SecureBrowser:TTS:Voices", cb);212 }213 addMessageListener("SecureBrowser:TTS:Voices", cb);214 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-tts-voices" });215 }216 /**217 * TTS VOICE218 */219 if (topic == "sb-dom-browser-tts-voice")220 {221 function cb (aMsg) 222 { 223 if (typeof(subject.wrappedJSObject.callback == "function")) 224 {225 subject.wrappedJSObject.callback(aMsg.data.voice);226 }227 removeMessageListener("SecureBrowser:TTS:Voice", cb);228 }229 addMessageListener("SecureBrowser:TTS:Voice", cb);230 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-tts-voice" });231 }232 /**233 * CLEAR CACHE234 */235 if (topic == "sb-dom-browser-air-clearcache")236 {237 function cb (aMsg) 238 { 239 removeMessageListener("SecureBrowser:AIR:ClearCache", cb);240 }241 addMessageListener("SecureBrowser:AIR:ClearCache", cb);242 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-clearcache" });243 }244 /**245 * CLEAR COOKIES246 */247 if (topic == "sb-dom-browser-air-clearcookies")248 {249 function cb (aMsg) 250 { 251 removeMessageListener("SecureBrowser:AIR:ClearCookies", cb);252 }253 addMessageListener("SecureBrowser:AIR:ClearCookies", cb);254 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-clearcookies" });255 }256 /**257 * SET BOOL PREF258 */259 if (topic == "sb-dom-browser-air-setboolpref")260 {261 // BrowserDebug.print("sb-dom-browser-air-setboolpref", subject.wrappedJSObject.name, subject.wrappedJSObject.value);262 function cb (aMsg) 263 { 264 removeMessageListener("SecureBrowser:AIR:SetBoolPref", cb);265 }266 let o =267 {268 name : subject.wrappedJSObject.name,269 value : subject.wrappedJSObject.value270 };271 addMessageListener("SecureBrowser:AIR:SetBoolPref", cb);272 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-setboolpref", o:o });273 }274 /**275 * SET STRING PREF276 */277 if (topic == "sb-dom-browser-air-setstringpref")278 {279 // BrowserDebug.print("sb-dom-browser-air-setstringpref", subject.wrappedJSObject.name, subject.wrappedJSObject.value);280 function cb (aMsg) 281 { 282 removeMessageListener("SecureBrowser:AIR:SetStringPref", cb);283 }284 let o =285 {286 name : subject.wrappedJSObject.name,287 value : subject.wrappedJSObject.value288 };289 addMessageListener("SecureBrowser:AIR:SetStringPref", cb);290 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-setstringpref", o:o });291 }292 /**293 * SET INT PREF294 */295 if (topic == "sb-dom-browser-air-setintpref")296 {297 // BrowserDebug.print("sb-dom-browser-air-setintpref", subject.wrappedJSObject.name, subject.wrappedJSObject.value);298 function cb (aMsg) 299 { 300 removeMessageListener("SecureBrowser:AIR:SetIntPref", cb);301 }302 let o =303 {304 name : subject.wrappedJSObject.name,305 value : subject.wrappedJSObject.value306 };307 addMessageListener("SecureBrowser:AIR:SetIntPref", cb);308 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-setintpref", o:o });309 }310 /**311 * CLEAR PREF312 */313 if (topic == "sb-dom-browser-air-clearpref")314 {315 function cb (aMsg) 316 { 317 removeMessageListener("SecureBrowser:AIR:ClearPref", cb);318 }319 let o = { name : subject.wrappedJSObject.name };320 addMessageListener("SecureBrowser:AIR:ClearPref", cb);321 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-clearpref", o:o });322 }323 /**324 * KILL PROCESS325 */326 if (topic == "sb-dom-browser-air-killprocess")327 {328 // BrowserDebug.print("sb-dom-browser-air-killprocess", subject.wrappedJSObject.name);329 function cb (aMsg) 330 { 331 removeMessageListener("SecureBrowser:AIR:KillProcess", cb);332 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.rv);333 }334 let o = { name : subject.wrappedJSObject.name };335 addMessageListener("SecureBrowser:AIR:KillProcess", cb);336 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-killprocess", o:o });337 }338 /**339 * LAUNCH PROCESS340 */341 if (topic == "sb-dom-browser-air-launchprocess")342 {343 // BrowserDebug.print("sb-dom-browser-air-launchprocess", subject.wrappedJSObject.name);344 function cb (aMsg) 345 { 346 removeMessageListener("SecureBrowser:AIR:LaunchProcess", cb);347 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.rv);348 }349 let o = { name : subject.wrappedJSObject.name };350 addMessageListener("SecureBrowser:AIR:LaunchProcess", cb);351 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-launchprocess", o:o });352 }353 /**354 * GET PROCESS LIST355 */356 if (topic == "sb-dom-browser-air-getprocesslist")357 {358 function cb (aMsg) 359 { 360 removeMessageListener("SecureBrowser:AIR:GetProcessList", cb);361 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(Cu.cloneInto(aMsg.data.list, subject.wrappedJSObject.window));362 }363 addMessageListener("SecureBrowser:AIR:GetProcessList", cb);364 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-getprocesslist" });365 }366 /**367 * EXAMINE PROCESS LIST368 */369 if (topic == "sb-dom-browser-security-examineprocesslist")370 {371 function cb (aMsg) 372 { 373 let inArray = subject.wrappedJSObject.plist;374 let rv = new Array;375 if (Array.isArray(inArray))376 {377 let plist = aMsg.data.list;378 // BrowserDebug.print("PROCESS LIST", plist);379 for (let iItem of inArray)380 {381 for (let eItem of plist)382 {383 // BrowserDebug.print(iItem.toLowerCase(), eItem.toLowerCase());384 if (iItem.toLowerCase() == eItem.toLowerCase()) rv.push(iItem);385 }386 }387 }388 removeMessageListener("SecureBrowser:AIR:ExamineProcessList", cb);389 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(Cu.cloneInto(rv, subject.wrappedJSObject.window));390 }391 addMessageListener("SecureBrowser:AIR:ExamineProcessList", cb);392 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-security-examineprocesslist" });393 }394 /**395 * SET ALT STARTPAGE396 */397 if (topic == "sb-dom-browser-security-setAltStartPage")398 {399 BrowserDebug.print("sb-dom-browser-security-setAltStartPage");400 function cb (aMsg) 401 { 402 removeMessageListener("SecureBrowser:SECURITY:SetAltStartPage", cb);403 }404 let o = { url : subject.wrappedJSObject.url };405 addMessageListener("SecureBrowser:SECURITY:SetAltStartPage", cb);406 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-security-setAltStartPage", o:o });407 }408 /**409 * RESTORE ALT STARTPAGE410 */411 if (topic == "sb-dom-browser-security-restoreDefaultStartPage")412 {413 BrowserDebug.print("sb-dom-browser-security-restoreDefaultStartPage");414 function cb (aMsg) 415 { 416 removeMessageListener("SecureBrowser:SECURITY:RestoreDefaultStartPage", cb);417 }418 addMessageListener("SecureBrowser:SECURITY:RestoreDefaultStartPage", cb);419 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-security-restoreDefaultStartPage" });420 }421 /**422 * SECURITY PERMISSIVE423 */424 if (topic == "sb-dom-browser-security-permissive")425 {426 function cb (aMsg) 427 { 428 try429 {430 // BrowserDebug.print("CALLBACK", "permissive", typeof(subject.wrappedJSObject.callback));431 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.o.p);432 removeMessageListener("SecureBrowser:SECURITY:Permissive", cb);433 }434 catch (e) { BrowserDebug.error(e); }435 }436 let o =437 {438 permissive : subject.wrappedJSObject.permissive439 };440 addMessageListener("SecureBrowser:SECURITY:Permissive", cb);441 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-security-permissive", o:o });442 }443 /**444 * READ445 */446 if (topic == "sb-dom-browser-air-read")447 {448 // BrowserDebug.print("sb-dom-browser-air-read");449 function cb (aMsg) 450 { 451 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.filedata);452 removeMessageListener("SecureBrowser:AIR:Read", cb);453 }454 let o =455 {456 key : subject.wrappedJSObject.key,457 filename : subject.wrappedJSObject.filename458 };459 addMessageListener("SecureBrowser:AIR:Read", cb);460 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-read", o:o });461 }462 /**463 * WRITE464 */465 if (topic == "sb-dom-browser-air-write")466 {467 BrowserDebug.print("sb-dom-browser-air-write");468 function cb (aMsg) 469 { 470 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.result);471 removeMessageListener("SecureBrowser:AIR:Write", cb);472 }473 let o =474 {475 key : subject.wrappedJSObject.key,476 filename : subject.wrappedJSObject.filename,477 data : subject.wrappedJSObject.data478 };479 addMessageListener("SecureBrowser:AIR:Write", cb);480 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-write", o:o });481 }482 /**483 * READ DIRECTORY484 */485 if (topic == "sb-dom-browser-air-readdirectory")486 {487 // BrowserDebug.print("sb-dom-browser-air-readdirectory");488 function cb (aMsg) 489 { 490 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(Cu.cloneInto(aMsg.data.entries, subject.wrappedJSObject.window));491 removeMessageListener("SecureBrowser:AIR:ReadDirectory", cb);492 }493 let o =494 {495 key : subject.wrappedJSObject.key,496 };497 addMessageListener("SecureBrowser:AIR:ReadDirectory", cb);498 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-readdirectory", o:o });499 }500 /**501 * REG WRITE DWORD502 */503 if (topic == "sb-dom-browser-air-regwritedword")504 {505 function cb (aMsg) 506 { 507 // BrowserDebug.print("success", aMsg.data.success);508 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.success);509 removeMessageListener("SecureBrowser:AIR:RegWriteDWORD", cb);510 }511 let o =512 {513 hkey : subject.wrappedJSObject.hkey,514 key : subject.wrappedJSObject.key,515 name : subject.wrappedJSObject.name,516 value : subject.wrappedJSObject.value,517 };518 addMessageListener("SecureBrowser:AIR:RegWriteDWORD", cb);519 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-regwritedword", o:o });520 }521 /**522 * REG WRITE BOOL523 */524 if (topic == "sb-dom-browser-air-regwritebool")525 {526 function cb (aMsg) 527 { 528 // BrowserDebug.print("success", aMsg.data.success);529 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.success);530 removeMessageListener("SecureBrowser:AIR:RegWriteBool", cb);531 }532 let o =533 {534 hkey : subject.wrappedJSObject.hkey,535 key : subject.wrappedJSObject.key,536 name : subject.wrappedJSObject.name,537 value : subject.wrappedJSObject.value,538 };539 addMessageListener("SecureBrowser:AIR:RegWriteBool", cb);540 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-regwritebool", o:o });541 }542 /**543 * REG WRITE STRING544 */545 if (topic == "sb-dom-browser-air-regwritestring")546 {547 function cb (aMsg) 548 { 549 // BrowserDebug.print("success", aMsg.data.success);550 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.success);551 removeMessageListener("SecureBrowser:AIR:RegWriteString", cb);552 }553 let o =554 {555 hkey : subject.wrappedJSObject.hkey,556 key : subject.wrappedJSObject.key,557 name : subject.wrappedJSObject.name,558 value : subject.wrappedJSObject.value,559 };560 addMessageListener("SecureBrowser:AIR:RegWriteString", cb);561 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-regwritestring", o:o });562 }563 /**564 * REG REMOVE565 */566 if (topic == "sb-dom-browser-air-regremove")567 {568 function cb (aMsg) 569 { 570 // BrowserDebug.print("success", aMsg.data.success);571 if (typeof(subject.wrappedJSObject.callback == "function")) subject.wrappedJSObject.callback(aMsg.data.success);572 removeMessageListener("SecureBrowser:AIR:RegRemove", cb);573 }574 let o =575 {576 hkey : subject.wrappedJSObject.hkey,577 key : subject.wrappedJSObject.key,578 name : subject.wrappedJSObject.name,579 };580 addMessageListener("SecureBrowser:AIR:RegRemove", cb);581 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-air-regremove", o:o });582 }583 /**584 * ADD EVENT LISTENER585 */586 if (topic == "sb-dom-browser-settings-addEventListener")587 {588 let domCallBack = subject.wrappedJSObject.callback;589 // BrowserDebug.print("sb-dom-browser-settings-addEventListener", "domCallBack", domCallBack);590 function handleDOM () { if (typeof(domCallBack == "function")) domCallBack(); }591 function cb (aMsg) 592 { 593 try594 {595 if (Components.utils.isDeadWrapper(subject.wrappedJSObject.window)) return;596 // BrowserDebug.print("CALLBACK", "SecureBrowser:EVENTS:AddEventListener");597 handleDOM();598 }599 catch (e) {}600 }601 let o = { event : subject.wrappedJSObject.event };602 removeMessageListener("SecureBrowser:EVENTS:AddEventListener", cb);603 addMessageListener("SecureBrowser:EVENTS:AddEventListener", cb);604 sendAsyncMessage("SecureBrowser:FrameMessageListener", { command: "sb-dom-browser-settings-addEventListener", o:o });605 }606 }607 }608};609Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-quit", false);610Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-restart", false);611Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-getMacAddress", false);612Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-tts-pause", false);613Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-tts-stop", false);614Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-tts-resume", false);615Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-tts-play", false);616Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-tts-status", false);617Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-tts-voices", false);618Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-tts-voice", false);619Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-clearcache", false);620Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-clearcookies", false);621Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-setboolpref", false);622Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-setstringpref", false);623Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-setintpref", false);624Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-clearpref", false);625Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-killprocess", false);626Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-launchprocess", false);627Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-getprocesslist", false);628Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-read", false);629Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-write", false);630Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-readdirectory", false);631Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-regwritedword", false);632Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-regwritebool", false);633Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-regwritestring", false);634Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-air-regremove", false);635Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-security-setAltStartPage", false);636Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-security-restoreDefaultStartPage", false);637Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-security-permissive", false);638Services.obs.addObserver(SecureBrowserFrame.DOMBrowserObserver, "sb-dom-browser-security-examineprocesslist", false);...
wrap-for-optimizing-test.js
Source:wrap-for-optimizing-test.js
1var vows = require('vows');2var assert = require('assert');3var wrapForOptimizing = require('../../lib/optimizer/wrap-for-optimizing').all;4vows.describe(wrapForOptimizing)5 .addBatch({6 'one': {7 'topic': function () {8 return wrapForOptimizing([9 [10 'property',11 ['property-name', 'margin'],12 ['property-value', '0'],13 ['property-value', '0']14 ]15 ], true);16 },17 'has one wrap': function (wrapped) {18 assert.lengthOf(wrapped, 1);19 },20 'has name': function (wrapped) {21 assert.deepEqual(wrapped[0].name, 'margin');22 },23 'has value': function (wrapped) {24 assert.deepEqual(wrapped[0].value, [['property-value', '0'], ['property-value', '0']]);25 },26 'is not a block': function (wrapped) {27 assert.isFalse(wrapped[0].block);28 },29 'has no components': function (wrapped) {30 assert.lengthOf(wrapped[0].components, 0);31 },32 'is not important': function (wrapped) {33 assert.isFalse(wrapped[0].important);34 },35 'is not dirty': function (wrapped) {36 assert.isFalse(wrapped[0].dirty);37 },38 'is not a shorthand': function (wrapped) {39 assert.isFalse(wrapped[0].shorthand);40 },41 'is unused': function (wrapped) {42 assert.isFalse(wrapped[0].unused);43 },44 'is hack': function (wrapped) {45 assert.isFalse(wrapped[0].hack);46 },47 'is multiplex': function (wrapped) {48 assert.isFalse(wrapped[0].multiplex);49 }50 },51 'two': {52 'topic': function () {53 return wrapForOptimizing([54 [55 'property',56 ['property-name', 'margin'],57 ['property-value', '0'],58 ['property-value', '0']59 ],60 [61 'property',62 ['property-name', 'color'],63 ['property-value', 'red']64 ]65 ], true);66 },67 'has two wraps': function (wrapped) {68 assert.lengthOf(wrapped, 2);69 }70 },71 'with comments': {72 'topic': function () {73 return wrapForOptimizing([74 [75 'comment',76 '/* comment */'77 ],78 [79 'property',80 ['property-name', 'color'],81 ['property-value', 'red']82 ]83 ], true);84 },85 'has one wrap': function (wrapped) {86 assert.lengthOf(wrapped, 1);87 },88 'sets position correctly': function (wrapped) {89 assert.equal(wrapped[0].position, 1);90 }91 },92 'longhand': {93 'topic': function () {94 return wrapForOptimizing([95 [96 'property',97 ['property-name', 'border-radius-top-left'],98 ['property-value', '1px'],99 ['property-value', '/'],100 ['property-value', '2px']101 ]102 ], true);103 },104 'has one wrap': function (wrapped) {105 assert.lengthOf(wrapped, 1);106 },107 'has name': function (wrapped) {108 assert.deepEqual(wrapped[0].name, 'border-radius-top-left');109 },110 'has value': function (wrapped) {111 assert.deepEqual(wrapped[0].value, [['property-value', '1px'], ['property-value', '/'], ['property-value', '2px']]);112 },113 'is multiplex': function (wrapped) {114 assert.isTrue(wrapped[0].multiplex);115 }116 },117 'variable': {118 'topic': function () {119 return wrapForOptimizing([120 [121 'property',122 ['property-name', '--color'],123 ['property-value', 'red']124 ]125 ], true);126 },127 'has one wrap': function (wrapped) {128 assert.lengthOf(wrapped, 1);129 },130 'has name': function (wrapped) {131 assert.deepEqual(wrapped[0].name, '--color');132 },133 'is not a block': function (wrapped) {134 assert.isFalse(wrapped[0].block);135 }136 },137 'variable reference': {138 'topic': function () {139 return wrapForOptimizing([140 [141 'property',142 ['property-name', 'color'],143 ['property-value', 'var(--red)']144 ]145 ], true);146 },147 'has one wrap': function (wrapped) {148 assert.lengthOf(wrapped, 1);149 },150 'has name': function (wrapped) {151 assert.deepEqual(wrapped[0].name, 'color');152 },153 'has value': function (wrapped) {154 assert.deepEqual(wrapped[0].value, [['property-value', 'var(--red)']]);155 }156 },157 'variable reference when variables are ignored': {158 'topic': function () {159 return wrapForOptimizing([160 [161 'property',162 ['property-name', 'color'],163 ['property-value', 'var(--red)']164 ]165 ], false);166 },167 'has one wrap': function (wrapped) {168 assert.lengthOf(wrapped, 0);169 }170 },171 'variable block': {172 'topic': function () {173 return wrapForOptimizing([174 [175 'property',176 ['property-name', '--color'],177 [178 'property-block',179 [180 [181 'property',182 ['property-name', 'color'],183 ['property-value', 'red']184 ],185 [186 'property',187 ['property-name', 'text-color'],188 ['property-value', 'red']189 ]190 ]191 ]192 ]193 ], true);194 },195 'has one wrap': function (wrapped) {196 assert.lengthOf(wrapped, 1);197 },198 'has name': function (wrapped) {199 assert.deepEqual(wrapped[0].name, '--color');200 },201 'has value': function (wrapped) {202 assert.deepEqual(wrapped[0].value, [203 [204 'property-block',205 [206 [207 'property',208 ['property-name', 'color'],209 ['property-value', 'red']210 ],211 [212 'property',213 ['property-name', 'text-color'],214 ['property-value', 'red']215 ]216 ]217 ]218 ], true);219 },220 'is a block': function (wrapped) {221 assert.isTrue(wrapped[0].block);222 }223 },224 'without value': {225 'topic': function () {226 return wrapForOptimizing([227 [228 'property',229 ['property-name', 'margin']230 ]231 ], true);232 },233 'has one wrap': function (wrapped) {234 assert.lengthOf(wrapped, 1);235 },236 'has value': function (wrapped) {237 assert.isUndefined(wrapped.value);238 },239 'unused is not set': function (wrapped) {240 assert.isFalse(wrapped[0].unused);241 }242 },243 'important': {244 'topic': function () {245 return wrapForOptimizing([246 [247 'property',248 ['property-name', 'margin'],249 ['property-value', '0!important']250 ]251 ], true);252 },253 'has one wrap': function (wrapped) {254 assert.lengthOf(wrapped, 1);255 },256 'has right value': function (wrapped) {257 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);258 },259 'has important set': function (wrapped) {260 assert.isTrue(wrapped[0].important);261 }262 },263 'important with prefix space': {264 'topic': function () {265 return wrapForOptimizing([266 [267 'property',268 ['property-name', 'margin'],269 ['property-value', '0'],270 ['property-value', '!important']271 ]272 ], true);273 },274 'has one wrap': function (wrapped) {275 assert.lengthOf(wrapped, 1);276 },277 'has right value': function (wrapped) {278 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);279 },280 'has important set': function (wrapped) {281 assert.isTrue(wrapped[0].important);282 }283 },284 'important with suffix space': {285 'topic': function () {286 return wrapForOptimizing([287 [288 'property',289 ['property-name', 'margin'],290 ['property-value', '0!'],291 ['property-value', 'important']292 ]293 ], true);294 },295 'has one wrap': function (wrapped) {296 assert.lengthOf(wrapped, 1);297 },298 'has right value': function (wrapped) {299 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);300 },301 'has important set': function (wrapped) {302 assert.isTrue(wrapped[0].important);303 }304 },305 'important with two spaces': {306 'topic': function () {307 return wrapForOptimizing([308 [309 'property',310 ['property-name', 'margin'],311 ['property-value', '0'],312 ['property-value', '!'],313 ['property-value', 'important']314 ]315 ], true);316 },317 'has one wrap': function (wrapped) {318 assert.lengthOf(wrapped, 1);319 },320 'has right value': function (wrapped) {321 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);322 },323 'has important set': function (wrapped) {324 assert.isTrue(wrapped[0].important);325 },326 'is not a bang hack': function (wrapped) {327 assert.isFalse(wrapped[0].hack);328 }329 },330 'underscore hack': {331 'topic': function () {332 return wrapForOptimizing([333 [334 'property',335 ['property-name', '_color'],336 ['property-value', 'red']337 ]338 ], true);339 },340 'has one wrap': function (wrapped) {341 assert.lengthOf(wrapped, 1);342 },343 'has right name': function (wrapped) {344 assert.deepEqual(wrapped[0].name, 'color');345 },346 'is a hack': function (wrapped) {347 assert.deepEqual(wrapped[0].hack, ['underscore']);348 }349 },350 'star hack': {351 'topic': function () {352 return wrapForOptimizing([353 [354 'property',355 ['property-name', '*color'],356 ['property-value', 'red']357 ]358 ], true);359 },360 'has one wrap': function (wrapped) {361 assert.lengthOf(wrapped, 1);362 },363 'has right name': function (wrapped) {364 assert.deepEqual(wrapped[0].name, 'color');365 },366 'is a hack': function (wrapped) {367 assert.deepEqual(wrapped[0].hack, ['asterisk']);368 }369 },370 'backslash hack': {371 'topic': function () {372 return wrapForOptimizing([373 [374 'property',375 ['property-name', 'margin'],376 ['property-value', '0\\9']377 ]378 ], true);379 },380 'has one wrap': function (wrapped) {381 assert.lengthOf(wrapped, 1);382 },383 'has right value': function (wrapped) {384 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);385 },386 'is a hack': function (wrapped) {387 assert.deepEqual(wrapped[0].hack, ['backslash', '9']);388 }389 },390 'backslash hack - single value': {391 'topic': function () {392 return wrapForOptimizing([393 [394 'property',395 ['property-name', 'margin'],396 ['property-value', '0']397 ]398 ], true);399 },400 'has one wrap': function (wrapped) {401 assert.lengthOf(wrapped, 1);402 },403 'has right value': function (wrapped) {404 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);405 },406 'is a hack': function (wrapped) {407 assert.isFalse(wrapped[0].hack);408 }409 },410 'backslash hack - space between values': {411 'topic': function () {412 return wrapForOptimizing([413 [414 'property',415 ['property-name', 'margin'],416 ['property-value', '0'],417 ['property-value', '\\9']418 ]419 ], true);420 },421 'has one wrap': function (wrapped) {422 assert.lengthOf(wrapped, 1);423 },424 'has right value': function (wrapped) {425 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);426 },427 'is a hack': function (wrapped) {428 assert.deepEqual(wrapped[0].hack, ['backslash', '9']);429 }430 },431 'bang hack': {432 'topic': function () {433 return wrapForOptimizing([434 [435 'property',436 ['property-name', 'margin'],437 ['property-value', '0!ie']438 ]439 ], true);440 },441 'has one wrap': function (wrapped) {442 assert.lengthOf(wrapped, 1);443 },444 'has right value': function (wrapped) {445 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);446 },447 'is a hack': function (wrapped) {448 assert.deepEqual(wrapped[0].hack, ['bang']);449 },450 'is not important': function (wrapped) {451 assert.isFalse(wrapped[0].important);452 }453 },454 'bang hack with space': {455 'topic': function () {456 return wrapForOptimizing([457 [458 'property',459 ['property-name', 'margin'],460 ['property-value', '0 !ie']461 ]462 ], true);463 },464 'has one wrap': function (wrapped) {465 assert.lengthOf(wrapped, 1);466 },467 'has right value': function (wrapped) {468 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);469 },470 'is a hack': function (wrapped) {471 assert.deepEqual(wrapped[0].hack, ['bang']);472 },473 'is not important': function (wrapped) {474 assert.isFalse(wrapped[0].important);475 }476 },477 'bang hack - space between values': {478 'topic': function () {479 return wrapForOptimizing([480 [481 'property',482 ['property-name', 'margin'],483 ['property-value', '0'],484 ['property-value', '!ie']485 ]486 ], true);487 },488 'has one wrap': function (wrapped) {489 assert.lengthOf(wrapped, 1);490 },491 'has right value': function (wrapped) {492 assert.deepEqual(wrapped[0].value, [['property-value', '0']]);493 },494 'is a hack': function (wrapped) {495 assert.deepEqual(wrapped[0].hack, ['bang']);496 },497 'is not important': function (wrapped) {498 assert.isFalse(wrapped[0].important);499 }500 },501 'two hacks': {502 'topic': function () {503 return wrapForOptimizing([504 [505 'property',506 ['property-name', 'color'],507 ['property-value', 'red\\9!important']508 ]509 ], true);510 },511 'has one wrap': function (wrapped) {512 assert.lengthOf(wrapped, 1);513 },514 'has right value': function (wrapped) {515 assert.deepEqual(wrapped[0].value, [['property-value', 'red']]);516 },517 'is important': function (wrapped) {518 assert.isTrue(wrapped[0].important);519 },520 'is a hack': function (wrapped) {521 assert.deepEqual(wrapped[0].hack, ['backslash', '9']);522 }523 },524 'source map': {525 'topic': function () {526 return wrapForOptimizing([527 [528 'property',529 ['property-name', 'color', [[1, 2, undefined]]],530 ['property-value', 'red', [[1, 2, undefined]]]531 ]532 ], true);533 },534 'has one wrap': function (wrapped) {535 assert.lengthOf(wrapped, 1);536 },537 'has right value': function (wrapped) {538 assert.deepEqual(wrapped[0].value, [['property-value', 'red', [[1, 2, undefined]]]]);539 }540 },541 'skipping properties': {542 'topic': function () {543 return wrapForOptimizing([544 [545 'property',546 ['property-name', 'background', [[1, 2, undefined]]],547 ['property-value', 'red', [[1, 12, undefined]]]548 ]549 ], true, ['background']);550 },551 'has no wrap': function (wrapped) {552 assert.lengthOf(wrapped, 0);553 }554 }555 })...
namespace-test.js
Source:namespace-test.js
1/*global bean:true, buster:true, Syn:true, assert:true, defer:true, features:true, globalSetUp:true, globalTearDown:true*/2buster.testCase('namespaces', {3 'setUp': globalSetUp4 , 'tearDown': globalTearDown5 , 'should be able to name handlers': {6 'setUp': function () {7 var self = this8 this.runTest = function (done, regFn) {9 var el1 = self.byId('foo')10 , trigger = self.trigger()11 , spy = self.spy()12 trigger.after(function () {13 assert.equals(spy.callCount, 1, 'triggered click event')14 done()15 })16 regFn(el1, trigger.wrap(spy))17 Syn.click(el1)18 }19 }20 , 'on()': function (done) {21 this.runTest(done, function (el1, wrappedSpy) {22 bean.on(el1, 'click.fat', wrappedSpy)23 })24 }25 , 'add()': function (done) {26 this.runTest(done, function (el1, wrappedSpy) {27 bean.add(el1, 'click.fat', wrappedSpy)28 })29 }30 }31 , 'should be able to add multiple handlers under the same namespace to the same element': {32 'setUp': function () {33 var self = this34 this.runTest = function (done, regFn) {35 var el1 = self.byId('foo')36 , trigger = self.trigger()37 , spy1 = self.spy()38 , spy2 = self.spy()39 trigger.after(function () {40 assert.equals(spy1.callCount, 1, 'triggered click event')41 assert.equals(spy2.callCount, 1, 'triggered click event')42 done()43 })44 regFn(el1, trigger.wrap(spy1), trigger.wrap(spy2))45 Syn.click(el1)46 }47 }48 , 'on()': function (done) {49 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2) {50 bean.on(el1, 'click.fat', wrappedSpy1)51 bean.on(el1, 'click.fat', wrappedSpy2)52 })53 }54 , 'add()': function (done) {55 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2) {56 bean.add(el1, 'click.fat', wrappedSpy1)57 bean.add(el1, 'click.fat', wrappedSpy2)58 })59 }60 }61 , 'should be able to fire an event without handlers': function () {62 var el1 = this.byId('foo')63 bean.fire(el1, 'click.fat')64 assert(true, 'fire namespaced event with no handlers (no exception)')65 }66 , 'should be able to target namespaced event handlers with fire': {67 'setUp': function () {68 var self = this69 this.runTest = function (done, regFn) {70 var el1 = self.byId('foo')71 , trigger = self.trigger()72 , spy1 = self.spy()73 , spy2 = self.spy()74 trigger.after(function () {75 assert.equals(spy1.callCount, 1, 'triggered click event (namespaced)')76 assert.equals(spy2.callCount, 0, 'should not trigger click event (plain)')77 done()78 })79 regFn(el1, trigger.wrap(spy1), trigger.wrap(spy2))80 bean.fire(el1, 'click.fat')81 }82 }83 , 'on()': function (done) {84 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2) {85 bean.on(el1, 'click.fat', wrappedSpy1)86 bean.on(el1, 'click', wrappedSpy2)87 })88 }89 , 'add()': function (done) {90 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2) {91 bean.add(el1, 'click.fat', wrappedSpy1)92 bean.add(el1, 'click', wrappedSpy2)93 })94 }95 }96 // changed in 0.5 so this doesn't fire, namespaces need to match97 , 'should not be able to target multiple namespaced event handlers with fire': {98 'setUp': function () {99 var self = this100 this.runTest = function (done, regFn) {101 var el1 = self.byId('foo')102 , spy1 = self.spy()103 , spy2 = self.spy()104 , spy3 = self.spy()105 regFn(el1, spy1, spy2, spy3)106 bean.fire(el1, 'click.fat.ded')107 defer(function () {108 assert.equals(spy1.callCount, 0, 'should not trigger click event (namespaced)')109 assert.equals(spy2.callCount, 0, 'should not trigger click event (namespaced)')110 assert.equals(spy3.callCount, 0, 'should not trigger click event (plain)')111 done()112 })113 }114 }115 , 'on()': function (done) {116 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2, wrappedSpy3) {117 bean.on(el1, 'click.fat', wrappedSpy1)118 bean.on(el1, 'click.ded', wrappedSpy2)119 bean.on(el1, 'click', wrappedSpy3)120 })121 }122 , 'add()': function (done) {123 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2, wrappedSpy3) {124 bean.add(el1, 'click.fat', wrappedSpy1)125 bean.add(el1, 'click.ded', wrappedSpy2)126 bean.add(el1, 'click', wrappedSpy3)127 })128 }129 }130 , 'should be able to remove handlers based on name': {131 'setUp': function () {132 var self = this133 this.runTest = function (done, regFn) {134 var el1 = self.byId('foo')135 , trigger = self.trigger()136 , spy1 = self.spy()137 , spy2 = self.spy()138 trigger.after(function () {139 assert.equals(spy1.callCount, 0, 'should not trigger click event (namespaced)')140 assert.equals(spy2.callCount, 1, 'triggered click event (plain)')141 done()142 })143 regFn(el1, trigger.wrap(spy1), trigger.wrap(spy2))144 bean.remove(el1, 'click.ded')145 Syn.click(el1)146 }147 }148 , 'on()': function (done) {149 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2) {150 bean.on(el1, 'click.ded', wrappedSpy1)151 bean.on(el1, 'click', wrappedSpy2)152 })153 }154 , 'add()': function (done) {155 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2) {156 bean.add(el1, 'click.ded', wrappedSpy1)157 bean.add(el1, 'click', wrappedSpy2)158 })159 }160 }161 // changed in 0.5 so this doesn't remove, namespaces need to match162 , 'should not be able to remove multiple handlers based on name': {163 'setUp': function () {164 var self = this165 this.runTest = function (done, regFn) {166 var el1 = self.byId('foo')167 , trigger = self.trigger()168 , spy1 = self.spy()169 , spy2 = self.spy()170 , spy3 = self.spy()171 trigger.after(function () {172 assert.equals(spy1.callCount, 1, 'triggered click event (namespaced)')173 assert.equals(spy2.callCount, 1, 'triggered click event (namespaced)')174 assert.equals(spy3.callCount, 1, 'triggered click event (plain)')175 done()176 })177 regFn(el1, trigger.wrap(spy1), trigger.wrap(spy2), trigger.wrap(spy3))178 bean.remove(el1, 'click.ded.fat')179 Syn.click(el1)180 }181 }182 , 'on()': function (done) {183 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2, wrappedSpy3) {184 bean.on(el1, 'click.fat', wrappedSpy1)185 bean.on(el1, 'click.ded', wrappedSpy2)186 bean.on(el1, 'click', wrappedSpy3)187 })188 }189 , 'add()': function (done) {190 this.runTest(done, function (el1, wrappedSpy1, wrappedSpy2, wrappedSpy3) {191 bean.add(el1, 'click.fat', wrappedSpy1)192 bean.add(el1, 'click.ded', wrappedSpy2)193 bean.add(el1, 'click', wrappedSpy3)194 })195 }196 }197 , 'should be able to add multiple custom events to a single handler and call them individually': {198 'setUp': function () {199 var self = this200 this.runTest = function (done, regFn) {201 var el1 = self.byId('foo')202 , trigger = self.trigger()203 , spy = self.spy()204 trigger.after(function () {205 assert.equals(spy.callCount, 2, 'triggered custom event')206 assert.equals(spy.firstCall.args[0], '1', 'expected array argument')207 assert.equals(spy.secondCall.args[0], '2', 'expected array argument')208 done()209 })210 regFn(el1, trigger.wrap(spy))211 bean.fire(el1, 'fat.test1', ['1'])212 bean.fire(el1, 'fat.test2', ['2'])213 }214 }215 , 'on()': function (done) {216 this.runTest(done, function (el1, wrappedSpy) {217 bean.on(el1, 'fat.test1 fat.test2', wrappedSpy)218 })219 }220 , 'add()': function (done) {221 this.runTest(done, function (el1, wrappedSpy) {222 bean.add(el1, 'fat.test1 fat.test2', wrappedSpy)223 })224 }225 }226 227 , 'should be able to fire an event if the fired namespace is within the event namespace range': {228 'setUp': function () {229 var self = this230 this.runTest = function (done, regFn) {231 var el1 = self.byId('foo')232 , trigger = self.trigger()233 , spy = self.spy()234 trigger.after(function () {235 assert.equals(spy.callCount, 4, 'triggered custom event')236 assert.equals(spy.firstCall.args[0], '1', 'expected array argument')237 assert.equals(spy.secondCall.args[0], '2', 'expected array argument')238 assert.equals(spy.thirdCall.args[0], '3', 'expected array argument')239 assert.equals(spy.lastCall.args[0], '3', 'expected array argument')240 done()241 })242 regFn(el1, trigger.wrap(spy))243 bean.fire(el1, 'fat.test1', ['1'])244 bean.fire(el1, 'fat.test2', ['2'])245 bean.fire(el1, 'fat.foo', ['3'])246 }247 }248 , 'on()': function (done) {249 this.runTest(done, function (el1, wrappedSpy) {250 bean.on(el1, 'fat.test1.foo fat.test2.foo', wrappedSpy)251 })252 }253 , 'add()': function (done) {254 this.runTest(done, function (el1, wrappedSpy) {255 bean.add(el1, 'fat.test1.foo fat.test2.foo', wrappedSpy)256 })257 }258 }259 , 'should be able to fire multiple events and fire them regardless of the order of the namespaces': {260 'setUp': function () {261 var self = this262 this.runTest = function (done, regFn) {263 var el1 = self.byId('foo')264 , trigger = self.trigger()265 , spy = self.spy()266 trigger.after(function () {267 assert.equals(spy.callCount, 4, 'triggered custom event')268 assert.equals(spy.firstCall.args[0], '1', 'expected array argument')269 assert.equals(spy.secondCall.args[0], '1', 'expected array argument')270 assert.equals(spy.thirdCall.args[0], '2', 'expected array argument')271 assert.equals(spy.lastCall.args[0], '2', 'expected array argument')272 done()273 })274 regFn(el1, trigger.wrap(spy))275 bean.fire(el1, 'fat.test.foo', ['1'])276 bean.fire(el1, 'fat.foo.test', ['2'])277 }278 }279 , 'on()': function (done) {280 this.runTest(done, function (el1, wrappedSpy) {281 bean.on(el1, 'fat.test.foo fat.foo.test', wrappedSpy)282 })283 }284 , 'add()': function (done) {285 this.runTest(done, function (el1, wrappedSpy) {286 bean.add(el1, 'fat.test.foo fat.foo.test', wrappedSpy)287 })288 }289 }290 291 , 'should only fire an event if the fired namespaces is within the event namespace or if the event namespace is within the fired namespace': {292 'setUp': function () {293 var self = this294 this.runTest = function (done, regFn) {295 var el1 = self.byId('foo')296 , trigger = self.trigger()297 , spy = self.spy()298 trigger.after(function () {299 assert.equals(spy.callCount, 5, 'triggered custom event')300 assert.equals(spy.firstCall.args[0], '1', 'expected array argument')301 assert.equals(spy.secondCall.args[0], '1', 'expected array argument')302 assert.equals(spy.thirdCall.args[0], '2', 'expected array argument')303 assert.equals(spy.getCall(3).args[0], '2', 'expected array argument')304 assert.equals(spy.getCall(4).args[0], '3', 'expected array argument')305 done()306 })307 regFn(el1, trigger.wrap(spy))308 bean.fire(el1, 'fat.test.foo', ['1'])309 bean.fire(el1, 'fat.foo.test', ['2'])310 bean.fire(el1, 'fat.test.ded', ['3'])311 }312 }313 , 'on()': function (done) {314 this.runTest(done, function (el1, wrappedSpy) {315 bean.on(el1, 'fat.test.foo.ded fat.foo.test fat.ded', wrappedSpy)316 })317 }318 , 'add()': function (done) {319 this.runTest(done, function (el1, wrappedSpy) {320 bean.add(el1, 'fat.test.foo.ded fat.foo.test fat.ded', wrappedSpy)321 })322 }323 }...
populate-components-test.js
Source:populate-components-test.js
1var assert = require('assert');2var vows = require('vows');3var wrapForOptimizing = require('../../../../lib/optimizer/wrap-for-optimizing').all;4var compatibilityFrom = require('../../../../lib/options/compatibility');5var validator = require('../../../../lib/optimizer/validator');6var populateComponents = require('../../../../lib/optimizer/level-2/properties/populate-components');7vows.describe(populateComponents)8 .addBatch({9 'shorthand': {10 'topic': function () {11 var wrapped = wrapForOptimizing([12 [13 'property',14 ['property-name', 'margin'],15 ['property-value', '0px'],16 ['property-value', '1px'],17 ['property-value', '2px'],18 ['property-value', '3px']19 ]20 ]);21 populateComponents(wrapped, validator(compatibilityFrom({})), []);22 return wrapped;23 },24 'has one': function (wrapped) {25 assert.lengthOf(wrapped, 1);26 },27 'becomes shorthand': function (wrapped) {28 assert.isTrue(wrapped[0].shorthand);29 },30 'is dirty': function (wrapped) {31 assert.isTrue(wrapped[0].dirty);32 },33 'gets 4 components': function (wrapped) {34 assert.lengthOf(wrapped[0].components, 4);35 },36 'gets a margin-top': function (wrapped) {37 assert.deepEqual(wrapped[0].components[0].name, 'margin-top');38 assert.deepEqual(wrapped[0].components[0].value, [['property-value', '0px']]);39 },40 'gets a margin-right': function (wrapped) {41 assert.deepEqual(wrapped[0].components[1].name, 'margin-right');42 assert.deepEqual(wrapped[0].components[1].value, [['property-value', '1px']]);43 },44 'gets a margin-bottom': function (wrapped) {45 assert.deepEqual(wrapped[0].components[2].name, 'margin-bottom');46 assert.deepEqual(wrapped[0].components[2].value, [['property-value', '2px']]);47 },48 'gets a margin-left': function (wrapped) {49 assert.deepEqual(wrapped[0].components[3].name, 'margin-left');50 assert.deepEqual(wrapped[0].components[3].value, [['property-value', '3px']]);51 }52 },53 'shorthand with shorthand components': {54 'topic': function () {55 var wrapped = wrapForOptimizing([56 [57 'property',58 ['property-name', 'border'],59 ['property-value', '1px'],60 ['property-value', 'solid'],61 ['property-value', 'red']62 ]63 ]);64 populateComponents(wrapped, validator(compatibilityFrom({})), []);65 return wrapped;66 },67 'has one': function (wrapped) {68 assert.lengthOf(wrapped, 1);69 },70 'becomes shorthand': function (wrapped) {71 assert.isTrue(wrapped[0].shorthand);72 },73 'is dirty': function (wrapped) {74 assert.isTrue(wrapped[0].dirty);75 },76 'gets 3 components': function (wrapped) {77 assert.lengthOf(wrapped[0].components, 3);78 },79 'gets a border-width with subcomponents': function (wrapped) {80 assert.deepEqual(wrapped[0].components[0].name, 'border-width');81 assert.deepEqual(wrapped[0].components[0].value, [82 ['property-value', '1px'],83 ['property-value', '1px'],84 ['property-value', '1px'],85 ['property-value', '1px']86 ]);87 assert.lengthOf(wrapped[0].components[0].components, 4);88 assert.deepEqual(wrapped[0].components[0].components.map(function (c) { return c.name; }), [89 'border-top-width',90 'border-right-width',91 'border-bottom-width',92 'border-left-width'93 ]);94 },95 'gets a border-style': function (wrapped) {96 assert.deepEqual(wrapped[0].components[1].name, 'border-style');97 assert.deepEqual(wrapped[0].components[1].value, [98 ['property-value', 'solid'],99 ['property-value', 'solid'],100 ['property-value', 'solid'],101 ['property-value', 'solid']102 ]);103 assert.lengthOf(wrapped[0].components[1].components, 4);104 assert.deepEqual(wrapped[0].components[1].components.map(function (c) { return c.name; }), [105 'border-top-style',106 'border-right-style',107 'border-bottom-style',108 'border-left-style'109 ]);110 },111 'gets a border-color': function (wrapped) {112 assert.deepEqual(wrapped[0].components[2].name, 'border-color');113 assert.deepEqual(wrapped[0].components[2].value, [114 ['property-value', 'red'],115 ['property-value', 'red'],116 ['property-value', 'red'],117 ['property-value', 'red']118 ]);119 assert.lengthOf(wrapped[0].components[2].components, 4);120 assert.deepEqual(wrapped[0].components[2].components.map(function (c) { return c.name; }), [121 'border-top-color',122 'border-right-color',123 'border-bottom-color',124 'border-left-color'125 ]);126 }127 },128 'longhand': {129 'topic': function () {130 var wrapped = wrapForOptimizing([131 [132 'property',133 ['property-name', 'margin-top'],134 ['property-value', '0px']135 ]136 ]);137 populateComponents(wrapped, validator(compatibilityFrom({})), []);138 return wrapped;139 },140 'has one': function (wrapped) {141 assert.lengthOf(wrapped, 1);142 },143 'gets no components': function (wrapped) {144 assert.isEmpty(wrapped[0].components);145 }146 },147 'no value': {148 'topic': function () {149 var wrapped = wrapForOptimizing([150 [151 'property',152 ['property-name', 'margin']153 ]154 ]);155 populateComponents(wrapped, validator(compatibilityFrom({})), []);156 return wrapped;157 },158 'has one': function (wrapped) {159 assert.lengthOf(wrapped, 1);160 },161 'is unused': function (wrapped) {162 assert.isTrue(wrapped[0].unused);163 }164 }165 })...
wrap-method.js
Source:wrap-method.js
1"use strict";2var getPropertyDescriptor = require("./get-property-descriptor");3var valueToString = require("./value-to-string");4var hasOwn = Object.prototype.hasOwnProperty;5function isFunction(obj) {6 return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply);7}8function mirrorProperties(target, source) {9 for (var prop in source) {10 if (!hasOwn.call(target, prop)) {11 target[prop] = source[prop];12 }13 }14}15// Cheap way to detect if we have ES5 support.16var hasES5Support = "keys" in Object;17module.exports = function wrapMethod(object, property, method) {18 if (!object) {19 throw new TypeError("Should wrap property of object");20 }21 if (typeof method !== "function" && typeof method !== "object") {22 throw new TypeError("Method wrapper should be a function or a property descriptor");23 }24 function checkWrappedMethod(wrappedMethod) {25 var error;26 if (!isFunction(wrappedMethod)) {27 error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +28 valueToString(property) + " as function");29 } else if (wrappedMethod.restore && wrappedMethod.restore.sinon) {30 error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already wrapped");31 } else if (wrappedMethod.calledBefore) {32 var verb = wrappedMethod.returns ? "stubbed" : "spied on";33 error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already " + verb);34 }35 if (error) {36 if (wrappedMethod && wrappedMethod.stackTrace) {37 error.stack += "\n--------------\n" + wrappedMethod.stackTrace;38 }39 throw error;40 }41 }42 var error, wrappedMethod, i;43 function simplePropertyAssignment() {44 wrappedMethod = object[property];45 checkWrappedMethod(wrappedMethod);46 object[property] = method;47 method.displayName = property;48 }49 // Firefox has a problem when using hasOwn.call on objects from other frames.50 var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property);51 if (hasES5Support) {52 var methodDesc = (typeof method === "function") ? {value: method} : method;53 var wrappedMethodDesc = getPropertyDescriptor(object, property);54 if (!wrappedMethodDesc) {55 error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " +56 property + " as function");57 } else if (wrappedMethodDesc.restore && wrappedMethodDesc.restore.sinon) {58 error = new TypeError("Attempted to wrap " + property + " which is already wrapped");59 }60 if (error) {61 if (wrappedMethodDesc && wrappedMethodDesc.stackTrace) {62 error.stack += "\n--------------\n" + wrappedMethodDesc.stackTrace;63 }64 throw error;65 }66 var types = Object.keys(methodDesc);67 for (i = 0; i < types.length; i++) {68 wrappedMethod = wrappedMethodDesc[types[i]];69 checkWrappedMethod(wrappedMethod);70 }71 mirrorProperties(methodDesc, wrappedMethodDesc);72 for (i = 0; i < types.length; i++) {73 mirrorProperties(methodDesc[types[i]], wrappedMethodDesc[types[i]]);74 }75 Object.defineProperty(object, property, methodDesc);76 // catch failing assignment77 // this is the converse of the check in `.restore` below78 if ( typeof method === "function" && object[property] !== method ) {79 // correct any wrongdoings caused by the defineProperty call above,80 // such as adding new items (if object was a Storage object)81 delete object[property];82 simplePropertyAssignment();83 }84 } else {85 simplePropertyAssignment();86 }87 method.displayName = property;88 // Set up a stack trace which can be used later to find what line of89 // code the original method was created on.90 method.stackTrace = (new Error("Stack Trace for original")).stack;91 method.restore = function () {92 // For prototype properties try to reset by delete first.93 // If this fails (ex: localStorage on mobile safari) then force a reset94 // via direct assignment.95 if (!owned) {96 // In some cases `delete` may throw an error97 try {98 delete object[property];99 } catch (e) {} // eslint-disable-line no-empty100 // For native code functions `delete` fails without throwing an error101 // on Chrome < 43, PhantomJS, etc.102 } else if (hasES5Support) {103 Object.defineProperty(object, property, wrappedMethodDesc);104 }105 if (hasES5Support) {106 var descriptor = getPropertyDescriptor(object, property);107 if (descriptor && descriptor.value === method) {108 object[property] = wrappedMethod;109 }110 }111 else {112 // Use strict equality comparison to check failures then force a reset113 // via direct assignment.114 if (object[property] === method) {115 object[property] = wrappedMethod;116 }117 }118 };119 method.wrappedMethod = wrappedMethod;120 method.restore.sinon = true;121 if (!hasES5Support) {122 mirrorProperties(method, wrappedMethod);123 }124 return method;...
Wrapper.js
Source:Wrapper.js
1/**2 *3 */4Ext.define('Ext.util.Wrapper', {5 mixins: ['Ext.mixin.Bindable'],6 constructor: function(elementConfig, wrappedElement) {7 var element = this.link('element', Ext.Element.create(elementConfig));8 if (wrappedElement) {9 element.insertBefore(wrappedElement);10 this.wrap(wrappedElement);11 }12 },13 bindSize: function(sizeName) {14 var wrappedElement = this.wrappedElement,15 boundMethodName;16 this.boundSizeName = sizeName;17 this.boundMethodName = boundMethodName = sizeName === 'width' ? 'setWidth' : 'setHeight';18 this.bind(wrappedElement, boundMethodName, 'onBoundSizeChange');19 wrappedElement[boundMethodName].call(wrappedElement, wrappedElement.getStyleValue(sizeName));20 },21 onBoundSizeChange: function(size, args) {22 var element = this.element;23 if (typeof size === 'string' && size.substr(-1) === '%') {24 args[0] = '100%';25 }26 else {27 size = '';28 }29 element[this.boundMethodName].call(element, size);30 },31 wrap: function(wrappedElement) {32 var element = this.element,33 innerDom;34 this.wrappedElement = wrappedElement;35 innerDom = element.dom;36 while (innerDom.firstElementChild !== null) {37 innerDom = innerDom.firstElementChild;38 }39 innerDom.appendChild(wrappedElement.dom);40 },41 destroy: function() {42 var element = this.element,43 dom = element.dom,44 wrappedElement = this.wrappedElement,45 boundMethodName = this.boundMethodName,46 parentNode = dom.parentNode,47 size;48 if (boundMethodName) {49 this.unbind(wrappedElement, boundMethodName, 'onBoundSizeChange');50 size = element.getStyle(this.boundSizeName);51 if (size) {52 wrappedElement[boundMethodName].call(wrappedElement, size);53 }54 }55 if (parentNode) {56 if (!wrappedElement.isDestroyed) {57 parentNode.replaceChild(dom.firstElementChild, dom);58 }59 delete this.wrappedElement;60 }61 this.callSuper();62 }...
wrapped-operation.js
Source:wrapped-operation.js
1if (typeof ot === 'undefined') {2 // Export for browsers3 var ot = {};4}5ot.WrappedOperation = (function (global) {6 'use strict';7 // A WrappedOperation contains an operation and corresponing metadata.8 function WrappedOperation (operation, meta) {9 this.wrapped = operation;10 this.meta = meta;11 }12 WrappedOperation.prototype.apply = function () {13 return this.wrapped.apply.apply(this.wrapped, arguments);14 };15 WrappedOperation.prototype.invert = function () {16 var meta = this.meta;17 return new WrappedOperation(18 this.wrapped.invert.apply(this.wrapped, arguments),19 meta && typeof meta === 'object' && typeof meta.invert === 'function' ?20 meta.invert.apply(meta, arguments) : meta21 );22 };23 // Copy all properties from source to target.24 function copy (source, target) {25 for (var key in source) {26 if (source.hasOwnProperty(key)) {27 target[key] = source[key];28 }29 }30 }31 function composeMeta (a, b) {32 if (a && typeof a === 'object') {33 if (typeof a.compose === 'function') { return a.compose(b); }34 var meta = {};35 copy(a, meta);36 copy(b, meta);37 return meta;38 }39 return b;40 }41 WrappedOperation.prototype.compose = function (other) {42 return new WrappedOperation(43 this.wrapped.compose(other.wrapped),44 composeMeta(this.meta, other.meta)45 );46 };47 function transformMeta (meta, operation) {48 if (meta && typeof meta === 'object') {49 if (typeof meta.transform === 'function') {50 return meta.transform(operation);51 }52 }53 return meta;54 }55 WrappedOperation.transform = function (a, b) {56 var transform = a.wrapped.constructor.transform;57 var pair = transform(a.wrapped, b.wrapped);58 return [59 new WrappedOperation(pair[0], transformMeta(a.meta, b.wrapped)),60 new WrappedOperation(pair[1], transformMeta(b.meta, a.wrapped))61 ];62 };63 return WrappedOperation;64}(this));65// Export for CommonJS66if (typeof module === 'object') {67 module.exports = ot.WrappedOperation;...
index_stopwatch_redux.js
Source:index_stopwatch_redux.js
1import React from "react";2import ReactDOM from "react-dom";3import { combineReducers, createStore } from "redux";4import { connect, Provider } from "react-redux";5const UPDATE_ACTION = "UPDATE_ACTION";6const createUpdateAction = () => ({7 type: UPDATE_ACTION8});9const stopWatch = function(10 initialState = {11 currentTimestamp: 012 },13 action14) {15 switch (action.type) {16 case UPDATE_ACTION:17 initialState.currentTimestamp = Date.now();18 return Object.assign({}, initialState);19 default:20 return initialState;21 }22};23const store = createStore(24 combineReducers({25 stopWatch26 })27);28class StopWatch extends React.Component {29 constructor(props) {30 super(props);31 const { update } = this.props;32 setInterval(update);33 }34 render() {35 const { currentTimestamp } = this.props;36 return <div>{currentTimestamp}</div>;37 }38}39const WrappedStopWatch = connect(40 function mapStateToProps(state, props) {41 const {42 stopWatch: { currentTimestamp }43 } = state;44 return {45 currentTimestamp46 };47 },48 function(dispatch) {49 return {50 update: () => {51 dispatch(createUpdateAction());52 }53 };54 }55)(StopWatch);56ReactDOM.render(57 <Provider store={store}>58 <div>59 <WrappedStopWatch />60 <WrappedStopWatch />61 <WrappedStopWatch />62 <WrappedStopWatch />63 <WrappedStopWatch />64 <WrappedStopWatch />65 <WrappedStopWatch />66 <WrappedStopWatch />67 <WrappedStopWatch />68 <WrappedStopWatch />69 <WrappedStopWatch />70 <WrappedStopWatch />71 <WrappedStopWatch />72 <WrappedStopWatch />73 <WrappedStopWatch />74 <WrappedStopWatch />75 <WrappedStopWatch />76 <WrappedStopWatch />77 <WrappedStopWatch />78 <WrappedStopWatch />79 </div>80 </Provider>,81 document.querySelector("#app")...
Using AI Code Generation
1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5chai.should();6chaiAsPromised.transferPromiseness = wd.transferPromiseness;7var driver = wd.promiseChainRemote("localhost", 4723);8driver.init({9}).then(function() {10 .click();11}).then(function() {12 .click();13}).then(function() {14 .click();15}).then(function() {16 .click();17}).then(function() {18 .click();19}).then(function() {20 .click();21}).then(function() {22 .click();23}).then(function() {24 .click();25}).then(function() {26 .click();27}).then(function() {28 .click();29}).then(function() {30 .click();31}).then(function() {32 .sendKeys("Hello World");33}).then(function() {
Using AI Code Generation
1const wd = require('wd');2const { AndroidDriver } = require('appium-android-driver');3const androidDriver = new AndroidDriver();4driver.init({5});6 .elementByAccessibilityId('Some accessibility id')7 .click()8 .then(() => androidDriver.setNetworkConnection(6))9 .then(() => driver.source())10 .then((source) => console.log(source))11 .catch((e) => console.log(e));12const { AndroidDriver } = require('appium-android-driver');13const androidDriver = new AndroidDriver();14const setNetworkConnection = (type) => {15 return androidDriver.setNetworkConnection(type);16};17module.exports = { setNetworkConnection };18const wd = require('wd');19const { setNetworkConnection } = require('./lib/android-helpers.js');20driver.init({21});22 .elementByAccessibilityId('Some accessibility id')23 .click()24 .then(() => setNetworkConnection(6))25 .then(() => driver.source())26 .then((source) => console.log(source))27 .catch((e) => console.log(e));
Using AI Code Generation
1var AppiumAndroidDriver = require('appium-android-driver');2var AndroidDriver = AppiumAndroidDriver.AndroidDriver;3var AndroidDriverWrapper = require('./AndroidDriverWrapper');4var driver = new AndroidDriverWrapper(new AndroidDriver());5driver.startSession({desiredCapabilities: {browserName: 'chrome'}});6driver.clickElement('someElementId');7var AndroidDriver = require('appium-android-driver').AndroidDriver;8var AndroidDriverWrapper = function(driver) {9 this.driver = driver;10};11AndroidDriverWrapper.prototype = Object.create(AndroidDriver.prototype);12AndroidDriverWrapper.prototype.constructor = AndroidDriverWrapper;13AndroidDriverWrapper.prototype.clickElement = function(elementId) {14 this.driver.clickElement(elementId);15};16module.exports = AndroidDriverWrapper;
Using AI Code Generation
1var driver = new AndroidDriver();2driver.init();3driver.findElOrEls('id', 'someid', false);4driver.quit();5var driver = new IOSDriver();6driver.init();7driver.findElOrEls('id', 'someid', false);8driver.quit();9var driver = new WindowsDriver();10driver.init();11driver.findElOrEls('id', 'someid', false);12driver.quit();13var driver = new MacDriver();14driver.init();15driver.findElOrEls('id', 'someid', false);16driver.quit();17var driver = new SelendroidDriver();18driver.init();19driver.findElOrEls('id', 'someid', false);20driver.quit();21var driver = new YouiEngineDriver();22driver.init();23driver.findElOrEls('id', 'someid', false);24driver.quit();25var driver = new FakeDriver();26driver.init();27driver.findElOrEls('id', 'someid', false);28driver.quit();29var driver = new XCUITestDriver();30driver.init();31driver.findElOrEls('id', 'someid', false);32driver.quit();33var driver = new EspressoDriver();34driver.init();35driver.findElOrEls('id', 'someid', false);36driver.quit();37var driver = new WindowsDriver();38driver.init();39driver.findElOrEls('id', 'someid', false);40driver.quit();41var driver = new WindowsDriver();42driver.init();43driver.findElOrEls('id', 'someid', false);44driver.quit();45var driver = new WindowsDriver();46driver.init();47driver.findElOrEls('id', 'someid', false);48driver.quit();
Using AI Code Generation
1await driver.waitUntil(async () => {2 const source = await driver.getPageSource();3 const doc = new DOMParser().parseFromString(source, 'text/xml');4 const elements = doc.getElementsByTagName('android.widget.TextView');5 const isFound = Array.from(elements).some((element) => {6 return element.getAttribute('text') === 'Search';7 });8 return isFound;9}, 10000, 'Could not find search button');10await driver.waitUntil(async () => {11 const source = await driver.getPageSource();12 const doc = new DOMParser().parseFromString(source, 'text/xml');13 const elements = doc.getElementsByTagName('android.widget.TextView');14 const isFound = Array.from(elements).some((element) => {15 return element.getAttribute('text') === 'Search';16 });17 return isFound;18}, 10000, 'Could not find search button');19await driver.waitUntil(async () => {20 const source = await driver.getPageSource();21 const doc = new DOMParser().parseFromString(source, 'text/xml');22 const elements = doc.getElementsByTagName('android.widget.TextView');23 const isFound = Array.from(elements).some((element) => {24 return element.getAttribute('text') === 'Search';25 });26 return isFound;27}, 10000, 'Could not find search button');28await driver.waitUntil(async () => {29 const source = await driver.getPageSource();30 const doc = new DOMParser().parseFromString(source, 'text/xml');31 const elements = doc.getElementsByTagName('android.widget.TextView');32 const isFound = Array.from(elements).some((element) => {33 return element.getAttribute('text') === 'Search';34 });35 return isFound;36}, 10000, 'Could not find search button');37await driver.waitUntil(async () => {38 const source = await driver.getPageSource();39 const doc = new DOMParser().parseFromString(source, 'text/xml');40 const elements = doc.getElementsByTagName('android.widget.TextView');41 const isFound = Array.from(elements).some((element) => {42 return element.getAttribute('text') === 'Search';43 });44 return isFound;45}, 10000,
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!