summaryrefslogtreecommitdiffstats
path: root/dom/midi/tests/browser_refresh_port_list.js
diff options
context:
space:
mode:
Diffstat (limited to 'dom/midi/tests/browser_refresh_port_list.js')
-rw-r--r--dom/midi/tests/browser_refresh_port_list.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/dom/midi/tests/browser_refresh_port_list.js b/dom/midi/tests/browser_refresh_port_list.js
new file mode 100644
index 0000000000..152b067254
--- /dev/null
+++ b/dom/midi/tests/browser_refresh_port_list.js
@@ -0,0 +1,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);
+});