mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 09:49:14 +00:00
Bug 1596101 - [remote] Forward Network.setUserAgentOverride to Emulation.setUserAgentOverride. r=remote-protocol-reviewers,maja_zf
The method under the Network domain is a redirect to Emulation only. It might be deprecated, but that's unclear in the current documentation. Differential Revision: https://phabricator.services.mozilla.com/D52929 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
727713505e
commit
dfa891644c
@ -75,6 +75,16 @@ class Network extends Domain {
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows overriding user agent with the given string.
|
||||
*
|
||||
* Redirected to Emulation.setUserAgentOverride.
|
||||
*/
|
||||
setUserAgentOverride(options) {
|
||||
const { id } = this.session;
|
||||
this.session.execute(id, "Emulation", "setUserAgentOverride", options);
|
||||
}
|
||||
|
||||
_onRequest(eventName, httpChannel, data) {
|
||||
const topFrame = getLoadContext(httpChannel).topFrameElement;
|
||||
const request = {
|
||||
|
@ -55,6 +55,59 @@ add_task(async function invalidUserAgent({ Emulation }) {
|
||||
ok(errorThrown, "Invalid user agent format raised error");
|
||||
});
|
||||
|
||||
// Network.setUserAgentOverride is a redirect to Emulation.setUserAgentOverride.
|
||||
// Run duplicated tests for Network to ensure the redirect works.
|
||||
|
||||
add_task(async function networkSetAndResetUserAgent({ Network }) {
|
||||
const userAgent = "foo bar";
|
||||
|
||||
await loadURL(DOC);
|
||||
isnot(
|
||||
await getNavigatorProperty("userAgent"),
|
||||
userAgent,
|
||||
"Custom user agent hasn't been set"
|
||||
);
|
||||
|
||||
try {
|
||||
await Network.setUserAgentOverride({ userAgent });
|
||||
await loadURL(DOC);
|
||||
is(
|
||||
await getNavigatorProperty("userAgent"),
|
||||
userAgent,
|
||||
"Custom user agent has been set"
|
||||
);
|
||||
|
||||
await Network.setUserAgentOverride({ userAgent: "" });
|
||||
await loadURL(DOC);
|
||||
isnot(
|
||||
await getNavigatorProperty("userAgent"),
|
||||
userAgent,
|
||||
"Custom user agent hasn't been set anymore"
|
||||
);
|
||||
} finally {
|
||||
Services.prefs.clearUserPref("general.useragent.override");
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function networkInvalidUserAgent({ Network }) {
|
||||
const userAgent = "foobar\n";
|
||||
|
||||
await loadURL(DOC);
|
||||
isnot(
|
||||
await getNavigatorProperty("userAgent"),
|
||||
userAgent,
|
||||
"Custom user agent hasn't been set"
|
||||
);
|
||||
|
||||
let errorThrown = false;
|
||||
try {
|
||||
await Network.setUserAgentOverride({ userAgent });
|
||||
} catch (e) {
|
||||
errorThrown = true;
|
||||
}
|
||||
ok(errorThrown, "Invalid user agent format raised error");
|
||||
});
|
||||
|
||||
async function getNavigatorProperty(prop) {
|
||||
return ContentTask.spawn(gBrowser.selectedBrowser, prop, _prop => {
|
||||
return content.navigator[_prop];
|
||||
|
Loading…
x
Reference in New Issue
Block a user