Best JavaScript code snippet using playwright-internal
nf-shell.js
Source:nf-shell.js
1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17/* global nf */18$(document).ready(function () {19 // configure the dialog20 $('#shell-dialog').modal({21 overlayBackground: true22 });23 // register a listener when the frame is closed24 $('#shell-close-button').click(function () {25 // close the shell26 $('#shell-dialog').modal('hide');27 });28 // register a listener when the frame is undocked29 $('#shell-undock-button').click(function () {30 var uri = $('#shell-iframe').attr('src');31 if (!nf.Common.isBlank(uri)) {32 // open the page and close the shell33 window.open(uri);34 // close the shell35 $('#shell-dialog').modal('hide');36 }37 });38 // add hover effects39 nf.Common.addHoverEffect('#shell-undock-button', 'undock-normal', 'undock-hover');40 nf.Common.addHoverEffect('#shell-close-button', 'close-normal', 'close-hover');41});42nf.Shell = (function () {43 return {44 /**45 * Shows a page in the shell.46 * 47 * @argument {string} uri The URI to show48 * @argument {boolean} canUndock Whether or not the shell is undockable49 */50 showPage: function (uri, canUndock) {51 // if the context menu is on this page, attempt to close52 if (nf.Common.isDefinedAndNotNull(nf.ContextMenu)) {53 nf.ContextMenu.hide();54 }55 56 return $.Deferred(function (deferred) {57 var shell = $('#shell');58 // default undockable to true59 if (nf.Common.isNull(canUndock) || nf.Common.isUndefined(canUndock)) {60 canUndock = true;61 }62 // remove the previous contents of the shell63 shell.empty();64 // register a new close handler65 $('#shell-dialog').modal('setHandler', {66 close: function () {67 deferred.resolve();68 }69 });70 // show the custom processor ui71 $('#shell-dialog').modal('show');72 // conditionally show the undock button73 if (canUndock) {74 $('#shell-undock-button').show();75 } else {76 $('#shell-undock-button').hide();77 }78 // create an iframe to hold the custom ui79 var shellIframe = $('<iframe/>', {80 id: 'shell-iframe',81 frameBorder: '0',82 src: uri83 }).css({84 width: shell.width(),85 height: shell.height()86 }).appendTo(shell);87 // add a window resize listener88 $(window).resize(function () {89 shellIframe.css({90 width: shell.width(),91 height: shell.height()92 });93 });94 }).promise();95 },96 97 /**98 * Shows the specified content in the shell. When the shell is closed, the content99 * will be hidden and returned to its previous location in the dom.100 * 101 * @argument {string} domId The id of the element to show in the shell102 */103 showContent: function (domId) {104 // if the context menu is on this page, attempt to close105 if (nf.Common.isDefinedAndNotNull(nf.ContextMenu)) {106 nf.ContextMenu.hide();107 }108 109 return $.Deferred(function (deferred) {110 var content = $(domId);111 if (content.length) {112 var shell = $('#shell');113 // remove the previous contents of the shell114 shell.empty();115 // get the parent of the content and detach it116 var parent = content.parent();117 content.detach();118 // register a new close handler119 $('#shell-dialog').modal('setHandler', {120 close: function () {121 deferred.resolve();122 // detach the content and add it back to the parent123 content.hide().detach().appendTo(parent);124 }125 });126 // hide the undock button127 $('#shell-undock-button').hide();128 // create the content container129 var contentContainer = $('<div>').css({130 width: shell.width(),131 height: shell.height()132 }).append(content).appendTo(shell);133 // show the content134 $('#shell-dialog').modal('show');135 content.show();136 // add a window resize listener137 $(window).resize(function () {138 contentContainer.css({139 width: shell.width(),140 height: shell.height()141 });142 });143 }144 }).promise();145 }146 };...
JmolAdapter.js
Source:JmolAdapter.js
1Clazz.declarePackage ("J.api");2Clazz.load (["J.c.QS"], "J.api.JmolAdapter", ["java.util.Hashtable", "JU.PT", "J.api.JmolViewer", "JU.Elements", "JV.JC"], function () {3c$ = Clazz.declareType (J.api, "JmolAdapter");4c$.getShellEnumeration = Clazz.defineMethod (c$, "getShellEnumeration", 5function (i) {6return J.c.QS.getItem (i);7}, "~N");8c$.getNewDfCoefMap = Clazz.defineMethod (c$, "getNewDfCoefMap", 9function () {10return J.c.QS.getNewDfCoefMap ();11});12c$.getElementSymbol = Clazz.defineMethod (c$, "getElementSymbol", 13function (elementNumber) {14return JU.Elements.elementSymbolFromNumber (elementNumber);15}, "~N");16c$.getElementNumber = Clazz.defineMethod (c$, "getElementNumber", 17function (elementSymbol) {18return JU.Elements.elementNumberFromSymbol (elementSymbol, false);19}, "~S");20c$.getNaturalIsotope = Clazz.defineMethod (c$, "getNaturalIsotope", 21function (elementNumber) {22return JU.Elements.getNaturalIsotope (elementNumber);23}, "~N");24c$.isHetero = Clazz.defineMethod (c$, "isHetero", 25function (group3) {26return JV.JC.isHetero (group3);27}, "~S");28c$.getQuantumShellTag = Clazz.defineMethod (c$, "getQuantumShellTag", 29function (id) {30return J.c.QS.getQuantumShellTag (id);31}, "~N");32c$.getQuantumShellTagID = Clazz.defineMethod (c$, "getQuantumShellTagID", 33function (tag) {34return J.c.QS.getQuantumShellTagID (tag);35}, "~S");36c$.getQuantumShellTagIDSpherical = Clazz.defineMethod (c$, "getQuantumShellTagIDSpherical", 37function (tag) {38return J.c.QS.getQuantumShellTagIDSpherical (tag);39}, "~S");40c$.getBondingRadius = Clazz.defineMethod (c$, "getBondingRadius", 41function (atomicNumberWithIsotope, charge) {42return JU.Elements.getBondingRadius (atomicNumberWithIsotope, charge);43}, "~N,~N");44Clazz.defineMethod (c$, "getAtomSetCollectionFromReader", 45function (name, type, bufferedReader, htParams) {46if (htParams == null) htParams = new java.util.Hashtable ();47if (!htParams.containsKey ("vwr")) htParams.put ("vwr", J.api.JmolViewer.allocateViewer (null, this));48var a = this.getAtomSetCollectionReader (name, type, bufferedReader, htParams);49if (Clazz.instanceOf (a, String)) return a;50return this.getAtomSetCollection (a);51}, "~S,~S,~O,java.util.Map");52Clazz.defineMethod (c$, "openBufferedReader", 53function (name, bufferedReader) {54return this.getAtomSetCollectionFromReader (name, null, bufferedReader, null);55}, "~S,java.io.BufferedReader");56Clazz.defineMethod (c$, "openBufferedReader", 57function (name, bufferedReader, htParams) {58return this.getAtomSetCollectionFromReader (name, null, bufferedReader, htParams);59}, "~S,java.io.BufferedReader,java.util.Map");60Clazz.defineMethod (c$, "openBufferedReader", 61function (name, type, bufferedReader) {62return this.getAtomSetCollectionFromReader (name, type, bufferedReader, null);63}, "~S,~S,java.io.BufferedReader");64c$.canonizeAlphaDigit = Clazz.defineMethod (c$, "canonizeAlphaDigit", 65 function (ch) {66return (JU.PT.isLetterOrDigit (ch) ? ch : '\0');67}, "~S");68c$.canonizeInsertionCode = Clazz.defineMethod (c$, "canonizeInsertionCode", 69function (insertionCode) {70return J.api.JmolAdapter.canonizeAlphaDigit (insertionCode);71}, "~S");72c$.canonizeAlternateLocationID = Clazz.defineMethod (c$, "canonizeAlternateLocationID", 73function (altLoc) {74return J.api.JmolAdapter.canonizeAlphaDigit (altLoc);75}, "~S");76Clazz.defineStatics (c$,77"ORDER_COVALENT_SINGLE", 1,78"ORDER_COVALENT_DOUBLE", 2,79"ORDER_COVALENT_TRIPLE", 3,80"ORDER_AROMATIC", 515,81"ORDER_AROMATIC_SINGLE", 513,82"ORDER_AROMATIC_DOUBLE", 514,83"ORDER_HBOND", 2048,84"ORDER_STEREO_NEAR", 1025,85"ORDER_STEREO_FAR", 1041,86"ORDER_PARTIAL01", 33,87"ORDER_PARTIAL12", 66,88"ORDER_PARTIAL23", 97,89"ORDER_PARTIAL32", 100,90"ORDER_UNSPECIFIED", 17,91"ORDER_PYMOL_SINGLE", 65536,92"ORDER_PYMOL_MULT", 98304);93c$.SHELL_S = c$.prototype.SHELL_S = J.c.QS.S.id;94c$.SHELL_P = c$.prototype.SHELL_P = J.c.QS.P.id;95c$.SHELL_SP = c$.prototype.SHELL_SP = J.c.QS.SP.id;96c$.SHELL_L = c$.prototype.SHELL_L = J.c.QS.SP.id;97c$.SHELL_D_SPHERICAL = c$.prototype.SHELL_D_SPHERICAL = J.c.QS.D_SPHERICAL.id;98c$.SHELL_D_CARTESIAN = c$.prototype.SHELL_D_CARTESIAN = J.c.QS.D_CARTESIAN.id;99c$.SHELL_F_SPHERICAL = c$.prototype.SHELL_F_SPHERICAL = J.c.QS.F_SPHERICAL.id;100c$.SHELL_F_CARTESIAN = c$.prototype.SHELL_F_CARTESIAN = J.c.QS.F_CARTESIAN.id;101c$.SHELL_G_SPHERICAL = c$.prototype.SHELL_G_SPHERICAL = J.c.QS.G_SPHERICAL.id;102c$.SHELL_G_CARTESIAN = c$.prototype.SHELL_G_CARTESIAN = J.c.QS.G_CARTESIAN.id;103c$.SHELL_H_SPHERICAL = c$.prototype.SHELL_H_SPHERICAL = J.c.QS.H_SPHERICAL.id;104c$.SHELL_H_CARTESIAN = c$.prototype.SHELL_H_CARTESIAN = J.c.QS.H_CARTESIAN.id;105c$.SUPPORTED_BASIS_FUNCTIONS = c$.prototype.SUPPORTED_BASIS_FUNCTIONS = "SPLDF";106c$.NOTE_SCRIPT_FILE = c$.prototype.NOTE_SCRIPT_FILE = "NOTE: file recognized as a script file: ";107Clazz.defineStatics (c$,108"cellParamNames", ["_cell_length_a", "_cell_length_b", "_cell_length_c", "_cell_angle_alpha", "_cell_angle_beta", "_cell_angle_gamma"]);
...
cp.js
Source:cp.js
1var shell = require('..');2var assert = require('assert'),3 path = require('path'),4 fs = require('fs');5// Node shims for < v0.76fs.existsSync = fs.existsSync || path.existsSync;7shell.config.silent = true;8function numLines(str) {9 return typeof str === 'string' ? str.match(/\n/g).length : 0;10}11shell.rm('-rf', 'tmp');12shell.mkdir('tmp');13//14// Invalids15//16shell.cp();17assert.ok(shell.error());18shell.cp('file1');19assert.ok(shell.error());20shell.cp('-f');21assert.ok(shell.error());22shell.rm('-rf', 'tmp/*');23shell.cp('-@', 'resources/file1', 'tmp/file1'); // option not supported, files OK24assert.ok(shell.error());25assert.equal(fs.existsSync('tmp/file1'), false);26shell.cp('-Z', 'asdfasdf', 'tmp/file2'); // option not supported, files NOT OK27assert.ok(shell.error());28assert.equal(fs.existsSync('tmp/file2'), false);29shell.cp('asdfasdf', 'tmp'); // source does not exist30assert.ok(shell.error());31assert.equal(numLines(shell.error()), 1);32assert.equal(fs.existsSync('tmp/asdfasdf'), false);33shell.cp('asdfasdf1', 'asdfasdf2', 'tmp'); // sources do not exist34assert.ok(shell.error());35assert.equal(numLines(shell.error()), 2);36assert.equal(fs.existsSync('tmp/asdfasdf1'), false);37assert.equal(fs.existsSync('tmp/asdfasdf2'), false);38shell.cp('asdfasdf1', 'asdfasdf2', 'resources/file1'); // too many sources (dest is file)39assert.ok(shell.error());40shell.cp('resources/file1', 'resources/file2'); // dest already exists41assert.ok(shell.error());42shell.cp('resources/file1', 'resources/file2', 'tmp/a_file'); // too many sources43assert.ok(shell.error());44assert.equal(fs.existsSync('tmp/a_file'), false);45//46// Valids47//48// simple - to dir49shell.cp('resources/file1', 'tmp');50assert.equal(shell.error(), null);51assert.equal(fs.existsSync('tmp/file1'), true);52// simple - to file53shell.cp('resources/file2', 'tmp/file2');54assert.equal(shell.error(), null);55assert.equal(fs.existsSync('tmp/file2'), true);56// simple - file list57shell.rm('-rf', 'tmp/*');58shell.cp('resources/file1', 'resources/file2', 'tmp');59assert.equal(shell.error(), null);60assert.equal(fs.existsSync('tmp/file1'), true);61assert.equal(fs.existsSync('tmp/file2'), true);62// simple - file list, array syntax63shell.rm('-rf', 'tmp/*');64shell.cp(['resources/file1', 'resources/file2'], 'tmp');65assert.equal(shell.error(), null);66assert.equal(fs.existsSync('tmp/file1'), true);67assert.equal(fs.existsSync('tmp/file2'), true);68shell.cp('resources/file2', 'tmp/file3');69assert.equal(fs.existsSync('tmp/file3'), true);70shell.cp('-f', 'resources/file2', 'tmp/file3'); // file exists, but -f specified71assert.equal(shell.error(), null);72assert.equal(fs.existsSync('tmp/file3'), true);73// wildcard74shell.rm('tmp/file1', 'tmp/file2');75shell.cp('resources/file*', 'tmp');76assert.equal(shell.error(), null);77assert.equal(fs.existsSync('tmp/file1'), true);78assert.equal(fs.existsSync('tmp/file2'), true);79//recursive, nothing exists80shell.rm('-rf', 'tmp/*');81shell.cp('-R', 'resources/cp', 'tmp');82assert.equal(shell.error(), null);83assert.equal(shell.ls('-R', 'resources/cp') + '', shell.ls('-R', 'tmp/cp') + '');84//recursive, nothing exists, source ends in '/' (see Github issue #15)85shell.rm('-rf', 'tmp/*');86shell.cp('-R', 'resources/cp/', 'tmp/');87assert.equal(shell.error(), null);88assert.equal(shell.ls('-R', 'resources/cp') + '', shell.ls('-R', 'tmp') + '');89//recursive, everything exists, no force flag90shell.rm('-rf', 'tmp/*');91shell.cp('-R', 'resources/cp', 'tmp');92shell.cp('-R', 'resources/cp', 'tmp');93assert.equal(shell.error(), null); // crash test only94//recursive, everything exists, with force flag95shell.rm('-rf', 'tmp/*');96shell.cp('-R', 'resources/cp', 'tmp');97'changing things around'.to('tmp/cp/dir_a/z');98assert.notEqual(shell.cat('resources/cp/dir_a/z'), shell.cat('tmp/cp/dir_a/z')); // before cp99shell.cp('-Rf', 'resources/cp', 'tmp');100assert.equal(shell.error(), null);101assert.equal(shell.cat('resources/cp/dir_a/z'), shell.cat('tmp/cp/dir_a/z')); // after cp102//recursive, creates dest dir since it's only one level deep (see Github issue #44)103shell.rm('-rf', 'tmp/*');104shell.cp('-r', 'resources/issue44/*', 'tmp/dir2');105assert.equal(shell.error(), null);106assert.equal(shell.ls('-R', 'resources/issue44') + '', shell.ls('-R', 'tmp/dir2') + '');107assert.equal(shell.cat('resources/issue44/main.js'), shell.cat('tmp/dir2/main.js'));108//recursive, does *not* create dest dir since it's too deep (see Github issue #44)109shell.rm('-rf', 'tmp/*');110shell.cp('-r', 'resources/issue44/*', 'tmp/dir2/dir3');111assert.ok(shell.error());112assert.equal(fs.existsSync('tmp/dir2'), false);...
WebNavigationFrames.jsm
Source:WebNavigationFrames.jsm
1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */4"use strict";5const EXPORTED_SYMBOLS = ["WebNavigationFrames"];6var Ci = Components.interfaces;7/* exported WebNavigationFrames */8/**9 * Retrieve the DOMWindow associated to the docShell passed as parameter.10 *11 * @param {nsIDocShell} docShell - the docShell that we want to get the DOMWindow from.12 * @returns {nsIDOMWindow} - the DOMWindow associated to the docShell.13 */14function docShellToWindow(docShell) {15 return docShell.QueryInterface(Ci.nsIInterfaceRequestor)16 .getInterface(Ci.nsIDOMWindow);17}18/**19 * The FrameDetail object which represents a frame in WebExtensions APIs.20 *21 * @typedef {Object} FrameDetail22 * @inner23 * @property {number} frameId - Represents the numeric id which identify the frame in its tab.24 * @property {number} parentFrameId - Represents the numeric id which identify the parent frame.25 * @property {string} url - Represents the current location URL loaded in the frame.26 * @property {boolean} errorOccurred - Indicates whether an error is occurred during the last load27 * happened on this frame (NOT YET SUPPORTED).28 */29/**30 * A generator function which iterates over a docShell tree, given a root docShell.31 *32 * @param {nsIDocShell} docShell - the root docShell object33 */34function* iterateDocShellTree(docShell) {35 let docShellsEnum = docShell.getDocShellEnumerator(36 docShell.typeContent, docShell.ENUMERATE_FORWARDS);37 while (docShellsEnum.hasMoreElements()) {38 yield docShellsEnum.getNext();39 }40}41/**42 * Returns the frame ID of the given window. If the window is the43 * top-level content window, its frame ID is 0. Otherwise, its frame ID44 * is its outer window ID.45 *46 * @param {Window} window - The window to retrieve the frame ID for.47 * @returns {number}48 */49function getFrameId(window) {50 if (window.parent === window) {51 return 0;52 }53 let utils = window.getInterface(Ci.nsIDOMWindowUtils);54 return utils.outerWindowID;55}56/**57 * Returns the frame ID of the given window's parent.58 *59 * @param {Window} window - The window to retrieve the parent frame ID for.60 * @returns {number}61 */62function getParentFrameId(window) {63 if (window.parent === window) {64 return -1;65 }66 return getFrameId(window.parent);67}68function getDocShellFrameId(docShell) {69 if (!docShell) {70 return undefined;71 }72 return getFrameId(docShell.QueryInterface(Ci.nsIInterfaceRequestor)73 .getInterface(Ci.nsIDOMWindow));74}75/**76 * Convert a docShell object into its internal FrameDetail representation.77 *78 * @param {nsIDocShell} docShell - the docShell object to be converted into a FrameDetail JSON object.79 * @returns {FrameDetail} the FrameDetail JSON object which represents the docShell.80 */81function convertDocShellToFrameDetail(docShell) {82 let window = docShellToWindow(docShell);83 return {84 frameId: getFrameId(window),85 parentFrameId: getParentFrameId(window),86 url: window.location.href,87 };88}89/**90 * Search for a frame starting from the passed root docShell and91 * convert it to its related frame detail representation.92 *93 * @param {number} frameId - the frame ID of the frame to retrieve, as94 * described in getFrameId.95 * @param {nsIDocShell} rootDocShell - the root docShell object96 * @returns {nsIDocShell?} the docShell with the given frameId, or null97 * if no match.98 */99function findDocShell(frameId, rootDocShell) {100 for (let docShell of iterateDocShellTree(rootDocShell)) {101 if (frameId == getFrameId(docShellToWindow(docShell))) {102 return docShell;103 }104 }105 return null;106}107var WebNavigationFrames = {108 iterateDocShellTree,109 findDocShell,110 getFrame(docShell, frameId) {111 let result = findDocShell(frameId, docShell);112 if (result) {113 return convertDocShellToFrameDetail(result);114 }115 return null;116 },117 getFrameId,118 getParentFrameId,119 getAllFrames(docShell) {120 return Array.from(iterateDocShellTree(docShell), convertDocShellToFrameDetail);121 },122 getDocShellFrameId,...
test_421977.js
Source:test_421977.js
1var Cc = Components.classes;2var Ci = Components.interfaces;3var Cr = Components.results;4const GCONF_BG_COLOR_KEY = "/desktop/gnome/background/primary_color";5var gShell;6var gGConf;7/**8 * Converts from a rgb numerical color valule (r << 16 | g << 8 | b)9 * into a hex string in #RRGGBB format.10 */11function colorToHex(aColor) {12 const rMask = 4294901760;13 const gMask = 65280;14 const bMask = 255;15 var r = (aColor & rMask) >> 16;16 var g = (aColor & gMask) >> 8;17 var b = (aColor & bMask);18 return "#" + [r, g, b].map(aInt =>19 aInt.toString(16).replace(/^(.)$/, "0$1"))20 .join("").toUpperCase();21}22/**23 * Converts a color string in #RRGGBB format to a rgb numerical color value24 * (r << 16 | g << 8 | b).25 */26function hexToColor(aString) {27 return parseInt(aString.substring(1, 3), 16) << 16 |28 parseInt(aString.substring(3, 5), 16) << 8 |29 parseInt(aString.substring(5, 7), 16);30}31/**32 * Checks that setting the GConf background key to aGConfColor will33 * result in the Shell component returning a background color equals34 * to aExpectedShellColor in #RRGGBB format.35 */36function checkGConfToShellColor(aGConfColor, aExpectedShellColor) {37 gGConf.setString(GCONF_BG_COLOR_KEY, aGConfColor);38 var shellColor = colorToHex(gShell.desktopBackgroundColor);39 do_check_eq(shellColor, aExpectedShellColor);40}41/**42 * Checks that setting the background color (in #RRGGBB format) using the Shell43 * component will result in having a GConf key for the background color set to44 * aExpectedGConfColor.45 */46function checkShellToGConfColor(aShellColor, aExpectedGConfColor) {47 gShell.desktopBackgroundColor = hexToColor(aShellColor);48 var gconfColor = gGConf.getString(GCONF_BG_COLOR_KEY);49 do_check_eq(gconfColor, aExpectedGConfColor);50}51function run_test() {52 // This test is Linux specific for now53 if (!("@mozilla.org/gnome-gconf-service;1" in Cc))54 return;55 try {56 // If GSettings is available, then the GConf tests57 // will fail58 Cc["@mozilla.org/gsettings-service;1"].59 getService(Ci.nsIGSettingsService).60 getCollectionForSchema("org.gnome.desktop.background");61 return;62 } catch (e) { }63 gGConf = Cc["@mozilla.org/gnome-gconf-service;1"].64 getService(Ci.nsIGConfService);65 gShell = Cc["@mozilla.org/browser/shell-service;1"].66 getService(Ci.nsIShellService);67 // Save the original background color so that we can restore it68 // after the test.69 var origGConfColor = gGConf.getString(GCONF_BG_COLOR_KEY);70 try {71 checkGConfToShellColor("#000", "#000000");72 checkGConfToShellColor("#00f", "#0000FF");73 checkGConfToShellColor("#b2f", "#BB22FF");74 checkGConfToShellColor("#fff", "#FFFFFF");75 checkGConfToShellColor("#000000", "#000000");76 checkGConfToShellColor("#0000ff", "#0000FF");77 checkGConfToShellColor("#b002f0", "#B002F0");78 checkGConfToShellColor("#ffffff", "#FFFFFF");79 checkGConfToShellColor("#000000000", "#000000");80 checkGConfToShellColor("#00f00f00f", "#000000");81 checkGConfToShellColor("#aaabbbccc", "#AABBCC");82 checkGConfToShellColor("#fffffffff", "#FFFFFF");83 checkGConfToShellColor("#000000000000", "#000000");84 checkGConfToShellColor("#000f000f000f", "#000000");85 checkGConfToShellColor("#00ff00ff00ff", "#000000");86 checkGConfToShellColor("#aaaabbbbcccc", "#AABBCC");87 checkGConfToShellColor("#111122223333", "#112233");88 checkGConfToShellColor("#ffffffffffff", "#FFFFFF");89 checkShellToGConfColor("#000000", "#000000000000");90 checkShellToGConfColor("#0000FF", "#00000000ffff");91 checkShellToGConfColor("#FFFFFF", "#ffffffffffff");92 checkShellToGConfColor("#0A0B0C", "#0a0a0b0b0c0c");93 checkShellToGConfColor("#A0B0C0", "#a0a0b0b0c0c0");94 checkShellToGConfColor("#AABBCC", "#aaaabbbbcccc");95 } finally {96 gGConf.setString(GCONF_BG_COLOR_KEY, origGConfColor);97 }...
ShellResize.js
Source:ShellResize.js
1/*if($.browser.msie) 2{3 if(parseInt($.browser.version)<=9)4 {5 location.href = "inner.html?"+location.href.split("?")[1];6 }78}*/9onResizeFn = function(e, _bool)10{11 var shellWidth = parseInt($('#shellHolder').css("width"));//1024;12 var shellHeight= parseInt($('#shellHolder').css("height"));//680;13 var newShellHeight;14 var newShellWidth;15 var agent=navigator.userAgent.toLowerCase();16 var is_ipad = ((agent.indexOf('ipad') != -1));1718 var actWid = Number($(window).width());19 var actHgt = Number($(window).height());20 if(actHgt < actWid)21 {22 newShellHeight = actHgt;23 var scale = Number(shellHeight/newShellHeight).toFixed(2);24 newShellWidth = (shellWidth/shellHeight)*newShellHeight;25 var _aleft = (actWid/2)-(Number(newShellWidth)/2);26 if(_aleft<0)27 {28 newShellWidth = actWid;29 //scale = Number(shellWidth/newShellWidth).toFixed(2); // Commented by Govinda to fix the Gizmo going out of the display area.30 scale = Number(shellWidth/newShellWidth).toFixed(2);31 newShellHeight = (shellHeight/shellWidth)*newShellWidth;32 }33 if(_bool)34 {35 var _nscale = 1/scale;36 if(_nscale < 0.6)37 {38 _nscale = 0.6;39 }40 $('#shellHolder').css(41 {42 "width":(parseInt($('#shellHolder').css("width")) * _nscale)+"px",43 "height":(parseInt($('#shellHolder').css("height")) * _nscale)+"px",44 });45 setTimeout(onResizeFn, 100);46 }47 else48 {49 if(scale != 1)50 {51 $('#shellHolder').css(52 {53 "transform": "translate(-"+(shellWidth/2)+"px,-"+(shellHeight/2)+"px) scale("+(1/scale)+","+(1/scale)+") translate("+(shellWidth/2)+"px,"+(shellHeight/2)+"px)",54 "-ms-transform": "translate(-"+(shellWidth/2)+"px,-"+(shellHeight/2)+"px) scale("+(1/scale)+","+(1/scale)+") translate("+(shellWidth/2)+"px,"+(shellHeight/2)+"px)",55 "-webkit-transform": "translate(-"+(shellWidth/2)+"px,-"+(shellHeight/2)+"px) scale("+(1/scale)+","+(1/scale)+") translate("+(shellWidth/2)+"px,"+(shellHeight/2)+"px)"56 });57 }58 else59 {60 $('#shellHolder').css(61 {62 "transform": "",63 "-ms-transform": "",64 "-webkit-transform": ""65 });66 }67 }68 }69 else70 {71 newShellWidth = actWid;72 var scale = Number(shellWidth/newShellWidth).toFixed(2);73 newShellHeight = (shellHeight/shellWidth)*newShellWidth;74 if(_bool)75 {76 var _nscale = 1/scale;77 if(_nscale < 0.6)78 {79 _nscale = 0.6;80 }81 $('#shellHolder').css(82 {83 "width":(parseInt($('#shellHolder').css("width")) * _nscale)+"px",84 "height":(parseInt($('#shellHolder').css("height")) * _nscale)+"px",85 });86 setTimeout(onResizeFn(), 100);87 }88 else89 {90 if(scale != 1)91 {92 $('#shellHolder').css(93 {94 "transform": "translate(-"+(shellWidth/2)+"px,-"+(shellHeight/2)+"px) scale("+(1/scale)+","+(1/scale)+") translate("+(shellWidth/2)+"px,"+(shellHeight/2)+"px)",95 "-ms-transform": "translate(-"+(shellWidth/2)+"px,-"+(shellHeight/2)+"px) scale("+(1/scale)+","+(1/scale)+") translate("+(shellWidth/2)+"px,"+(shellHeight/2)+"px)",96 "-webkit-transform": "translate(-"+(shellWidth/2)+"px,-"+(shellHeight/2)+"px) scale("+(1/scale)+","+(1/scale)+") translate("+(shellWidth/2)+"px,"+(shellHeight/2)+"px)"97 });98 }99 else100 {101 $('#shellHolder').css(102 {103 "transform": "",104 "-ms-transform": "",105 "-webkit-transform": ""106 });107 }108 }109 }110 scaleVal = scale;111 var _left = (actWid/2)-(Number(newShellWidth)/2);112 var _top = (actHgt/2)-(Number(newShellHeight)/2);113 $('#shellHolder').css("left", _left);114 $('#shellHolder').css("top", _top);115}116117$(window).mouseup(function(e) {118 if(document.getElementById("shellHolder").contentWindow)119 {120 document.getElementById("shellHolder").contentWindow.onWindowMouseUp();121 }
...
clean.js
Source:clean.js
1const shell = require('shelljs');2const addCheckMark = require('./helpers/checkmark.js');3if (!shell.which('git')) {4 shell.echo('Sorry, this script requires git');5 shell.exit(1);6}7if (!shell.test('-e', 'internals/templates')) {8 shell.echo('The example is deleted already.');9 shell.exit(1);10}11process.stdout.write('Cleanup started...');12// Reuse existing LanguageProvider and i18n tests13shell.mv(14 'app/containers/LanguageProvider/tests',15 'internals/templates/containers/LanguageProvider',16);17shell.cp('app/tests/i18n.test.js', 'internals/templates/tests/i18n.test.js');18// Cleanup components/19shell.rm('-rf', 'app/components/*');20// Handle containers/21shell.rm('-rf', 'app/containers');22shell.mv('internals/templates/containers', 'app');23// Handle tests/24shell.mv('internals/templates/tests', 'app');25// Handle translations/26shell.rm('-rf', 'app/translations');27shell.mv('internals/templates/translations', 'app');28// Handle utils/29shell.rm('-rf', 'app/utils');30shell.mv('internals/templates/utils', 'app');31// Replace the files in the root app/ folder32shell.cp('internals/templates/app.js', 'app/app.js');33shell.cp('internals/templates/global-styles.js', 'app/global-styles.js');34shell.cp('internals/templates/i18n.js', 'app/i18n.js');35shell.cp('internals/templates/locales.js', 'app/locales.js');36shell.cp('internals/templates/index.html', 'app/index.html');37shell.cp('internals/templates/reducers.js', 'app/reducers.js');38shell.cp('internals/templates/configureStore.js', 'app/configureStore.js');39// Remove the templates folder40shell.rm('-rf', 'internals/templates');41addCheckMark();42// Commit the changes43if (44 shell.exec('git add . --all && git commit -qm "Remove default example"')45 .code !== 046) {47 shell.echo('\nError: Git commit failed');48 shell.exit(1);49}...
DocShellCapabilities.jsm
Source:DocShellCapabilities.jsm
1/* This Source Code Form is subject to the terms of the Mozilla Public2* License, v. 2.0. If a copy of the MPL was not distributed with this file,3* You can obtain one at http://mozilla.org/MPL/2.0/. */4"use strict";5this.EXPORTED_SYMBOLS = ["DocShellCapabilities"];6/**7 * The external API exported by this module.8 */9this.DocShellCapabilities = Object.freeze({10 collect(docShell) {11 return DocShellCapabilitiesInternal.collect(docShell);12 },13 restore(docShell, disallow) {14 return DocShellCapabilitiesInternal.restore(docShell, disallow);15 },16});17const CAPABILITIES_TO_IGNORE = new Set(["Javascript"]);18/**19 * Internal functionality to save and restore the docShell.allow* properties.20 */21var DocShellCapabilitiesInternal = {22 // List of docShell capabilities to (re)store. These are automatically23 // retrieved from a given docShell if not already collected before.24 // This is made so they're automatically in sync with all nsIDocShell.allow*25 // properties.26 caps: null,27 allCapabilities(docShell) {28 if (!this.caps) {29 let keys = Object.keys(docShell);30 this.caps = keys.filter(k => k.startsWith("allow")).map(k => k.slice(5));31 }32 return this.caps;33 },34 collect(docShell) {35 let caps = this.allCapabilities(docShell);36 return caps.filter(cap => !docShell["allow" + cap]37 && !CAPABILITIES_TO_IGNORE.has(cap));38 },39 restore(docShell, disallow) {40 let caps = this.allCapabilities(docShell);41 for (let cap of caps)42 docShell["allow" + cap] = !disallow.has(cap);43 },...
Using AI Code Generation
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.tracing.start({ screenshots: true, snapshots: true });7 await page.tracing.stop({ path: 'trace.zip' });8 await browser.close();9})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('[placeholder="Search"]');7 await page.fill('[placeholder="Search"]', 'playwright');8 await page.press('[placeholder="Search"]', 'Enter');
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('input[name="q"]');7 await page.fill('input[name="q"]', 'Playwright');8 await page.press('input[name="q"]', 'Enter');9 await page.close();10 await context.close();11 await browser.close();12})();
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.type('input[aria-label="Search"]', 'playwright');7 await page.keyboard.press('Enter');8 await page.waitForSelector('text=Playwright');9 await page.click('text=Playwright');10 await page.waitForSelector('text=Playwright is a Node library to automate');11 await page.click('text=Playwright is a Node library to automate');12 await page.waitForSelector('text=GitHub - microsoft/playwright: Node.js library');13 await page.click('text=GitHub - microsoft/playwright: Node.js library');14 await page.waitForSelector('text=Playwright is a Node library to automate');15 await page.click('text=Playwright is a Node library to automate');16 await page.waitForSelector('text=Playwright is a Node library to automate');17 await page.click('text=Playwright is a Node library to automate');18 await page.waitForSelector('text=GitHub - microsoft/playwright: Node.js library');19 await page.click('text=GitHub - microsoft/playwright: Node.js library');20 await page.waitForSelector('text=Playwright is a Node library to automate');21 await page.click('text=Playwright is a Node library to automate');22 await page.waitForSelector('text=GitHub - microsoft/playwright: Node.js library');23 await page.click('text=GitHub - microsoft/playwright: Node.js library');24 await page.waitForSelector('text=Playwright is a Node library to automate');25 await page.click('text=Playwright is a Node library to automate');26 await page.waitForSelector('text=GitHub - microsoft/playwright: Node.js library');27 await page.click('text=GitHub - microsoft/playwright: Node.js library');28 await page.waitForSelector('text=Playwright is a Node library to automate');29 await page.click('text=Playwright is a Node library to automate');30 await page.waitForSelector('text=GitHub - microsoft/playwright: Node.js library');31 await page.click('text=GitHub - microsoft/playwright: Node.js library');32 await page.waitForSelector('text=Playwright is a Node library to automate');
Using AI Code Generation
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 const shell = await page.shell();7 await shell.type('xterm -e "bash -c \\"echo hello; bash\\""\r');8 await page.waitForTimeout(1000);9 await shell.type('exit\r');10 await page.waitForTimeout(1000);11 await browser.close();12})();
Using AI Code Generation
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.click('input[name="q"]');7 await page.type('input[name="q"]', 'Hello World!');8 await page.keyboard.press('Enter');9 await page.screenshot({ path: `example.png` });10 await browser.close();11})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.fill('input[title="Search"]', 'Playwright');7 await page.keyboard.press('Enter');8 await page.waitForTimeout(3000);9 await page.click('text=Playwright - Node.js library to automate Chromium, Firefox and WebKit with a single API');10 await page.waitForTimeout(3000);11 await page.click('text=Docs');12 await page.waitForTimeout(3000);13 await page.click('text=API');14 await page.waitForTimeout(3000);15 await page.click('text=class: Browser');16 await page.waitForTimeout(3000);17 await page.click('text=class: BrowserContext');18 await page.waitForTimeout(3000);19 await page.click('text=class: ConsoleMessage');20 await page.waitForTimeout(3000);21 await page.click('text=class: Dialog');22 await page.waitForTimeout(3000);23 await page.click('text=class: Download');24 await page.waitForTimeout(3000);25 await page.click('text=class: ElementHandle');26 await page.waitForTimeout(3000);27 await page.click('text=class: Frame');28 await page.waitForTimeout(3000);29 await page.click('text=class: JSHandle');30 await page.waitForTimeout(3000);31 await page.click('text=class: Page');32 await page.waitForTimeout(3000);33 await page.click('text=class: Request');34 await page.waitForTimeout(3000);35 await page.click('text=class: Response');36 await page.waitForTimeout(3000);37 await page.click('text=class: Route');38 await page.waitForTimeout(3000);39 await page.click('text=class: Selectors');40 await page.waitForTimeout(3000);41 await page.click('text=class: TimeoutError');42 await page.waitForTimeout(3000);43 await page.click('text=class: Worker');44 await page.waitForTimeout(3000);45 await page.click('text=class: BrowserType');46 await page.waitForTimeout(3000);47 await page.click('text=class: ChromiumBrowser
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({4 });5 const page = await browser.newPage();6 await page.click('text=Show more details');7 const userAgent = await page.$eval('#detected_value', (el) => el.textContent);8 console.log(userAgent);9 await browser.close();10})();11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch({14 });15 const page = await browser.newPage();16 await page.click('text=Show more details');17 const userAgent = await page.$eval('#detected_value', (el) => el.textContent);18 console.log(userAgent);19 await browser.close();20})();21const { chromium } = require('playwright');22(async () => {23 const browser = await chromium.launch({24 });25 const page = await browser.newPage();26 await page.click('text=Show more details');27 const userAgent = await page.$eval('#detected_value', (el) => el.textContent);28 console.log(userAgent);29 await browser.close();30})();31const { chromium } = require('playwright');32(async () => {33 const browser = await chromium.launch({34 });35 const page = await browser.newPage();36 await page.click('text=Show more details');37 const userAgent = await page.$eval('#detected_value', (el) => el.textContent);38 console.log(userAgent);39 await browser.close();40})();
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.evaluate(() => {6 window.shell = require('electron').shell;7 });8 await page.evaluate(() => {9 });10 await browser.close();11})();12const {chromium} = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const page = await browser.newPage();16 await page.evaluate(() => {17 window.electron = require('electron');18 });19 await page.evaluate(() => {20 });21 await browser.close();22})();23const {chromium} = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const page = await browser.newPage();27 await page.evaluate(() => {28 window.electron = require('electron');29 });30 await page.evaluate(() => {31 });32 await browser.close();33})();34const {chromium} = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const page = await browser.newPage();38 await page.evaluate(() => {39 window.electron = require('electron');40 });41 await page.evaluate(() => {
Using AI Code Generation
1const { chromium } = require('playwright');2const { test, expect } = require('@playwright/test');3test('Test for Shell', async ({ page }) => {4 const title = await page.title();5 expect(title).toBe('Playwright');6 const url = await page.url();7 await page.click('text="Docs"');8 await page.waitForSelector('text="Introduction"');9 const title1 = await page.title();10 expect(title1).toBe('Playwright');11 const url1 = await page.url();12 const browser = await shell.browser();13 const pages = await browser.pages();14 const newPage = pages[0];15 const title2 = await newPage.title();16 expect(title2).toBe('Google');17 const url2 = await newPage.url();18});
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.
Get 100 minutes of automation test minutes FREE!!