How to use poll_for_stash method in wpt

Best JavaScript code snippet using wpt

resolve-url.js

Source:resolve-url.js Github

copy

Full Screen

...20 var expected_utf8 = expected_obj['utf-8'];21 function msg(expected, got) {22 return 'expected substring '+expected+' got '+got;23 }24 function poll_for_stash(test_obj, uuid, expected) {25 var start = new Date();26 var poll = test_obj.step_func(function () {27 var xhr = new XMLHttpRequest();28 xhr.open('GET', stash_take + uuid);29 xhr.onload = test_obj.step_func(function(e) {30 if (xhr.response == "") {31 if (new Date() - start > 10000) {32 // If we set the status to TIMEOUT here we avoid a race between the33 // page and the test timing out34 test_obj.force_timeout();35 }36 setTimeout(poll, 200);37 } else {38 assert_equals(xhr.response, expected);39 test_obj.done();40 }41 });42 xhr.send();43 })44 setTimeout(poll, 200);45 }46 // background attribute, check with getComputedStyle47 function test_background(tag) {48 var spec_url = 'https://html.spec.whatwg.org/multipage/rendering.html';49 spec_url += tag == 'body' ? '#the-page' : '#tables';50 test(function() {51 var elm = document.createElement(tag);52 document.body.appendChild(elm);53 this.add_cleanup(function() {54 document.body.removeChild(elm);55 });56 elm.setAttribute('background', input_url_png);57 var got = getComputedStyle(elm).backgroundImage;58 assert_true(got.indexOf(expected_current) > -1, msg(expected_current, got));59 }, 'getComputedStyle <'+tag+' background>',60 {help:spec_url});61 }62 'body, table, thead, tbody, tfoot, tr, td, th'.split(', ').forEach(function(str) {63 test_background(str);64 });65 // get a reflecting IDL attributes whose content attribute takes a URL or a list of space-separated URLs66 function test_reflecting(tag, attr, idlAttr, multiple) {67 idlAttr = idlAttr || attr;68 var input = input_url_html;69 if (multiple) {70 input += ' ' + input;71 }72 test(function() {73 var elm = document.createElement(tag);74 assert_true(idlAttr in elm, idlAttr + ' is not supported');75 elm.setAttribute(attr, input);76 var got = elm[idlAttr];77 assert_true(got.indexOf(expected_current) > -1, msg(expected_current, got));78 }, 'Getting <'+tag+'>.'+idlAttr + (multiple ? ' (multiple URLs)' : ''),79 {help:'https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes'});80 }81 ('iframe src, a href, base href, link href, img src, embed src, object data, track src, video src, audio src, input src, form action, ' +82 'input formaction formAction, button formaction formAction, script src').split(', ').forEach(function(str) {83 var arr = str.split(' ');84 test_reflecting(arr[0], arr[1], arr[2]);85 });86 'a ping'.split(', ').forEach(function(str) {87 var arr = str.split(' ');88 test_reflecting(arr[0], arr[1], arr[2], true);89 });90 function setup_navigation(elm, iframe, id, test_obj) {91 iframe.name = id;92 elm.target = id;93 elm.setAttribute('href', input_url_html);94 document.body.appendChild(iframe);95 document.body.appendChild(elm);96 test_obj.add_cleanup(function() {97 document.body.removeChild(iframe);98 document.body.removeChild(elm);99 });100 }101 // follow hyperlink102 function test_follow_link(tag) {103 async_test(function() {104 var elm = document.createElement(tag);105 var iframe = document.createElement('iframe');106 setup_navigation(elm, iframe, 'test_follow_link_'+tag, this);107 iframe.onload = this.step_func_done(function() { // when the page navigated to has loaded108 assert_equals(iframe.contentDocument.body.textContent, expected_current);109 });110 // follow the hyperlink111 elm.click();112 // check that navigation succeeded by ...??? XXX113 }, 'follow hyperlink <'+tag+' href>',114 {help:'https://html.spec.whatwg.org/multipage/#following-hyperlinks'});115 }116 'a, area, link'.split(', ').forEach(function(str) {117 test_follow_link(str);118 });119 // follow hyperlink with ping attribute120 function test_follow_link_ping(tag) {121 async_test(function() {122 var uuid = token();123 var elm = document.createElement(tag);124 // check if ping is supported125 assert_true('ping' in elm, 'ping not supported');126 elm.setAttribute('ping', stash_put + uuid);127 var iframe = document.createElement('iframe');128 setup_navigation(elm, iframe, 'test_follow_link_ping_'+tag, this);129 // follow the hyperlink130 elm.click();131 // check that navigation succeeded by ...??? XXX132 // check that the right URL was requested for the ping133 poll_for_stash(this, uuid, expected_current);134 }, 'hyperlink auditing <'+tag+' ping>',135 {help:'https://html.spec.whatwg.org/multipage/#hyperlink-auditing'});136 }137 'a, area'.split(', ').forEach(function(str) {138 test_follow_link_ping(str);139 });140 // navigating with meta refresh141 async_test(function() {142 var iframe = document.createElement('iframe');143 iframe.src = blank;144 document.body.appendChild(iframe);145 this.add_cleanup(function() {146 document.body.removeChild(iframe);147 });148 iframe.onload = this.step_func_done(function() {149 var doc = iframe.contentDocument;150 var got = doc.body.textContent;151 if (got == '') {152 doc.write('<meta http-equiv=refresh content="0; URL='+input_url_html+'">REFRESH');153 doc.close();154 return;155 }156 assert_equals(got, expected_current);157 });158 }, 'meta refresh',159 {help:'https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv-refresh'});160 // loading html (or actually svg to support <embed>)161 function test_load_nested_browsing_context(tag, attr, spec_url) {162 async_test(function() {163 var id = 'test_load_nested_browsing_context_'+tag;164 var elm = document.createElement(tag);165 elm.setAttribute(attr, input_url_svg);166 elm.name = id;167 document.body.appendChild(elm);168 this.add_cleanup(function() {169 document.body.removeChild(elm);170 });171 elm.onload = this.step_func_done(function() {172 assert_equals(window[id].document.documentElement.textContent, expected_current);173 });174 }, 'load nested browsing context <'+tag+' '+attr+'>',175 {help:spec_url});176 }177 spec_url_load_nested_browsing_context = {178 frame:'https://html.spec.whatwg.org/multipage/#process-the-frame-attributes',179 iframe:'https://html.spec.whatwg.org/multipage/#process-the-iframe-attributes',180 object:'https://html.spec.whatwg.org/multipage/#the-object-element',181 embed:'https://html.spec.whatwg.org/multipage/#the-embed-element-setup-steps'182 };183 'frame src, iframe src, object data, embed src'.split(', ').forEach(function(str) {184 var arr = str.split(' ');185 test_load_nested_browsing_context(arr[0], arr[1], spec_url_load_nested_browsing_context[arr[0]]);186 });187 // loading css with <link>188 async_test(function() {189 var elm = document.createElement('link');190 elm.href = input_url_css;191 elm.rel = 'stylesheet';192 document.head.appendChild(elm);193 this.add_cleanup(function() {194 document.head.removeChild(elm);195 });196 elm.onload = this.step_func_done(function() {197 var got = elm.sheet.href;198 assert_true(elm.sheet.href.indexOf(expected_current) > -1, 'sheet.href ' + msg(expected_current, got));199 assert_equals(elm.sheet.cssRules[0].style.content, '"'+expected_current+'"', 'sheet.cssRules[0].style.content');200 });201 }, 'loading css <link>',202 {help:['https://html.spec.whatwg.org/multipage/#the-link-element',203 'https://html.spec.whatwg.org/multipage/#styling']});204 // loading js205 async_test(function() {206 var elm = document.createElement('script');207 elm.src = input_url_js + '&var=test_load_js_got';208 document.head.appendChild(elm); // no cleanup209 elm.onload = this.step_func_done(function() {210 assert_equals(window.test_load_js_got, expected_current);211 });212 }, 'loading js <script>',213 {help:'https://html.spec.whatwg.org/multipage/#prepare-a-script'});214 // loading image215 function test_load_image(tag, attr, spec_url) {216 async_test(function() {217 var elm = document.createElement(tag);218 if (tag == 'input') {219 elm.type = 'image';220 }221 elm.setAttribute(attr, input_url_png);222 document.body.appendChild(elm);223 this.add_cleanup(function() {224 document.body.removeChild(elm);225 });226 elm.onload = this.step_func_done(function() {227 var got = elm.offsetWidth;228 assert_equals(got, query_to_image_width[expected_current], msg(expected_current, image_width_to_query[got]));229 });230 // <video poster> doesn't notify when the image is loaded so we need to poll :-(231 var interval;232 var check_video_width = function() {233 var width = elm.offsetWidth;234 if (width != 300 && width != 0) {235 clearInterval(interval);236 elm.onload();237 }238 }239 if (tag == 'video') {240 interval = setInterval(check_video_width, 10);241 }242 }, 'loading image <'+tag+' '+attr+'>',243 {help:spec_url});244 }245 var query_to_image_width = {246 '%E5':1,247 '%C3%A5':2,248 '%3F':16,249 'unknown query':256,250 'default intrinsic width':300251 };252 var image_width_to_query = {};253 (function() {254 for (var x in query_to_image_width) {255 image_width_to_query[query_to_image_width[x]] = x;256 }257 })();258 var spec_url_load_image = {259 img:'https://html.spec.whatwg.org/multipage/#update-the-image-data',260 embed:'https://html.spec.whatwg.org/multipage/#the-embed-element-setup-steps',261 object:'https://html.spec.whatwg.org/multipage/#the-object-element',262 input:'https://html.spec.whatwg.org/multipage/#image-button-state-(type=image)',263 video:'https://html.spec.whatwg.org/multipage/#poster-frame'264 };265 'img src, embed src, object data, input src, video poster'.split(', ').forEach(function(str) {266 var arr = str.split(' ');267 test_load_image(arr[0], arr[1], spec_url_load_image[arr[0]]);268 });269 // XXX test <img srcset> or its successor270 // loading video271 function test_load_video(tag, use_source_element) {272 async_test(function() {273 var elm = document.createElement(tag);274 var video_ext = '';275 if (elm.canPlayType('video/ogg; codecs="theora,flac"')) {276 video_ext = 'ogv';277 } else if (elm.canPlayType('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')) {278 video_ext = 'mp4';279 }280 assert_not_equals(video_ext, '', 'no supported video format');281 var source;282 if (use_source_element) {283 source = document.createElement('source');284 elm.appendChild(source);285 } else {286 source = elm;287 }288 source.src = input_url_video + '&ext=' + video_ext;289 elm.preload = 'auto';290 elm.load();291 this.add_cleanup(function() {292 elm.removeAttribute('src');293 if (elm.firstChild) {294 elm.removeChild(elm.firstChild);295 }296 elm.load();297 });298 elm.onloadedmetadata = this.step_func_done(function() {299 var got = Math.round(elm.duration);300 assert_equals(got, query_to_video_duration[expected_current], msg(expected_current, video_duration_to_query[got]));301 });302 }, 'loading video <'+tag+'>' + (use_source_element ? '<source>' : ''),303 {help:'https://html.spec.whatwg.org/multipage/#concept-media-load-algorithm'});304 }305 var query_to_video_duration = {306 '%E5':3,307 '%C3%A5':5,308 '%3F':30,309 'unknown query':300,310 'Infinity':Infinity,311 'NaN':NaN312 };313 var video_duration_to_query = {};314 (function() {315 for (var x in query_to_video_duration) {316 video_duration_to_query[query_to_video_duration[x]] = x;317 }318 })();319 'video, audio'.split(', ').forEach(function(str) {320 test_load_video(str);321 test_load_video(str, true);322 });323 // loading webvtt324 async_test(function() {325 var video = document.createElement('video');326 var track = document.createElement('track');327 video.appendChild(track);328 track.src = input_url_webvtt;329 track.track.mode = 'showing';330 track.onload = this.step_func_done(function() {331 var got = track.track.cues[0].text;332 assert_equals(got, expected_current);333 });334 }, 'loading webvtt <track>',335 {help:'https://html.spec.whatwg.org/multipage/#track-url'});336 // XXX downloading seems hard to automate337 // <a href download>338 // <area href download>339 // submit forms340 function test_submit_form(tag, attr) {341 async_test(function(){342 var elm = document.createElement(tag);343 elm.setAttribute(attr, input_url_html);344 var form;345 var button;346 if (tag == 'form') {347 form = elm;348 button = document.createElement('button');349 } else {350 form = document.createElement('form');351 button = elm;352 }353 form.method = 'post';354 form.appendChild(button);355 var iframe = document.createElement('iframe');356 var id = 'test_submit_form_' + tag;357 iframe.name = id;358 form.target = id;359 button.type = 'submit';360 document.body.appendChild(form);361 document.body.appendChild(iframe);362 this.add_cleanup(function() {363 document.body.removeChild(form);364 document.body.removeChild(iframe);365 });366 button.click();367 iframe.onload = this.step_func_done(function() {368 var got = iframe.contentDocument.body.textContent;369 if (got == '') {370 return;371 }372 assert_equals(got, expected_current);373 });374 }, 'submit form <'+tag+' '+attr+'>',375 {help:'https://html.spec.whatwg.org/multipage/#concept-form-submit'});376 }377 'form action, input formaction, button formaction'.split(', ').forEach(function(str) {378 var arr = str.split(' ');379 test_submit_form(arr[0], arr[1]);380 });381 // <base href>382 async_test(function() {383 var iframe = document.createElement('iframe');384 iframe.src = blank;385 document.body.appendChild(iframe);386 this.add_cleanup(function() {387 document.body.removeChild(iframe);388 });389 iframe.onload = this.step_func_done(function() {390 var doc = iframe.contentDocument;391 doc.write('<!doctype html><base href="'+input_url+'"><a href></a>');392 doc.close();393 var got_baseURI = doc.baseURI;394 assert_true(got_baseURI.indexOf(expected_current) > -1, msg(expected_current, got_baseURI), 'doc.baseURI');395 var got_a_href = doc.links[0].href;396 assert_true(got_a_href.indexOf(expected_current) > -1, msg(expected_current, got_a_href), 'a.href');397 });398 }, '<base href>',399 {help:['https://html.spec.whatwg.org/multipage/#set-the-frozen-base-url',400 'https://dom.spec.whatwg.org/#dom-node-baseuri',401 'https://html.spec.whatwg.org/multipage/#the-a-element']});402 // XXX drag and drop (<a href> or <img src>) seems hard to automate403 // Worker()404 async_test(function() {405 var worker = new Worker(input_url_worker);406 worker.onmessage = this.step_func_done(function(e) {407 assert_equals(e.data, expected_current);408 });409 }, 'Worker constructor',410 {help:'https://html.spec.whatwg.org/multipage/#dom-worker'});411 // SharedWorker()412 async_test(function() {413 var worker = new SharedWorker(input_url_sharedworker);414 worker.port.onmessage = this.step_func_done(function(e) {415 assert_equals(e.data, expected_current);416 });417 }, 'SharedWorker constructor',418 {help:'https://html.spec.whatwg.org/multipage/#dom-sharedworker'});419 // EventSource()420 async_test(function() {421 var source = new EventSource(input_url_eventstream);422 this.add_cleanup(function() {423 source.close();424 });425 source.onmessage = this.step_func_done(function(e) {426 assert_equals(e.data, expected_current);427 });428 }, 'EventSource constructor',429 {help:'https://html.spec.whatwg.org/multipage/#dom-eventsource'});430 // EventSource#url431 test(function() {432 var source = new EventSource(input_url_eventstream);433 source.close();434 var got = source.url;435 assert_true(source.url.indexOf(expected_current) > -1, msg(expected_current, got));436 }, 'EventSource#url',437 {help:'https://html.spec.whatwg.org/multipage/#dom-eventsource'});438 // XMLDocument#load()439 async_test(function() {440 var doc = document.implementation.createDocument(null, "x");441 doc.load(input_url_svg);442 doc.onload = this.step_func_done(function() {443 assert_equals(doc.documentElement.textContent, expected_current);444 });445 }, 'XMLDocument#load()',446 {help:'https://html.spec.whatwg.org/multipage/#dom-xmldocument-load'});447 // window.open448 async_test(function() {449 var id = 'test_window_open';450 var iframe = document.createElement('iframe');451 iframe.name = id;452 document.body.appendChild(iframe);453 this.add_cleanup(function() {454 document.body.removeChild(iframe);455 });456 window.open(input_url_html, id);457 iframe.onload = this.step_func(function() {458 var got = iframe.contentDocument.body.textContent;459 if (got != "") {460 assert_equals(got, expected_current);461 this.done();462 }463 });464 }, 'window.open()',465 {help:'https://html.spec.whatwg.org/multipage/#dom-open'});466 // location467 function test_location(func, desc) {468 async_test(function() {469 var iframe = document.createElement('iframe');470 document.body.appendChild(iframe);471 this.add_cleanup(function() {472 document.body.removeChild(iframe);473 });474 func(iframe.contentWindow, input_url_html);475 iframe.onload = this.step_func(function() {476 var got = iframe.contentDocument.body.textContent;477 if (got != '') {478 assert_equals(got, expected_current);479 this.done();480 }481 });482 }, desc,483 {help:'https://html.spec.whatwg.org/multipage/#the-location-interface'});484 }485 [[function(win, input) { win.location = input; }, "location [PutForwards]"],486 [function(win, input) { win.location.assign(input); }, "location.assign()"],487 [function(win, input) { win.location.replace(input); }, "location.replace()"],488 [function(win, input) { win.location.href = input; }, "location.href"]].forEach(function(arr) {489 test_location(arr[0], arr[1]);490 });491 // location.search492 async_test(function() {493 var iframe = document.createElement('iframe');494 iframe.src = input_url_html;495 document.body.appendChild(iframe);496 this.add_cleanup(function() {497 document.body.removeChild(iframe);498 });499 var i = 0;500 iframe.onload = this.step_func(function() {501 i++;502 if (i == 1) {503 iframe.contentWindow.location.search = '?' + input_url_html.split('?')[1] + '&other=foobar';504 } else {505 var got = iframe.contentDocument.body.textContent;506 assert_equals(got, expected_current);507 this.done();508 }509 });510 }, 'location.search',511 {help:['https://html.spec.whatwg.org/multipage/#the-location-interface',512 'http://url.spec.whatwg.org/#dom-url-search']});513 // a.search, area.search514 function test_hyperlink_search(tag) {515 test(function() {516 var elm = document.createElement(tag);517 var input_arr = input_url_html.split('?');518 elm.href = input_arr[0];519 elm.search = '?' + input_arr[1];520 var got_href = elm.getAttribute('href');521 assert_true(got_href.indexOf(expected_current) > -1, 'href content attribute ' + msg(expected_current, got_href));522 var got_search = elm.search;523 assert_true(got_search.indexOf(expected_current) > -1, 'getting .search '+msg(expected_current, got_search));524 }, '<'+tag+'>.search',525 {help:['https://html.spec.whatwg.org/multipage/#the-'+tag+'-element',526 'http://url.spec.whatwg.org/#dom-url-search']});527 }528 'a, area'.split(', ').forEach(function(str) {529 test_hyperlink_search(str);530 });531 // history.pushState532 // history.replaceState533 function test_history(prop) {534 async_test(function() {535 var iframe = document.createElement('iframe');536 iframe.src = blank;537 document.body.appendChild(iframe);538 this.add_cleanup(function() {539 document.body.removeChild(iframe);540 });541 iframe.onload = this.step_func_done(function() {542 iframe.contentWindow.history[prop](null, null, input_url_html); // this should resolve against the test's URL, not the iframe's URL543 var got = iframe.contentWindow.location.href;544 assert_true(got.indexOf(expected_current) > -1, msg(expected_current, got));545 assert_equals(got.indexOf('/resources/resources/'), -1, 'url was resolved against the iframe\'s URL instead of the settings object\'s API base URL');546 });547 }, 'history.'+prop,548 {help:'https://html.spec.whatwg.org/multipage/#dom-history-'+prop.toLowerCase()});549 }550 'pushState, replaceState'.split(', ').forEach(function(str) {551 test_history(str);552 });553 // SVG554 var ns = {svg:'http://www.w3.org/2000/svg', xlink:'http://www.w3.org/1999/xlink'};555 // a556 async_test(function() {557 SVGAElement; // check support558 var iframe = document.createElement('iframe');559 var id = 'test_svg_a';560 iframe.name = id;561 var svg = document.createElementNS(ns.svg, 'svg');562 var a = document.createElementNS(ns.svg, 'a');563 a.setAttributeNS(ns.xlink, 'xlink:href', input_url_html);564 a.setAttribute('target', id);565 var span = document.createElement('span');566 a.appendChild(span);567 svg.appendChild(a);568 document.body.appendChild(iframe);569 document.body.appendChild(svg);570 this.add_cleanup(function() {571 document.body.removeChild(iframe);572 document.body.removeChild(svg);573 });574 span.click();575 iframe.onload = this.step_func_done(function() {576 var got = iframe.contentDocument.body.textContent;577 if (got != '') {578 assert_equals(got, expected_current);579 }580 });581 }, 'SVG <a>');582 // feImage, image, use583 function test_svg(func, tag) {584 async_test(function() {585 var uuid = token();586 var id = 'test_svg_'+tag;587 var svg = document.createElementNS(ns.svg, 'svg');588 var parent = func(svg, id);589 var elm = document.createElementNS(ns.svg, tag);590 elm.setAttributeNS(ns.xlink, 'xlink:href', stash_put + uuid + '#foo');591 parent.appendChild(elm);592 document.body.appendChild(svg);593 this.add_cleanup(function() {594 document.body.removeChild(svg);595 });596 poll_for_stash(this, uuid, expected_current);597 }, 'SVG <' + tag + '>',598 {help:'https://www.w3.org/Bugs/Public/show_bug.cgi?id=24148'});599 }600 [[function(svg, id) {601 SVGFEImageElement; // check support602 var filter = document.createElementNS(ns.svg, 'filter');603 filter.setAttribute('id', id);604 svg.appendChild(filter);605 var rect = document.createElementNS(ns.svg, 'rect');606 rect.setAttribute('filter', 'url(#'+id+')');607 svg.appendChild(rect);608 return filter;609 }, 'feImage'],610 [function(svg, id) { SVGImageElement; return svg; }, 'image'],611 [function(svg, id) { SVGUseElement; return svg; }, 'use']].forEach(function(arr) {612 test_svg(arr[0], arr[1]);613 });614 // UTF-8:615 // XHR616 async_test(function() {617 var xhr = new XMLHttpRequest();618 xhr.open('GET', input_url_html);619 xhr.onload = this.step_func_done(function() {620 assert_equals(xhr.response, expected_utf8);621 });622 xhr.send();623 }, 'XMLHttpRequest#open()',624 {help:'https://xhr.spec.whatwg.org/#the-open()-method'});625 // in a worker626 async_test(function() {627 var worker = new Worker(input_url_worker_importScripts);628 worker.onmessage = this.step_func_done(function(e) {629 assert_equals(e.data, expected_utf8);630 });631 }, 'importScripts() in a dedicated worker',632 {help:['https://html.spec.whatwg.org/multipage/#set-up-a-worker-script-settings-object',633 'https://html.spec.whatwg.org/multipage/#dom-workerglobalscope-importscripts']});634 async_test(function() {635 var worker = new Worker(input_url_worker_worker);636 worker.onmessage = this.step_func_done(function(e) {637 assert_equals(e.data, expected_utf8);638 });639 }, 'Worker() in a dedicated worker',640 {help:['https://html.spec.whatwg.org/multipage/#set-up-a-worker-script-settings-object',641 'https://html.spec.whatwg.org/multipage/#dom-worker']});642 async_test(function() {643 var worker = new Worker(input_url_worker_sharedworker);644 worker.onmessage = this.step_func_done(function(e) {645 assert_equals(e.data, expected_utf8);646 });647 }, 'SharedWorker() in a dedicated worker',648 {help:['https://html.spec.whatwg.org/multipage/#set-up-a-worker-script-settings-object',649 'https://html.spec.whatwg.org/multipage/#dom-sharedworker']});650 async_test(function() {651 var worker = new SharedWorker(input_url_sharedworker_importScripts);652 worker.port.onmessage = this.step_func_done(function(e) {653 assert_equals(e.data, expected_utf8);654 });655 }, 'importScripts() in a shared worker',656 {help:['https://html.spec.whatwg.org/multipage/#set-up-a-worker-script-settings-object',657 'https://html.spec.whatwg.org/multipage/#dom-workerglobalscope-importscripts']});658 async_test(function() {659 var worker = new SharedWorker(input_url_sharedworker_worker);660 worker.port.onmessage = this.step_func_done(function(e) {661 assert_equals(e.data, expected_utf8);662 });663 }, 'Worker() in a shared worker',664 {help:['https://html.spec.whatwg.org/multipage/#set-up-a-worker-script-settings-object',665 'https://html.spec.whatwg.org/multipage/#dom-worker']});666 async_test(function() {667 var worker = new SharedWorker(input_url_sharedworker_sharedworker);668 worker.port.onmessage = this.step_func_done(function(e) {669 assert_equals(e.data, expected_utf8);670 });671 }, 'SharedWorker() in a shared worker',672 {help:['https://html.spec.whatwg.org/multipage/#set-up-a-worker-script-settings-object',673 'https://html.spec.whatwg.org/multipage/#dom-sharedworker']});674 // WebSocket()675 async_test(function(){676 var ws = new WebSocket('ws://{{host}}:{{ports[ws][0]}}/echo-query?\u00E5');677 this.add_cleanup(function() {678 ws.close();679 });680 ws.onmessage = this.step_func_done(function(e) {681 assert_equals(e.data, expected_utf8);682 });683 }, 'WebSocket constructor',684 {help:'https://html.spec.whatwg.org/multipage/#parse-a-websocket-url\'s-components'});685 // WebSocket#url686 test(function(){687 var ws = new WebSocket('ws://{{host}}:{{ports[ws][0]}}/echo-query?\u00E5');688 ws.close();689 var got = ws.url;690 assert_true(ws.url.indexOf(expected_utf8) > -1, msg(expected_utf8, got));691 }, 'WebSocket#url',692 {help:'https://html.spec.whatwg.org/multipage/#dom-websocket-url'});693 // Parsing cache manifest694 function test_cache_manifest(mode) {695 async_test(function() {696 var iframe = document.createElement('iframe');697 var uuid = token();698 iframe.src = 'resources/page-using-manifest.py?id='+uuid+'&encoding='+encoding+'&mode='+mode;699 document.body.appendChild(iframe);700 this.add_cleanup(function() {701 document.body.removeChild(iframe);702 });703 poll_for_stash(this, uuid, expected_utf8);704 }, 'Parsing cache manifest (' + mode + ')',705 {help:'https://html.spec.whatwg.org/multipage/#parse-a-manifest'});706 }707 'CACHE, FALLBACK, NETWORK'.split(', ').forEach(function(str) {708 test_cache_manifest(str);709 });710 // CSS711 function test_css(tmpl, expected_cssom, encoding, use_style_element) {712 var desc = ['CSS', (use_style_element ? '<style>' : '<link> (' + encoding + ')'), tmpl].join(' ');713 async_test(function(){714 css_is_supported(tmpl, expected_cssom, this);715 var uuid = token();716 var id = 'test_css_' + uuid;717 var url = 'url(stash.py?q=%s&action=put&id=' + uuid + ')';718 tmpl = tmpl.replace(/<id>/g, id).replace(/<url>/g, url);719 var link;720 if (use_style_element) {721 link = document.createElement('style');722 link.textContent = tmpl.replace(/%s/g, '\u00E5').replace(/stash\.py/g, 'resources/stash.py');723 } else {724 link = document.createElement('link');725 link.rel = 'stylesheet';726 link.href = 'resources/css-tmpl.py?encoding='+encoding+'&tmpl='+encodeURIComponent(tmpl);727 }728 var div = document.createElement('div');729 div.id = id;730 div.textContent='x';731 document.head.appendChild(link);732 document.body.appendChild(div);733 this.add_cleanup(function() {734 document.head.removeChild(link);735 document.body.removeChild(div);736 });737 poll_for_stash(this, uuid, expected_utf8);738 }, desc,739 {help:'https://www.w3.org/Bugs/Public/show_bug.cgi?id=23968'});740 }741 // fail fast if the input doesn't parse into the expected cssom742 function css_is_supported(tmpl, expected_cssom, test_obj) {743 if (expected_cssom === null) {744 return;745 }746 var style = document.createElement('style');747 style.textContent = tmpl.replace(/<id>/g, 'x').replace(/<url>/g, 'url(data:,)');748 document.head.appendChild(style);749 test_obj.add_cleanup(function() {750 document.head.removeChild(style);751 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3 console.log(data);4});5var wpt = require('webpagetest');6var client = wpt('www.webpagetest.org');7client.get_locations(function(err, data) {8 console.log(data);9});10var wpt = require('webpagetest');11var client = wpt('www.webpagetest.org');12client.get_testers(function(err, data) {13 console.log(data);14});15var wpt = require('webpagetest');16var client = wpt('www.webpagetest.org');17 console.log(data);18});19var wpt = require('webpagetest');20var client = wpt('www.webpagetest.org');21 console.log(data);22});23var wpt = require('webpagetest');24var client = wpt('www.webpagetest.org');25client.get_testers(function(err, data) {26 console.log(data);27});28var wpt = require('webpagetest');29var client = wpt('www.webpagetest.org');30client.get_testers(function(err, data) {31 console.log(data);32});33var wpt = require('webpagetest');34var client = wpt('www.webpagetest.org');35client.get_testers(function(err, data) {36 console.log(data);37});38var wpt = require('webpagetest');39var client = wpt('www.webpagetest.org');

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});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt_client');2var wpt_client = new wpt('your_api_key');3wpt_client.poll_for_stash('stash_id', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('wpt_client');11var wpt_client = new wpt('your_api_key');12wpt_client.get_test_info('test_id', function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('wpt_client');20var wpt_client = new wpt('your_api_key');21wpt_client.get_test_result('test_id', function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('wpt_client');29var wpt_client = new wpt('your_api_key');30wpt_client.get_test_result('test_id', function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var wpt = require('wpt_client');38var wpt_client = new wpt('your_api_key');39wpt_client.get_test_status('test_id', function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var wpt = require('wpt_client');47var wpt_client = new wpt('your_api_key');48wpt_client.get_test_video('test_id', function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var wpt = require('wpt_client');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var wpt = new wpt("API_KEY");3wpt.poll_for_stash("STASH_ID", function(err, data) {4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});

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