tor-browser

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

browser_screenshot_button_warning.js (1776B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that warning messages emitted when taking a screenshot are displayed in the UI.
      7 
      8 const TEST_URL = `http://example.net/document-builder.sjs?html=
      9  <style>
     10    body {
     11      margin: 0;
     12      height: 10001px;
     13    }
     14  </style>Hello world`;
     15 
     16 addRDMTask(
     17  TEST_URL,
     18  async function ({ ui, browser, manager }) {
     19    const { toolWindow } = ui;
     20    const { document } = toolWindow;
     21 
     22    info(
     23      "Set a big viewport and high dpr so the screenshot dpr gets downsized"
     24    );
     25    // The viewport can't be bigger than 9999×9999
     26    await setViewportSize(ui, manager, 9999, 9999);
     27    const dpr = 3;
     28    await selectDevicePixelRatio(ui, dpr);
     29    await waitForDevicePixelRatio(ui, dpr);
     30 
     31    info("Click the screenshot button");
     32    const onScreenshotDownloaded = waitUntilDownload();
     33    const screenshotButton = document.getElementById("screenshot-button");
     34    screenshotButton.click();
     35 
     36    const filePath = await onScreenshotDownloaded;
     37    ok(filePath, "The screenshot was taken");
     38 
     39    info(
     40      "Check that a warning message was displayed to indicate the dpr was changed"
     41    );
     42 
     43    const box = gBrowser.getNotificationBox(browser);
     44    await waitUntil(() => box.currentNotification);
     45 
     46    const notificationEl = box.currentNotification;
     47    ok(notificationEl, "Notification should be visible");
     48    is(
     49      notificationEl.messageText.textContent.trim(),
     50      "The device pixel ratio was reduced to 1 as the resulting image was too large",
     51      "The expected warning was displayed"
     52    );
     53 
     54    //Remove the downloaded screenshot file
     55    await IOUtils.remove(filePath);
     56    await resetDownloads();
     57  },
     58  { waitForDeviceList: true }
     59 );