Best JavaScript code snippet using wpt
mixed-content-test-case.js
Source: mixed-content-test-case.js
1/**2 * @fileoverview Test case for mixed-content in Web Platform Tests.3 * @author burnik@google.com (Kristijan Burnik)4 */5/**6 * MixedContentTestCase exercises all the tests for checking browser behavior7 * when resources regarded as mixed-content are requested. A single run covers8 * only a single scenario.9 * @param {object} scenario A JSON describing the test arrangement and10 * expectation(s). Refer to /mixed-content/spec.src.json for details.11 * @param {string} description The test scenario verbose description.12 * @param {SanityChecker} sanityChecker Instance of an object used to check the13 * running scenario. Useful in debug mode. See ./sanity-checker.js.14 * Run {@code ./tools/generate.py -h} for info on test generating modes.15 * @return {object} Object wrapping the start method used to run the test.16 */17function MixedContentTestCase(scenario, description, sanityChecker) {18 var httpProtocol = "http";19 var httpsProtocol = "https";20 var wsProtocol = "ws";21 var wssProtocol = "wss";22 var sameOriginHost = location.hostname;23 var crossOriginHost = "{{domains[www1]}}";24 // These values can evaluate to either empty strings or a ":port" string.25 var httpPort = getNormalizedPort(parseInt("{{ports[http][0]}}", 10));26 var httpsPort = getNormalizedPort(parseInt("{{ports[https][0]}}", 10));27 var wsPort = getNormalizedPort(parseInt("{{ports[ws][0]}}", 10));28 var wssPort = getNormalizedPort(parseInt("{{ports[wss][0]}}", 10));29 var resourcePath = "/mixed-content/generic/expect.py";30 var wsResourcePath = "/stash_responder";31 // Map all endpoints to scenario for use in the test.32 var endpoint = {33 "same-origin":34 location.origin + resourcePath,35 "same-host-https":36 httpsProtocol + "://" + sameOriginHost + httpsPort + resourcePath,37 "same-host-http":38 httpProtocol + "://" + sameOriginHost + httpPort + resourcePath,39 "cross-origin-https":40 httpsProtocol + "://" + crossOriginHost + httpsPort + resourcePath,41 "cross-origin-http":42 httpProtocol + "://" + crossOriginHost + httpPort + resourcePath,43 "same-host-wss":44 wssProtocol + "://" + sameOriginHost + wssPort + wsResourcePath,45 "same-host-ws":46 wsProtocol + "://" + sameOriginHost + wsPort + wsResourcePath,47 "cross-origin-wss":48 wssProtocol + "://" + crossOriginHost + wssPort + wsResourcePath,49 "cross-origin-ws":50 wsProtocol + "://" + crossOriginHost + wsPort + wsResourcePath51 };52 // Mapping all the resource requesting methods to the scenario.53 var resourceMap = {54 "a-tag": requestViaAnchor,55 "area-tag": requestViaArea,56 "fetch-request": requestViaFetch,57 "form-tag": requestViaForm,58 "iframe-tag": requestViaIframe,59 "img-tag": requestViaImage,60 "script-tag": requestViaScript,61 "worker-request": requestViaWorker,62 "xhr-request": requestViaXhr,63 "audio-tag": requestViaAudio,64 "video-tag": requestViaVideo,65 "picture-tag": requestViaPicture,66 "object-tag": requestViaObject,67 "link-css-tag": requestViaLinkStylesheet,68 "link-prefetch-tag": requestViaLinkPrefetch,69 "websocket-request": requestViaWebSocket70 };71 sanityChecker.checkScenario(scenario, resourceMap);72 // Mapping all expected MIME types to the scenario.73 var contentType = {74 "a-tag": "text/html",75 "area-tag": "text/html",76 "fetch-request": "application/json",77 "form-tag": "text/html",78 "iframe-tag": "text/html",79 "img-tag": "image/png",80 "script-tag": "text/javascript",81 "worker-request": "application/javascript",82 "xhr-request": "application/json",83 "audio-tag": "audio/mpeg",84 "video-tag": "video/mp4",85 "picture-tag": "image/png",86 "object-tag": "text/html",87 "link-css-tag": "text/css",88 "link-prefetch-tag": "text/html",89 "websocket-request": "application/json"90 };91 var mixed_content_test = async_test(description);92 function runTest() {93 sanityChecker.setFailTimeout(mixed_content_test);94 var key = guid();95 var value = guid();96 // We use the same path for both HTTP/S and WS/S stash requests.97 var stash_path = encodeURIComponent("/mixed-content");98 var announceResourceRequestUrl = endpoint['same-origin'] +99 "?action=put&key=" + key +100 "&value=" + value +101 "&path=" + stash_path;102 var assertResourceRequestUrl = endpoint['same-origin'] +103 "?action=take&key=" + key +104 "&path=" + stash_path;105 var resourceRequestUrl = endpoint[scenario.origin] + "?redirection=" +106 scenario.redirection + "&action=purge&key=" + key +107 "&path=" + stash_path + "&content_type=" +108 contentType[scenario.subresource];109 xhrRequest(announceResourceRequestUrl)110 .then(function(response) {111 // Send out the real resource request.112 // This should tear down the key if it's not blocked.113 return resourceMap[scenario.subresource](resourceRequestUrl);114 })115 .then(function() {116 mixed_content_test.step(function() {117 assert_equals("allowed", scenario.expectation,118 "The triggered event should match '" +119 scenario.expectation + "'.");120 }, "Check if success event was triggered.");121 // Send request to check if the key has been torn down.122 return xhrRequest(assertResourceRequestUrl);123 }, function(error) {124 mixed_content_test.step(function() {125 assert_equals("blocked", scenario.expectation,126 "The triggered event should match '" +127 scenario.expectation + "'.");128 // TODO(kristijanburnik): param "error" can be an event or error.129 // Map assertion by resource.130 // e.g.: assert_equals(e.type, "error");131 }, "Check if error event was triggered.");132 // When requestResource fails, we also check the key state.133 return xhrRequest(assertResourceRequestUrl);134 })135 .then(function(response) {136 // Now check if the value has been torn down. If it's still there,137 // we have blocked the request to mixed-content.138 mixed_content_test.step(function() {139 assert_equals(response.status, scenario.expectation,140 "The resource request should be '" + scenario.expectation +141 "'.");142 }, "Check if request was sent.");143 mixed_content_test.done();144 });145 } // runTest146 return {start: runTest};...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});
Using AI Code Generation
1var wpt = require('webpagetest');2var wptInstance = new wpt('API_KEY');3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var wptInstance = new wpt('API_KEY');11wptInstance.requestTestResults('testId', function(err, data) {12 if(err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18var wpt = require('webpagetest');19var wptInstance = new wpt('API_KEY');20wptInstance.requestTestResults('testId', function(err, data) {21 if(err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('webpagetest');28var wptInstance = new wpt('API_KEY');29wptInstance.requestTestStatus('testId', function(err, data) {30 if(err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('webpagetest');
Using AI Code Generation
1const {requestViaWebSocket} = require('wpt-api');2requestViaWebSocket({3}).then((data) => {4 console.log(data);5});6const {requestViaWebSocket} = require('wpt-api');7requestViaWebSocket({8}).then((data) => {9 console.log(data);10});11const {requestViaWebSocket} = require('wpt-api');12requestViaWebSocket({13}).then((data) => {14 console.log(data);15});16const {requestViaWebSocket} = require('wpt-api');17requestViaWebSocket({18}).then((data) => {19 console.log(data);20});21const {requestViaWebSocket} = require('wpt-api');22requestViaWebSocket({23}).then((data) => {24 console.log(data);25});26const {requestViaWebSocket} = require('wpt-api');27requestViaWebSocket({28}).then((data) => {29 console.log(data);30});31const {requestViaWebSocket
Using AI Code Generation
1const WPT = require('wpt-api');2const wpt = new WPT('API_KEY');3}).then((data) => {4 console.log(data);5}).catch((err) => {6 console.error(err);7});8### `new WPT(apiKey, [options])`9### `wpt.request(url, [options], [callback])`
Using AI Code Generation
1const wpt = require('wpt-api');2const wptOptions = {3 videoParams: {4 },5};6wpt.requestViaWebSocket(wptO
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var client = wpt('www.webpagetest.org');8 if (err) return console.error(err);9 console.log(data);10});11var wpt = require('webpagetest');12var client = wpt('www.webpagetest.org');13 if (err) return console.error(err);14 console.log(data);15});16var wpt = require('webpagetest');17var client = wpt('www.webpagetest.org');18 if (err) return console.error(err);19 console.log(data);20});21var wpt = require('webpagetest');22var client = wpt('www.webpagetest.org');23 if (err) return console.error(err);24 console.log(data);25});
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!!