Skip to content

Commit 28946b8

Browse files
mfreed7chromium-wpt-export-bot
authored andcommitted
Add attribute reflection behavior for dialog closedBy [2/N]
This implements reflection of `closedBy` including the "limited to known values" behavior. See spec PR for details: whatwg/html#10737 Bug: 376516550 Change-Id: Iddefd573fe19fd39f4b3aebe13390235fea969b9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5988652 Commit-Queue: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: David Baron <[email protected]> Auto-Submit: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1379228}
1 parent eb02ec4 commit 28946b8

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

html/semantics/interactive-elements/the-dialog-element/dialog-closedby.tentative.html

+21-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
<dialog closedby="closerequest" data-behavior="closerequest"></dialog>
1616
<dialog closedby="none" data-behavior="none"></dialog>
1717

18-
<dialog closedby data-behavior="closerequest"></dialog>
19-
<dialog closedby="invalid" data-behavior="closerequest"></dialog>
20-
<dialog data-behavior="closerequest"></dialog>
21-
2218
<dialog closedby="AnY" data-behavior="any"></dialog>
2319
<dialog closedby="ClOsErEqUeSt" data-behavior="closerequest"></dialog>
2420
<dialog closedby="NoNe" data-behavior="none"></dialog>
2521

22+
<dialog closedby="invalid" data-behavior="auto"></dialog>
23+
<dialog closedby data-behavior="auto"></dialog>
24+
<dialog data-behavior="auto"></dialog>
25+
2626
<script>
2727
function openDialog(dialog,modal) {
2828
assert_false(dialog.open);
@@ -41,6 +41,7 @@
4141
t.add_cleanup(() => dialog.close());
4242
// Try hitting ESC
4343
openDialog(dialog,modal);
44+
const closedByReflectionWhileOpen = dialog.closedBy;
4445
const ESC = '\uE00C';
4546
await new test_driver.send_keys(document.documentElement,ESC);
4647
const respondsToEsc = !dialog.open;
@@ -51,6 +52,8 @@
5152
const respondsToLightDismiss = !dialog.open;
5253
dialog.close();
5354
// See if expectations match
55+
let expectedReflectionWhileOpen = dialog.dataset.behavior;
56+
let expectedReflectionWhileClosed = dialog.dataset.behavior;
5457
switch (dialog.dataset.behavior) {
5558
case 'any':
5659
assert_true(respondsToEsc,'Dialog should respond to ESC');
@@ -64,11 +67,24 @@
6467
assert_false(respondsToEsc,'Dialog should NOT respond to ESC');
6568
assert_false(respondsToLightDismiss,'Dialog should NOT respond to light dismiss');
6669
break;
70+
case 'auto':
71+
if (modal) {
72+
assert_true(respondsToEsc,'Modal dialog in auto state should respond to ESC');
73+
assert_false(respondsToLightDismiss,'Modal dialog in auto state should NOT respond to light dismiss');
74+
expectedReflectionWhileOpen = 'closerequest';
75+
} else {
76+
assert_false(respondsToEsc,'Non-modal dialog in auto state should NOT respond to ESC');
77+
assert_false(respondsToLightDismiss,'Non-modal dialog in auto state should NOT respond to light dismiss');
78+
expectedReflectionWhileOpen = 'none';
79+
}
80+
expectedReflectionWhileClosed = 'none';
81+
break;
6782
default:
6883
assert_notreached('Invalid expectation');
6984
}
7085
// Check reflection
71-
assert_equals(dialog.closedBy,dialog.dataset.behavior,'Reflection should be limited to known values');
86+
assert_equals(closedByReflectionWhileOpen,expectedReflectionWhileOpen,'Reflection should be limited to known values (open)');
87+
assert_equals(dialog.closedBy,expectedReflectionWhileClosed,'Reflection should be limited to known values (closed)');
7288
}, `closedby=${dialog.getAttribute('closedby')}, ${modal ? 'Modal' : 'Non-modal'}`);
7389
}
7490
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<link rel=author href="mailto:[email protected]">
3+
<link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element">
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="/resources/testdriver.js"></script>
7+
<script src="/resources/testdriver-actions.js"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<script src="/close-watcher/resources/helpers.js"></script>
10+
11+
<dialog>Dialog</dialog>
12+
13+
<script>
14+
promise_test(async () => {
15+
const dialog = document.querySelector('dialog');
16+
assert_false(dialog.open);
17+
dialog.show();
18+
assert_true(dialog.open);
19+
await sendEscKey();
20+
assert_true(dialog.open,'Escape does not close a non-modal dialog');
21+
dialog.close();
22+
dialog.showModal();
23+
assert_true(dialog.open);
24+
await sendEscKey();
25+
assert_false(dialog.open,'Escape does close a modal dialog');
26+
},'Non-modal dialogs should not be cancelable via ESC');
27+
</script>

0 commit comments

Comments
 (0)