browser_document_builder_sjs.js (2086B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Checks that document-builder.sjs works as expected 6 add_task(async function assertHtmlParam() { 7 const html = "<main><h1>I'm built different</h1></main>"; 8 const delay = 5000; 9 10 const params = new URLSearchParams({ 11 delay, 12 html, 13 }); 14 params.append("headers", "x-header-1:a"); 15 params.append("headers", "x-header-2:b"); 16 17 const startTime = performance.now(); 18 const request = new Request( 19 `https://example.com/document-builder.sjs?${params}` 20 ); 21 info("Do a fetch request to document-builder.sjs"); 22 const response = await fetch(request); 23 const duration = performance.now() - startTime; 24 25 is(response.status, 200, "Response is a 200"); 26 Assert.greater( 27 duration, 28 delay, 29 `The delay parameter works as expected (took ${duration}ms)` 30 ); 31 32 const responseText = await response.text(); 33 is(responseText, html, "The response has the expected content"); 34 35 is( 36 response.headers.get("content-type"), 37 "text/html", 38 "response has the expected content-type" 39 ); 40 is( 41 response.headers.get("x-header-1"), 42 "a", 43 "first header was set as expected" 44 ); 45 is( 46 response.headers.get("x-header-2"), 47 "b", 48 "second header was set as expected" 49 ); 50 }); 51 52 add_task(async function assertFileParam() { 53 const file = `browser/testing/mochitest/tests/browser/dummy.html`; 54 const request = new Request( 55 `https://example.com/document-builder.sjs?file=${file}` 56 ); 57 58 info("Do a fetch request to document-builder.sjs with a `file` parameter"); 59 const response = await fetch(request); 60 is(response.status, 200, "Response is a 200"); 61 is( 62 response.headers.get("content-type"), 63 "text/html", 64 "response has the expected content-type" 65 ); 66 67 const responseText = await response.text(); 68 const parser = new DOMParser(); 69 const doc = parser.parseFromString(responseText, "text/html"); 70 is( 71 doc.body.innerHTML.trim(), 72 "This is a dummy page", 73 "The response has the file content" 74 ); 75 });