tor-browser

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

browser_backOrSidebarButtonFitts.js (2707B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/
      3 */
      4 
      5 async function test_back_button(x, y) {
      6  // If the first button is the back button, set up history.
      7  let firstLocation =
      8    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      9    "http://example.org/browser/browser/base/content/test/general/dummy_page.html";
     10  await BrowserTestUtils.openNewForegroundTab(gBrowser, firstLocation);
     11  await ContentTask.spawn(gBrowser.selectedBrowser, {}, async function () {
     12    // Mark the first entry as having been interacted with.
     13    content.document.notifyUserGestureActivation();
     14    content.history.pushState("page2", "page2", "page2");
     15  });
     16 
     17  let popStatePromise = BrowserTestUtils.waitForContentEvent(
     18    gBrowser.selectedBrowser,
     19    "popstate",
     20    true
     21  );
     22  EventUtils.synthesizeMouseAtPoint(x, y, {}, window);
     23  await popStatePromise;
     24  is(
     25    gBrowser.selectedBrowser.currentURI.spec,
     26    firstLocation,
     27    "Clicking the first pixel should have navigated back."
     28  );
     29  gBrowser.removeCurrentTab();
     30 }
     31 
     32 async function test_sidebar_button(x, y) {
     33  // If the first button is the sidebar, check initial sidebar state
     34  let sidebarMain = document.getElementById("sidebar-main");
     35  let initialSidebarHiddenState = sidebarMain.hidden;
     36 
     37  EventUtils.synthesizeMouseAtPoint(x, y, {}, window);
     38  is(
     39    sidebarMain.hidden,
     40    !initialSidebarHiddenState,
     41    "Clicking the first pixel should toggle the sidebar"
     42  );
     43 
     44  // Ensure sidebar is put back into original state for following tests
     45  EventUtils.synthesizeMouseAtPoint(x, y, {}, window);
     46  is(
     47    sidebarMain.hidden,
     48    initialSidebarHiddenState,
     49    "Clicking the first pixel should toggle the sidebar"
     50  );
     51  Services.prefs.clearUserPref("browser.engagement.sidebar-button.has-used");
     52 }
     53 
     54 add_task(async function () {
     55  let navBarCustomizationTarget = document.getElementById(
     56    "nav-bar-customization-target"
     57  );
     58  // The first button in the nav bar could be either the back or sidebar button, depending
     59  // on whether sidebar.revamp is true and what OS we are using.
     60  let firstNavBarButton = navBarCustomizationTarget.childNodes[0].id;
     61 
     62  window.maximize();
     63 
     64  // Find where the nav-bar is vertically.
     65  var navBar = document.getElementById("nav-bar");
     66  var boundingRect = navBar.getBoundingClientRect();
     67  var yPixel = boundingRect.top + Math.floor(boundingRect.height / 2);
     68  var xPixel = 0; // Use the first pixel of the screen since it is maximized.
     69 
     70  if (firstNavBarButton == "back-button") {
     71    await test_back_button(xPixel, yPixel);
     72  } else if (firstNavBarButton == "sidebar-button") {
     73    await test_sidebar_button(xPixel, yPixel);
     74  }
     75 
     76  window.restore();
     77 });