How to use check_starting_elements method in wpt

Best JavaScript code snippet using wpt

multi-touch-interactions.js

Source:multi-touch-interactions.js Github

copy

Full Screen

...46function check_targets(list, target) {47 for(i=0; i<list.length; i++)48 assert_true(list.item(i).target==target, "item(" + i + ").target is element receiving event");49}50function check_starting_elements(list) {51 for (i=0; i<list.length; i++) {52 assert_equals(list.item(i).target, starting_elements[list.item(i).identifier], "item(" + i + ").target matches starting element");53 }54}55function run() {56 var target0 = document.getElementById("target0");57 var target1 = document.getElementById("target1");58 var test_touchstart = async_test("touchstart event received");59 var test_touchmove = async_test("touchmove event received");60 var test_touchend = async_test("touchend event received");61 var test_mousedown = async_test("Interaction with mouse events");62 var touchstart_received = 0;63 var touchmove_received = 0;64 var touchend_received = 0;65 var touchstart_identifier;66 // last received touch lists for comparison67 var last_touches;68 var last_targetTouches={};69 var last_changedTouches={};70 on_event(window, "touchstart", function onTouchStart(ev) {71 // process event only if it's targeted at target0 or target172 if(ev.target != target0 && ev.target != target1 )73 return;74 ev.preventDefault();75 if(!touchstart_received) {76 // Check event ordering TA: 1.6.177 test_touchstart.step(function() {78 assert_true(touchmove_received==0, "touchstart precedes touchmove");79 assert_true(touchend_received==0, "touchstart precedes touchend");80 });81 test_touchstart.done();82 test_mousedown.done(); // If we got here, then the mouse event test is not needed.83 }84 touchstart_received++;85 // TA: 1.3.2.2, 1.3.2.486 test(function() {87 assert_true(ev.changedTouches.length >= 1, "changedTouches.length is at least 1");88 assert_true(ev.changedTouches.length <= ev.touches.length, "changedTouches.length is smaller than touches.length");89 check_list_subset_of_targetlist(ev.changedTouches, "changedTouches", ev.touches, "touches");90 }, "touchstart #" + touchstart_received + ": changedTouches is a subset of touches");91 // TA: 1.3.3.2, 1.3.3.392 test(function() {93 assert_true(ev.targetTouches.length >= 1, "targetTouches.length is at least 1");94 assert_true(ev.targetTouches.length <= ev.touches.length, "targetTouches.length is smaller than touches.length");95 check_list_subset_of_targetlist(ev.targetTouches, "targetTouches", ev.touches, "touches");96 }, "touchstart #" + touchstart_received + ": targetTouches is a subset of touches");97 // TA: 1.3.3.998 test(function() {99 check_targets(ev.targetTouches, ev.target);100 }, "touchstart #" + touchstart_received + ": targets of targetTouches are correct");101 // TA: 1.3.4.2102 test(function() {103 assert_true(ev.touches.length >= 1, "touches.length is at least 1");104 }, "touchstart #" + touchstart_received + ": touches.length is valid");105 if(touchstart_received == 1) {106 // TA: 1.3.3.5, 1.3.3.7107 test(function() {108 assert_true(ev.targetTouches.length <= ev.changedTouches.length, "targetTouches.length is smaller than changedTouches.length");109 check_list_subset_of_targetlist(ev.targetTouches, "targetTouches", ev.changedTouches, "changedTouches");110 }, "touchstart #" + touchstart_received + ": targetTouches is a subset of changedTouches");111 // TA: 1.3.4.3112 test(function() {113 assert_true(ev.touches.length==ev.changedTouches.length, "touches and changedTouches have the same length");114 }, "touchstart #" + touchstart_received + ": touches and changedTouches have the same length");115 } else {116 // TA: 1.3.3.6117 test(function() {118 var diff_in_targetTouches = ev.targetTouches.length - (last_targetTouches[ev.target.id] ? last_targetTouches[ev.target.id].length : 0);119 assert_true(diff_in_targetTouches > 0, "targetTouches.length is larger than last received targetTouches.length");120 assert_true(diff_in_targetTouches <= ev.changedTouches.length, "change in targetTouches.length is smaller than changedTouches.length");121 }, "touchstart #" + touchstart_received + ": change in targetTouches.length is valid");122 // TA: 1.3.3.8123 test(function() {124 assert_true(is_at_least_one_item_in_targetlist(ev.targetTouches, ev.changedTouches), "at least one item of targetTouches is in changedTouches");125 }, "touchstart #" + touchstart_received + ": at least one targetTouches item in changedTouches");126 // TA: 1.3.4.4127 test(function() {128 var diff_in_touches = ev.touches.length - last_touches.length;129 assert_true(diff_in_touches > 0, "touches.length is larger than last received touches.length");130 assert_true(diff_in_touches == ev.changedTouches.length, "change in touches.length equals changedTouches.length");131 }, "touchstart #" + touchstart_received + ": change in touches.length is valid");132 // TA: 1.3.4.5133 test(function() {134 check_list_subset_of_two_targetlists(ev.touches, "touches", ev.changedTouches, "changedTouches", last_touches, "last touches");135 }, "touchstart #" + touchstart_received + ": touches is subset of {changedTouches, last received touches}");136 }137 // save starting element of each new touch point138 for (i=0; i<ev.changedTouches.length; i++) {139 starting_elements[ev.changedTouches.item(i).identifier] = ev.changedTouches.item(i).target;140 }141 last_touches = ev.touches;142 last_targetTouches[ev.target.id] = ev.targetTouches;143 last_changedTouches = {}; // changedTouches are only saved for touchend events144 });145 on_event(window, "touchmove", function onTouchMove(ev) {146 // process event only if it's targeted at target0 or target1147 if(ev.target != target0 && ev.target != target1 )148 return;149 ev.preventDefault();150 // TA: 1.6.1151 test_touchmove.step(function() {152 assert_true(touchstart_received>0, "touchmove follows touchstart");153 // assert_false(touchend_received, "touchmove precedes touchend"); // this applies to scenario tests154 });155 test_touchmove.done();156 touchmove_received++;157 // do the detailed checking only for a few times158 if(touchmove_received<6) {159 // TA: 1.4.2.2, 1.4.2.4160 test(function() {161 assert_true(ev.changedTouches.length >= 1, "changedTouches.length is at least 1");162 assert_true(ev.changedTouches.length <= ev.touches.length, "changedTouches.length is smaller than touches.length");163 check_list_subset_of_targetlist(ev.changedTouches, "changedTouches", ev.touches, "touches");164 }, "touchmove #" + touchmove_received + ": changedTouches is a subset of touches");165 // TA: 1.4.3.2, 1.4.3.4166 test(function() {167 assert_true(ev.targetTouches.length >= 1, "targetTouches.length is at least 1");168 assert_true(ev.targetTouches.length <= ev.touches.length, "targetTouches.length is smaller than touches.length");169 check_list_subset_of_targetlist(ev.targetTouches, "targetTouches", ev.touches, "touches");170 }, "touchmove #" + touchmove_received + ": targetTouches is a subset of touches");171 // TA: 1.4.3.6172 test(function() {173 assert_true(is_at_least_one_item_in_targetlist(ev.targetTouches, ev.changedTouches), "at least one item of targetTouches is in changedTouches");174 }, "touchmove #" + touchmove_received + ": at least one targetTouches item in changedTouches");175 // TA: 1.4.3.8176 test(function() {177 check_targets(ev.targetTouches, ev.target);178 }, "touchmove #" + touchmove_received + ": targets of targetTouches are correct");179 // TA: 1.4.4.2180 test(function() {181 assert_true(ev.touches.length==last_touches.length, "length of touches is same as length of last received touches");182 check_list_subset_of_targetlist(ev.touches, "touches", last_touches, "last received touches");183 }, "touchmove #" + touchmove_received + ": touches must be same as last received touches");184 // TA: 1.6.3185 check_starting_elements(ev.changedTouches);186 }187 last_touches = ev.touches;188 last_targetTouches[ev.target.id] = ev.targetTouches;189 last_changedTouches = {}; // changedTouches are only saved for touchend events190 });191 on_event(window, "touchend", function onTouchEnd(ev) {192 // process event only if it's targeted at target0 or target1193 if(ev.target != target0 && ev.target != target1 )194 return;195 test_touchend.step(function() {196 assert_true(touchstart_received>0, "touchend follows touchstart");197 });198 test_touchend.done();199 touchend_received++;200 debug_print("touchend #" + touchend_received + ":<br>");201 debug_print("changedTouches.length=" + ev.changedTouches.length + "<br>");202 debug_print("targetTouches.length=" + ev.targetTouches.length + "<br>");203 debug_print("touches.length=" + ev.touches.length + "<br>");204 for(i=0; i<ev.changedTouches.length; i++)205 debug_print("changedTouches.item(" + i + ").target=" + ev.changedTouches.item(i).target.id + "<br>");206 // TA: 1.5.2.2207 test(function() {208 assert_true(ev.changedTouches.length >= 1, "changedTouches.length is at least 1");209 }, "touchend #" + touchend_received + ": length of changedTouches is valid");210 // TA: 1.5.2.3211 test(function() {212 check_list_subset_of_targetlist(ev.changedTouches, "changedTouches", last_touches, "last received touches");213 }, "touchend #" + touchend_received + ": changedTouches is a subset of last received touches");214 // TA: 1.5.2.4, 1.5.2.5215 test(function() {216 check_no_item_in_targetlist(ev.changedTouches, "changedTouches", ev.touches, "touches");217 check_no_item_in_targetlist(ev.changedTouches, "changedTouches", ev.targetTouches, "targetTouches");218 }, "touchend #" + touchend_received + ": no item in changedTouches are in touches or targetTouches");219 // TA: 1.5.2.6220 test(function() {221 var found=false;222 for (i=0; i<ev.changedTouches.length; i++)223 if (ev.changedTouches.item(i).target == ev.target)224 found=true;225 assert_true(found, "at least one item in changedTouches has matching target");226 }, "touchend #" + touchend_received + ": at least one item in changedTouches targeted at this element");227 // TA: 1.5.3.2, 1.5.3.3228 test(function() {229 assert_true(ev.targetTouches.length >= 0, "targetTouches.length is non-negative");230 assert_true(ev.targetTouches.length <= ev.touches.length, "targetTouches.length is smaller than touches.length");231 check_list_subset_of_targetlist(ev.targetTouches, "targetTouches", ev.touches, "touches");232 }, "touchend #" + touchend_received + ": targetTouches is a subset of touches");233 // TA: 1.5.3.5 (new)234 test(function() {235 check_targets(ev.targetTouches, ev.target);236 }, "touchend #" + touchend_received + ": targets of targetTouches are correct");237 // In some cases, when multiple touch points are released simultaneously238 // the UA would dispatch the "same" touchend event (same changedTouches, same touches, but possibly different targetTouches)239 // to each of the elements that are starting elements of the released touch points.240 // in these situations, the subsequent events are exempt from TA 1.5.3.4 and 1.5.4.2241 var same_event_as_last = false;242 if (last_changedTouches && last_changedTouches.length==ev.changedTouches.length) {243 same_event_as_last = true; // assume true until proven otherwise244 for (i=0; i<last_changedTouches.length; i++) {245 var match = false;246 for (j=0; j<ev.changedTouches.length; j++)247 if (last_changedTouches.item(i) == ev.changedTouches.item(j)) {248 match = true;249 break;250 }251 if (!match)252 same_event_as_last = false;253 }254 }255 if (!same_event_as_last) {256 // TA: 1.5.3.4257 // Getting semi-random failures on this and 1.5.4.2.258 // See 1.5.4.2. Not sure if it's the same issue...259 test(function() {260 assert_true(last_targetTouches[ev.target.id].length > 0, "last received targetTouches.length is not zero");261 var diff_in_targetTouches = last_targetTouches[ev.target.id].length - ev.targetTouches.length;262 debug_print("diff_in_targetTouches=" + diff_in_targetTouches + "<br>");263 assert_true(diff_in_targetTouches > 0, "targetTouches.length is smaller than last received targetTouches.length");264 assert_true(diff_in_targetTouches <= ev.changedTouches.length, "change in targetTouches.length is smaller than changedTouches.length");265 }, "touchend #" + touchend_received + ": change in targetTouches.length is valid");266 // TA: 1.5.4.2267 // Getting semi-random failures on this and 1.5.3.4.268 // It looks like if fingers are lifted simultaneously, the "same" touchend event can be dispatched to two target elements269 // but adapted to the element (same touches, changedTouches but different targetTouches).270 // When one event is processed after another, ev.touches would end up being identical to last_touches, leading to failure.271 // Question is why done() does not stop the processing of the latter event.272 test(function() {273 assert_true(last_touches.length > 0, "last received touches.length is not zero");274 var diff_in_touches = last_touches.length - ev.touches.length;275 debug_print("diff_in_touches=" + diff_in_touches + "<br>");276 assert_true(diff_in_touches > 0, "touches.length is smaller than last received touches.length");277 assert_equals(diff_in_touches, ev.changedTouches.length, "change in touches.length equals changedTouches.length");278 }, "touchend #" + touchend_received + ": change in touches.length is valid");279 }280 // TA: 1.6.4281 debug_print("touchend #" + touchend_received + ": TA 1.6.4<br>");282 test(function() {283 check_starting_elements(ev.changedTouches);284 }, "touchend #" + touchend_received + ": event dispatched to correct element<br>");285 debug_print("touchend #" + touchend_received + ": saving touch lists<br>");286 last_touches = ev.touches;287 last_targetTouches[ev.target.id] = ev.targetTouches;288 last_changedTouches = ev.changedTouches;289 debug_print("touchend #" + touchend_received + ": done<br>");290 if(ev.touches.length==0)291 done();292 });293 on_event(target0, "mousedown", function onMouseDown(ev) {294 test_mousedown.step(function() {295 assert_true(touchstart_received,296 "The touchstart event must be dispatched before any mouse " +297 "events. (If this fails, it might mean that the user agent does " +...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wpt = new wpt('API_KEY');3 if(err) {4 console.log(err);5 }6 else {7 console.log(data);8 }9});10var wpt = require('./wpt.js');11var wpt = new wpt('API_KEY');12 if(err) {13 console.log(err);14 }15 else {16 console.log(data);17 }18});19var wpt = require('./wpt.js');20var wpt = new wpt('API_KEY');21 if(err) {22 console.log(err);23 }24 else {25 console.log(data);26 }27});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var wpt = new WebPageTest('www.webpagetest.org');3 if(err) {4 console.log('Error: ' + err);5 } else {6 console.log('Data: ' + data);7 }8});9### WebPageTest(host)10### WebPageTest.getLocations(callback)11### WebPageTest.getTests(callback)12### WebPageTest.getTest(testId, callback)13### WebPageTest.runTest(url, options, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1function test()2{3 var wpt = new WebPageTest('www.webpagetest.org');4 if (err) {5 console.log(err);6 }7 else {8 console.log(data);9 }10 });11}12test();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('../wpt.js');2var word = 123;3var word1 = "hello";4var word2 = "hello";5var word3 = "hello";6var word4 = "hello";7var word5 = "hello";8var word6 = "hello";9var word7 = "hello";10var word8 = "hello";11var word9 = "hello";12var word10 = "hello";13var word11 = "hello";14var word12 = "hello";15var word13 = "hello";16var word14 = "hello";17var word15 = "hello";18var word16 = "hello";19var word17 = "hello";20var word18 = "hello";21var word19 = "hello";22var word20 = "hello";23var word21 = "hello";24var word22 = "hello";25var word23 = "hello";26var word24 = "hello";27var word25 = "hello";28var word26 = "hello";29var word27 = "hello";30var word28 = "hello";31var word29 = "hello";32var word30 = "hello";33var word31 = "hello";34var word32 = "hello";35var word33 = "hello";36var word34 = "hello";37var word35 = "hello";38var word36 = "hello";39var word37 = "hello";40var word38 = "hello";41var word39 = "hello";42var word40 = "hello";43var word41 = "hello";44var word42 = "hello";45var word43 = "hello";46var word44 = "hello";47var word45 = "hello";48var word46 = "hello";49var word47 = "hello";50var word48 = "hello";51var word49 = "hello";52var word50 = "hello";53var word51 = "hello";54var word52 = "hello";55var word53 = "hello";56var word54 = "hello";57var word55 = "hello";58var word56 = "hello";59var word57 = "hello";60var word58 = "hello";61var word59 = "hello";62var word60 = "hello";63var word61 = "hello";64var word62 = "hello";65var word63 = "hello";66var word64 = "hello";

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log(data);7 }8});9 if (err) {10 console.log('Error: ' + err);11 } else {12 console.log(data);13 }14});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful