How to use subresource_element method in wpt

Best JavaScript code snippet using wpt

sriharness.js

Source:sriharness.js Github

copy

Full Screen

1var SRIScriptTest = function(pass, name, src, integrityValue, crossoriginValue, nonce) {2 this.pass = pass;3 this.name = "Script: " + name;4 this.src = src;5 this.integrityValue = integrityValue;6 this.crossoriginValue = crossoriginValue;7 this.nonce = nonce;8}9SRIScriptTest.prototype.execute = function() {10 var test = async_test(this.name);11 var e = document.createElement("script");12 e.src = this.src;13 e.setAttribute("integrity", this.integrityValue);14 if(this.crossoriginValue) {15 e.setAttribute("crossorigin", this.crossoriginValue);16 }17 if(this.nonce) {18 e.setAttribute("nonce", this.nonce);19 }20 if(this.pass) {21 e.addEventListener("load", function() {test.done()});22 e.addEventListener("error", function() {23 test.step(function(){ assert_unreached("Good load fired error handler.") })24 });25 } else {26 e.addEventListener("load", function() {27 test.step(function() { assert_unreached("Bad load succeeded.") })28 });29 e.addEventListener("error", function() {test.done()});30 }31 document.body.appendChild(e);32};33function set_extra_attributes(element, attrs) {34 // Apply the rest of the attributes, if any.35 for (const [attr_name, attr_val] of Object.entries(attrs)) {36 element[attr_name] = attr_val;37 }38}39function buildElementFromDestination(resource_url, destination, attrs) {40 // Assert: |destination| is a valid destination.41 let element;42 // The below switch is responsible for:43 // 1. Creating the correct subresource element44 // 2. Setting said element's href, src, or fetch-instigating property45 // appropriately.46 switch (destination) {47 case "script":48 element = document.createElement(destination);49 set_extra_attributes(element, attrs);50 element.src = resource_url;51 break;52 case "style":53 element = document.createElement('link');54 set_extra_attributes(element, attrs);55 element.rel = 'stylesheet';56 element.href = resource_url;57 break;58 case "image":59 element = document.createElement('img');60 set_extra_attributes(element, attrs);61 element.src = resource_url;62 break;63 default:64 assert_unreached("INVALID DESTINATION");65 }66 return element;67}68const SRIPreloadTest = (preload_sri_success, subresource_sri_success, name,69 destination, resource_url, link_attrs,70 subresource_attrs) => {71 const test = async_test(name);72 const link = document.createElement('link');73 // Early-fail in UAs that do not support `preload` links.74 test.step_func(() => {75 assert_true(link.relList.supports('preload'),76 "This test is automatically failing because the browser does not" +77 "support `preload` links.");78 })();79 // Build up the link.80 link.rel = 'preload';81 link.as = destination;82 link.href = resource_url;83 for (const [attr_name, attr_val] of Object.entries(link_attrs)) {84 link[attr_name] = attr_val; // This may override `rel` to modulepreload.85 }86 // Preload + subresource success and failure loading functions.87 const valid_preload_failed = test.step_func(() =>88 { assert_unreached("Valid preload fired error handler.") });89 const invalid_preload_succeeded = test.step_func(() =>90 { assert_unreached("Invalid preload load succeeded.") });91 const valid_subresource_failed = test.step_func(() =>92 { assert_unreached("Valid subresource fired error handler.") });93 const invalid_subresource_succeeded = test.step_func(() =>94 { assert_unreached("Invalid subresource load succeeded.") });95 const subresource_pass = test.step_func(() => { test.done(); });96 const preload_pass = test.step_func(() => {97 const subresource_element = buildElementFromDestination(98 resource_url,99 destination,100 subresource_attrs101 );102 if (subresource_sri_success) {103 subresource_element.onload = subresource_pass;104 subresource_element.onerror = valid_subresource_failed;105 } else {106 subresource_element.onload = invalid_subresource_succeeded;107 subresource_element.onerror = subresource_pass;108 }109 document.body.append(subresource_element);110 });111 if (preload_sri_success) {112 link.onload = preload_pass;113 link.onerror = valid_preload_failed;114 } else {115 link.onload = invalid_preload_succeeded;116 link.onerror = preload_pass;117 }118 document.head.append(link);119}120// <link> tests121// Style tests must be done synchronously because they rely on the presence122// and absence of global style, which can affect later tests. Thus, instead123// of executing them one at a time, the style tests are implemented as a124// queue that builds up a list of tests, and then executes them one at a125// time.126var SRIStyleTest = function(queue, pass, name, attrs, customCallback, altPassValue) {127 this.pass = pass;128 this.name = "Style: " + name;129 this.customCallback = customCallback || function () {};130 this.attrs = attrs || {};131 this.passValue = altPassValue || "rgb(255, 255, 0)";132 this.test = async_test(this.name);133 this.queue = queue;134 this.queue.push(this);135}136SRIStyleTest.prototype.execute = function() {137 var that = this;138 var container = document.getElementById("container");139 while (container.hasChildNodes()) {140 container.removeChild(container.firstChild);141 }142 var test = this.test;143 var div = document.createElement("div");144 div.className = "testdiv";145 var e = document.createElement("link");146 // The link relation is guaranteed to not be "preload" or "modulepreload".147 this.attrs.rel = this.attrs.rel || "stylesheet";148 for (var key in this.attrs) {149 if (this.attrs.hasOwnProperty(key)) {150 e.setAttribute(key, this.attrs[key]);151 }152 }153 if(this.pass) {154 e.addEventListener("load", function() {155 test.step(function() {156 var background = window.getComputedStyle(div, null).getPropertyValue("background-color");157 assert_equals(background, that.passValue);158 test.done();159 });160 });161 e.addEventListener("error", function() {162 test.step(function(){ assert_unreached("Good load fired error handler.") })163 });164 } else {165 e.addEventListener("load", function() {166 test.step(function() { assert_unreached("Bad load succeeded.") })167 });168 e.addEventListener("error", function() {169 test.step(function() {170 var background = window.getComputedStyle(div, null).getPropertyValue("background-color");171 assert_not_equals(background, that.passValue);172 test.done();173 });174 });175 }176 container.appendChild(div);177 container.appendChild(e);178 this.customCallback(e, container);...

Full Screen

Full Screen

aflprep_sriharness.js

Source:aflprep_sriharness.js Github

copy

Full Screen

1var SRIScriptTest = function(pass, name, src, integrityValue, crossoriginValue, nonce) {2 this.pass = pass;3 this.name = "Script: " + name;4 this.src = src;5 this.integrityValue = integrityValue;6 this.crossoriginValue = crossoriginValue;7 this.nonce = nonce;8}9SRIScriptTest.prototype.execute = function() {10 var test = async_test(this.name);11 var e = document.createElement("script");12 e.src = this.src;13 e.setAttribute("integrity", this.integrityValue);14 if(this.crossoriginValue) {15 e.setAttribute("crossorigin", this.crossoriginValue);16 }17 if(this.nonce) {18 e.setAttribute("nonce", this.nonce);19 }20 if(this.pass) {21 e.addEventListener("load", function() {test.done()});22 e.addEventListener("error", function() {23 test.step(function(){ assert_unreached("Good load fired error handler.") })24 });25 } else {26 e.addEventListener("load", function() {27 test.step(function() { assert_unreached("Bad load succeeded.") })28 });29 e.addEventListener("error", function() {test.done()});30 }31 document.body.appendChild(e);32};33function set_extra_attributes(element, attrs) {34 for (const [attr_name, attr_val] of Object.entries(attrs)) {35 element[attr_name] = attr_val;36 }37}38function buildElementFromDestination(resource_url, destination, attrs) {39 let element;40 switch (destination) {41 case "script":42 element = document.createElement(destination);43 set_extra_attributes(element, attrs);44 element.src = resource_url;45 break;46 case "style":47 element = document.createElement('link');48 set_extra_attributes(element, attrs);49 element.rel = 'stylesheet';50 element.href = resource_url;51 break;52 case "image":53 element = document.createElement('img');54 set_extra_attributes(element, attrs);55 element.src = resource_url;56 break;57 default:58 assert_unreached("INVALID DESTINATION");59 }60 return element;61}62const SRIPreloadTest = (preload_sri_success, subresource_sri_success, name,63 number_of_requests, destination, resource_url,64 link_attrs, subresource_attrs) => {65 const test = async_test(name);66 const link = document.createElement('link');67 test.step_func(() => {68 assert_true(link.relList.supports('preload'),69 "This test is automatically failing because the browser does not" +70 "support `preload` links.");71 })();72 link.rel = 'preload';73 link.as = destination;74 link.href = resource_url;75 for (const [attr_name, attr_val] of Object.entries(link_attrs)) {76 }77 const valid_preload_failed = test.step_func(() =>78 { assert_unreached("Valid preload fired error handler.") });79 const invalid_preload_succeeded = test.step_func(() =>80 { assert_unreached("Invalid preload load succeeded.") });81 const valid_subresource_failed = test.step_func(() =>82 { assert_unreached("Valid subresource fired error handler.") });83 const invalid_subresource_succeeded = test.step_func(() =>84 { assert_unreached("Invalid subresource load succeeded.") });85 const subresource_pass = test.step_func(() => {86 verifyNumberOfResourceTimingEntries(resource_url, number_of_requests);87 test.done();88 });89 const preload_pass = test.step_func(() => {90 const subresource_element = buildElementFromDestination(91 resource_url,92 destination,93 subresource_attrs94 );95 if (subresource_sri_success) {96 subresource_element.onload = subresource_pass;97 subresource_element.onerror = valid_subresource_failed;98 } else {99 subresource_element.onload = invalid_subresource_succeeded;100 subresource_element.onerror = subresource_pass;101 }102 document.body.append(subresource_element);103 });104 if (preload_sri_success) {105 link.onload = preload_pass;106 link.onerror = valid_preload_failed;107 } else {108 link.onload = invalid_preload_succeeded;109 link.onerror = preload_pass;110 }111 document.head.append(link);112}113var SRIStyleTest = function(queue, pass, name, attrs, customCallback, altPassValue) {114 this.pass = pass;115 this.name = "Style: " + name;116 this.customCallback = customCallback || function () {};117 this.attrs = attrs || {};118 this.passValue = altPassValue || "rgb(255, 255, 0)";119 this.test = async_test(this.name);120 this.queue = queue;121 this.queue.push(this);122}123SRIStyleTest.prototype.execute = function() {124 var that = this;125 var container = document.getElementById("container");126 while (container.hasChildNodes()) {127 container.removeChild(container.firstChild);128 }129 var test = this.test;130 var div = document.createElement("div");131 div.className = "testdiv";132 var e = document.createElement("link");133 this.attrs.rel = this.attrs.rel || "stylesheet";134 for (var key in this.attrs) {135 if (this.attrs.hasOwnProperty(key)) {136 e.setAttribute(key, this.attrs[key]);137 }138 }139 if(this.pass) {140 e.addEventListener("load", function() {141 test.step(function() {142 var background = window.getComputedStyle(div, null).getPropertyValue("background-color");143 assert_equals(background, that.passValue);144 test.done();145 });146 });147 e.addEventListener("error", function() {148 test.step(function(){ assert_unreached("Good load fired error handler.") })149 });150 } else {151 e.addEventListener("load", function() {152 test.step(function() { assert_unreached("Bad load succeeded.") })153 });154 e.addEventListener("error", function() {155 test.step(function() {156 var background = window.getComputedStyle(div, null).getPropertyValue("background-color");157 assert_not_equals(background, that.passValue);158 test.done();159 });160 });161 }162 container.appendChild(div);163 container.appendChild(e);164 this.customCallback(e, container);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var WPT = require('webpagetest');2var wpt = new WPT('API_KEY');3wpt.getTestResults('TEST_ID', function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data.data.median.firstView.subresourc

Full Screen

Using AI Code Generation

copy

Full Screen

1function run_test()2{3 var testpath = get_root_directory(gTestPath);4 var srv = createServer({hosts: [["*", testpath + "files"]]});5 srv.registerDirectory("/data/", testpath + "data");6 srv.start(-1);7 var channel = make_channel(testURL);8 channel.asyncOpen(new ChannelListener(checkRequest, channel), null);9 do_test_pending();10}11function checkRequest(request, data, ctx)12{13 do_check_eq(data, "test");14 do_test_finished();15}16function make_channel(url)17{18 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);19 return ios.newChannel(url, "", null);20}21function get_root_directory(aTestPath)22{23 var rootDirectory = aTestPath.replace(/\/[^\/]*$/, "");24 return rootDirectory;25}26function createServer(aOptions)27{28 var srv = new HttpServer();29 srv.start(-1);30 srv.registerPathHandler("/subresource", subresource_handler);31 return srv;32}33function subresource_handler(request, response)34{35 response.setHeader("Content-Type", "text/plain", false);36 response.bodyOutputStream.write("test", 4);37}38+interface HttpServer : nsISupports {39+ void registerDirectory(in string aPath, in nsIFile aDirectory);40+ void registerPathHandler(in string aPath, in HttpHandler aHandler);41+ void start(in long aPort);42+ void stop();43+};44+interface HttpServer : nsISupports {

Full Screen

Using AI Code Generation

copy

Full Screen

1var subresource = subresource_element("test.png");2document.body.appendChild(subresource);3var subresource = subresource_element("test2.png");4document.body.appendChild(subresource);5var subresource = subresource_element("test3.png");6document.body.appendChild(subresource);7var subresource = subresource_element("test4.png");8document.body.appendChild(subresource);9var subresource = subresource_element("test5.png");10document.body.appendChild(subresource);11var subresource = subresource_element("test6.png");12document.body.appendChild(subresource);13var subresource = subresource_element("test7.png");14document.body.appendChild(subresource);15var subresource = subresource_element("test8.png");16document.body.appendChild(subresource);17var subresource = subresource_element("test9.png");18document.body.appendChild(subresource);19var subresource = subresource_element("test10.png");20document.body.appendChild(subresource);21var subresource = subresource_element("test11.png");22document.body.appendChild(subresource);23var subresource = subresource_element("test12.png");24document.body.appendChild(subresource);25var subresource = subresource_element("test13.png");26document.body.appendChild(subresource);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wptdriver');2 if (err) {3 console.log('Error: ' + err);4 } else {5 console.log('Result: ' + result);6 }7});8var wpt = require('wptdriver');9 if (err) {10 console.log('Error: ' + err);11 } else {12 console.log('Result: ' + result);13 }14});15var wpt = require('wptdriver');16 if (err) {17 console.log('Error: ' + err);18 } else {19 console.log('Result: ' + result);20 }21});22var wpt = require('wptdriver');23 if (err) {24 console.log('Error: ' + err);25 } else {26 console.log('Result: ' + result);27 }28});29var wpt = require('wptdriver');30 if (err) {31 console.log('Error: ' + err);32 } else {33 console.log('Result: ' + result);34 }35});36var wpt = require('wptdriver');37 if (err) {38 console.log('Error: ' + err);39 } else {40 console.log('Result: ' + result);41 }42});

Full Screen

Using AI Code Generation

copy

Full Screen

1function subresource() {2 return subresource_element('wpt');3}4function subresource2() {5 return subresource_element('wpt2');6}7function subresource3() {8 return subresource_element('wpt3');9}10function subresource4() {11 return subresource_element('wpt4');12}13function subresource5() {14 return subresource_element('wpt5');15}16function subresource6() {17 return subresource_element('wpt6');18}19function subresource7() {20 return subresource_element('wpt7');21}22function subresource8() {23 return subresource_element('wpt8');24}25function subresource9() {26 return subresource_element('wpt9');27}28function subresource10() {29 return subresource_element('wpt10');30}31function subresource11() {32 return subresource_element('wpt11');33}34function subresource12() {35 return subresource_element('wpt12');36}37function subresource13() {38 return subresource_element('wpt13');39}40function subresource14() {41 return subresource_element('wpt14');42}43function subresource15() {44 return subresource_element('wpt15');45}46function subresource16() {47 return subresource_element('wpt16');48}49function subresource17() {50 return subresource_element('wpt17');51}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2wptdriver.subresource_element("id", "subresource", function(err, element) {3 console.log(element);4});5{ type: 'div',6 value: '' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2 console.log(element);3});4var wptdriver = require('wptdriver');5 console.log(element);6});7var wptdriver = require('wptdriver');8 console.log(element);9});10var wptdriver = require('wptdriver');11 console.log(element);12});13var wptdriver = require('wptdriver');14 console.log(element);15});16var wptdriver = require('wptdriver');17 console.log(element);18});19var wptdriver = require('wptdriver');20 console.log(element);21});22var wptdriver = require('wptdriver');23 console.log(element);24});25var wptdriver = require('wptdriver');26 console.log(element);27});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2wptdriver.subresource_element('css selector', 'div', function(err, result) {3console.log(result);4});5Your name to display (optional):6Your name to display (optional):7Your name to display (optional):8Your name to display (optional):9Your name to display (optional):10Your name to display (optional):11Your name to display (optional):12Your name to display (optional):13Your name to display (optional):14Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1const { WptDriver } = require("wptdriver");2const driver = new WptDriver();3const { By } = WptDriver;4(async () => {5 await driver.init();6 await driver.switchTo().frame("iframeResult");7 const element = await driver.subresource_element("submit_get", "submit");8 await element.click();9 await driver.switchTo().defaultContent();10 await driver.wait(async () => {11 const text = await driver.findElement(By.id("demo")).getText();12 return text === "Hello World!";13 });14 await driver.quit();15})();16const { WptDriver } = require("wptdriver");17const driver = new WptDriver();18const { By } = WptDriver;19(async () => {20 await driver.init();21 await driver.switchTo().frame("iframeResult");22 const elements = await driver.subresource_elements("submit_get", "submit");23 await elements[0].click();24 await driver.switchTo().defaultContent();25 await driver.wait(async () => {26 const text = await driver.findElement(By.id("demo")).getText();27 return text === "Hello World!";28 });29 await driver.quit();30})();31const { WptDriver } = require("wptdriver");32const driver = new WptDriver();33const { By } = WptDriver;34(async () => {35 await driver.init();36 await driver.switchTo().frame("iframeResult");37 const element = await driver.subresource_element("submit_get", "submit");

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