Best JavaScript code snippet using wpt
addItemDialog.js
Source:addItemDialog.js
1function AddItemDialog() {2 this.dialog = null;3 this.itemLevelInput = null;4 this.dropLevelInput = null;5 this.qualityInput = null;6 this.raritySelect = null;7 this.itemClassInput = null;8 this.baseTypeInput = null;9 this.socketsInput = null;10 this.inventorySizeInput = null;11 this.corruptedInput = null;12 this.identifiedInput = null;13 this.nameInput = null;14 this.influenceInput = null;15 this.fracturedItemInput = null;16 this.synthesisedItemInput = null;17 this.shapedMapInput = null;18 this.blightedMapInput = null;19 this.mapTierInput = null;20 this.gemLevelInput = null;21 this.stackSizeInput = null;22 this.explicitModsInput = null;23 this.showHiddenInput = null;24 this.identifiedLine = null;25 this.nameLine = null;26 this.fracturedItemLine = null;27 this.synthesisedItemLine = null;28 this.shapedMapLine = null;29 this.blightedMapLine == null;30 this.mapTierLine = null;31 this.gemLevelLine = null;32 this.stackSizeLine = null;33 this.areHiddenStatsShown = false;34 this.init = function() {35 this.dialog = document.getElementById( 'additem-dialog' );36 for (var i=0; i < this.dialog.children.length; i++) {37 var p = this.dialog.children[i];38 switch (p.getAttribute('data')) {39 case 'base-type':40 this.baseTypeInput = getTextField( p );41 this.baseTypeInput.addEventListener('keydown', onKeyDown);42 this.baseTypeInput.addEventListener('change', onChange);43 break;44 case 'class':45 this.itemClassInput = getTextField( p );46 this.itemClassInput.addEventListener('keydown', onKeyDown);47 this.itemClassInput.addEventListener('change', onChange);48 break;49 case 'item-level':50 this.itemLevelInput = getTextField( p );51 this.itemLevelInput.addEventListener('keydown', onKeyDown);52 break;53 case 'drop-level':54 this.dropLevelInput = getTextField( p );55 this.dropLevelInput.addEventListener('keydown', onKeyDown);56 break;57 case 'rarity':58 this.raritySelect = getSelect( p );59 this.raritySelect.addEventListener('keydown', onKeyDown);60 this.raritySelect.addEventListener('change', onChange);61 break;62 case 'inventory-size':63 this.inventorySizeInput = getTextField( p );64 this.inventorySizeInput.addEventListener('keydown', onKeyDown);65 break;66 case 'sockets':67 this.socketsInput = getTextField( p );68 this.socketsInput.addEventListener('keydown', onKeyDown);69 break;70 case 'quality':71 this.qualityInput = getTextField( p );72 this.qualityInput.addEventListener('keydown', onKeyDown);73 break;74 case 'corrupted':75 this.corruptedInput = $(p).find('span > input')[0];76 this.corruptedInput.addEventListener('keydown', onKeyDown);77 this.corruptedInput.addEventListener('change', onChange);78 break;79 case 'identified':80 this.identifiedLine = p;81 this.identifiedInput = $(p).find('span > input')[0];82 this.identifiedInput.addEventListener('keydown', onKeyDown);83 this.identifiedInput.addEventListener('change', onChange);84 break;85 case 'name':86 this.nameLine = p;87 this.nameInput = getTextField( p );88 this.nameInput.addEventListener('keydown', onKeyDown);89 break;90 case 'influence':91 this.influenceInput = getTextField( p );92 this.influenceInput.addEventListener('keydown', onKeyDown);93 break;94 case 'fracturedItem':95 this.fracturedItemLine = p;96 this.fracturedItemInput = $(p).find('span > input')[0];97 this.fracturedItemInput.addEventListener('keydown', onKeyDown);98 break;99 case 'synthesisedItem':100 this.synthesisedItemLine = p;101 this.synthesisedItemInput = $(p).find('span > input')[0];102 this.synthesisedItemInput.addEventListener('keydown', onKeyDown);103 break;104 case 'shaped-map':105 this.shapedMapLine = p;106 this.shapedMapInput = $(p).find('span > input')[0];107 this.shapedMapInput.addEventListener('keydown', onKeyDown);108 break;109 case 'blighted-map':110 this.blightedMapLine = p;111 this.blightedMapInput = $(p).find('span > input')[0];112 this.blightedMapInput.addEventListener('keydown', onKeyDown);113 break;114 case 'map-tier':115 this.mapTierLine = p;116 this.mapTierInput = getTextField(p);117 this.mapTierInput.addEventListener('keydown', onKeyDown);118 break;119 case 'gem-level':120 this.gemLevelLine = p;121 this.gemLevelInput = getTextField(p);122 this.gemLevelInput.addEventListener('keydown', onKeyDown);123 break;124 case 'stack-size':125 this.stackSizeLine = p;126 this.stackSizeInput = getTextField(p);127 this.stackSizeInput.addEventListener('keydown', onKeyDown);128 break;129 case 'explicit-mods':130 this.explicitModsInput = getTextField( p );131 this.explicitModsInput.addEventListener('keydown', onKeyDown);132 break;133 }134 }135 this.showHiddenInput = document.getElementById( 'show-hidden-stats-checkbox' );136 this.showHiddenInput.addEventListener('keydown', onKeyDown);137 this.showHiddenInput.addEventListener('change', onChange);138 this.clear();139 }140 this.show = function() {141 var position = this.findOptimalPosition();142 this.dialog.style.left = position.x;143 this.dialog.style.top = position.y;144 this.dialog.style.display = 'block';145 }146 this.hide = function() {147 this.dialog.style.display = 'none';148 }149 this.isOpen = function() {150 return this.dialog.style.display !== 'none';151 }152 this.clear = function() {153 this.itemLevelInput.value = "";154 this.dropLevelInput.value = "";155 this.qualityInput.value = "";156 this.raritySelect.selectedIndex = 0;157 this.itemClassInput.value = "";158 this.baseTypeInput.value = "";159 this.socketsInput.value = "";160 this.inventorySizeInput.value = "";161 this.identifiedInput.checked = false;162 this.corruptedInput.checked = false;163 this.nameInput.value = "";164 this.identifiedLine.style.display = "none";165 this.nameLine.style.display = "none";166 this.influenceInput.value = "";167 this.fracturedItemLine.style.display = this.areHiddenStatsShown ? "block" : "none";168 this.fracturedItemInput.checked = false;169 this.synthesisedItemLine.style.display = this.areHiddenStatsShown ? "block" : "none";170 this.synthesisedItemInput.checked = false;171 this.shapedMapLine.style.display = 'none';172 this.shapedMapInput.checked = false;173 this.blightedMapLine.style.display = 'none';174 this.blightedMapInput.checked = false;175 this.mapTierLine.style.display = 'none';176 this.mapTierInput.value = "1";177 this.stackSizeInput.value = "1";178 this.explicitModsInput.value = "";179 this.showHiddenInput.checked = this.areHiddenStatsShown;180 }181 // This is called whenever any value that affects visibility of identified182 // checkbox or name text field is changed.183 this.onChange = function(event) {184 this.areHiddenStatsShown = this.showHiddenInput.checked;185 // Show Shaped Map checkbox only for maps186 if (this.itemClassInput.value === 'Maps' || this.itemClassInput === 'Map') {187 this.shapedMapLine.style.display = 'block';188 this.blightedMapLine.style.display = 'block';189 this.mapTierLine.style.display = 'block';190 } else {191 this.shapedMapLine.style.display = 'none';192 this.blightedMapLine.style.display = 'none';193 this.mapTierLine.style.display = 'none';194 this.mapTierInput.value = '0';195 }196 // For non-magic items, never show idenfied or name.197 // They always count as not identified for the game.198 // We don't show the name separately even if they're corrupted.199 if (getSelectedText(this.raritySelect) === "Normal") {200 this.identifiedInput.checked = false;201 this.identifiedLine.style.display = "none";202 this.nameInput.value = this.baseTypeInput.value;203 this.nameLine.style.display = "none";204 }205 // Corrupted items are always identified.206 // We remove the identified checkbox and show the name input.207 // Note that this applies only to non-normal items.208 if (this.corruptedInput.checked) {209 this.identifiedInput.checked = true;210 this.identifiedLine.style.display = "block";211 this.nameLine.style.display = "block";212 } else {213 // Non-normal, non-corrupted items always display the id checkbox.214 this.identifiedLine.style.display = "block";215 }216 // Show name input field only for identified items.217 if (this.identifiedInput.checked) {218 this.nameLine.style.display = "block";219 }220 else {221 this.nameLine.style.display = "none";222 this.nameInput.value = this.baseTypeInput.value;223 }224 // Show Synthesis-exclusive stats only when Show Hidden is enabled225 if (this.areHiddenStatsShown) {226 this.fracturedItemLine.style.display = "block";227 this.synthesisedItemLine.style.display = "block";228 }229 else {230 this.fracturedItemLine.style.display = "none";231 this.fracturedItemInput.checked = false;232 this.synthesisedItemLine.style.display = "none";233 this.synthesisedItemInput.checked = false;234 }235 }236 this.focus = function() {237 this.baseTypeInput.focus();238 }239 this.getItem = function() {240 var inventorySize = parseInventorySize( this.inventorySizeInput.value );241 var result = {242 name: this.nameInput.value,243 itemLevel: parseInt( this.itemLevelInput.value ),244 dropLevel: parseInt( this.dropLevelInput.value ),245 quality: StrUtils.parseIntOrDefault( this.qualityInput.value, 0 ),246 rarity: Rarity.parse( getSelectedText( this.raritySelect ) ),247 itemClass: this.itemClassInput.value,248 baseType: this.baseTypeInput.value,249 width: inventorySize.width,250 height: inventorySize.height,251 sockets: parseSockets( this.socketsInput.value ),252 identified: this.identifiedInput.checked,253 corrupted: this.corruptedInput.checked,254 influence: Influence.parse( this.influenceInput.value ),255 fracturedItem: this.fracturedItemInput.checked,256 synthesisedItem: this.synthesisedItemInput.checked,257 shapedMap: this.shapedMapInput.checked,258 blightedMap: this.blightedMapInput.checked,259 mapTier: parseInt( this.mapTierInput.value ),260 gemLevel: parseInt( this.gemLevelInput.value ),261 stackSize: parseInt( this.stackSizeInput.value ),262 explicitMods: this.explicitModsInput.value.split(',')263 };264 ItemDefinition.validate( result );265 return result;266 }267 function parseInventorySize (str) {268 var parts = str.split( 'x' );269 if (parts.length !== 2 || isNaN(parseInt(parts[0])) || isNaN(parseInt(parts[1]))) {270 throw "Invalid Item Size. Expected {width}x{height}. Example: 2x3";271 }272 return {273 width: parseInt( parts[0] ),274 height: parseInt( parts[1] )275 };276 }277 function parseSockets (str) {278 for (var i=0; i < str.length; i++) {279 switch (str[i]) {280 case ' ':281 case 'R':282 case 'G':283 case 'B':284 break;285 default:286 throw "Invalid '" + str[i] + "' character in socket definition. Please use only R, G, B and Space";287 }288 }289 return str.split( ' ' );290 }291 function getTextField (elem) {292 return getChildOfType( elem, 'INPUT' );293 }294 function getInput (elem) {295 return getChildOfType( elem, 'INPUT' );296 }297 function getSelect (elem) {298 return getChildOfType( elem, 'SELECT' );299 }300 function getChildOfType (elem, type) {301 for (var i=0; i < elem.children.length; i++) {302 var child = elem.children[i];303 if (child.nodeName === type) {304 return child;305 }306 }307 }308 function getSelectedText (select) {309 var i = select.selectedIndex;310 return select.options[i].text;311 }312 this.findOptimalPosition = function() {313 // make visible so we can read actual size314 var previousDisplay = this.dialog.style.display;315 this.dialog.style.display = 'block';316 var button = document.getElementById( 'additem-button' );317 var buttonRect = button.getBoundingClientRect();318 var dialogRect = this.dialog.getBoundingClientRect();319 var canPlaceRight = buttonRect.right + dialogRect.width <= window.innerWidth;320 var canPlaceBottom = buttonRect.bottom + dialogRect.height <= window.innerHeight;321 var canPlaceLeft = buttonRect.left - dialogRect.width >= 0;322 var canPlaceTop = buttonRect.top - dialogRect.height >= 0;323 var optimalX = 0;324 var optimalY = 0;325 if (canPlaceRight) { optimalX = buttonRect.right; }326 else if (canPlaceLeft) { optimalX = buttonRect.left - dialogRect.width; }327 else { optimalX = window.innerWidth - dialogRect.width; }328 if (canPlaceBottom) { optimalY = buttonRect.bottom; }329 else if (canPlaceTop) { optimalY = buttonRect.top - dialogRect.height; }330 else { optimalX = window.innerHeight - dialogRect.height; }331 // undo any changes to visibility332 this.dialog.style.display = previousDisplay;333 return {334 x: optimalX,335 y: optimalY336 };337 }338 function onKeyDown(event) {339 var keyCode = EventUtils.getKeyCode(event);340 // Enter341 if (keyCode === 13) {342 PoEdit.addItemDialog.onPressEnter();343 return;344 }345 // Esc346 if (keyCode === 27) {347 PoEdit.addItemDialog.hide();348 PoEdit.addItemDialog.clear();349 }350 }351 function onChange(event) {352 PoEdit.addItemDialog.onChange(event);353 }...
decompression-corrupt-input.tentative.any.js
Source:decompression-corrupt-input.tentative.any.js
1// META global=window,worker2// This test checks that DecompressionStream behaves according to the standard3// when the input is corrupted. To avoid a combinatorial explosion in the4// number of tests, we only mutate one field at a time, and we only test5// "interesting" values.6'use strict';7// The many different cases are summarised in this data structure.8const expectations = [9 {10 format: 'deflate',11 // Decompresses to 'expected output'.12 baseInput: [120, 156, 75, 173, 40, 72, 77, 46, 73, 77, 81, 200, 47, 45, 41,13 40, 45, 1, 0, 48, 173, 6, 36],14 // See RFC1950 for the definition of the various fields used by deflate:15 // https://tools.ietf.org/html/rfc1950.16 fields: [17 {18 // The function of this field. This matches the name used in the RFC.19 name: 'CMF',20 // The offset of the field in bytes from the start of the input.21 offset: 0,22 // The length of the field in bytes.23 length: 1,24 cases: [25 {26 // The value to set the field to. If the field contains multiple27 // bytes, all the bytes will be set to this value.28 value: 0,29 // The expected result. 'success' means the input is decoded30 // successfully. 'error' means that the stream will be errored.31 result: 'error'32 }33 ]34 },35 {36 name: 'FLG',37 offset: 1,38 length: 1,39 // FLG contains a 4-bit checksum (FCHECK) which is calculated in such a40 // way that there are 4 valid values for this field.41 cases: [42 {43 value: 218,44 result: 'success'45 },46 {47 value: 1,48 result: 'success'49 },50 {51 value: 94,52 result: 'success'53 },54 {55 // The remaining 252 values cause an error.56 value: 157,57 result: 'error'58 }59 ]60 },61 {62 name: 'DATA',63 // In general, changing any bit of the data will trigger a checksum64 // error. Only the last byte does anything else.65 offset: 18,66 length: 1,67 cases: [68 {69 value: 4,70 result: 'success'71 },72 {73 value: 5,74 result: 'error'75 }76 ]77 },78 {79 name: 'ADLER',80 offset: -4,81 length: 4,82 cases: [83 {84 value: 255,85 result: 'error'86 }87 ]88 }89 ]90 },91 {92 format: 'gzip',93 // Decompresses to 'expected output'.94 baseInput: [31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 75, 173, 40, 72, 77, 46, 73,95 77, 81, 200, 47, 45, 41, 40, 45, 1, 0, 176, 1, 57, 179, 15, 0,96 0, 0],97 // See RFC1952 for the definition of the various fields used by gzip:98 // https://tools.ietf.org/html/rfc1952.99 fields: [100 {101 name: 'ID',102 offset: 0,103 length: 2,104 cases: [105 {106 value: 255,107 result: 'error'108 }109 ]110 },111 {112 name: 'CM',113 offset: 2,114 length: 1,115 cases: [116 {117 value: 0,118 result: 'error'119 }120 ]121 },122 {123 name: 'FLG',124 offset: 3,125 length: 1,126 cases: [127 {128 value: 1, // FTEXT129 result: 'success'130 },131 {132 value: 2, // FHCRC133 result: 'error'134 }135 ]136 },137 {138 name: 'MTIME',139 offset: 4,140 length: 4,141 cases: [142 {143 // Any value is valid for this field.144 value: 255,145 result: 'success'146 }147 ]148 },149 {150 name: 'XFL',151 offset: 8,152 length: 1,153 cases: [154 {155 // Any value is accepted.156 value: 255,157 result: 'success'158 }159 ]160 },161 {162 name: 'OS',163 offset: 9,164 length: 1,165 cases: [166 {167 // Any value is accepted.168 value: 128,169 result: 'success'170 }171 ]172 },173 {174 name: 'DATA',175 // The last byte of the data is the most interesting.176 offset: 26,177 length: 1,178 cases: [179 {180 value: 3,181 result: 'error'182 },183 {184 value: 4,185 result: 'success'186 }187 ]188 },189 {190 name: 'CRC',191 offset: -8,192 length: 4,193 cases: [194 {195 // Any change will error the stream.196 value: 0,197 result: 'error'198 }199 ]200 },201 {202 name: 'ISIZE',203 offset: -4,204 length: 4,205 cases: [206 {207 // A mismatch will error the stream.208 value: 1,209 result: 'error'210 }211 ]212 }213 ]214 }215];216async function tryDecompress(input, format) {217 const ds = new DecompressionStream(format);218 const reader = ds.readable.getReader();219 const writer = ds.writable.getWriter();220 writer.write(input).catch(() => {});221 writer.close().catch(() => {});222 let out = [];223 while (true) {224 try {225 const { value, done } = await reader.read();226 if (done) {227 break;228 }229 out = out.concat(Array.from(value));230 } catch (e) {231 return { result: 'error' };232 }233 }234 const expectedOutput = 'expected output';235 if (out.length !== expectedOutput.length) {236 return { result: 'corrupt' };237 }238 for (let i = 0; i < out.length; ++i) {239 if (out[i] !== expectedOutput.charCodeAt(i)) {240 return { result: 'corrupt' };241 }242 }243 return { result: 'success' };244}245function corruptInput(input, offset, length, value) {246 const output = new Uint8Array(input);247 if (offset < 0) {248 offset += input.length;249 }250 for (let i = offset; i < offset + length; ++i) {251 output[i] = value;252 }253 return output;254}255for (const { format, baseInput, fields } of expectations) {256 promise_test(async () => {257 const { result } = await tryDecompress(new Uint8Array(baseInput), format);258 assert_equals(result, 'success', 'decompression should succeed');259 }, `the unchanged input for '${format}' should decompress successfully`);260 promise_test(async () => {261 const truncatedInput = new Uint8Array(baseInput.slice(0, -1));262 const { result } = await tryDecompress(truncatedInput, format);263 assert_equals(result, 'error', 'decompression should fail');264 }, `truncating the input for '${format}' should give an error`);265 promise_test(async () => {266 const extendedInput = new Uint8Array(baseInput.concat([0]));267 const { result } = await tryDecompress(extendedInput, format);268 assert_equals(result, 'error', 'decompression should fail');269 }, `trailing junk for '${format}' should give an error`);270 for (const { name, offset, length, cases } of fields) {271 for (const { value, result } of cases) {272 promise_test(async () => {273 const corruptedInput = corruptInput(baseInput, offset, length, value);274 const { result: actual } =275 await tryDecompress(corruptedInput, format);276 assert_equals(actual, result, 'result should match');277 }, `format '${format}' field ${name} should be ${result} for ${value}`);278 }279 }...
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3var options = {4};5test.runTest(options, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});
Using AI Code Generation
1var wpt = require('webpagetest');2var fs = require('fs');3var exec = require('child_process').exec;4var child;5var wpt = new WebPageTest('www.webpagetest.org', 'A.3b6a7c1a1a8b0f3a0e1e9f2e2b3a3b1d');6var options = {7};8var test = wpt.runTest(url, options, function(err, data) {9 if (err) return console.log(err);10 console.log(data);11 var id = data.data.testId;12 var url = data.data.summary;13 console.log(id);14 console.log(url);15 var child = exec('node corruptedInput.js ' + id + ' ' + url, function(err, stdout, stderr) {16 console.log(stdout);17 console.log(stderr);18 if (err !== null) {19 console.log('exec error: ' + err);20 }21 });22});23var wpt = require('webpagetest');24var fs = require('fs');25var exec = require('child_process').exec;26var child;27var wpt = new WebPageTest('www.webpagetest.org', 'A.3b6a7c1a1a8b0f3a0e1e9f2e2b3a3b1d');28var id = process.argv[2];29var url = process.argv[3];30console.log(id);31console.log(url);32var test = wpt.getTestResults(id, function(err, data) {33 if (err) return console.log(err);34 console.log(data);35 var corruptedInput = data.data.median.firstView.results;36 console.log(corruptedInput);37 fs.writeFile('corruptedInput.json', JSON.stringify(corruptedInput, null, 4), function(err) {38 if (err) {39 console.log(err);40 } else {41 console.log("JSON saved to corruptedInput.json");42 }43 });44 var child = exec('node test2.js', function(err, stdout, stderr) {45 console.log(stdout);46 console.log(stderr);47 if (
Using AI Code Generation
1var wpt = require('webpagetest');2var location = 'Dulles:Chrome';3var runs = 3;4var firstViewOnly = false;5var connectivity = 'Cable';6var bandwidthDown = 5000;7var latency = 28;8var packetLoss = 0;9var label = 'test';10webpagetest.corruptedInput(url, location, runs, firstViewOnly, connectivity, bandwidthDown, latency, packetLoss, label, function(err, data) {11 if(err) {12 console.log(err);13 }14 else if(data) {15 console.log(data);16 }17});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('A.7c4d4c9f4a8c1a4b7f4b1f1fa7a8c2a2');3var options = {4};5test.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options.key);5 if (err) return console.error(err);6 console.log(data);7});8 if (err) return console.error(err);9 console.log(data);10});11}, function(err, data) {12 if (err) return console.error(err);13 console.log(data);14});15}, function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19}, function(err, data) {20 if (err) return console.error(err);21 console.log(data);22});23}, function(err, data) {24 if (err) return console.error(err);
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!!