Best JavaScript code snippet using wpt
compute_pressure_different_quantizations_across_iframes.tentative.https.window.js
Source:compute_pressure_different_quantizations_across_iframes.tentative.https.window.js
1'use strict';2promise_test(async t => {3 const observer1_updates = [];4 const observer1 = new ComputePressureObserver(5 update => { observer1_updates.push(update); },6 {cpuUtilizationThresholds: [0.5], cpuSpeedThresholds: [0.5]});7 t.add_cleanup(() => observer1.stop());8 // Ensure that observer1's quantization scheme gets registered as the origin's9 // scheme before observer2 starts.10 await observer1.observe();11 // iframe numbers are aligned with observer numbers. The first observer is in12 // the main frame, so there is no iframe1.13 const iframe2 = document.createElement('iframe');14 document.body.appendChild(iframe2);15 const observer2_updates = [];16 await new Promise((resolve, reject) => {17 const observer2 = new iframe2.contentWindow.ComputePressureObserver(18 update => {19 observer2_updates.push(update);20 resolve();21 },22 {cpuUtilizationThresholds: [0.25], cpuSpeedThresholds: [0.75]});23 t.add_cleanup(() => observer2.stop());24 observer2.observe().catch(reject);25 });26 // observer2 uses a different quantization scheme than observer1. After27 // observer2.observe() completes, observer1 should no longer be active.28 //29 // The check below assumes that observer2.observe() completes before the30 // browser dispatches any update for observer1. This assumption is highly31 // likely to be true, because there shold be a 1-second delay between32 // observer1.observe() and the first update that observer1 would receive.33 assert_equals(34 observer1_updates.length, 0,35 'observer2.observe() should have stopped observer1; the two observers ' +36 'have different quantization schemes');37 assert_equals(observer2_updates.length, 1);38 assert_in_array(observer2_updates[0].cpuUtilization, [0.125, 0.625],39 'cpuUtilization quantization');40 assert_in_array(observer2_updates[0].cpuSpeed, [0.375, 0.875],41 'cpuSpeed quantization');42 // Go through one more update cycle so any (incorrect) update for observer143 // makes it through the IPC queues.44 observer1_updates.length = 0;45 observer2_updates.length = 0;46 const iframe3 = document.createElement('iframe');47 document.body.appendChild(iframe3);48 const observer3_updates = [];49 await new Promise((resolve, reject) => {50 const observer3 = new iframe3.contentWindow.ComputePressureObserver(51 update => {52 observer3_updates.push(update);53 resolve();54 },55 {cpuUtilizationThresholds: [0.75], cpuSpeedThresholds: [0.25]});56 t.add_cleanup(() => observer3.stop());57 observer3.observe().catch(reject);58 });59 assert_equals(60 observer1_updates.length, 0,61 'observer2.observe() should have stopped observer1; the two observers ' +62 'have different quantization schemes');63 // observer3 uses a different quantization scheme than observer2. So,64 // observer3.observe() should stop observer2.65 assert_equals(66 observer2_updates.length, 0,67 'observer3.observe() should have stopped observer2; the two observers ' +68 'have different quantization schemes');69 assert_equals(observer3_updates.length, 1);70 assert_in_array(observer3_updates[0].cpuUtilization, [0.375, 0.875],71 'cpuUtilization quantization');72 assert_in_array(observer3_updates[0].cpuSpeed, [0.125, 0.625],73 'cpuSpeed quantization');74}, 'ComputePressureObserver with a new quantization schema stops all ' +...
compute_pressure_different_quantizations.tentative.https.window.js
Source:compute_pressure_different_quantizations.tentative.https.window.js
1'use strict';2promise_test(async t => {3 const observer1_updates = [];4 const observer1 = new ComputePressureObserver(5 update => { observer1_updates.push(update); },6 {cpuUtilizationThresholds: [0.5], cpuSpeedThresholds: [0.5]});7 t.add_cleanup(() => observer1.stop());8 // Ensure that observer1's quantization scheme gets registered as the origin's9 // scheme before observer2 starts.10 await observer1.observe();11 const observer2_updates = [];12 await new Promise((resolve, reject) => {13 const observer2 = new ComputePressureObserver(14 update => {15 observer2_updates.push(update);16 resolve();17 },18 {cpuUtilizationThresholds: [0.25], cpuSpeedThresholds: [0.75]});19 t.add_cleanup(() => observer2.stop());20 observer2.observe().catch(reject);21 });22 // observer2 uses a different quantization scheme than observer1. After23 // observer2.observe() completes, observer1 should no longer be active.24 //25 // The check below assumes that observer2.observe() completes before the26 // browser dispatches any update for observer1. This assumption is highly27 // likely to be true, because there shold be a 1-second delay between28 // observer1.observe() and the first update that observer1 would receive.29 assert_equals(30 observer1_updates.length, 0,31 'observer2.observe() should have stopped observer1; the two observers ' +32 'have different quantization schemes');33 assert_equals(observer2_updates.length, 1);34 assert_in_array(observer2_updates[0].cpuUtilization, [0.125, 0.625],35 'cpuUtilization quantization');36 assert_in_array(observer2_updates[0].cpuSpeed, [0.375, 0.875],37 'cpuSpeed quantization');38 // Go through one more update cycle so any (incorrect) update for observer139 // makes it through the IPC queues.40 observer1_updates.length = 0;41 observer2_updates.length = 0;42 const observer3_updates = [];43 await new Promise((resolve, reject) => {44 const observer3 = new ComputePressureObserver(45 update => {46 observer3_updates.push(update);47 resolve();48 },49 {cpuUtilizationThresholds: [0.75], cpuSpeedThresholds: [0.25]});50 t.add_cleanup(() => observer3.stop());51 observer3.observe().catch(reject);52 });53 assert_equals(54 observer1_updates.length, 0,55 'observer2.observe() should have stopped observer1; the two observers ' +56 'have different quantization schemes');57 // observer3 uses a different quantization scheme than observer2. So,58 // observer3.observe() should stop observer2.59 assert_equals(60 observer2_updates.length, 0,61 'observer3.observe() should have stopped observer2; the two observers ' +62 'have different quantization schemes');63 assert_equals(observer3_updates.length, 1);64 assert_in_array(observer3_updates[0].cpuUtilization, [0.375, 0.875],65 'cpuUtilization quantization');66 assert_in_array(observer3_updates[0].cpuSpeed, [0.125, 0.625],67 'cpuSpeed quantization');68}, 'ComputePressureObserver with a new quantization schema stops all ' +...
compute_pressure_stop_idempotent.tentative.https.window.js
Source:compute_pressure_stop_idempotent.tentative.https.window.js
1'use strict';2promise_test(async t => {3 const observer1_updates = [];4 const observer1 = new ComputePressureObserver(5 update => { observer1_updates.push(update); },6 {cpuUtilizationThresholds: [0.5], cpuSpeedThresholds: [0.5]});7 t.add_cleanup(() => observer1.stop());8 // Ensure that observer1's schema gets registered before observer2 starts.9 observer1.observe();10 observer1.stop();11 observer1.stop();12 const observer2_updates = [];13 await new Promise((resolve, reject) => {14 const observer2 = new ComputePressureObserver(15 update => {16 observer2_updates.push(update);17 resolve();18 },19 {cpuUtilizationThresholds: [0.5], cpuSpeedThresholds: [0.5]});20 t.add_cleanup(() => observer2.stop());21 observer2.observe().catch(reject);22 });23 assert_equals(observer1_updates.length, 0,24 'stopped observers should not receive callbacks');25 assert_equals(observer2_updates.length, 1);26 assert_in_array(observer2_updates[0].cpuUtilization, [0.25, 0.75],27 'cpuUtilization quantization');28 assert_in_array(observer2_updates[0].cpuSpeed, [0.25, 0.75],29 'cpuSpeed quantization');30 // Go through one more update cycle so any (incorrect) update for observer131 // makes it through the IPC queues.32 const observer3_updates = [];33 await new Promise((resolve, reject) => {34 const observer3 = new ComputePressureObserver(35 update => {36 observer3_updates.push(update);37 resolve();38 },39 {cpuUtilizationThresholds: [0.75], cpuSpeedThresholds: [0.25]});40 t.add_cleanup(() => observer3.stop());41 observer3.observe().catch(reject);42 });43 assert_equals(observer1_updates.length, 0,44 'stopped observers should not receive callbacks');45 assert_equals(observer3_updates.length, 1);46 assert_in_array(observer3_updates[0].cpuUtilization, [0.375, 0.875],47 'cpuUtilization quantization');48 assert_in_array(observer3_updates[0].cpuSpeed, [0.125, 0.625],49 'cpuSpeed quantization');...
Using AI Code Generation
1var observer3 = new MutationObserver(function(mutations) {2 mutations.forEach(function(mutation) {3 if (mutation.attributeName === "class") {4 var attributeValue = $(mutation.target).prop(mutation.attributeName);5 console.log("Class attribute changed to:", attributeValue);6 }7 });8});9var targetNode = document.getElementById("myDiv");10var config = { attributes: true, childList: true, characterData: true };11observer3.observe(targetNode, config);12var observer4 = new MutationObserver(function(mutations) {13 mutations.forEach(function(mutation) {14 if (mutation.attributeName === "class") {15 var attributeValue = $(mutation.target).prop(mutation.attributeName);16 console.log("Class attribute changed to:", attributeValue);17 }18 });19});20var targetNode = document.getElementById("myDiv");21var config = { attributes: true, childList: true, characterData: true };22observer4.observe(targetNode, config);23var observer5 = new MutationObserver(function(mutations) {24 mutations.forEach(function(mutation) {25 if (mutation.attributeName === "class") {26 var attributeValue = $(mutation.target).prop(mutation.attributeName);27 console.log("Class attribute changed to:", attributeValue);28 }29 });30});31var targetNode = document.getElementById("myDiv");32var config = { attributes: true, childList: true, characterData: true };33observer5.observe(targetNode, config);
Using AI Code Generation
1var observer3 = new PerformanceObserver(function(list, observer) {2 var entry = list.getEntries()[0];3 console.log(entry.name + " took " + entry.duration + "ms.");4 observer.disconnect();5});6observer3.observe({entryTypes: ["measure"]});7performance.measure("test", "start", "end");
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest(options);5wpt.observeTest('160529_3C_3a3b3a22d7d9e9c0b7a1a1f2d7d9e9c0', function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});9var wpt = require('webpagetest');10var options = {11};12var wpt = new WebPageTest(options);13wpt.observeTest('160529_3C_3a3b3a22d7d9e9c0b7a1a1f2d7d9e9c0', function(err, data) {14 if (err) return console.error(err);15 console.log(data);16});17var wpt = require('webpagetest');18var options = {19};20var wpt = new WebPageTest(options);21wpt.observeTest('160529_3C_3a3b3a22d7d9e9c0b7
Using AI Code Generation
1function observer3() {2 var observer = new MutationObserver(function(mutations) {3 console.log("mutation observer called");4 mutations.forEach(function(mutation) {5 console.log(mutation.type);6 });7 });8 var target = document.getElementById('target');9 var config = { attributes: true, childList: true, characterData: true };10 observer.observe(target, config);11}12function observer2() {13 var target = document.getElementById('target');14 var observer = new MutationObserver(function(mutations) {15 console.log("mutation observer called");16 mutations.forEach(function(mutation) {17 console.log(mutation.type);18 });19 });20 var config = { attributes: true, childList: true, characterData: true };21 observer.observe(target, config);22}23function observer() {24 var target = document.getElementById('target');25 var observer = new MutationObserver(function(mutations) {26 console.log("mutation observer called");27 mutations.forEach(function(mutation) {28 console.log(mutation.type);29 });30 });31 var config = { attributes: true, childList: true, characterData: true };32 observer.observe(target, config);33}34function observer() {35 var target = document.getElementById('target');36 var observer = new MutationObserver(function(mutations) {37 console.log("mutation observer called");38 mutations.forEach(function(mutation) {39 console.log(mutation.type);40 });41 });42 var config = { attributes: true, childList: true, characterData: true };43 observer.observe(target, config);44}45function observer() {46 var target = document.getElementById('target');47 var observer = new MutationObserver(function
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new wpt('A.1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9u0v1w2x3y4z5');3var test = {4 videoParams: {5 }6};7wpt.runTest(test.url, test, function(err, data) {8 if (err) {9 console.log('Error: ' + err);10 return;11 }12 console.log('Test submitted successfully. View your test at: ' + data.data.userUrl);13 console.log('Poll the test results at: ' + data.data.jsonUrl);14});
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var webpagetest = new wpt(options);5}, function(err, data) {6 if (err) {7 return console.error(err);8 }9 console.log(data);10 webpagetest.getTestResults(data.data.testId, function(err, data) {11 if (err) {12 return console.error(err);13 }14 console.log(data);15 });16});17var wpt = require('webpagetest');18var options = {19};20var webpagetest = new wpt(options);21}, function(err, data) {22 if (err) {23 return console.error(err);24 }25 console.log(data);26 webpagetest.getTestResults(data.data.testId, function(err, data) {27 if (err) {28 return console.error(err);29 }30 console.log(data);31 });32});33var wpt = require('webpagetest');34var options = {35};36var webpagetest = new wpt(options);
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!!