summaryrefslogtreecommitdiffstats
path: root/widget/tests/browser/browser_test_AZERTY_digit_shortcut.js
blob: ef5112ac0110b28d67ef85fc0ecd44c9e29527a6 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function () {
  let tabs = [];
  for (let i = 0; i < 10; i++) {
    const tab = BrowserTestUtils.addTab(gBrowser);
    tabs.push(tab);
  }
  const kIsMac = AppConstants.platform == "macosx";

  await BrowserTestUtils.withNewTab(
    "https://example.com/browser/toolkit/content/tests/browser/file_empty.html",
    async function (browser) {
      let NativeKeyConstants = {};
      Services.scriptloader.loadSubScript(
        "chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js",
        NativeKeyConstants
      );

      function promiseSynthesizeAccelHyphenMinusWithAZERTY() {
        return new Promise(resolve =>
          EventUtils.synthesizeNativeKey(
            EventUtils.KEYBOARD_LAYOUT_FRENCH_PC,
            kIsMac
              ? NativeKeyConstants.MAC_VK_ANSI_6
              : NativeKeyConstants.WIN_VK_6,
            { accelKey: true },
            kIsMac ? "-" : "",
            kIsMac ? "-" : "",
            resolve
          )
        );
      }

      async function waitForCondition(aFunc) {
        for (let i = 0; i < 60; i++) {
          await new Promise(resolve =>
            requestAnimationFrame(() => requestAnimationFrame(resolve))
          );
          if (aFunc(ZoomManager.getFullZoomForBrowser(browser))) {
            return true;
          }
        }
        return false;
      }

      const minZoomLevel = ZoomManager.MIN;
      while (true) {
        const currentZoom = ZoomManager.getFullZoomForBrowser(browser);
        if (minZoomLevel == currentZoom) {
          break;
        }
        info(`Trying to zoom out: ${currentZoom}`);
        await promiseSynthesizeAccelHyphenMinusWithAZERTY();
        if (!(await waitForCondition(aZoomLevel => aZoomLevel < currentZoom))) {
          ok(false, `Failed to zoom out from ${currentZoom}`);
          return;
        }
      }

      await promiseSynthesizeAccelHyphenMinusWithAZERTY();
      await waitForCondition(() => false);
      is(
        gBrowser.selectedBrowser,
        browser,
        "Tab shouldn't be changed by Ctrl+- of AZERTY keyboard layout"
      );
      // Reset the zoom before going to the next test.
      EventUtils.synthesizeKey("0", { accelKey: true });
      await waitForCondition(aZoomLevel => aZoomLevel == 1);
    }
  );

  while (tabs.length) {
    await new Promise(resolve => {
      const tab = tabs.shift();
      BrowserTestUtils.waitForTabClosing(tab).then(resolve);
      BrowserTestUtils.removeTab(tab);
    });
  }
});