Best JavaScript code snippet using wpt
referrer-tests.js
Source:referrer-tests.js
...16// fetchType: 'top-level' or 'descendant',17// referrerPolicy: 'no-referrer',18// scriptsOrigins: { topLevel: 'same', descendant: 'remote' }19// };20function runReferrerTest(settings) {21 const kWindowURL =22 'resources/referrer-window.html' +23 `?pipe=header(Referrer-Policy, ${settings.referrerPolicy})`;24 return openWindow(kWindowURL).then(win => {25 const promise = new Promise(resolve => window.onmessage = resolve);26 win.postMessage(settings, '*');27 return promise;28 }).then(msg_event => assert_equals(msg_event.data, 'RESOLVED'));29}30// Runs a series of tests related to the referrer policy on a worklet.31//32// Usage:33// runReferrerTests("paint");34function runReferrerTests(workletType) {35 const worklet = get_worklet(workletType);36 // Tests for top-level script fetch -----------------------------------------37 promise_test(() => {38 return runReferrerTest({ workletType: workletType,39 fetchType: 'top-level',40 referrerPolicy: 'no-referrer',41 scriptOrigins: { topLevel: 'same' } });42 }, 'Importing a same-origin script from a page that has "no-referrer" ' +43 'referrer policy should not send referrer.');44 promise_test(() => {45 return runReferrerTest({ workletType: workletType,46 fetchType: 'top-level',47 referrerPolicy: 'no-referrer',48 scriptOrigins: { topLevel: 'remote' } });49 }, 'Importing a remote-origin script from a page that has "no-referrer" ' +50 'referrer policy should not send referrer.');51 promise_test(() => {52 return runReferrerTest({ workletType: workletType,53 fetchType: 'top-level',54 referrerPolicy: 'origin',55 scriptOrigins: { topLevel: 'same' } });56 }, 'Importing a same-origin script from a page that has "origin" ' +57 'referrer policy should send only an origin as referrer.');58 promise_test(() => {59 return runReferrerTest({ workletType: workletType,60 fetchType: 'top-level',61 referrerPolicy: 'origin',62 scriptOrigins: { topLevel: 'remote' } });63 }, 'Importing a remote-origin script from a page that has "origin" ' +64 'referrer policy should send only an origin as referrer.');65 promise_test(() => {66 return runReferrerTest({ workletType: workletType,67 fetchType: 'top-level',68 referrerPolicy: 'same-origin',69 scriptOrigins: { topLevel: 'same' } });70 }, 'Importing a same-origin script from a page that has "same-origin" ' +71 'referrer policy should send referrer.');72 promise_test(() => {73 return runReferrerTest({ workletType: workletType,74 fetchType: 'top-level',75 referrerPolicy: 'same-origin',76 scriptOrigins: { topLevel: 'remote' } });77 }, 'Importing a remote-origin script from a page that has "same-origin" ' +78 'referrer policy should not send referrer.');79 // Tests for descendant script fetch -----------------------------------------80 // Referrer policy: no-referrer.81 promise_test(() => {82 return runReferrerTest({ workletType: workletType,83 fetchType: 'descendant',84 referrerPolicy: 'no-referrer',85 scriptOrigins: { topLevel: 'same',86 descendant: 'same' } });87 }, 'Importing a same-origin script from a same-origin worklet script that ' +88 'has "no-referrer" referrer policy should not send referrer.');89 promise_test(() => {90 return runReferrerTest({ workletType: workletType,91 fetchType: 'descendant',92 referrerPolicy: 'no-referrer',93 scriptOrigins: { topLevel: 'same',94 descendant: 'remote' } });95 }, 'Importing a remote-origin script from a same-origin worklet script ' +96 'that has "no-referrer" referrer policy should not send referrer.');97 promise_test(() => {98 return runReferrerTest({ workletType: workletType,99 fetchType: 'descendant',100 referrerPolicy: 'no-referrer',101 scriptOrigins: { topLevel: 'remote',102 descendant: 'same' } });103 }, 'Importing a same-origin script from a remote-origin worklet script ' +104 'that has "no-referrer" referrer policy should not send referrer.');105 promise_test(() => {106 return runReferrerTest({ workletType: workletType,107 fetchType: 'descendant',108 referrerPolicy: 'no-referrer',109 scriptOrigins: { topLevel: 'remote',110 descendant: 'remote' } });111 }, 'Importing a remote-origin script from a remote-origin worklet script ' +112 'that has "no-referrer" referrer policy should not send referrer.');113 // Referrer policy: origin.114 promise_test(() => {115 return runReferrerTest({ workletType: workletType,116 fetchType: 'descendant',117 referrerPolicy: 'origin',118 scriptOrigins: { topLevel: 'same',119 descendant: 'same' } });120 }, 'Importing a same-origin script from a same-origin worklet script that ' +121 'has "origin" referrer policy should send referrer.');122 promise_test(() => {123 return runReferrerTest({ workletType: workletType,124 fetchType: 'descendant',125 referrerPolicy: 'origin',126 scriptOrigins: { topLevel: 'same',127 descendant: 'remote' } });128 }, 'Importing a remote-origin script from a same-origin worklet script ' +129 'that has "origin" referrer policy should send referrer.');130 promise_test(() => {131 return runReferrerTest({ workletType: workletType,132 fetchType: 'descendant',133 referrerPolicy: 'origin',134 scriptOrigins: { topLevel: 'remote',135 descendant: 'same' } });136 }, 'Importing a same-origin script from a remote-origin worklet script ' +137 'that has "origin" referrer policy should send referrer.');138 promise_test(() => {139 return runReferrerTest({ workletType: workletType,140 fetchType: 'descendant',141 referrerPolicy: 'origin',142 scriptOrigins: { topLevel: 'remote',143 descendant: 'remote' } });144 }, 'Importing a remote-origin script from a remote-origin worklet script ' +145 'that has "origin" referrer policy should send referrer.');146 // Referrer policy: same-origin.147 promise_test(() => {148 return runReferrerTest({ workletType: workletType,149 fetchType: 'descendant',150 referrerPolicy: 'same-origin',151 scriptOrigins: { topLevel: 'same',152 descendant: 'same' } });153 }, 'Importing a same-origin script from a same-origin worklet script that ' +154 'has "same-origin" referrer policy should send referrer.');155 promise_test(() => {156 return runReferrerTest({ workletType: workletType,157 fetchType: 'descendant',158 referrerPolicy: 'same-origin',159 scriptOrigins: { topLevel: 'same',160 descendant: 'remote' } });161 }, 'Importing a remote-origin script from a same-origin worklet script ' +162 'that has "same-origin" referrer policy should not send referrer.');163 promise_test(() => {164 return runReferrerTest({ workletType: workletType,165 fetchType: 'descendant',166 referrerPolicy: 'same-origin',167 scriptOrigins: { topLevel: 'remote',168 descendant: 'same' } });169 }, 'Importing a same-origin script from a remote-origin worklet script ' +170 'that has "same-origin" referrer policy should send referrer.');171 promise_test(() => {172 return runReferrerTest({ workletType: workletType,173 fetchType: 'descendant',174 referrerPolicy: 'same-origin',175 scriptOrigins: { topLevel: 'remote',176 descendant: 'remote' } });177 }, 'Importing a remote-origin script from a remote-origin worklet script ' +178 'that has "same-origin" referrer policy should not send referrer.');179 // TODO(domfarolino): Add tests for more referrer policies....
Using AI Code Generation
1function runReferrerTest() {2 wptReferrerTest.runReferrerTest();3}4function runReferrerTest() {5 wptReferrerTest.runReferrerTest();6}7function runReferrerTest() {8 wptReferrerTest.runReferrerTest();9}10function runReferrerTest() {11 wptReferrerTest.runReferrerTest();12}13function runReferrerTest() {14 wptReferrerTest.runReferrerTest();15}16function runReferrerTest() {17 wptReferrerTest.runReferrerTest();18}19function runReferrerTest() {20 wptReferrerTest.runReferrerTest();21}22function runReferrerTest() {23 wptReferrerTest.runReferrerTest();24}25function runReferrerTest() {26 wptReferrerTest.runReferrerTest();27}28function runReferrerTest() {29 wptReferrerTest.runReferrerTest();30}31function runReferrerTest() {32 wptReferrerTest.runReferrerTest();33}34function runReferrerTest() {35 wptReferrerTest.runReferrerTest();36}
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 if(err) {4 console.log('Error: ' + err);5 } else {6 console.log('Test ID: ' + data.data.testId);7 }8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');11 if(err) {12 console.log('Error: ' + err);13 } else {14 console.log('Test ID: ' + data.data.testId);15 }16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');19 if(err) {20 console.log('Error: ' + err);21 } else {22 console.log('Test ID: ' + data.data.testId);23 }24});25var wpt = require('wpt');26var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');27 if(err) {28 console.log('Error: ' + err);29 } else {30 console.log('Test ID: ' + data.data
Using AI Code Generation
1var wpt = require('wpt.js');2 console.log(data);3});4exports.runReferrerTest = function(url, referrer, callback) {5 var options = {6 };7 var req = http.get(options, function(res) {8 var bodyChunks = [];9 res.on('data', function(chunk) {10 bodyChunks.push(chunk);11 }).on('end', function() {12 var body = Buffer.concat(bodyChunks);13 callback(body.toString());14 })15 });16 req.on('error', function(e) {17 console.log('ERROR: ' + e.message);18 });19};20 at errnoException (net.js:901:11)21 at Object.afterConnect [as oncomplete] (net.js:892:19)
Using AI Code Generation
1var wpt = require('./wpt.js');2 console.log(data);3});4var http = require('http');5var querystring = require('querystring');6var wpt = {7 runReferrerTest: function(url, testid, resultid, jsonid, callback){8 var postData = querystring.stringify({9 });10 var options = {11 headers: {12 }13 };14 var req = http.request(options, function(res){15 res.setEncoding('utf8');16 res.on('data', function(chunk){17 callback(chunk);18 });19 });20 req.write(postData);21 req.end();22 }23};24module.exports = wpt;
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.8c4e4b4f4c4a4b4c4a4b4c4a4b4c4a4');3var options = {4};5wpt.runTest(test_url, options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test Status: ' + data.statusText);8 console.log('Test ID: ' + data.data.testId);9 wpt.getTestResults(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log(data);12 });13});
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!!