tor-browser

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

browser_remote_tabs_button.js (2836B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 */
      5 "use strict";
      6 
      7 let { Service } = ChromeUtils.importESModule(
      8  "resource://services-sync/service.sys.mjs"
      9 );
     10 const { UIState } = ChromeUtils.importESModule(
     11  "resource://services-sync/UIState.sys.mjs"
     12 );
     13 
     14 let getState;
     15 let originalSync;
     16 let syncWasCalled = false;
     17 
     18 // TODO: This test should probably be re-written, we don't really test much here.
     19 add_task(async function testSyncRemoteTabsButtonFunctionality() {
     20  info("Test the Sync Remote Tabs button in the panel");
     21  storeInitialValues();
     22  mockFunctions();
     23 
     24  // Force UI update.
     25  Services.obs.notifyObservers(null, UIState.ON_UPDATE);
     26 
     27  // add the sync remote tabs button to the panel
     28  CustomizableUI.addWidgetToArea(
     29    "sync-button",
     30    CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
     31  );
     32 
     33  await waitForOverflowButtonShown();
     34 
     35  // check the button's functionality
     36  await document.getElementById("nav-bar").overflowable.show();
     37  info("The panel menu was opened");
     38 
     39  let syncRemoteTabsBtn = document.getElementById("sync-button");
     40  ok(
     41    syncRemoteTabsBtn,
     42    "The sync remote tabs button was added to the Panel Menu"
     43  );
     44  // click the button - the panel should open.
     45  syncRemoteTabsBtn.click();
     46  let remoteTabsPanel = document.getElementById("PanelUI-remotetabs");
     47  let viewShown = BrowserTestUtils.waitForEvent(remoteTabsPanel, "ViewShown");
     48  await viewShown;
     49  ok(remoteTabsPanel.getAttribute("visible"), "Sync Panel is in view");
     50 
     51  // Find and click the "setup" button.
     52  let syncNowButton = document.getElementById("PanelUI-remotetabs-syncnow");
     53  syncNowButton.click();
     54  info("The sync now button was clicked");
     55 
     56  await TestUtils.waitForCondition(() => syncWasCalled);
     57 
     58  // We need to stop the Syncing animation manually otherwise the button
     59  // will be disabled at the beginning of a next test.
     60  gSync._onActivityStop();
     61 });
     62 
     63 add_task(async function asyncCleanup() {
     64  // reset the panel UI to the default state
     65  await resetCustomization();
     66  ok(CustomizableUI.inDefaultState, "The panel UI is in default state again.");
     67 
     68  if (isOverflowOpen()) {
     69    let panelHidePromise = promiseOverflowHidden(window);
     70    PanelUI.overflowPanel.hidePopup();
     71    await panelHidePromise;
     72  }
     73 
     74  restoreValues();
     75 });
     76 
     77 function mockFunctions() {
     78  // mock UIState.get()
     79  UIState.get = () => ({
     80    status: UIState.STATUS_SIGNED_IN,
     81    lastSync: new Date(),
     82    email: "user@mozilla.com",
     83  });
     84 
     85  Service.sync = mocked_sync;
     86 }
     87 
     88 function mocked_sync() {
     89  syncWasCalled = true;
     90 }
     91 
     92 function restoreValues() {
     93  UIState.get = getState;
     94  Service.sync = originalSync;
     95 }
     96 
     97 function storeInitialValues() {
     98  getState = UIState.get;
     99  originalSync = Service.sync;
    100 }