How to use same_site_origin method in wpt

Best JavaScript code snippet using wpt

local-fs-test-helpers.js

Source:local-fs-test-helpers.js Github

copy

Full Screen

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

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.error(err);5 } else {6 console.log(data);7 }8 });9}10function test() {11 var wpt = new WebPageTest('www.webpagetest.org');12 if (err) {13 console.error(err);14 } else {15 console.log(data);16 }17 });18}19function test() {20 var wpt = new WebPageTest('www.webpagetest.org');21 if (err) {22 console.error(err);23 } else {24 console.log(data);25 }26 });27}28function test() {29 var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var xhr = new XMLHttpRequest()2xhr.open("GET", url, false);3xhr.send();4xhr = new XMLHttpRequest()5xhr.open("GET", url, false);6xhr.send();

Full Screen

Using AI Code Generation

copy

Full Screen

1function same_site_origin() {2 var xhr = new XMLHttpRequest();3 xhr.open("GET", url, true);4 xhr.onload = function() {5 console.log("same_site_origin");6 };7 xhr.send();8}9function cross_site() {10 var xhr = new XMLHttpRequest();11 xhr.open("GET", url, true);12 xhr.onload = function() {13 console.log("cross_site");14 };15 xhr.send();16}17function same_site_none() {18 var xhr = new XMLHttpRequest();19 xhr.open("GET", url, true);20 xhr.onload = function() {21 console.log("same_site_none");22 };23 xhr.send();24}25function same_site_origin() {26 var xhr = new XMLHttpRequest();27 xhr.open("GET", url, true);28 xhr.onload = function() {29 console.log("same_site_origin");30 };31 xhr.send();32}33function cross_site() {34 var xhr = new XMLHttpRequest();35 xhr.open("GET", url, true);36 xhr.onload = function() {37 console.log("cross_site");38 };39 xhr.send();40}41function same_site_none() {42 var xhr = new XMLHttpRequest();43 xhr.open("GET", url, true);44 xhr.onload = function() {45 console.log("same_site_none");46 };47 xhr.send();48}49function same_site_origin() {

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run wpt 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