How to use assert_not_prefetched method in wpt

Best JavaScript code snippet using wpt

utils.sub.js

Source:utils.sub.js Github

copy

Full Screen

1/**2 * Utilities for initiating prefetch via speculation rules.3 */4// Resolved URL to find this script.5const SR_PREFETCH_UTILS_URL = new URL(document.currentScript.src, document.baseURI);6// Hostname for cross origin urls.7const PREFETCH_PROXY_BYPASS_HOST = "{{hosts[alt][]}}";8class PrefetchAgent extends RemoteContext {9 constructor(uuid, t) {10 super(uuid);11 this.t = t;12 }13 getExecutorURL(options = {}) {14 let {hostname, protocol, ...extra} = options;15 let params = new URLSearchParams({uuid: this.context_id, ...extra});16 let url = new URL(`executor.sub.html?${params}`, SR_PREFETCH_UTILS_URL);17 if(hostname !== undefined) {18 url.hostname = hostname;19 }20 if(protocol !== undefined) {21 url.protocol = protocol;22 url.port = protocol === "https" ? "{{ports[https][0]}}" : "{{ports[http][0]}}";23 }24 return url;25 }26 // Requests prefetch via speculation rules.27 //28 // In the future, this should also use browser hooks to force the prefetch to29 // occur despite heuristic matching, etc., and await the completion of the30 // prefetch.31 async forceSinglePrefetch(url, extra = {}) {32 await this.execute_script((url, extra) => {33 insertSpeculationRules({ prefetch: [{source: 'list', urls: [url], ...extra}] });34 }, [url, extra]);35 return new Promise(resolve => this.t.step_timeout(resolve, 2000));36 }37 async navigate(url) {38 await this.execute_script((url) => {39 window.executor.suspend(() => {40 location.href = url;41 });42 }, [url]);43 assert_equals(44 await this.execute_script(() => location.href),45 url.toString(),46 "expected navigation to reach destination URL");47 await this.execute_script(() => {});48 }49 async getRequestHeaders() {50 return this.execute_script(() => requestHeaders);51 }52}53// Produces n URLs with unique UUIDs which will record when they are prefetched.54function getPrefetchUrlList(n) {55 let urls = [];56 for (let i=0; i<n; i++) {57 let params = new URLSearchParams({uuid: token()});58 urls.push(new URL(`prefetch.py?${params}`, SR_PREFETCH_UTILS_URL));59 }60 return urls;61}62async function isUrlPrefetched(url) {63 let response = await fetch(url);64 assert_true(response.ok);65 return response.json();66}67// Must also include /common/utils.js and /common/dispatcher/dispatcher.js to use this.68async function spawnWindow(t, extra = {}) {69 let agent = new PrefetchAgent(token(), t);70 let w = window.open(agent.getExecutorURL(), extra);71 t.add_cleanup(() => w.close());72 return agent;73}74function insertSpeculationRules(body) {75 let script = document.createElement('script');76 script.type = 'speculationrules';77 script.textContent = JSON.stringify(body);78 document.head.appendChild(script);79}80function assert_prefetched (requestHeaders, description) {81 assert_in_array(requestHeaders.purpose, ["", "prefetch"], "The vendor-specific header Purpose, if present, must be 'prefetch'.");82 assert_equals(requestHeaders.sec_purpose, "prefetch", description);83}84function assert_not_prefetched (requestHeaders, description){85 assert_equals(requestHeaders.purpose, "", description);86 assert_equals(requestHeaders.sec_purpose, "", description);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("/resources/testharness.js");2wpt.add_completion_callback(function() {3 wpt.done();4});5wpt.add_cleanup(function() {6 wpt.done();7});8wpt.test(func

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert_not_prefetched = async_test("Test that the resource is not prefetched");2var request = new XMLHttpRequest();3request.open("GET", "resources/prefetch.py?test=assert_not_prefetched");4request.send();5request.onload = assert_not_prefetched.step_func(function() {6 assert_equals(request.status, 200, "Request status should be 200");7 assert_not_prefetched.done();8});9def main(request, response):10 if request.GET.first("test") == "assert_not_prefetched":

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptserve = require('./wptserve');2var assert_not_prefetched = wptserve.assert_not_prefetched;3var assert = wptserve.assert;4function setup() {5 return {headers: {'Cache-Control': 'max-age=3600'}};6}7function response(request, response_headers) {8 var url = request.url;9 var headers = request.headers;10 var cookie = headers.cookie;11 assert_not_prefetched(request, "Request should not be prefetched");12 assert_not_cached(request, "Request should not be cached");13 return "PASS";14}15function assert_not_cached(request, message) {16 var headers = request.headers;17 var cookie = headers.cookie;18 assert(cookie.indexOf('cached') == -1, message);19}20var wptserve = require('./wptserve');21var assert_not_prefetched = wptserve.assert_not_prefetched;22var assert = wptserve.assert;23function setup() {24 return {headers: {'Cache-Control': 'max-age=3600'}};25}26function response(request, response_headers) {27 var url = request.url;28 var headers = request.headers;29 var cookie = headers.cookie;30 assert_not_prefetched(request, "Request should not be prefetched");31 assert_not_cached(request, "Request should not be cached");32 return "PASS";33}34function assert_not_cached(request, message) {35 var headers = request.headers;36 var cookie = headers.cookie;37 assert(cookie.indexOf('cached') == -1, message);38}

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