File: test_panel_list_anchoring.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (164 lines) | stat: -rw-r--r-- 4,895 bytes parent folder | download | duplicates (7)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Test Panel List Anchoring</title>
    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    <link
      rel="stylesheet"
      href="chrome://mochikit/content/tests/SimpleTest/test.css"
    />
  </head>
  <body>
    <p id="display"></p>
    <div id="content">
      <button id="anchor-button">Open</button>
      <panel-list id="panel-list">
        <panel-item>one</panel-item>
        <panel-item>two</panel-item>
        <panel-item>three</panel-item>
      </panel-list>
    </div>
    <script class="testbody" type="application/javascript">
      const { BrowserTestUtils } = ChromeUtils.importESModule(
        "resource://testing-common/BrowserTestUtils.sys.mjs"
      );
      let anchorButton, panelList, panelItems;

      add_setup(function setup() {
        panelList = document.getElementById("panel-list");
        anchorButton = document.getElementById("anchor-button");
        anchorButton.addEventListener("click", e => panelList.toggle(e));
      });

      add_task(async function checkAlignment() {
        async function getBounds() {
          await new Promise(resolve => requestAnimationFrame(resolve));
          let button = anchorButton.getBoundingClientRect();
          let menu = panelList.getBoundingClientRect();
          return {
            button: {
              top: Math.round(button.top),
              right: Math.round(button.right),
              bottom: Math.round(button.bottom),
              left: Math.round(button.left),
            },
            menu: {
              top: Math.round(menu.top),
              right: Math.round(menu.right),
              bottom: Math.round(menu.bottom),
              left: Math.round(menu.left),
            },
          };
        }

        async function showPanel() {
          let shown = BrowserTestUtils.waitForEvent(panelList, "shown");
          anchorButton.click();
          await shown;
        }

        async function hidePanel() {
          let hidden = BrowserTestUtils.waitForEvent(panelList, "hidden");
          panelList.hide();
          await hidden;
        }

        anchorButton.style.position = "fixed";

        info(
          "Verify menu alignment in the top left corner of the browser window"
        );

        anchorButton.style.top = "32px";
        anchorButton.style.right = "unset";
        anchorButton.style.bottom = "unset";
        anchorButton.style.left = "32px";

        await showPanel();
        let bounds = await getBounds();
        is(
          bounds.menu.top,
          bounds.button.bottom,
          "Button's bottom matches Menu's top"
        );
        is(
          bounds.menu.left,
          bounds.button.left,
          "Button and Menu have the same left value"
        );
        await hidePanel();

        info(
          "Verify menu alignment in the top right corner of the browser window"
        );

        anchorButton.style.top = "32px";
        anchorButton.style.right = "32px";
        anchorButton.style.bottom = "unset";
        anchorButton.style.left = "unset";

        await showPanel();
        bounds = await getBounds();
        is(
          bounds.menu.top,
          bounds.button.bottom,
          "Button's bottom matches Menu's top"
        );
        is(
          bounds.menu.right,
          bounds.button.right,
          "Button and Menu have the same right value"
        );
        await hidePanel();

        info(
          "Verify menu alignment in the bottom right corner of the browser window"
        );

        anchorButton.style.top = "unset";
        anchorButton.style.right = "32px";
        anchorButton.style.bottom = "32px";
        anchorButton.style.left = "unset";

        await showPanel();
        bounds = await getBounds();
        is(
          bounds.menu.bottom,
          bounds.button.top,
          "Button's top matches Menu's bottom"
        );
        is(
          bounds.menu.right,
          bounds.button.right,
          "Button and Menu have the same right value"
        );
        await hidePanel();

        info(
          "Verify menu alignment in the bottom left corner of the browser window"
        );

        anchorButton.style.top = "unset";
        anchorButton.style.right = "unset";
        anchorButton.style.bottom = "32px";
        anchorButton.style.left = "32px";

        await showPanel();
        bounds = await getBounds();
        is(
          bounds.menu.bottom,
          bounds.button.top,
          "Button's top matches Menu's bottom"
        );
        is(
          bounds.menu.left,
          bounds.button.left,
          "Button and Menu have the same left value"
        );
        await hidePanel();
      });
    </script>
  </body>
</html>