gecko-dev/browser/base/content/test/about/browser_aboutStopReload.js
Nika Layzell 42028efc71 Bug 1671983 - Part 4: Stop awaiting BrowserTestUtils.loadURI, r=annyG,remote-protocol-reviewers,extension-reviewers,preferences-reviewers,whimboo,zombie
This method only is async in order to allow callers to wait for a process switch
triggered by the call to `loadURI` to be finished before resolving. With
DocumentChannel, we should never trigger a process switch eagerly like this
again, so we don't need any of the async behaviour here anymore.

This part is largely mechanical changes to tests, removing the `await` calls on
`loadURI`, and a follow-up part will remove the actual async logic from
`BrowserTestUtils.loadURI`.

Differential Revision: https://phabricator.services.mozilla.com/D94641
2020-11-12 18:01:03 +00:00

169 lines
5.1 KiB
JavaScript

async function waitForNoAnimation(elt) {
return TestUtils.waitForCondition(() => !elt.hasAttribute("animate"));
}
async function getAnimatePromise(elt) {
return BrowserTestUtils.waitForAttribute("animate", elt).then(() =>
Assert.ok(true, `${elt.id} should animate`)
);
}
function stopReloadMutationCallback() {
Assert.ok(
false,
"stop-reload's animate attribute should not have been mutated"
);
}
// Force-enable the animation
gReduceMotionOverride = false;
add_task(async function checkDontShowStopOnNewTab() {
let stopReloadContainer = document.getElementById("stop-reload-button");
let stopReloadContainerObserver = new MutationObserver(
stopReloadMutationCallback
);
await waitForNoAnimation(stopReloadContainer);
stopReloadContainerObserver.observe(stopReloadContainer, {
attributeFilter: ["animate"],
});
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: "about:robots",
waitForStateStop: true,
});
BrowserTestUtils.removeTab(tab);
Assert.ok(
true,
"Test finished: stop-reload does not animate when navigating to local URI on new tab"
);
stopReloadContainerObserver.disconnect();
});
add_task(async function checkDontShowStopFromLocalURI() {
let stopReloadContainer = document.getElementById("stop-reload-button");
let stopReloadContainerObserver = new MutationObserver(
stopReloadMutationCallback
);
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: "about:robots",
waitForStateStop: true,
});
await waitForNoAnimation(stopReloadContainer);
stopReloadContainerObserver.observe(stopReloadContainer, {
attributeFilter: ["animate"],
});
BrowserTestUtils.loadURI(tab.linkedBrowser, "about:mozilla");
BrowserTestUtils.removeTab(tab);
Assert.ok(
true,
"Test finished: stop-reload does not animate when navigating between local URIs"
);
stopReloadContainerObserver.disconnect();
});
add_task(async function checkDontShowStopFromNonLocalURI() {
let stopReloadContainer = document.getElementById("stop-reload-button");
let stopReloadContainerObserver = new MutationObserver(
stopReloadMutationCallback
);
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: "https://example.com",
waitForStateStop: true,
});
await waitForNoAnimation(stopReloadContainer);
stopReloadContainerObserver.observe(stopReloadContainer, {
attributeFilter: ["animate"],
});
BrowserTestUtils.loadURI(tab.linkedBrowser, "about:mozilla");
BrowserTestUtils.removeTab(tab);
Assert.ok(
true,
"Test finished: stop-reload does not animate when navigating to local URI from non-local URI"
);
stopReloadContainerObserver.disconnect();
});
add_task(async function checkDoShowStopOnNewTab() {
let stopReloadContainer = document.getElementById("stop-reload-button");
let reloadButton = document.getElementById("reload-button");
let stopPromise = BrowserTestUtils.waitForAttribute(
"displaystop",
reloadButton
);
await waitForNoAnimation(stopReloadContainer);
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: "https://example.com",
waitForStateStop: true,
});
await stopPromise;
await waitForNoAnimation(stopReloadContainer);
BrowserTestUtils.removeTab(tab);
info(
"Test finished: stop-reload shows stop when navigating to non-local URI during tab opening"
);
});
add_task(async function checkAnimateStopOnTabAfterTabFinishesOpening() {
let stopReloadContainer = document.getElementById("stop-reload-button");
await waitForNoAnimation(stopReloadContainer);
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
waitForStateStop: true,
});
await TestUtils.waitForCondition(() => {
info(
"Waiting for tabAnimationsInProgress to equal 0, currently " +
gBrowser.tabAnimationsInProgress
);
return !gBrowser.tabAnimationsInProgress;
});
let animatePromise = getAnimatePromise(stopReloadContainer);
BrowserTestUtils.loadURI(tab.linkedBrowser, "https://example.com");
await animatePromise;
BrowserTestUtils.removeTab(tab);
info(
"Test finished: stop-reload animates when navigating to non-local URI on new tab after tab has opened"
);
});
add_task(async function checkDoShowStopFromLocalURI() {
let stopReloadContainer = document.getElementById("stop-reload-button");
await waitForNoAnimation(stopReloadContainer);
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: "about:robots",
waitForStateStop: true,
});
await TestUtils.waitForCondition(() => {
info(
"Waiting for tabAnimationsInProgress to equal 0, currently " +
gBrowser.tabAnimationsInProgress
);
return !gBrowser.tabAnimationsInProgress;
});
let animatePromise = getAnimatePromise(stopReloadContainer);
BrowserTestUtils.loadURI(tab.linkedBrowser, "https://example.com");
await animatePromise;
await waitForNoAnimation(stopReloadContainer);
BrowserTestUtils.removeTab(tab);
info(
"Test finished: stop-reload animates when navigating to non-local URI from local URI"
);
});