Best JavaScript code snippet using wpt
fetch-canvas-tainting-tests.js
Source:fetch-canvas-tainting-tests.js
1// This is the main driver of the canvas tainting tests.2const NOT_TAINTED = 'NOT_TAINTED';3const TAINTED = 'TAINTED';4const LOAD_ERROR = 'LOAD_ERROR';5let frame;6// Creates a single promise_test.7function canvas_taint_test(url, cross_origin, expected_result) {8 promise_test(t => {9 return frame.contentWindow.create_test_case_promise(url, cross_origin)10 .then(result => {11 assert_equals(result, expected_result);12 });13 }, 'url "' + url + '" with crossOrigin "' + cross_origin + '" should be ' +14 expected_result);15}16// Runs all the tests. The given |params| has these properties:17// * |resource_path|: the relative path to the (image/video) resource to test.18// * |cache|: when true, the service worker bounces responses into19// Cache Storage and back out before responding with them.20function do_canvas_tainting_tests(params) {21 const host_info = get_host_info();22 let resource_path = params.resource_path;23 if (params.cache)24 resource_path += "&cache=true";25 const resource_url = host_info['HTTPS_ORIGIN'] + resource_path;26 const remote_resource_url = host_info['HTTPS_REMOTE_ORIGIN'] + resource_path;27 // Set up the service worker and the frame.28 promise_test(function(t) {29 const SCOPE = 'resources/fetch-canvas-tainting-iframe.html';30 const SCRIPT = 'resources/fetch-rewrite-worker.js';31 const host_info = get_host_info();32 // login_https() is needed because some test cases use credentials.33 return login_https(t)34 .then(function() {35 return service_worker_unregister_and_register(t, SCRIPT, SCOPE);36 })37 .then(function(registration) {38 promise_test(() => {39 if (frame)40 frame.remove();41 return registration.unregister();42 }, 'restore global state');43 return wait_for_state(t, registration.installing, 'activated');44 })45 .then(function() { return with_iframe(SCOPE); })46 .then(f => {47 frame = f;48 });49 }, 'initialize global state');50 // Reject tests. Add '&reject' so the service worker responds with a rejected promise.51 // A load error is expected.52 canvas_taint_test(resource_url + '&reject', '', LOAD_ERROR);53 canvas_taint_test(resource_url + '&reject', 'anonymous', LOAD_ERROR);54 canvas_taint_test(resource_url + '&reject', 'use-credentials', LOAD_ERROR);55 // Fallback tests. Add '&ignore' so the service worker does not respond to the fetch56 // request, and we fall back to network.57 canvas_taint_test(resource_url + '&ignore', '', NOT_TAINTED);58 canvas_taint_test(remote_resource_url + '&ignore', '', TAINTED);59 canvas_taint_test(remote_resource_url + '&ignore', 'anonymous', LOAD_ERROR);60 canvas_taint_test(61 remote_resource_url + '&ACAOrigin=' + host_info['HTTPS_ORIGIN'] +62 '&ignore',63 'anonymous',64 NOT_TAINTED);65 canvas_taint_test(remote_resource_url + '&ignore', 'use-credentials', LOAD_ERROR);66 canvas_taint_test(67 remote_resource_url + '&ACAOrigin=' + host_info['HTTPS_ORIGIN'] +68 '&ignore',69 'use-credentials',70 LOAD_ERROR);71 canvas_taint_test(72 remote_resource_url + '&ACAOrigin=' + host_info['HTTPS_ORIGIN'] +73 '&ACACredentials=true&ignore',74 'use-credentials',75 NOT_TAINTED);76 // Credential tests (with fallback). Add '&Auth' so the server requires authentication.77 // Furthermore, add '&ignore' so the service worker falls back to network.78 canvas_taint_test(resource_url + '&Auth&ignore', '', NOT_TAINTED);79 canvas_taint_test(remote_resource_url + '&Auth&ignore', '', TAINTED);80 canvas_taint_test(81 remote_resource_url + '&Auth&ignore', 'anonymous', LOAD_ERROR);82 canvas_taint_test(83 remote_resource_url + '&Auth&ignore',84 'use-credentials',85 LOAD_ERROR);86 canvas_taint_test(87 remote_resource_url + '&Auth&ACAOrigin=' + host_info['HTTPS_ORIGIN'] +88 '&ignore',89 'use-credentials',90 LOAD_ERROR);91 canvas_taint_test(92 remote_resource_url + '&Auth&ACAOrigin=' + host_info['HTTPS_ORIGIN'] +93 '&ACACredentials=true&ignore',94 'use-credentials',95 NOT_TAINTED);96 // In the following tests, the service worker provides a response.97 // Add '&url' so the service worker responds with fetch(url).98 // Add '&mode' to configure the fetch request options.99 // Basic response tests. Set &url to the original url.100 canvas_taint_test(101 resource_url + '&mode=same-origin&url=' + encodeURIComponent(resource_url),102 '',103 NOT_TAINTED);104 canvas_taint_test(105 resource_url + '&mode=same-origin&url=' + encodeURIComponent(resource_url),106 'anonymous',107 NOT_TAINTED);108 canvas_taint_test(109 resource_url + '&mode=same-origin&url=' + encodeURIComponent(resource_url),110 'use-credentials',111 NOT_TAINTED);112 canvas_taint_test(113 remote_resource_url + '&mode=same-origin&url=' +114 encodeURIComponent(resource_url),115 '',116 NOT_TAINTED);117 canvas_taint_test(118 remote_resource_url + '&mode=same-origin&url=' +119 encodeURIComponent(resource_url),120 'anonymous',121 NOT_TAINTED);122 canvas_taint_test(123 remote_resource_url + '&mode=same-origin&url=' +124 encodeURIComponent(resource_url),125 'use-credentials',126 NOT_TAINTED);127 // Opaque response tests. Set &url to the cross-origin URL, and &mode to128 // 'no-cors' so we expect an opaque response.129 canvas_taint_test(130 resource_url +131 '&mode=no-cors&url=' + encodeURIComponent(remote_resource_url),132 '',133 TAINTED);134 canvas_taint_test(135 resource_url +136 '&mode=no-cors&url=' + encodeURIComponent(remote_resource_url),137 'anonymous',138 LOAD_ERROR);139 canvas_taint_test(140 resource_url +141 '&mode=no-cors&url=' + encodeURIComponent(remote_resource_url),142 'use-credentials',143 LOAD_ERROR);144 canvas_taint_test(145 remote_resource_url +146 '&mode=no-cors&url=' + encodeURIComponent(remote_resource_url),147 '',148 TAINTED);149 canvas_taint_test(150 remote_resource_url +151 '&mode=no-cors&url=' + encodeURIComponent(remote_resource_url),152 'anonymous',153 LOAD_ERROR);154 canvas_taint_test(155 remote_resource_url +156 '&mode=no-cors&url=' + encodeURIComponent(remote_resource_url),157 'use-credentials',158 LOAD_ERROR);159 // CORS response tests. Set &url to the cross-origin URL, and &mode160 // to 'cors' to attempt a CORS request.161 canvas_taint_test(162 resource_url + '&mode=cors&url=' +163 encodeURIComponent(remote_resource_url +164 '&ACAOrigin=' + host_info['HTTPS_ORIGIN']),165 '',166 LOAD_ERROR); // We expect LOAD_ERROR since the server doesn't respond167 // with an Access-Control-Allow-Credentials header.168 canvas_taint_test(169 resource_url + '&mode=cors&credentials=same-origin&url=' +170 encodeURIComponent(remote_resource_url +171 '&ACAOrigin=' + host_info['HTTPS_ORIGIN']),172 '',173 NOT_TAINTED);174 canvas_taint_test(175 resource_url + '&mode=cors&url=' +176 encodeURIComponent(remote_resource_url +177 '&ACAOrigin=' + host_info['HTTPS_ORIGIN']),178 'anonymous',179 NOT_TAINTED);180 canvas_taint_test(181 resource_url + '&mode=cors&url=' +182 encodeURIComponent(remote_resource_url +183 '&ACAOrigin=' + host_info['HTTPS_ORIGIN']),184 'use-credentials',185 LOAD_ERROR); // We expect LOAD_ERROR since the server doesn't respond186 // with an Access-Control-Allow-Credentials header.187 canvas_taint_test(188 resource_url + '&mode=cors&url=' +189 encodeURIComponent(190 remote_resource_url +191 '&ACACredentials=true&ACAOrigin=' + host_info['HTTPS_ORIGIN']),192 'use-credentials',193 NOT_TAINTED);194 canvas_taint_test(195 remote_resource_url + '&mode=cors&url=' +196 encodeURIComponent(remote_resource_url +197 '&ACAOrigin=' + host_info['HTTPS_ORIGIN']),198 '',199 LOAD_ERROR); // We expect LOAD_ERROR since the server doesn't respond200 // with an Access-Control-Allow-Credentials header.201 canvas_taint_test(202 remote_resource_url + '&mode=cors&credentials=same-origin&url=' +203 encodeURIComponent(remote_resource_url +204 '&ACAOrigin=' + host_info['HTTPS_ORIGIN']),205 '',206 NOT_TAINTED);207 canvas_taint_test(208 remote_resource_url + '&mode=cors&url=' +209 encodeURIComponent(remote_resource_url +210 '&ACAOrigin=' + host_info['HTTPS_ORIGIN']),211 'anonymous',212 NOT_TAINTED);213 canvas_taint_test(214 remote_resource_url + '&mode=cors&url=' +215 encodeURIComponent(remote_resource_url +216 '&ACAOrigin=' + host_info['HTTPS_ORIGIN']),217 'use-credentials',218 LOAD_ERROR); // We expect LOAD_ERROR since the server doesn't respond219 // with an Access-Control-Allow-Credentials header.220 canvas_taint_test(221 remote_resource_url + '&mode=cors&url=' +222 encodeURIComponent(223 remote_resource_url +224 '&ACACredentials=true&ACAOrigin=' + host_info['HTTPS_ORIGIN']),225 'use-credentials',226 NOT_TAINTED);...
defaultFodder.js
Source:defaultFodder.js
1crystal.loadExternal({2 basepath: "https://www.stormlin.com/",3 type: "defaultFodder",4 storagekey: "crystal_defaultFodder",5 version: "20190730",6 default_index_link: [7 "http://users.qq.com",8 "http://users.qq.com",9 "http://time.qq.com/?pgv_ref=ad",10 "https://news.qq.com/mobile/index.htm"11 ],12 default_index_count: 4,13 default_qq: {14 "15.2": [15 {16 scale: 15.2,17 size: "big",18 resource_url: "1400x90_[index].png"19 }20 ],21 "12.0": [22 {23 scale: 12.0,24 size: "big",25 resource_url: "920x75_[index].png"26 }27 ],28 "10.8": [29 {30 scale: 10.8,31 resource_url: "1000x90_[index].png"32 }33 ],34 "10.22": [35 {36 scale: 10.22,37 resource_url: "920x90_[index].png"38 }39 ],40 "10": [41 {42 scale: 10,43 resource_url: "960x90_[index].png"44 }45 ],46 "8.5": [47 {48 scale: 8.5,49 resource_url: "700x75_[index].png"50 }51 ],52 "7.7": [53 {54 scale: 7.7,55 resource_url: "700x90_[index].png"56 }57 ],58 "7.3": [59 {60 scale: 7.3,61 resource_url: "660x90_[index].png"62 }63 ],64 "5.3": [65 {66 scale: 5.3,67 resource_url: "640x120_[index].png"68 }69 ],70 "4.8": [71 {72 scale: 4.8,73 resource_url: "440x90_[index].png"74 }75 ],76 "3.57": [77 {78 scale: 3.57,79 resource_url: "280x90_[index].png"80 }81 ],82 "3.3": [83 {84 scale: 3.3,85 resource_url: "280x90_[index].png"86 }87 ],88 "2.1": [89 {90 scale: 2.1,91 resource_url: "240x100_[index].png"92 }93 ],94 "1.55": [95 {96 scale: 1.55,97 resource_url: "300x190_[index].png"98 }99 ],100 "1.2": [101 {102 scale: 1.2,103 resource_url: "300x250_[index].png"104 }105 ],106 "1.12": [107 {108 scale: 1.12,109 resource_url: "320x285_[index].png"110 }111 ],112 "1.0": [113 {114 scale: 1.0,115 resource_url: "250x230_[index].png"116 }117 ],118 "0.7": [119 {120 scale: 0.7,121 resource_url: "280x320_[index].png"122 }123 ],124 "0.4": [125 {126 scale: 0.4,127 resource_url: "300x600_[index].png"128 }129 ],130 "0": [131 {132 scale: 0,133 resource_url: "180x600_[index].png"134 }135 ]136 },137 www: {138 "12.0": [139 {140 scale: 12.0,141 size: "big",142 priority: 1,143 resource_url: "https://www.stormlin.com/920x75_www.png",144 link_to: "https://news.qq.com/mobile/index.htm"145 }146 ],147 "10.22": [148 {149 scale: 10.22,150 priority: 1,151 resource_url: "https://www.stormlin.com/920x90_www.png",152 link_to: "https://news.qq.com/mobile/index.htm"153 }154 ],155 "15.2": [156 {157 scale: 15.2,158 priority: 1,159 resource_url:160 "https://www.stormlin.com/1400x90_www.png",161 link_to: "https://news.qq.com/mobile/index.htm"162 }163 ]164 },165 v: []...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var url = wpt.resourceUrl('images/logo.png');4console.log(url);5var wpt = require('webpagetest');6var wpt = new WebPageTest('www.webpagetest.org');7var url = wpt.resourceUrl('images/logo.png');8console.log(url);9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11var url = wpt.resourceUrl('images/logo.png');12console.log(url);13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15var url = wpt.resourceUrl('images/logo.png');16console.log(url);17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19var url = wpt.resourceUrl('images/logo.png');20console.log(url);21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23var url = wpt.resourceUrl('images/logo.png');24console.log(url);25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27var url = wpt.resourceUrl('images/logo.png');28console.log(url);29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1var resource_url = require('wpt/resource_url');2var url = resource_url('test.jpg');3console.log(url);4var resource_url = require('wpt/resource_url');5var url = resource_url('test.jpg');6console.log(url);7var resource_url = require('wpt/resource_url');8var url = resource_url('test.jpg');9console.log(url);10var resource_url = require('wpt/resource_url');11var url = resource_url('test.jpg');12console.log(url);13var resource_url = require('wpt/resource_url');14var url = resource_url('test.jpg');15console.log(url);16var resource_url = require('wpt/resource_url');17var url = resource_url('test.jpg');18console.log(url);19var resource_url = require('wpt/resource_url');20var url = resource_url('test.jpg');21console.log(url);22var resource_url = require('wpt/resource_url');23var url = resource_url('test.jpg');24console.log(url);25var resource_url = require('wpt/resource_url');26var url = resource_url('test.jpg');27console.log(url);28var resource_url = require('wpt/resource_url');29var url = resource_url('test.jpg');30console.log(url);31var resource_url = require('w
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getTestStatus('130618_3K_3c1e8a6d0e0f5e9a2a6f8d0d5a6a0a1f', function(err, data) {4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8wpt.getTestStatus('130618_3K_3c1e8a6d0e0f5e9a2a6f8d0d5a6a0a1f', function(err, data) {9 console.log(data);10});11var http = require('http');12var server = http.createServer(function (request, response) {13 response.writeHead(200, {"Content-Type":
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('API_KEY');3var fs = require('fs');4var request = require('request');5var options = {6};7client.runTest(url, options, function(err, data) {8 if (err) {9 console.log(err);10 } else {11 console.log(data);12 var testId = data.data.testId;13 client.getTestResults(testId, function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 var image_url = client.resource_url(testId, data.data.median.firstView.images[0].image);19 console.log(image_url);20 request(image_url).pipe(fs.createWriteStream('image.png'));21 }22 });23 }24});
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!!