1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const DOC = toDataURL(`<script>document.write(navigator.userAgent);</script>`);
// Network.setUserAgentOverride is a redirect to Emulation.setUserAgentOverride.
// Run at least one test for setting and resetting the user agent to make sure
// that the redirect works.
add_task(async function forwardToEmulation({ client }) {
const { Network } = client;
const userAgent = "Mozilla/5.0 (rv: 23) Romanesco/42.0";
const platform = "foobar";
await loadURL(DOC);
const originalUserAgent = await getNavigatorProperty("userAgent");
const originalPlatform = await getNavigatorProperty("platform");
isnot(originalUserAgent, userAgent, "Custom user agent hasn't been set");
isnot(originalPlatform, platform, "Custom platform hasn't been set");
await Network.setUserAgentOverride({ userAgent, platform });
await loadURL(DOC);
is(
await getNavigatorProperty("userAgent"),
userAgent,
"Custom user agent has been set"
);
is(
await getNavigatorProperty("platform"),
platform,
"Custom platform has been set"
);
await Network.setUserAgentOverride({ userAgent: "", platform: "" });
await loadURL(DOC);
is(
await getNavigatorProperty("userAgent"),
originalUserAgent,
"Custom user agent has been reset"
);
is(
await getNavigatorProperty("platform"),
originalPlatform,
"Custom platform has been reset"
);
await Network.setUserAgentOverride({ userAgent, platform });
await loadURL(DOC);
is(
await getNavigatorProperty("userAgent"),
userAgent,
"Custom user agent has been set"
);
is(
await getNavigatorProperty("platform"),
platform,
"Custom platform has been set"
);
});
async function getNavigatorProperty(prop) {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [prop], _prop => {
return content.navigator[_prop];
});
}
|