зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1628608 - P2 - Browser Mochitests added to test if loading a blob URL in a new foreground tab works r=baku
Two cases have been tested: 1. Loading a blob URL, which points to a blob of type text 2. Loading a blob URL, which points to a blob of type html, which fetches another blob URL Depends on D71889 Differential Revision: https://phabricator.services.mozilla.com/D72026
This commit is contained in:
Родитель
c4ebd85665
Коммит
0254684859
|
@ -11,9 +11,10 @@ const RESOURCE_LINK =
|
|||
|
||||
const blobDataAsString = `!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`;
|
||||
|
||||
// Helper method to open link in new tab and return the content of the first <pre> under <body>
|
||||
// Link is selected by using string argument 'selector' as id
|
||||
async function open_in_new_tab_and_return_content(selector) {
|
||||
// Helper method to right click on the provided link (selector as id),
|
||||
// open in new tab and return the content of the first <pre> under the
|
||||
// <body> of the new tab's document.
|
||||
async function rightClickOpenInNewTabAndReturnContent(selector) {
|
||||
const loaded = BrowserTestUtils.browserLoaded(
|
||||
gBrowser.selectedBrowser,
|
||||
false,
|
||||
|
@ -80,13 +81,62 @@ async function open_in_new_tab_and_return_content(selector) {
|
|||
}
|
||||
);
|
||||
|
||||
let tabClosed = BrowserTestUtils.waitForTabClosing(openTab);
|
||||
await BrowserTestUtils.removeTab(openTab);
|
||||
await tabClosed;
|
||||
|
||||
return blobDataFromContent;
|
||||
}
|
||||
|
||||
// Helper method to open selected link in new tab (selector as id),
|
||||
// and return the content of the first <pre> under the <body> of
|
||||
// the new tab's document.
|
||||
async function openInNewTabAndReturnContent(selector) {
|
||||
const loaded = BrowserTestUtils.browserLoaded(
|
||||
gBrowser.selectedBrowser,
|
||||
false,
|
||||
RESOURCE_LINK
|
||||
);
|
||||
await BrowserTestUtils.loadURI(gBrowser.selectedBrowser, RESOURCE_LINK);
|
||||
await loaded;
|
||||
|
||||
const generatedBlobURL = await ContentTask.spawn(
|
||||
gBrowser.selectedBrowser,
|
||||
{ selector },
|
||||
async args => {
|
||||
return content.document.getElementById(args.selector).href;
|
||||
}
|
||||
);
|
||||
|
||||
let openTab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
generatedBlobURL
|
||||
);
|
||||
|
||||
let blobDataFromContent = await ContentTask.spawn(
|
||||
gBrowser.selectedBrowser,
|
||||
null,
|
||||
async function() {
|
||||
while (!content.document.querySelector("body pre")) {
|
||||
await new Promise(resolve =>
|
||||
content.setTimeout(() => {
|
||||
resolve();
|
||||
}, 100)
|
||||
);
|
||||
}
|
||||
return content.document.body.firstElementChild.innerText.trim();
|
||||
}
|
||||
);
|
||||
|
||||
let tabClosed = BrowserTestUtils.waitForTabClosing(openTab);
|
||||
await BrowserTestUtils.removeTab(openTab);
|
||||
await tabClosed;
|
||||
|
||||
return blobDataFromContent;
|
||||
}
|
||||
|
||||
add_task(async function test_rightclick_open_bloburl_in_new_tab() {
|
||||
let blobDataFromLoadedPage = await open_in_new_tab_and_return_content(
|
||||
let blobDataFromLoadedPage = await rightClickOpenInNewTabAndReturnContent(
|
||||
"blob-url-link"
|
||||
);
|
||||
is(
|
||||
|
@ -97,7 +147,29 @@ add_task(async function test_rightclick_open_bloburl_in_new_tab() {
|
|||
});
|
||||
|
||||
add_task(async function test_rightclick_open_bloburl_referrer_in_new_tab() {
|
||||
let blobDataFromLoadedPage = await open_in_new_tab_and_return_content(
|
||||
let blobDataFromLoadedPage = await rightClickOpenInNewTabAndReturnContent(
|
||||
"blob-url-referrer-link"
|
||||
);
|
||||
is(
|
||||
blobDataFromLoadedPage,
|
||||
blobDataAsString,
|
||||
"The blobURL is correctly loaded"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_open_bloburl_in_new_tab() {
|
||||
let blobDataFromLoadedPage = await openInNewTabAndReturnContent(
|
||||
"blob-url-link"
|
||||
);
|
||||
is(
|
||||
blobDataFromLoadedPage,
|
||||
blobDataAsString,
|
||||
"The blobURL is correctly loaded"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_open_bloburl_referrer_in_new_tab() {
|
||||
let blobDataFromLoadedPage = await openInNewTabAndReturnContent(
|
||||
"blob-url-referrer-link"
|
||||
);
|
||||
is(
|
||||
|
|
Загрузка…
Ссылка в новой задаче