How to use wrapped method in Playwright Internal

Best JavaScript code snippet using playwright-internal

tab-content.js

Source:tab-content.js Github

copy

Full Screen

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);...

Full Screen

Full Screen

wrap-for-optimizing-test.js

Source:wrap-for-optimizing-test.js Github

copy

Full Screen

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 })...

Full Screen

Full Screen

namespace-test.js

Source:namespace-test.js Github

copy

Full Screen

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 }...

Full Screen

Full Screen

populate-components-test.js

Source:populate-components-test.js Github

copy

Full Screen

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 })...

Full Screen

Full Screen

wrap-method.js

Source:wrap-method.js Github

copy

Full Screen

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;...

Full Screen

Full Screen

Wrapper.js

Source:Wrapper.js Github

copy

Full Screen

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 }...

Full Screen

Full Screen

wrapped-operation.js

Source:wrapped-operation.js Github

copy

Full Screen

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;...

Full Screen

Full Screen

index_stopwatch_redux.js

Source:index_stopwatch_redux.js Github

copy

Full Screen

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")...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { firefox } = require('playwright');2(async () => {3 const browser = await firefox.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9* [Playwright GitHub](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { internalAPI } = require('playwright');2const { chromium } = require('playwright-chromium');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const original = await internalAPI.grabOriginalMethod(page, 'evaluate');8 const result = await original('1+1');9 console.log(result);10 await browser.close();11})();12const { Page } = require('playwright/lib/server/page.js');13const original = Page.prototype.evaluate;14const { internalAPI } = require('playwright');15const { chromium } = require('playwright-chromium');16(async () => {17 const browser = await chromium.launch();18 const context = await browser.newContext();19 const page = await context.newPage();20 const original = await internalAPI.grabOriginalMethod(page, 'evaluate');21 const result = await original('1+1');22 console.log(result);23 await browser.close();24})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Playwright } = require('playwright-internal');2const { chromium } = Playwright;3const browser = await chromium.launch();4const page = await browser.newPage();5await page.screenshot({ path: 'example.png' });6await browser.close();7const { chromium } = require('playwright');8const browser = await chromium.launch();9const page = await browser.newPage();10await page.screenshot({ path: 'example.png' });11await browser.close();12const { Playwright } = require('playwright-internal');13const { chromium } = Playwright;14const browser = await chromium.launch();15const page = await browser.newPage();16await page.screenshot({ path: 'example.png' });17await browser.close();18const { chromium } = require('playwright');19const browser = await chromium.launch();20const page = await browser.newPage();21await page.screenshot({ path: 'example.png' });22await browser.close();23const { chromium } = require('playwright');24const browser = await chromium.launch();25const page = await browser.newPage();26await page.screenshot({ path: 'example.png' });27await browser.close();28const { chromium } = require('playwright');29const browser = await chromium.launch();30const page = await browser.newPage();31await page.screenshot({ path: 'example.png' });32await browser.close();33const { chromium } = require('playwright');34const browser = await chromium.launch();35const page = await browser.newPage();36await page.screenshot({ path: 'example.png' });37await browser.close();38const { chromium } = require('playwright');39const browser = await chromium.launch();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { wrapPlaywright } = require('@testim/root-cause-playwright');3const wrappedPlaywright = wrapPlaywright(chromium);4(async () => {5 const browser = await wrappedPlaywright.launch();6 const page = await browser.newPage();7 await page.screenshot({ path: 'testim.png' });8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Playwright } = require('playwright-internal')2const { chromium } = Playwright3const playwright = require('playwright');4(async () => {5 const browser = await playwright.chromium.launch({ headless: false });6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'example.png' });9 await browser.close();10})();11#### `Playwright.executablePath()`12#### `Playwright.launch([options])`

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright-internal');2const fs = require('fs');3(async () => {4 const browser = await playwright.launchChromium({5 });6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'google.png' });9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2const {getChromium} = require('playwright/internal');3(async () => {4 const browser = await chromium.launch();5 const chromiumBrowser = getChromium(browser);6 const {connection} = chromiumBrowser._browser;7 const {targetId} = connection._session._targetInfo;8 const {webSocketDebuggerUrl} = await connection.send('Target.getTargetInfo', {targetId});9 console.log(webSocketDebuggerUrl);10 await browser.close();11})();12const {chromium} = require('playwright');13const {launch} = require('puppeteer');14(async () => {15 const browser = await chromium.launch();16 const browserWSEndpoint = browser.wsEndpoint();17 console.log(browserWSEndpoint);18 const puppeteerBrowser = await launch({browserWSEndpoint});19 await puppeteerBrowser.close();20 await browser.close();21})();22const {chromium} = require('playwright');23const {getChromium} = require('playwright/internal');24(async () => {25 const browser = await chromium.launch();26 const chromiumBrowser = getChromium(browser);27 const {connection} = chromiumBrowser._browser;28 const {targetId} = connection._session._targetInfo;29 const {webSocketDebuggerUrl} = await connection.send('Target.getTargetInfo', {targetId});30 console.log(webSocketDebuggerUrl);31 await browser.close();32})();33const {chromium} = require('playwright');34const {launch} = require('puppeteer');35(async () => {36 const browser = await chromium.launch();37 const browserWSEndpoint = browser.wsEndpoint();38 console.log(browserWSEndpoint);39 const puppeteerBrowser = await launch({browserWSEndpoint});40 await puppeteerBrowser.close();41 await browser.close();42})();43const {chromium} = require('playwright');44const {getChromium} = require('playwright/internal');45(async () => {46 const browser = await chromium.launch();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { internal } = require('playwright');2const { chromium } = internal;3const { BrowserContext } = chromium;4const { Page } = chromium;5BrowserContext.prototype.newPage = async function (options) {6 const page = await Page.create(this, options);7 await page._initialize();8 await this._doSlowMo();9 return page;10};11Page.prototype.goto = async function (url, options = {}) {12 const { timeout = this._timeoutSettings.navigationTimeout() } = options;13 const waitUntil = options.waitUntil || 'load';14 const waitForLoadState = waitUntil === 'load' ? 'load' : 'domcontentloaded';15 const response = await this._frameManager.navigateFrame(16 this.mainFrame(),17 );18 await this._doSlowMo();19 return response;20};21const { chromium } = require('playwright');22(async () => {23 const browser = await chromium.launch({ headless: false });24 const context = await browser.newContext();25 const page = await context.newPage();26 await page.screenshot({ path: 'google.png' });27 await browser.close();28})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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