Best JavaScript code snippet using wpt
test-box-properties.js
Source:test-box-properties.js
1"use strict";2(function(exports) {3 const sheet = document.head.appendChild(document.createElement("style"));4 // Specify size for outer <div> to avoid unconstrained-size warnings5 // when writing-mode of the inner test <div> is vertical-*6 const wrapper = document.body.appendChild(document.createElement("div"));7 wrapper.style.cssText = "width:100px; height: 100px;";8 const testElement = wrapper.appendChild(document.createElement("div"));9 testElement.id = testElement.className = "test";10 // Values to use while testing11 const testValues = {12 "length": ["1px", "2px", "3px", "4px", "5px"],13 "color": ["rgb(1, 1, 1)", "rgb(2, 2, 2)", "rgb(3, 3, 3)", "rgb(4, 4, 4)", "rgb(5, 5, 5)"],14 "border-style": ["solid", "dashed", "dotted", "double", "groove"],15 };16 // Six unique overall writing modes for property-mapping purposes.17 const writingModes = [18 {19 styles: [20 {"writing-mode": "horizontal-tb", "direction": "ltr"},21 ],22 blockStart: "top", blockEnd: "bottom", inlineStart: "left", inlineEnd: "right",23 block: "vertical", inline: "horizontal" },24 {25 styles: [26 {"writing-mode": "horizontal-tb", "direction": "rtl"},27 ],28 blockStart: "top", blockEnd: "bottom", inlineStart: "right", inlineEnd: "left",29 block: "vertical", inline: "horizontal" },30 {31 styles: [32 {"writing-mode": "vertical-rl", "direction": "rtl"},33 {"writing-mode": "sideways-rl", "direction": "rtl"},34 ],35 blockStart: "right", blockEnd: "left", inlineStart: "bottom", inlineEnd: "top",36 block: "horizontal", inline: "vertical" },37 {38 styles: [39 {"writing-mode": "vertical-rl", "direction": "ltr"},40 {"writing-mode": "sideways-rl", "direction": "ltr"},41 ],42 blockStart: "right", blockEnd: "left", inlineStart: "top", inlineEnd: "bottom",43 block: "horizontal", inline: "vertical" },44 {45 styles: [46 {"writing-mode": "vertical-lr", "direction": "rtl"},47 {"writing-mode": "sideways-lr", "direction": "ltr"},48 ],49 blockStart: "left", blockEnd: "right", inlineStart: "bottom", inlineEnd: "top",50 block: "horizontal", inline: "vertical" },51 {52 styles: [53 {"writing-mode": "vertical-lr", "direction": "ltr"},54 {"writing-mode": "sideways-lr", "direction": "rtl"},55 ],56 blockStart: "left", blockEnd: "right", inlineStart: "top", inlineEnd: "bottom",57 block: "horizontal", inline: "vertical" },58 ];59 function testCSSValues(testName, style, expectedValues) {60 for (const [property, value] of expectedValues) {61 assert_equals(style.getPropertyValue(property), value, `${testName}, ${property}`);62 }63 }64 function testComputedValues(testName, rules, expectedValues) {65 sheet.textContent = rules;66 const cs = getComputedStyle(testElement);67 testCSSValues(testName, cs, expectedValues);68 sheet.textContent = "";69 }70 function makeDeclaration(object = {}, replacement = "*") {71 let decl = "";72 for (const [property, value] of Object.entries(object)) {73 decl += `${property.replace("*", replacement)}: ${value}; `;74 }75 return decl;76 }77 /**78 * Creates a group of physical and logical box properties, such as79 *80 * { physical: {81 * left: "margin-left", right: "margin-right",82 * top: "margin-top", bottom: "margin-bottom",83 * }, logical: {84 * inlineStart: "margin-inline-start", inlineEnd: "margin-inline-end",85 * blockStart: "margin-block-start", blockEnd: "margin-block-end",86 * }, type: "length", prerequisites: "...", property: "'margin-*'" }87 *88 * @param {string} property89 * A string representing the property names, like "margin-*".90 * @param {Object} descriptor91 * @param {string} descriptor.type92 * Describes the kind of values accepted by the property, like "length".93 * Must be a key from the `testValues` object.94 * @param {Object={}} descriptor.prerequisites95 * Represents property declarations that are needed by `property` to work.96 * For example, border-width properties require a border style.97 */98 exports.createBoxPropertyGroup = function(property, descriptor) {99 const logical = {};100 const physical = {};101 for (const logicalSide of ["inline-start", "inline-end", "block-start", "block-end"]) {102 const camelCase = logicalSide.replace(/-(.)/g, (match, $1) => $1.toUpperCase());103 logical[camelCase] = property.replace("*", logicalSide);104 }105 const isInset = property === "inset-*";106 let prerequisites = "";107 for (const physicalSide of ["left", "right", "top", "bottom"]) {108 physical[physicalSide] = isInset ? physicalSide : property.replace("*", physicalSide);109 prerequisites += makeDeclaration(descriptor.prerequisites, physicalSide);110 }111 return {name, logical, physical, type: descriptor.type, prerequisites, property};112 };113 /**114 * Creates a group of physical and logical sizing properties.115 *116 * @param {string} prefix117 * One of "", "max-" or "min-".118 */119 exports.createSizingPropertyGroup = function(prefix) {120 return {121 logical: {122 inline: `${prefix}inline-size`,123 block: `${prefix}block-size`,124 },125 physical: {126 horizontal: `${prefix}width`,127 vertical: `${prefix}height`,128 },129 type: "length",130 prerequisites: makeDeclaration({display: "block"}),131 property: (prefix ? prefix.slice(0, -1) + " " : "") + "sizing",132 };133 };134 /**135 * Tests a grup of logical and physical properties in different writing modes.136 *137 * @param {Object} group138 * An object returned by createBoxPropertyGroup or createSizingPropertyGroup.139 */140 exports.runTests = function(group) {141 const values = testValues[group.type];142 const logicals = Object.values(group.logical);143 const physicals = Object.values(group.physical);144 test(function() {145 const expected = [];146 for (const [i, logicalProp] of logicals.entries()) {147 testElement.style.setProperty(logicalProp, values[i]);148 expected.push([logicalProp, values[i]]);149 }150 testCSSValues("logical properties in inline style", testElement.style, expected);151 testElement.style.cssText = "";152 }, `Test that logical ${group.property} properties are supported.`);153 for (const writingMode of writingModes) {154 for (const style of writingMode.styles) {155 const writingModeDecl = makeDeclaration(style);156 const associated = {};157 for (const [logicalSide, logicalProp] of Object.entries(group.logical)) {158 const physicalProp = group.physical[writingMode[logicalSide]];159 associated[logicalProp] = physicalProp;160 associated[physicalProp] = logicalProp;161 }162 // Test that logical properties are converted to their physical163 // equivalent correctly when all in the group are present on a single164 // declaration, with no overwriting of previous properties and165 // no physical properties present. We put the writing mode properties166 // on a separate declaration to test that the computed values of these167 // properties are used, rather than those on the same declaration.168 test(function() {169 let decl = group.prerequisites;170 const expected = [];171 for (const [i, logicalProp] of logicals.entries()) {172 decl += `${logicalProp}: ${values[i]}; `;173 expected.push([logicalProp, values[i]]);174 expected.push([associated[logicalProp], values[i]]);175 }176 testComputedValues("logical properties on one declaration, writing " +177 `mode properties on another, '${writingModeDecl}'`,178 `.test { ${writingModeDecl} } .test { ${decl} }`,179 expected);180 }, `Test that logical ${group.property} properties share computed values `181 + `with their physical associates, with '${writingModeDecl}'.`);182 // Test that logical and physical properties are cascaded together,183 // honoring their relative order on a single declaration184 // (a) with a single logical property after the physical ones185 // (b) with a single physical property after the logical ones186 test(function() {187 for (const lastIsLogical of [true, false]) {188 const lasts = lastIsLogical ? logicals : physicals;189 const others = lastIsLogical ? physicals : logicals;190 for (const lastProp of lasts) {191 let decl = writingModeDecl + group.prerequisites;192 const expected = [];193 for (const [i, prop] of others.entries()) {194 decl += `${prop}: ${values[i]}; `;195 const valueIdx = associated[prop] === lastProp ? others.length : i;196 expected.push([prop, values[valueIdx]]);197 expected.push([associated[prop], values[valueIdx]]);198 }199 decl += `${lastProp}: ${values[others.length]}; `;200 testComputedValues(`'${lastProp}' last on single declaration, '${writingModeDecl}'`,201 `.test { ${decl} }`,202 expected);203 }204 }205 }, `Test that ${group.property} properties honor order of appearance when both `206 + `logical and physical associates are declared, with '${writingModeDecl}'.`);207 // Test that logical and physical properties are cascaded properly when208 // on different declarations209 // (a) with a logical property in the high specificity rule210 // (b) with a physical property in the high specificity rule211 test(function() {212 for (const highIsLogical of [true, false]) {213 let lowDecl = writingModeDecl + group.prerequisites;214 const high = highIsLogical ? logicals : physicals;215 const others = highIsLogical ? physicals : logicals;216 for (const [i, prop] of others.entries()) {217 lowDecl += `${prop}: ${values[i]}; `;218 }219 for (const highProp of high) {220 const highDecl = `${highProp}: ${values[others.length]}; `;221 const expected = [];222 for (const [i, prop] of others.entries()) {223 const valueIdx = associated[prop] === highProp ? others.length : i;224 expected.push([prop, values[valueIdx]]);225 expected.push([associated[prop], values[valueIdx]]);226 }227 testComputedValues(`'${highProp}', two declarations, '${writingModeDecl}'`,228 `#test { ${highDecl} } .test { ${lowDecl} }`,229 expected);230 }231 }232 }, `Test that ${group.property} properties honor selector specificty when both `233 + `logical and physical associates are declared, with '${writingModeDecl}'.`);234 }235 }236 };...
Using AI Code Generation
1var wpt = new WebPageTest('www.webpagetest.org');2var data = {3};4wpt.createSizingPropertyGroup(data, function(err, data) {5 if(err) {6 console.log(err);7 }8 console.log(data);9});10WebPageTest.prototype.createSizingPropertyGroup = function(data, callback) {11 var self = this;12 self.postRequest('createSizingPropertyGroup', data, callback);13};14WebPageTest.prototype.postRequest = function(command, data, callback) {15 var self = this;16 var postData = JSON.stringify(data);17 var options = {18 headers: {19 }20 };21 var req = http.request(options, function(res) {22 res.setEncoding('utf8');23 res.on('data', function (chunk) {24 callback(null, chunk);25 });26 });27 req.on('error', function(e) {28 callback(e);29 });30 req.write(postData);31 req.end();32};
Using AI Code Generation
1wpt.createSizingPropertyGroup("sizingPropertyGroup1");2wpt.createSizingPropertyGroup("sizingPropertyGroup2");3wpt.createSizingPropertyGroup("sizingPropertyGroup3");4wpt.createSizingPropertyGroup("sizingPropertyGroup4");5wpt.createSizingPropertyGroup("sizingPropertyGroup5");6wpt.createSizingPropertyGroup("sizingPropertyGroup6");7wpt.createSizingPropertyGroup("sizingPropertyGroup7");8wpt.createSizingPropertyGroup("sizingPropertyGroup8");9wpt.createSizingPropertyGroup("sizingPropertyGroup9");10wpt.createSizingPropertyGroup("sizingPropertyGroup10");11wpt.createSizingPropertyGroup("sizingPropertyGroup11");12wpt.createSizingPropertyGroup("sizingPropertyGroup12");13wpt.createSizingPropertyGroup("sizingPropertyGroup13");14wpt.createSizingPropertyGroup("sizingPropertyGroup14");15wpt.createSizingPropertyGroup("sizingPropertyGroup15");16wpt.createSizingPropertyGroup("sizingPropertyGroup16");17wpt.createSizingPropertyGroup("sizingPropertyGroup17");
Using AI Code Generation
1var wpt = new WebPageTest();2var group = wpt.createSizingPropertyGroup();3group.setSizingProperty("width", 100);4group.setSizingProperty("height", 100);5group.setSizingProperty("width", 200);6group.setSizingProperty("height", 200);7group.setSizingProperty("width", 300);8group.setSizingProperty("height", 300);9group.setSizingProperty("width", 400);10group.setSizingProperty("height", 400);11group.setSizingProperty("width", 500);12group.setSizingProperty("height", 500);13group.setSizingProperty("width", 600);14group.setSizingProperty("height", 600);15group.setSizingProperty("width", 700);16group.setSizingProperty("height", 700);17group.setSizingProperty("width", 800);18group.setSizingProperty("height", 800);19group.setSizingProperty("width", 900);20group.setSizingProperty("height", 900);21group.setSizingProperty("width", 1000);22group.setSizingProperty("height", 1000);23group.setSizingProperty("width", 1100);24group.setSizingProperty("height", 1100);25group.setSizingProperty("width", 1200);26group.setSizingProperty("height", 1200);27group.setSizingProperty("width", 1300);28group.setSizingProperty("height", 1300);29group.setSizingProperty("width", 1400);30group.setSizingProperty("height", 1400);31group.setSizingProperty("width", 1500);32group.setSizingProperty("height", 1500);33group.setSizingProperty("width", 1600);34group.setSizingProperty("height", 1600);35group.setSizingProperty("width", 1700);36group.setSizingProperty("height", 1700);37group.setSizingProperty("width", 1800);38group.setSizingProperty("height", 1800);39group.setSizingProperty("width", 1900);40group.setSizingProperty("height", 1900);41group.setSizingProperty("width", 2000);42group.setSizingProperty("height", 2000);43group.setSizingProperty("width", 2100);
Using AI Code Generation
1var wpt = new ActiveXObject("WPT.WPT");2var sizingPropertyGroup = wpt.createSizingPropertyGroup();3sizingPropertyGroup.add("test1","test1");4sizingPropertyGroup.add("test2","test2");5sizingPropertyGroup.add("test3","test3");6sizingPropertyGroup.add("test4","test4");7sizingPropertyGroup.add("test5","test5");8sizingPropertyGroup.add("test6","test6");9sizingPropertyGroup.add("test7","test7");10sizingPropertyGroup.add("test8","test8");11sizingPropertyGroup.add("test9","test9");12sizingPropertyGroup.add("test10","test10");13sizingPropertyGroup.add("test11","test11");14sizingPropertyGroup.add("test12","test12");15sizingPropertyGroup.add("test13","test13");16sizingPropertyGroup.add("test14","test14");17sizingPropertyGroup.add("test15","test15");18sizingPropertyGroup.add("test16","test16");19sizingPropertyGroup.add("test17","test17");20sizingPropertyGroup.add("test18","test18");21sizingPropertyGroup.add("test19","test19");22sizingPropertyGroup.add("test20","test20");23sizingPropertyGroup.add("test21","test21");24sizingPropertyGroup.add("test22","test22");25sizingPropertyGroup.add("test23","test23");26sizingPropertyGroup.add("test24","test24");27sizingPropertyGroup.add("test25","test25");28sizingPropertyGroup.add("test26","test26");29sizingPropertyGroup.add("test27","test27");30sizingPropertyGroup.add("test28","test28");31sizingPropertyGroup.add("test29","test29");32sizingPropertyGroup.add("test30","test30");33sizingPropertyGroup.add("test31","test31");34sizingPropertyGroup.add("test32","test32");35sizingPropertyGroup.add("test33","test33");36sizingPropertyGroup.add("test34","test34");37sizingPropertyGroup.add("test35","test35");38sizingPropertyGroup.add("test36","test36");39sizingPropertyGroup.add("test37","test37");40sizingPropertyGroup.add("test38","test38");41sizingPropertyGroup.add("test39","test39");
Using AI Code Generation
1var wpt = new WebPageTest();2var result = wpt.createSizingPropertyGroup("Test Group");3if (result) {4 alert("Group created successfully");5} else {6 alert("Failed to create group");7}8WPT.createSizingPropertyGroup(groupName)9var wpt = new WebPageTest();10var result = wpt.createSizingPropertyGroup("Test Group");11if (result) {12 alert("Group created successfully");13} else {14 alert("Failed to create group");15}
Using AI Code Generation
1var myTextFrame = app.activeDocument.pages[0].textFrames[0];2var myPropertyGroup = myTextFrame.createSizingPropertyGroup("myPropertyGroup");3alert(myPropertyGroup.name);4var myTextFrame = app.activeDocument.pages[0].textFrames[0];5var myPropertyGroup = myTextFrame.createSizingPropertyGroup("myPropertyGroup");6alert(myPropertyGroup.name);7var myTextFrame = app.activeDocument.pages[0].textFrames[0];8var myPropertyGroup = myTextFrame.createSizingPropertyGroup("myPropertyGroup");9alert(myPropertyGroup.name);10var myTextFrame = app.activeDocument.pages[0].textFrames[0];11var myPropertyGroup = myTextFrame.createSizingPropertyGroup("myPropertyGroup");12alert(myPropertyGroup.name);13var myTextFrame = app.activeDocument.pages[0].textFrames[0];14var myPropertyGroup = myTextFrame.createSizingPropertyGroup("myPropertyGroup");15alert(myPropertyGroup.name);16var myTextFrame = app.activeDocument.pages[0].textFrames[0];17var myPropertyGroup = myTextFrame.createSizingPropertyGroup("myPropertyGroup");18alert(myPropertyGroup.name);
Using AI Code Generation
1var wptools = require("wptools");2var wp = new wptools.WPTools();3var props = wp.createSizingPropertyGroup(120, 300, 150, 150);4console.log("props: " + JSON.stringify(props));5props: {"top":120,"left":300,"width":150,"height":150}6var wptools = require("wptools");7var wp = new wptools.WPTools();8var props = wp.createSizingPropertyGroup(120, 300, 150, 150);9var comp = wp.createComponent("MyComponent", "Button", props);10console.log("comp: " + JSON.stringify(comp));11comp: {"name":"MyComponent","type":"Button","top":120,"left":300,"width":150,"height":150}12var wptools = require("wptools");13var wp = new wptools.WPTools();14var props = wp.createSizingPropertyGroup(0, 0, 0, 0);15var comp = wp.createComponent("MyComponent", "Button", props);16console.log("comp: " + JSON.stringify(comp
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var location = 'Dulles:Chrome';4var runs = 1;5var timeout = 30;6var data = {7};8var propertyGroup = wpt.createSizingPropertyGroup();9propertyGroup.set('label', 'My Label');10propertyGroup.set('sizing', '1024x768');11wpt.runTest(url, data, function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18wpt.getPropertyGroup('sizing', function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27var location = 'Dulles:Chrome';28var runs = 1;29var timeout = 30;30var data = {31};32var propertyGroup = wpt.createCustomPropertyGroup();33propertyGroup.set('label', 'My Label');34propertyGroup.set('sizing', '1024x768');35propertyGroup.set('userAgent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36');36wpt.runTest(url, data, function(err, data) {37 if (err) {38 console.log(err);39 } else {40 console.log(data);41 }42});43wpt.getPropertyGroup('custom', function(err, data) {44 if (err) {45 console.log(err);46 } else {47 console.log(data
Using AI Code Generation
1function test()2{3 var wpt = app.activeDocument.warpingPlugin;4 var doc = app.activeDocument;5 var layer = doc.activeLayer;6 var layerBounds = layer.bounds;7 var layerWidth = layerBounds[2] - layerBounds[0];8 var layerHeight = layerBounds[3] - layerBounds[1];9 var width = 100;10 var height = 100;11 var sizingPropertyGroup = wpt.createSizingPropertyGroup(layer);12 var sizingPropertyGroupItem = sizingPropertyGroup.createSizingPropertyGroupItem(layerWidth, layerHeight, width, height);13 var sizingPropertyGroupItemValue = sizingPropertyGroupItem.createSizingPropertyGroupItemValue(layerWidth, layerHeight, width, height);14 alert(sizingPropertyGroupItemValue.getText());15}16test();
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!!