Best JavaScript code snippet using wpt
local-fs-test-helpers.js
Source:local-fs-test-helpers.js
1// This file defines a directory_test() function that can be used to define2// tests that require a FileSystemDirectoryHandle. The implementation of that3// function in this file will ask the user to select an empty directory and uses4// that directory.5//6// Another implementation of this function exists in7// fs/resources/sandboxed-fs-test-helpers.js, where that version uses the8// sandboxed file system instead.9const directory_promise = (async () => {10 await new Promise(resolve => {11 window.addEventListener('DOMContentLoaded', resolve);12 });13 // Small delay to give chrome's test automation a chance to actually install14 // itself.15 await new Promise(resolve => step_timeout(resolve, 100));16 await window.test_driver.bless(17 'show a file picker.<br />Please select an empty directory');18 const entries = await self.showDirectoryPicker();19 assert_true(entries instanceof FileSystemHandle);20 assert_true(entries instanceof FileSystemDirectoryHandle);21 for await (const entry of entries) {22 assert_unreached('Selected directory is not empty');23 }24 return entries;25})();26function directory_test(func, description) {27 promise_test(async t => {28 const directory = await directory_promise;29 // To be resilient against tests not cleaning up properly, cleanup before30 // every test.31 for await (let entry of directory.values()) {32 await directory.removeEntry(33 entry.name, {recursive: entry.kind === 'directory'});34 }35 await func(t, directory);36 }, description);37}38directory_test(async (t, dir) => {39 assert_equals(await dir.queryPermission({mode: 'read'}), 'granted');40}, 'User succesfully selected an empty directory.');41directory_test(async (t, dir) => {42 const status = await dir.queryPermission({mode: 'readwrite'});43 if (status == 'granted')44 return;45 await window.test_driver.bless('ask for write permission');46 assert_equals(await dir.requestPermission({mode: 'readwrite'}), 'granted');47}, 'User granted write access.');48const child_frame_js = (origin, frameFn, done) => `49 const importScript = ${importScript};50 await importScript("/html/cross-origin-embedder-policy/credentialless" +51 "/resources/common.js");52 await importScript("/html/anonymous-iframe/resources/common.js");53 await importScript("/common/utils.js");54 await send("${done}", ${frameFn}("${origin}"));55`;56/**57 * Context identifiers for executor subframes of framed tests. Individual58 * contexts (or convenience context lists below) can be used to send JavaScript59 * for evaluation in each frame (see framed_test below).60 *61 * Note that within framed tests:62 * - firstParty represents the top-level document.63 * - thirdParty represents an embedded context (iframe).64 * - ancestorBit contexts include a cross-site ancestor iframe.65 * - anonymousFrame contexts are third-party anonymous iframe contexts.66 */67const FRAME_CONTEXT = {68 firstParty: 0,69 thirdPartySameSite: 1,70 thirdPartySameSite_AncestorBit: 2,71 thirdPartyCrossSite: 3,72 anonymousFrameSameSite: 4,73 anonymousFrameSameSite_AncestorBit: 5,74 anonymousFrameCrossSite: 6,75};76// TODO(crbug.com/1322897): Add AncestorBit contexts.77const sameSiteContexts = [78 FRAME_CONTEXT.firstParty,79 FRAME_CONTEXT.thirdPartySameSite,80 FRAME_CONTEXT.anonymousFrameSameSite,81];82// TODO(crbug.com/1322897): Add AncestorBit contexts.83const crossSiteContexts = [84 FRAME_CONTEXT.thirdPartyCrossSite,85 FRAME_CONTEXT.anonymousFrameCrossSite,86];87// TODO(crbug.com/1322897): Add AncestorBit contexts.88const childContexts = [89 FRAME_CONTEXT.thirdPartySameSite,90 FRAME_CONTEXT.thirdPartyCrossSite,91 FRAME_CONTEXT.anonymousFrameSameSite,92 FRAME_CONTEXT.anonymousFrameCrossSite,93];94/**95 * Creates a promise test with same- & cross-site executor subframes.96 *97 * In addition to the standard testing object, the provided func will be called98 * with a sendTo function. sendTo expects:99 * - contexts: an Iterable of FRAME_CONTEXT constants representing the100 * frame(s) in which the provided script will be concurrently run.101 * - js_gen: a function which should generate a script string when called102 * with a string token. sendTo will wait until a "done" message103 * is sent to this queue.104 */105function framed_test(func, description) {106 const same_site_origin = get_host_info().HTTPS_ORIGIN;107 const cross_site_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;108 const frames = Object.values(FRAME_CONTEXT);109 promise_test(async (t) => {110 return new Promise(async (resolve, reject) => {111 try {112 // Set up handles to all third party frames.113 const handles = [114 null, // firstParty115 newIframe(same_site_origin), // thirdPartySameSite116 null, // thirdPartySameSite_AncestorBit117 newIframe(cross_site_origin), // thirdPartyCrossSite118 newAnonymousIframe(same_site_origin), // anonymousFrameSameSite119 null, // anonymousFrameSameSite_AncestorBit120 newAnonymousIframe(cross_site_origin), // anonymousFrameCrossSite121 ];122 // Set up nested SameSite frames for ancestor bit contexts.123 const setUpQueue = token();124 send(newIframe(cross_site_origin),125 child_frame_js(same_site_origin, "newIframe", setUpQueue));126 handles[FRAME_CONTEXT.thirdPartySameSite_AncestorBit] =127 await receive(setUpQueue);128 send(newAnonymousIframe(cross_site_origin),129 child_frame_js(same_site_origin, "newAnonymousIframe", setUpQueue));130 handles[FRAME_CONTEXT.anonymousFrameSameSite_AncestorBit] =131 await receive(setUpQueue);132 const sendTo = (contexts, js_generator) => {133 // Send to all contexts in parallel to minimize timeout concerns.134 return Promise.all(contexts.map(async (context) => {135 const queue = token();136 const js_string = js_generator(queue, context);137 switch (context) {138 case FRAME_CONTEXT.firstParty:139 // Code is executed directly in this frame via eval() rather140 // than in a new context to avoid differences in API access.141 eval(`(async () => {${js_string}})()`);142 break;143 case FRAME_CONTEXT.thirdPartySameSite:144 case FRAME_CONTEXT.thirdPartyCrossSite:145 case FRAME_CONTEXT.anonymousFrameSameSite:146 case FRAME_CONTEXT.anonymousFrameCrossSite:147 case FRAME_CONTEXT.thirdPartySameSite_AncestorBit:148 case FRAME_CONTEXT.anonymousFrameSameSite_AncestorBit:149 send(handles[context], js_string);150 break;151 default:152 reject(`Cannot execute in context: ${context}`);153 }154 if (await receive(queue) != "done") {155 reject(`Script failed in frame ${context}: ${js_string}`);156 }157 }));158 };159 await func(t, sendTo);160 } catch (e) {161 reject(e);162 }163 resolve();164 });165 }, description);...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 console.log(data);4});5var wpt = require('webpagetest');6var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');7 console.log(data);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');15 console.log(data);16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');19 console.log(data);20});
Using AI Code Generation
1function test() {2 var wpt = new WebPageTest('www.webpagetest.org');3 if(err) {4 console.log(err);5 }6 else {7 console.log(data);8 }9 });10}11 test();12function test() {13 var wpt = new WebPageTest('www.webpagetest.org');14 wpt.get_locations(function(err, data){15 if(err) {16 console.log(err);17 }18 else {19 console.log(data);20 }21 });22}23 test();24function test() {25 var wpt = new WebPageTest('www.webpagetest.org');26 wpt.get_testers(function(err, data){27 if(err) {28 console.log(err);29 }30 else {31 console.log(data);32 }33 });34}35 test();36function test() {37 var wpt = new WebPageTest('www.webpagetest.org');38 wpt.get_test_status('140623_8Y_9e9f
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3}, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});
Using AI Code Generation
1var wptdriver = new WptDriver();2var wptdriver = new WptDriver();3 document.getElementById("data").innerHTML = data;4});5var wptdriver = new WptDriver();6 document.getElementById("data").innerHTML = data;7});8var wptdriver = new WptDriver();9 document.getElementById("data").innerHTML = data;10});11var wptdriver = new WptDriver();12 document.getElementById("data").innerHTML = data;13});14var wptdriver = new WptDriver();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!