Best JavaScript code snippet using wpt
cookie.tentative.https.window.js
Source: cookie.tentative.https.window.js
1// META: script=/common/get-host-info.sub.js2// META: script=/common/utils.js3// META: script=/common/dispatcher/dispatcher.js4// META: script=../credentialless/resources/common.js5// META: script=./resources/common.js6const same_origin = get_host_info().HTTPS_ORIGIN;7const cross_origin = get_host_info().HTTPS_REMOTE_ORIGIN;8const cookie_key = "anonymous_iframe_load_cookie";9const cookie_same_origin = "same_origin";10const cookie_cross_origin = "cross_origin";11const cookieFromResource = async resource_token => {12 let headers = JSON.parse(await receive(resource_token));13 return parseCookies(headers)[cookie_key];14};15// Load an anonymous iframe, return the HTTP request cookies.16const cookieFromAnonymousIframeRequest = async (iframe_origin) => {17 const resource_token = token();18 let iframe = document.createElement("iframe");19 iframe.src = `${showRequestHeaders(iframe_origin, resource_token)}`;20 iframe.anonymous = true;21 document.body.appendChild(iframe);22 return await cookieFromResource(resource_token);23};24// Load a resource `type` from the iframe with `document_token`,25// return the HTTP request cookies.26const cookieFromResourceInIframe =27 async (document_token, resource_origin, type = "img") => {28 const resource_token = token();29 send(document_token, `30 let el = document.createElement("${type}");31 el.src = "${showRequestHeaders(resource_origin, resource_token)}";32 document.body.appendChild(el);33 `);34 return await cookieFromResource(resource_token);35};36promise_test_parallel(async test => {37 await Promise.all([38 setCookie(same_origin, cookie_key, cookie_same_origin),39 setCookie(cross_origin, cookie_key, cookie_cross_origin),40 ]);41 promise_test_parallel(async test => {42 assert_equals(43 await cookieFromAnonymousIframeRequest(same_origin),44 undefined45 );46 }, "Anonymous same-origin iframe is loaded without credentials");47 promise_test_parallel(async test => {48 assert_equals(49 await cookieFromAnonymousIframeRequest(cross_origin),50 undefined51 );52 }, "Anonymous cross-origin iframe is loaded without credentials");53 let iframe_same_origin = newAnonymousIframe(same_origin);54 let iframe_cross_origin = newAnonymousIframe(cross_origin);55 promise_test_parallel(async test => {56 assert_equals(57 await cookieFromResourceInIframe(iframe_same_origin, same_origin),58 undefined59 );60 }, "same_origin anonymous iframe can't send same_origin credentials");61 promise_test_parallel(async test => {62 assert_equals(63 await cookieFromResourceInIframe(iframe_same_origin, cross_origin),64 undefined65 );66 }, "same_origin anonymous iframe can't send cross_origin credentials");67 promise_test_parallel(async test => {68 assert_equals(69 await cookieFromResourceInIframe(iframe_cross_origin, cross_origin),70 undefined71 );72 }, "cross_origin anonymous iframe can't send cross_origin credentials");73 promise_test_parallel(async test => {74 assert_equals(75 await cookieFromResourceInIframe(iframe_cross_origin, same_origin),76 undefined77 );78 }, "cross_origin anonymous iframe can't send same_origin credentials");79 promise_test_parallel(async test => {80 assert_equals(81 await cookieFromResourceInIframe(iframe_same_origin, same_origin,82 "iframe"),83 undefined84 );85 }, "same_origin anonymous iframe can't send same_origin credentials "86 + "on child iframe");87 promise_test_parallel(async test => {88 assert_equals(89 await cookieFromResourceInIframe(iframe_same_origin, cross_origin,90 "iframe"),91 undefined92 );93 }, "same_origin anonymous iframe can't send cross_origin credentials "94 + "on child iframe");95 promise_test_parallel(async test => {96 assert_equals(97 await cookieFromResourceInIframe(iframe_cross_origin, cross_origin,98 "iframe"),99 undefined100 );101 }, "cross_origin anonymous iframe can't send cross_origin credentials "102 + "on child iframe");103 promise_test_parallel(async test => {104 assert_equals(105 await cookieFromResourceInIframe(iframe_cross_origin, same_origin,106 "iframe"),107 undefined108 );109 }, "cross_origin anonymous iframe can't send same_origin credentials "110 + "on child iframe");...
web_security_spec.js
Source: web_security_spec.js
1const systemTests = require('../lib/system-tests').default2const onServer = function (app) {3 app.get('/link', (req, res) => {4 res.send('<html><h1>link</h1><a href=\'https://www.foo.com:44665/cross_origin\'>second</a></html>')5 })6 app.get('/cross_origin', (req, res) => {7 res.send('<html><h1>cross origin</h1></html>')8 })9 app.get('/form', (req, res) => {10 res.send(`\11<html>12<h1>form</h1>13<form method='POST' action='https://www.foo.com:44665/submit'>14 <input type='submit' name='foo' value='bar' />15</form>16</html>\17`)18 })19 app.post('/submit', (req, res) => {20 res.redirect('https://www.foo.com:44665/cross_origin')21 })22 app.get('/javascript', (req, res) => {23 res.send(`\24<html>25<script type='text/javascript'>26 window.redirect = function(){27 window.location.href = 'https://www.foo.com:44665/cross_origin'28 }29</script>30<h1>javascript</h1>31<button onclick='redirect()'>click me</button>32</html>\33`)34 })35 app.get('/cors', (req, res) => {36 res.send(`<script>37 fetch('https://127.0.0.2:44665/cross_origin')38 .then((res) => res.text())39 .then(text => {40 if (text.includes('cross origin')) document.write('success!')41 })42 .catch(err => document.write(err.message))43 </script>`)44 })45}46describe('e2e web security', () => {47 systemTests.setup({48 servers: [{49 port: 4466,50 onServer,51 }, {52 port: 44665,53 https: true,54 onServer,55 }],56 settings: {57 hosts: {58 '*.foo.com': '127.0.0.1',59 },60 },61 })62 context('when enabled', () => {63 systemTests.it('fails', {64 spec: 'web_security_spec.js',65 snapshot: true,66 expectedExitCode: 4,67 })68 })69 context('when disabled', () => {70 systemTests.it('passes', {71 spec: 'web_security_spec.js',72 config: {73 chromeWebSecurity: false,74 },75 snapshot: true,76 browser: ['chrome', 'electron'],77 })78 })79 context('firefox', () => {80 systemTests.it('displays warning when firefox and chromeWebSecurity:false', {81 spec: 'simple_passing_spec.js',82 snapshot: true,83 browser: 'firefox',84 config: {85 chromeWebSecurity: false,86 },87 onStdout (stdout) {88 expect(stdout).include('Your project has set the configuration option: `chromeWebSecurity: false`\n\nThis option will not have an effect in Firefox.')89 },90 })91 })...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 lighthouseConfig: {4 settings: {5 throttling: {6 },7 },8 },9 lighthouseConfig: {10 settings: {11 throttling: {12 },13 },14 },
Using AI Code Generation
1const wpt = require('webpagetest');2const client = wpt('www.webpagetest.org');3 videoParams: {4 }5}, function (err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12#### runTest(url, options, callback)13 with the location ID (e.g. `Dulles:Chrome`) or an object with the following
Using AI Code Generation
1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3}, function(err, data) {4 if (err) return console.error(err);5 console.log('Test status: ' + data.statusText);6 console.log('Test ID: ' + data.data.testId);7 console.log('Test URL: ' + data.data.userUrl);8 console.log('Test results: ' + data.data.summary);9});10var wpt = require('webpagetest');11var api = new wpt('www.webpagetest.org', 'API_KEY');12}, function(err, data) {13 if (err) return console.error(err);14 console.log('Test status: ' + data.statusText);15 console.log('Test ID: ' + data.data.testId);16 console.log('Test URL: ' + data.data.userUrl);17 console.log('Test results: ' + data.data.summary);18});19var wpt = require('webpagetest');20}, function(err, data) {21 if (err) return console.error(err);22 console.log('Test status: ' + data.statusText);23 console.log('Test ID: ' + data.data.testId);24 console.log('Test URL: ' + data.data.userUrl);25 console.log('Test results: ' + data.data.summary);26});27var wpt = require('webpagetest');
Using AI Code Generation
1function run_test()2{3 var channel = make_channel(url);4 channel.asyncOpen(new ChannelListener(checkRequest, null, CL_ALLOW_UNKNOWN_CL), null);5}6function checkRequest(request, data, ctx)7{8 do_check_eq(request.status, Components.results.NS_OK);9 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).responseStatus, 200);10 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).responseStatusText, "OK");11 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Content-Type"), "text/html");12 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Access-Control-Allow-Origin"), "*");13 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Access-Control-Allow-Methods"), "POST, GET, OPTIONS");14 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Access-Control-Allow-Headers"), "X-PINGOTHER, Content-Type");15 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Access-Control-Max-Age"), "1728000");16 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Access-Control-Expose-Headers"), "X-My-Custom-Header, X-Another-Custom-Header");17 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Access-Control-Allow-Credentials"), "true");18 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Access-Control-Request-Method"), "POST");19 do_check_eq(request.QueryInterface(Components.interfaces.nsIHttpChannel).getResponseHeader("Access-Control-Request-Headers"), "X-PINGOTHER, Content-Type");20 run_next_test();21}22<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>23function runTest()24{25 var xhr = new XMLHttpRequest();26 xhr.setRequestHeader("X-PINGOTHER", "ping
Check out the latest blogs from LambdaTest on this topic:
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
We launched LT Browser in 2020, and we were overwhelmed by the response as it was awarded as the #5 product of the day on the ProductHunt platform. Today, after 74,585 downloads and 7,000 total test runs with an average of 100 test runs each day, the LT Browser has continued to help developers build responsive web designs in a jiffy.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.
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!!