1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
5 const TEST_PATH = getRootDirectory(gTestPath).replace(
6 "chrome://mochitests/content",
9 const MULTIPART_URI = `${TEST_PATH}file_basic_multipart.sjs`;
11 add_task(async function viewsource_multipart_uri() {
12 await BrowserTestUtils.withNewTab("about:blank", async browser => {
13 BrowserTestUtils.loadURI(browser, MULTIPART_URI);
14 await BrowserTestUtils.browserLoaded(browser);
15 is(browser.currentURI.spec, MULTIPART_URI);
17 // Continue probing the URL until we find the h1 we're expecting. This
18 // should handle cases where we somehow beat the second document having
20 await TestUtils.waitForCondition(async () => {
21 let value = await SpecialPowers.spawn(browser, [], async () => {
22 let headers = content.document.querySelectorAll("h1");
23 is(headers.length, 1, "only one h1 should be present");
24 return headers[0].textContent;
27 ok(value == "First" || value == "Second", "some other value was found?");
28 return value == "Second";
31 // Load a view-source version of the page, which should show the full
32 // content, not handling multipart.
33 BrowserTestUtils.loadURI(browser, `view-source:${MULTIPART_URI}`);
34 await BrowserTestUtils.browserLoaded(browser);
36 let viewSourceContent = await SpecialPowers.spawn(browser, [], async () => {
37 return content.document.body.textContent;
40 ok(viewSourceContent.includes("<h1>First</h1>"), "first header");
41 ok(viewSourceContent.includes("<h1>Second</h1>"), "second header");
42 ok(viewSourceContent.includes("BOUNDARY"), "boundary");