Bug 1686820 [wpt PR 27193] - Origin-keyed agent clusters: make COI imply origin-keyin...
[gecko.git] / docshell / test / browser / browser_viewsource_multipart.js
blob3a3a5836af6d273b0bc3b33d6a393141a80f3cae
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
3 "use strict";
5 const TEST_PATH = getRootDirectory(gTestPath).replace(
6   "chrome://mochitests/content",
7   "http://example.com"
8 );
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
19     // loaded.
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;
25       });
27       ok(value == "First" || value == "Second", "some other value was found?");
28       return value == "Second";
29     });
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;
38     });
40     ok(viewSourceContent.includes("<h1>First</h1>"), "first header");
41     ok(viewSourceContent.includes("<h1>Second</h1>"), "second header");
42     ok(viewSourceContent.includes("BOUNDARY"), "boundary");
43   });
44 });