tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_reshow_in_background.js (2087B)


      1 "use strict";
      2 
      3 /**
      4 * Tests that when PopupNotifications for background tabs are reshown, they
      5 * don't show up in the foreground tab, but only in the background tab that
      6 * they belong to.
      7 */
      8 add_task(
      9  async function test_background_notifications_dont_reshow_in_foreground() {
     10    // Our initial tab will be A. Let's open two more tabs B and C, but keep
     11    // A selected. Then, we'll trigger a PopupNotification in C, and then make
     12    // it reshow.
     13    let tabB = BrowserTestUtils.addTab(gBrowser, "https://example.com/");
     14    await BrowserTestUtils.browserLoaded(tabB.linkedBrowser);
     15 
     16    let tabC = BrowserTestUtils.addTab(gBrowser, "https://example.com/");
     17    await BrowserTestUtils.browserLoaded(tabC.linkedBrowser);
     18 
     19    let seenEvents = [];
     20 
     21    let options = {
     22      dismissed: false,
     23      eventCallback(popupEvent) {
     24        seenEvents.push(popupEvent);
     25      },
     26    };
     27 
     28    let notification = PopupNotifications.show(
     29      tabC.linkedBrowser,
     30      "test-notification",
     31      "",
     32      "geo-notification-icon",
     33      null,
     34      null,
     35      options
     36    );
     37    Assert.deepEqual(seenEvents, [], "Should have seen no events yet.");
     38 
     39    await BrowserTestUtils.switchTab(gBrowser, tabB);
     40    Assert.deepEqual(seenEvents, [], "Should have seen no events yet.");
     41 
     42    notification.reshow();
     43    Assert.deepEqual(seenEvents, [], "Should have seen no events yet.");
     44 
     45    let panelShown = BrowserTestUtils.waitForEvent(
     46      PopupNotifications.panel,
     47      "popupshown"
     48    );
     49    await BrowserTestUtils.switchTab(gBrowser, tabC);
     50    await panelShown;
     51 
     52    Assert.equal(seenEvents.length, 2, "Should have seen two events.");
     53    Assert.equal(
     54      seenEvents[0],
     55      "showing",
     56      "Should have said popup was showing."
     57    );
     58    Assert.equal(seenEvents[1], "shown", "Should have said popup was shown.");
     59 
     60    let panelHidden = BrowserTestUtils.waitForEvent(
     61      PopupNotifications.panel,
     62      "popuphidden"
     63    );
     64    PopupNotifications.remove(notification);
     65    await panelHidden;
     66 
     67    BrowserTestUtils.removeTab(tabB);
     68    BrowserTestUtils.removeTab(tabC);
     69  }
     70 );