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
69
70
71
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const EXAMPLE_ORG_URL = "https://example.org/browser/dom/midi/tests/";
const PAGE = "refresh_port_list.html";
async function get_access(browser) {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
return content.wrappedJSObject.get_access();
});
}
async function reset_access(browser) {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
return content.wrappedJSObject.reset_access();
});
}
async function get_num_ports(browser) {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
return content.wrappedJSObject.get_num_ports();
});
}
async function add_port(browser) {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
return content.wrappedJSObject.add_port();
});
}
async function remove_port(browser) {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
return content.wrappedJSObject.remove_port();
});
}
async function force_refresh(browser) {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
return content.wrappedJSObject.force_refresh();
});
}
add_task(async function () {
gBrowser.selectedTab = BrowserTestUtils.addTab(
gBrowser,
EXAMPLE_ORG_URL + PAGE
);
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
await get_access(gBrowser.selectedBrowser);
let ports_num = await get_num_ports(gBrowser.selectedBrowser);
Assert.equal(ports_num, 4, "We start with four ports");
await add_port(gBrowser.selectedBrowser);
ports_num = await get_num_ports(gBrowser.selectedBrowser);
Assert.equal(ports_num, 5, "One port is added manually");
// This causes the test service to refresh the ports the next time a refresh
// is requested, it will happen after we reload the tab later on and will add
// back the port that we're removing on the next line.
await force_refresh(gBrowser.selectedBrowser);
await remove_port(gBrowser.selectedBrowser);
ports_num = await get_num_ports(gBrowser.selectedBrowser);
Assert.equal(ports_num, 4, "One port is removed manually");
await BrowserTestUtils.reloadTab(gBrowser.selectedTab);
await get_access(gBrowser.selectedBrowser);
let refreshed_ports_num = await get_num_ports(gBrowser.selectedBrowser);
Assert.equal(refreshed_ports_num, 5, "One port is added by the refresh");
gBrowser.removeTab(gBrowser.selectedTab);
});
|