summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/interactive-elements/the-dialog-element/non-modal-dialog-layout.html
blob: 248bec86f6fdce7da969bcc87d036ae37c70bc71 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=author href="mailto:falken@chromium.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element">
<link rel=help href="https://bugs.chromium.org/p/chromium/issues/detail?id=382594">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<style>
/* Remove body margin and dialog styles for easier positioning expected values */
body {
  height: 10000px;
  margin: 0;
}

dialog {
  margin: 0;
  border: 0;
  padding: 0;
  width: auto;
  height: auto;
  max-width: initial;
  max-height: initial;
}

#absolute-div {
  position: absolute;
  top: 800px;
  height: 50px;
  width: 90%;
}

#relative-div {
  position: relative;
  top: 20px;
  height: 30px;
}
</style>

<div id="absolute-div">
  <div id="relative-div">
    <dialog id="dialog">It is my dialog.</dialog>
  </div>
</div>

<script>
test(() => {
  const dialog = document.querySelector('#dialog');
  const div = document.querySelector('#div-dialog');
  const relativeContainer = document.querySelector('#relative-div');
  const offset = 50;
  dialog.style.top = offset + 'px';
  dialog.style.left = offset + 'px';

  dialog.style.position = 'absolute';
  dialog.show();
  assert_equals(
    dialog.getBoundingClientRect().top,
    relativeContainer.getBoundingClientRect().top + offset,
    'Absolute position.');
  assert_equals(
    dialog.getBoundingClientRect().left,
    relativeContainer.getBoundingClientRect().left + offset,
    'Absolute position.');

  dialog.style.position = 'static';
  assert_true(dialog.open);
  assert_equals(
    dialog.getBoundingClientRect().top,
    relativeContainer.getBoundingClientRect().top,
    'Static position.');
  assert_equals(
    dialog.getBoundingClientRect().left,
    relativeContainer.getBoundingClientRect().left,
    'Static position.');
  dialog.close();

  dialog.style.position = 'relative';
  dialog.show();
  assert_equals(
    dialog.getBoundingClientRect().top,
    relativeContainer.getBoundingClientRect().top + offset,
    'Relative position.');
  assert_equals(
    dialog.getBoundingClientRect().left,
    relativeContainer.getBoundingClientRect().left + offset,
    'Relative position.');
  dialog.close();

  dialog.style.position = 'fixed';
  dialog.show();
  assert_equals(
    dialog.getBoundingClientRect().top,
    offset,
    'Fixed position.');
  assert_equals(
    dialog.getBoundingClientRect().left,
    offset,
    'Fixed position.');
  dialog.close();
}, 'Tests layout of non-modal dialogs.');
</script>