Best JavaScript code snippet using wpt
compute_pressure_basic_async.tentative.https.window.js
Source:compute_pressure_basic_async.tentative.https.window.js
1// META: script=/resources/test-only-api.js2// META: script=resources/pressure-helpers.js3'use strict';4pressure_test((t, mockPressureService) => {5 const observer = new PressureObserver(() => {6 assert_unreached('The observer callback should not be called');7 });8 mockPressureService.setExpectedFailure(9 new DOMException('', 'NotSupportedError'));10 return promise_rejects_dom(t, 'NotSupportedError', observer.observe('cpu'));11}, 'Return NotSupportedError when calling observer()');12pressure_test((t, mockPressureService) => {13 const observer = new PressureObserver(() => {14 assert_unreached('The observer callback should not be called');15 });16 mockPressureService.setExpectedFailure(new DOMException('', 'SecurityError'));17 return promise_rejects_dom(t, 'SecurityError', observer.observe('cpu'));18}, 'Return SecurityError when calling observer()');19pressure_test(async (t, mockPressureService) => {20 const update = await new Promise(async resolve => {21 const observer = new PressureObserver(resolve);22 await observer.observe('cpu');23 mockPressureService.setPressureState({cpuUtilization: 0.5});24 mockPressureService.sendUpdate();25 });26 assert_equals(update.cpuUtilization, 0.5);27}, 'Basic functionality test');28pressure_test((t, mockPressureService) => {29 const observer = new PressureObserver(() => {30 assert_unreached('The observer callback should not be called');31 });32 observer.observe('cpu');33 observer.unobserve('cpu');34 mockPressureService.setPressureState({cpuUtilization: 0.5});35 mockPressureService.sendUpdate();36 return new Promise(resolve => t.step_timeout(resolve, 1000));37}, 'Removing observer before observe() resolves works');38pressure_test(async (t, mockPressureService) => {39 const callbackPromises = [];40 const observePromises = [];41 for (let i = 0; i < 2; i++) {42 callbackPromises.push(new Promise(resolve => {43 const observer = new PressureObserver(resolve);44 observePromises.push(observer.observe('cpu'));45 }));46 }47 await Promise.all(observePromises);48 mockPressureService.setPressureState({cpuUtilization: 0.5});49 mockPressureService.sendUpdate();50 return Promise.all(callbackPromises);51}, 'Calling observe() multiple times works');52pressure_test(async (t, mockPressureService) => {53 const update = await new Promise(async resolve => {54 const observer1 =55 new PressureObserver(resolve, {cpuUtilizationThresholds: [0.5]});56 await observer1.observe('cpu');57 const observer2 =58 new PressureObserver(() => {}, {cpuUtilizationThresholds: [0.5]});59 await observer2.observe('cpu');60 mockPressureService.setPressureState({cpuUtilization: 0.5});61 mockPressureService.sendUpdate();62 });63 assert_equals(update.cpuUtilization, 0.5);64}, 'Same quantization should not stop other observers');65pressure_test(async (t, mockPressureService) => {66 const observer1 = new PressureObserver(() => {67 assert_unreached('The observer callback should not be called');68 }, {cpuUtilizationThresholds: [0.5]});69 await observer1.observe('cpu');70 const observer2 =71 new PressureObserver(() => {}, {cpuUtilizationThresholds: [0.3]});72 await observer2.observe('cpu');73 mockPressureService.setPressureState({cpuUtilization: 0.5});74 mockPressureService.sendUpdate();75 await new Promise(resolve => t.step_timeout(resolve, 1000));...
ife_pressure_test.js
Source:ife_pressure_test.js
1/**2 * Created by Exbo on 2016/4/13.3 */4ife.pressure_test={};5ife.pressure_test.init=function(){6 this.object_count=0;7 stgClearCanvas("ui");8 //åå¼¹çèæ¬9 this.blt_func = function () {10 //触å£åå¼¹11 if (stg_target.move.pos[0] > stg_frame_w) {12 stg_target.move.pos[0] = stg_frame_w;13 stg_target.move.speed_angle = PI - stg_target.move.speed_angle;14 }15 if (stg_target.move.pos[0] < 0) {16 stg_target.move.pos[0] = 0;17 stg_target.move.speed_angle = PI - stg_target.move.speed_angle;18 }19 if (stg_target.move.pos[1] > stg_frame_h) {20 stg_target.move.pos[1] = stg_frame_h;21 stg_target.move.speed_angle = -stg_target.move.speed_angle;22 }23 if (stg_target.move.pos[1] < 0) {24 stg_target.move.pos[1] = 0;25 stg_target.move.speed_angle = -stg_target.move.speed_angle;26 }27 //å¦æéè¦åå°åå¼¹ï¼å°±å é¤èªå·±28 if (ife.pressure_test.reduce >= 0) {29 stgDeleteSelf();30 ife.pressure_test.reduce--;31 ife.pressure_test.object_count--;32 }33 };34 var ay = new RenderText(10, 570);35 ay.script = function () {36 this.render.text = "ç©ä½æ°ï¼ " + _pool.length + "";37 };38 ay = new RenderText(10, 600);39 ay.script = function () {40 this.render.text = "å¤å®æ°ï¼ " + _hit_pool.length + "-"+_hit_by_pool.length;41 };42 this.qnt=0;43 this.f2=180;44};45ife.pressure_test.script=function(){46 this.f2--;47 if(stg_fps>=58 || this.f2>0){48 stgCreateShotA1(50,50,3,Math.random()*360,"tDD",0,(stg_rand(1)*8)>>1).script=this.blt_func;49 stgCreateShotA1(50,50,3,Math.random()*360,"mMD",0,(stg_rand(1)*8)>>1).script=this.blt_func;50 stgCreateShotA1(50,50,3,Math.random()*360,"mDD",0,(stg_rand(1)*8)>>1).script=this.blt_func;51 stgCreateShotA1(50,50,3,Math.random()*360,"sXD",0,(stg_rand(1)*8)>>1).script=this.blt_func;52 stgCreateShotA1(50,50,3,Math.random()*360,"tDD",0,(stg_rand(1)*8)>>1).script=this.blt_func;53 this.object_count+=5;54 }else{55 // if(!this.topped) {56 // this.topped = 1;57 // this.f = 0;58 // }59 this.reduce=60-stg_fps;60 }61 if(this.topped){62 this.f++;63 this.qnt+=_hit_pool.length;64 }65 if(this.f>200){66 this.qnt=this.qnt/this.f;67 var ay = new RenderText(240, 570);68 ay.render.text = "å¯æ¸²æåå¼¹ï¼" +(this.qnt>>0) + "个";69 stgAddObject(ay);70 this.script=function(){71 for(var i=0;i<_pool.length;i++){72 if(_pool[i] && _pool[i].type==stg_const.OBJ_BULLET){73 stgDeleteObject(_pool[i]);74 }75 }76 this.script=null;77 }78 }79};...
Using AI Code Generation
1var wpt = require('./wpt');2wpt.pressure_test(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);3var wpt = require('./wpt');4module.exports = {5};6exports.pressure_test = function (a, b, c, d, e, f, g, h, i, j) {7 console.log(a, b, c, d, e, f, g, h, i, j);8};
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 if (err) {4 console.log(err);5 } else {6 console.log('Test started - waiting for results');7 console.log(data);8 wpt.getTestResults(data.data.testId, function(err, data) {9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14 });15 }16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');19 if (err) {20 console.log(err);21 } else {22 console.log('Test started - waiting for results');23 console.log(data);24 wpt.getTestResults(data.data.testId, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30 });31 }32});33var wpt = require('wpt');34var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');35 if (err) {36 console.log(err);37 } else {38 console.log('Test started - waiting for results');39 console.log(data);40 wpt.getTestResults(data.data.testId, function(err, data) {41 if (err) {42 console.log(err);43 } else {44 console.log(data);45 }
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');3wpt.pressure_test('www.google.com', {runs: 1, location: 'Dulles_MotoG4:Chrome', pollResults: 5}, function(err, data) {4 if(err){5 console.log(err);6 }else{7 console.log(data);8 }9});10## pressure_test_status (testId, callback)11var wpt = require('wpt');12var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');13wpt.pressure_test_status('20161030_5V_1a2e2e', function(err, data) {14 if(err){15 console.log(err);16 }else{17 console.log(data);18 }19});20## pressure_test_results (testId, callback)21var wpt = require('wpt');22var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');23wpt.pressure_test_results('20161030_5V_1a2e2e', function(err, data) {24 if(err){25 console.log(err);26 }else{27 console.log(data);28 }29});30## pressure_test_delete (testId, callback)
Using AI Code Generation
1var wpt = require('wpt');2var wptObj = new wpt();3wptObj.pressure_test('www.google.com', function(err, response) {4 if (err) {5 console.log(err);6 } else {7 console.log(response);8 }9});
Using AI Code Generation
1var Wpt = require('wpt');2var wpt = new Wpt('API_KEY');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var Wpt = require('wpt');10var wpt = new Wpt('API_KEY');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var Wpt = require('wpt');18var wpt = new Wpt('API_KEY');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var Wpt = require('wpt');26var wpt = new Wpt('API_KEY');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var Wpt = require('wpt');34var wpt = new Wpt('API_KEY');35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});
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!!