browser_viewsource_multipart.js (1797B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 const TEST_PATH = getRootDirectory(gTestPath).replace( 6 "chrome://mochitests/content", 7 "https://example.com" 8 ); 9 const MULTIPART_URI = `${TEST_PATH}file_basic_multipart.sjs`; 10 11 add_task(async function viewsource_multipart_uri() { 12 await BrowserTestUtils.withNewTab("about:blank", async browser => { 13 BrowserTestUtils.startLoadingURIString(browser, MULTIPART_URI); 14 await BrowserTestUtils.browserLoaded(browser); 15 is(browser.currentURI.spec, MULTIPART_URI); 16 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 }); 26 27 ok(value == "First" || value == "Second", "some other value was found?"); 28 return value == "Second"; 29 }); 30 31 // Load a view-source version of the page, which should show the full 32 // content, not handling multipart. 33 BrowserTestUtils.startLoadingURIString( 34 browser, 35 `view-source:${MULTIPART_URI}` 36 ); 37 await BrowserTestUtils.browserLoaded(browser); 38 39 let viewSourceContent = await SpecialPowers.spawn(browser, [], async () => { 40 return content.document.body.textContent; 41 }); 42 43 ok(viewSourceContent.includes("<h1>First</h1>"), "first header"); 44 ok(viewSourceContent.includes("<h1>Second</h1>"), "second header"); 45 ok(viewSourceContent.includes("BOUNDARY"), "boundary"); 46 }); 47 });