summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive/test/browser/browser_screenshot_button_warning.js
blob: f7940b3cbf17d04bb897a4699511610be3c716d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that warning messages emitted when taking a screenshot are displayed in the UI.

const TEST_URL = `http://example.net/document-builder.sjs?html=
  <style>
    body {
      margin: 0;
      height: 10001px;
    }
  </style>Hello world`;

addRDMTask(
  TEST_URL,
  async function ({ ui, browser, manager }) {
    const { toolWindow } = ui;
    const { document } = toolWindow;

    info(
      "Set a big viewport and high dpr so the screenshot dpr gets downsized"
    );
    // The viewport can't be bigger than 9999×9999
    await setViewportSize(ui, manager, 9999, 9999);
    const dpr = 3;
    await selectDevicePixelRatio(ui, dpr);
    await waitForDevicePixelRatio(ui, dpr);

    info("Click the screenshot button");
    const onScreenshotDownloaded = waitUntilScreenshot();
    const screenshotButton = document.getElementById("screenshot-button");
    screenshotButton.click();

    const filePath = await onScreenshotDownloaded;
    ok(filePath, "The screenshot was taken");

    info(
      "Check that a warning message was displayed to indicate the dpr was changed"
    );

    const box = gBrowser.getNotificationBox(browser);
    await waitUntil(() => box.currentNotification);

    const notificationEl = box.currentNotification;
    ok(notificationEl, "Notification should be visible");
    is(
      notificationEl.messageText.textContent.trim(),
      "The device pixel ratio was reduced to 1 as the resulting image was too large",
      "The expected warning was displayed"
    );

    //Remove the downloaded screenshot file
    await IOUtils.remove(filePath);
    await resetDownloads();
  },
  { waitForDeviceList: true }
);