summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/popovers/popover-open-in-beforetoggle.html
blob: 1e22b73c686edbb5a879510c1b9e681fafbcb7b5 (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
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Popover beforetoggle event opening new popovers</title>
<link rel="author" href="mailto:masonf@chromium.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/indices.html#event-beforetoggle">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/popover-utils.js"></script>

<div popover id=p1>Popover 1
  <div popover id=p2>Popover 2
    <div popover id=p3>Popover 3</div>
  </div>
</div>
<div id=outside>Outside</div>
<dialog id=dialog>Dialog</dialog>

<script>
  function getSignal(t) {
    const controller = new AbortController();
    t.add_cleanup(() => controller.abort());
    return controller.signal;
  }

  test((t) => {
    p1.showPopover();
    p1.addEventListener('beforetoggle',() => p2.showPopover(),{signal: getSignal(t)});
    p1.hidePopover(); // Potential crash here
    assert_false(p1.matches(':popover-open'));
    assert_false(p2.matches(':popover-open'));
  },'Open popover from closing beforetoggle event');

  test((t) => {
    p1.showPopover();
    p1.addEventListener('beforetoggle',() => p2.showPopover(),{signal: getSignal(t)});
    p2.addEventListener('beforetoggle',() => p3.showPopover(),{signal: getSignal(t)});
    p1.hidePopover(); // Potential crash here
    assert_false(p1.matches(':popover-open'));
    assert_false(p2.matches(':popover-open'));
    assert_false(p3.matches(':popover-open'));
  },'Open double-nested popovers from closing beforetoggle event');

  test(t => {
    p1.showPopover();
    p1.addEventListener('beforetoggle',() => p2.showPopover(),{signal: getSignal(t)});
    p2.addEventListener('beforetoggle',() => p3.showPopover(),{signal: getSignal(t)});
    dialog.showModal(); // Potential crash here
    assert_false(p1.matches(':popover-open'));
    assert_false(p2.matches(':popover-open'));
    assert_false(p3.matches(':popover-open'));
    dialog.close();
  },'Open double-nested popovers from closing beforetoggle event, dialog open');

  promise_test(async t => {
    p1.showPopover();
    p1.addEventListener('beforetoggle',() => p2.showPopover(),{signal: getSignal(t)});
    p2.addEventListener('beforetoggle',() => p3.showPopover(),{signal: getSignal(t)});
    await clickOn(outside); // Potential crash here
    assert_false(p1.matches(':popover-open'));
    assert_false(p2.matches(':popover-open'));
    assert_false(p3.matches(':popover-open'));
  },'Open double-nested popovers from closing beforetoggle event, light dismiss');
</script>