browser_refresh_port_list.js (2449B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const EXAMPLE_ORG_URL = "https://example.org/browser/dom/midi/tests/"; 5 const PAGE = "refresh_port_list.html"; 6 7 async function get_access() { 8 return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { 9 return content.wrappedJSObject.get_access(); 10 }); 11 } 12 13 async function reset_access() { 14 return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { 15 return content.wrappedJSObject.reset_access(); 16 }); 17 } 18 19 async function get_num_ports() { 20 return SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { 21 return content.wrappedJSObject.get_num_ports(); 22 }); 23 } 24 25 async function add_port() { 26 return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { 27 return content.wrappedJSObject.add_port(); 28 }); 29 } 30 31 async function remove_port() { 32 return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { 33 return content.wrappedJSObject.remove_port(); 34 }); 35 } 36 37 async function force_refresh() { 38 return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => { 39 return content.wrappedJSObject.force_refresh(); 40 }); 41 } 42 43 add_task(async function () { 44 gBrowser.selectedTab = BrowserTestUtils.addTab( 45 gBrowser, 46 EXAMPLE_ORG_URL + PAGE 47 ); 48 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 49 50 await get_access(gBrowser.selectedBrowser); 51 let ports_num = await get_num_ports(gBrowser.selectedBrowser); 52 Assert.equal(ports_num, 4, "We start with four ports"); 53 await add_port(gBrowser.selectedBrowser); 54 ports_num = await get_num_ports(gBrowser.selectedBrowser); 55 Assert.equal(ports_num, 5, "One port is added manually"); 56 // This causes the test service to refresh the ports the next time a refresh 57 // is requested, it will happen after we reload the tab later on and will add 58 // back the port that we're removing on the next line. 59 await force_refresh(gBrowser.selectedBrowser); 60 await remove_port(gBrowser.selectedBrowser); 61 ports_num = await get_num_ports(gBrowser.selectedBrowser); 62 Assert.equal(ports_num, 4, "One port is removed manually"); 63 64 await BrowserTestUtils.reloadTab(gBrowser.selectedTab); 65 66 await get_access(gBrowser.selectedBrowser); 67 let refreshed_ports_num = await get_num_ports(gBrowser.selectedBrowser); 68 Assert.equal(refreshed_ports_num, 5, "One port is added by the refresh"); 69 70 gBrowser.removeTab(gBrowser.selectedTab); 71 });