Files
Alexandre Poirot 25c8ad77e8 Bug 2007539 - [devtools] Reload pages as Firefox does in DevTools tests. r=devtools-reviewers,nchevobbe
The `gBrowser.reloadTab` method was doing a very light reload,
which could preserve iframe overriden locations.
The new method ensures we load the original HTML content back,
this seems to also have an impact on keep-alive which is not longer guaranteed.

Only supports reloading the currently selected tab, to better replicate
real user scenarios. But also to comply to `BrowserCommands.reload`,
which only supports reloading the selected tab.

Also tune the har test, now that requests are really cancelled
and we may try to fetch reponse content for such request.

Differential Revision: https://phabricator.services.mozilla.com/D277433
2026-01-20 20:44:46 +00:00

100 lines
3.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_JSON_FILE = "simple_json.json";
add_task(async function () {
info("Test JSON refresh started");
// generate file:// URI for JSON file and load in new tab
const dir = getChromeDir(getResolvedURI(gTestPath));
dir.append(TEST_JSON_FILE);
dir.normalize();
const uri = Services.io.newFileURI(dir);
const tab = await addJsonViewTab(uri.spec);
// perform sanity checks for URI and principals in loadInfo
await SpecialPowers.spawn(
tab.linkedBrowser,
[{ TEST_JSON_FILE }],
// eslint-disable-next-line no-shadow
async function ({ TEST_JSON_FILE }) {
const channel = content.docShell.currentDocumentChannel;
const channelURI = channel.URI.spec;
ok(
channelURI.startsWith("file://") && channelURI.includes(TEST_JSON_FILE),
"sanity: correct channel uri"
);
const contentPolicyType = channel.loadInfo.externalContentPolicyType;
is(
contentPolicyType,
Ci.nsIContentPolicy.TYPE_DOCUMENT,
"sanity: correct contentPolicyType"
);
const loadingPrincipal = channel.loadInfo.loadingPrincipal;
is(loadingPrincipal, null, "sanity: correct loadingPrincipal");
const triggeringPrincipal = channel.loadInfo.triggeringPrincipal;
ok(
triggeringPrincipal.isSystemPrincipal,
"sanity: correct triggeringPrincipal"
);
const principalToInherit = channel.loadInfo.principalToInherit;
ok(
principalToInherit.isNullPrincipal,
"sanity: correct principalToInherit"
);
is(
content.document.nodePrincipal.origin,
"resource://devtools",
"sanity: correct doc.nodePrincipal"
);
}
);
// reload the tab
await reloadSelectedTab();
// check principals in loadInfo are still correct
await SpecialPowers.spawn(
tab.linkedBrowser,
[{ TEST_JSON_FILE }],
// eslint-disable-next-line no-shadow
async function ({ TEST_JSON_FILE }) {
// eslint-disable-line
const channel = content.docShell.currentDocumentChannel;
const channelURI = channel.URI.spec;
ok(
channelURI.startsWith("file://") && channelURI.includes(TEST_JSON_FILE),
"reloaded: correct channel uri"
);
const contentPolicyType = channel.loadInfo.externalContentPolicyType;
is(
contentPolicyType,
Ci.nsIContentPolicy.TYPE_DOCUMENT,
"reloaded: correct contentPolicyType"
);
const loadingPrincipal = channel.loadInfo.loadingPrincipal;
is(loadingPrincipal, null, "reloaded: correct loadingPrincipal");
const triggeringPrincipal = channel.loadInfo.triggeringPrincipal;
ok(
triggeringPrincipal.isSystemPrincipal,
"reloaded: correct triggeringPrincipal"
);
const principalToInherit = channel.loadInfo.principalToInherit;
ok(
principalToInherit.isNullPrincipal,
"sanity: correct principalToInherit"
);
is(
content.document.nodePrincipal.origin,
"resource://devtools",
"reloaded: correct doc.nodePrincipal"
);
}
);
});