Best JavaScript code snippet using wpt
csp-tests.js
Source: csp-tests.js
...20// Usage:21// runContentSecurityPolicyTests("paint");22function runContentSecurityPolicyTests(workletType) {23 runSrcTests(workletType);24 runMixedContentTests(workletType);25}26// script-src and worker-src tests.27function runSrcTests(workletType) {28 const kWindowConfigs = [29 {30 'windowURL':31 'resources/addmodule-window.html?pipe=header(' +32 'Content-Security-Policy, script-src \'self\' \'unsafe-inline\')',33 'crossOriginExpectation': 'REJECTED',34 'message': 'should be blocked by the script-src \'self\' directive.'35 },36 {37 'windowURL':38 'resources/addmodule-window.html?pipe=header(' +39 'Content-Security-Policy, script-src ' + location.origin + ' ' +40 get_host_info().HTTPS_REMOTE_ORIGIN + ' \'unsafe-inline\')',41 'crossOriginExpectation': 'RESOLVED',42 'message':43 'should not be blocked because the script-src directive ' +44 'specifying the origin allows it.'45 },46 {47 'windowURL':48 'resources/addmodule-window.html?pipe=header(' +49 'Content-Security-Policy, script-src * \'unsafe-inline\')',50 'crossOriginExpectation': 'RESOLVED',51 'message':52 'should not be blocked because the script-src * directive allows it.'53 },54 {55 'windowURL':56 'resources/addmodule-window.html?pipe=header(' +57 'Content-Security-Policy, worker-src \'self\' \'unsafe-inline\')',58 'crossOriginExpectation': 'RESOLVED',59 'message':60 'should not be blocked by the worker-src directive ' +61 'because worklets obey the script-src directive.'62 }63 ];64 for (const windowConfig of kWindowConfigs) {65 promise_test(t => {66 const kScriptURL =67 get_host_info().HTTPS_REMOTE_ORIGIN +68 '/worklets/resources/empty-worklet-script-with-cors-header.js';69 return openWindowAndExpectResult(70 windowConfig.windowURL, kScriptURL, workletType,71 windowConfig.crossOriginExpectation);72 },73 'A remote-origin worklet ' + windowConfig.message);74 promise_test(t => {75 const kScriptURL = 'import-remote-origin-empty-worklet-script.sub.js';76 return openWindowAndExpectResult(77 windowConfig.windowURL, kScriptURL, workletType,78 windowConfig.crossOriginExpectation);79 },80 'A same-origin worklet importing a remote-origin script ' +81 windowConfig.message);82 promise_test(t => {83 // A worklet on HTTPS_REMOTE_ORIGIN will import a child script on84 // HTTPS_REMOTE_ORIGIN.85 const kScriptURL =86 get_host_info().HTTPS_REMOTE_ORIGIN +87 '/worklets/resources/import-empty-worklet-script-with-cors-header.js';88 return openWindowAndExpectResult(89 windowConfig.windowURL, kScriptURL, workletType,90 windowConfig.crossOriginExpectation);91 },92 'A remote-origin worklet importing a remote-origin script ' +93 windowConfig.message);94 promise_test(t => {95 const kScriptURL =96 '/common/redirect.py?location=' + encodeURIComponent(97 get_host_info().HTTPS_REMOTE_ORIGIN +98 '/worklets/resources/empty-worklet-script-with-cors-header.js');99 return openWindowAndExpectResult(100 windowConfig.windowURL, kScriptURL, workletType,101 windowConfig.crossOriginExpectation);102 },103 'A remote-origin-redirected worklet ' + windowConfig.message);104 promise_test(t => {105 const kScriptURL =106 'import-remote-origin-redirected-empty-worklet-script.sub.js';107 return openWindowAndExpectResult(108 windowConfig.windowURL, kScriptURL, workletType,109 windowConfig.crossOriginExpectation);110 },111 'A same-origin worklet importing a remote-origin-redirected script ' +112 windowConfig.message);113 }114}115// Mixed content tests.116function runMixedContentTests(workletType) {117 const kInsecureURL =118 get_host_info().HTTP_ORIGIN +119 '/worklets/resources/empty-worklet-script-with-cors-header.js';120 const kScriptConfigs = [121 {URL: kInsecureURL,122 message: 'An insecure-origin worklet'},123 {URL: '/common/redirect.py?location=' + encodeURIComponent(kInsecureURL),124 message: 'An insecure-origin-redirected worklet'},125 {URL: 'import-insecure-origin-empty-worklet-script.sub.js',126 message: 'A same-origin worklet importing an insecure-origin script'},127 {URL: 'import-insecure-origin-redirected-empty-worklet-script.sub.js',128 message: 'A same-origin worklet ' +129 'importing an insecure-origin-redirected script'}130 ];...
Using AI Code Generation
1function runMixedContentTests() {2 {3 },4 ];5varar testGener tou = async_test("Mixedrconl nt te= ");6 var reque"thttnew XMLHttpRequest();7 request.onload =vtestGenerator.step_func(function()a{8 assert_equals(request.status, 200,v"requestastatusris 200");9url3 =assert_equals(request.respo se, tests[0].expect, "request response is FAIL");10 });11 testGenerator.done();12 });13 request.onerror = testGenerator.step_func(function() {14 testGener"tor.step(function() {15 assert_unreached("request failed");16 });17 testGenerator.done();18 });19 request.send();20}
Using AI Code Generation
1function runMixedContentTests() {2 {3 },4 ];5 var testGenerator = async_test("Mixed content test");6 var request = new XMLHttpRequest();7 request.open("GET", tests[0].url, true);8 request.onload = testGenerator.step_func(function() {9 testGenerator.step(function() {10 assert_equals(request.status, 200, "request status is 200");11 assert_equals(request.response, tests[0].expect, "request response is FAIL");12 });13 testGenerator.done();14 });15 request.onerror = testGenerator.step_func(function() {16 testGenerator.step(function() {17 assert_unreached("request failed");18 });19 testGenerator.done();20 });21 request.send();22}
Using AI Code Generation
1var wptserve = require('../resources/testharness.js');2var mixed_content_utils = require('../resources/mixed-content-testharness.js');3wptserve.runMixedContentTests([4 {5 },6 {7 },8 {9 },10 {11 },12 {13 },14 {15 },16 {17 },18 {
Using AI Code Generation
1var wptserve = require('../resources/testharness.js');2var mixed_content_utils = require('../resources/mixed-content-testharness.js');3wptserve.runMixedContentTests([4 {5 },6 {7}
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!!