browser_many_toggles.js (1613B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Verify RDM can be toggled many times in a raw 7 8 const TEST_URL = "https://example.com/"; 9 10 addRDMTask( 11 null, 12 async function () { 13 const tab = await addTab(TEST_URL); 14 15 // Record all currently active RDMs, there may not be one created on each loop 16 let opened = 0; 17 ResponsiveUIManager.on("on", () => opened++); 18 ResponsiveUIManager.on("off", () => opened--); 19 20 for (let i = 0; i < 10; i++) { 21 info(`Toggling RDM #${i + 1}`); 22 // This may throw when we were just closing is still ongoing, 23 // ignore any exception. 24 openRDM(tab).catch(() => {}); 25 // Sometime pause in order to cover both full synchronous opening and close 26 // but also the same but with some pause between each operation. 27 if (i % 2 == 0) { 28 info("Wait a bit after open"); 29 await wait(250); 30 } 31 closeRDM(tab); 32 if (i % 3 == 0) { 33 info("Wait a bit after close"); 34 await wait(250); 35 } 36 } 37 38 // Wait a bit so that we can receive the very last ResponsiveUIManager `on` event, 39 // and properly wait for its closing. 40 await wait(1000); 41 42 // This is important to wait for all destruction as closing the tab while RDM 43 // is still closing may lead to exception because of pending cleanup RDP requests. 44 info("Wait for all opened RDM to be closed before closing the tab"); 45 await waitFor(() => opened == 0); 46 info("All RDM are closed"); 47 48 await removeTab(tab); 49 }, 50 { onlyPrefAndTask: true } 51 );