Skip to content

Commit

Permalink
Bug 1929412 [wpt PR 48989] - Add attribute reflection behavior for di…
Browse files Browse the repository at this point in the history
…alog closedBy [2/N], a=testonly

Automatic update from web-platform-tests
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 <masonf@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Commit-Queue: David Baron <dbaron@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1379228}

--

wpt-commits: 28946b88d5b2e037bb2506ae4984e8725ba5560b
wpt-pr: 48989
  • Loading branch information
mfreed7 authored and moz-wptsync-bot committed Nov 7, 2024
1 parent b02272f commit 7ef3aa7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
<dialog closedby="closerequest" data-behavior="closerequest"></dialog>
<dialog closedby="none" data-behavior="none"></dialog>

<dialog closedby data-behavior="closerequest"></dialog>
<dialog closedby="invalid" data-behavior="closerequest"></dialog>
<dialog data-behavior="closerequest"></dialog>

<dialog closedby="AnY" data-behavior="any"></dialog>
<dialog closedby="ClOsErEqUeSt" data-behavior="closerequest"></dialog>
<dialog closedby="NoNe" data-behavior="none"></dialog>

<dialog closedby="invalid" data-behavior="auto"></dialog>
<dialog closedby data-behavior="auto"></dialog>
<dialog data-behavior="auto"></dialog>

<script>
function openDialog(dialog,modal) {
assert_false(dialog.open);
Expand All @@ -41,6 +41,7 @@
t.add_cleanup(() => dialog.close());
// Try hitting ESC
openDialog(dialog,modal);
const closedByReflectionWhileOpen = dialog.closedBy;
const ESC = '\uE00C';
await new test_driver.send_keys(document.documentElement,ESC);
const respondsToEsc = !dialog.open;
Expand All @@ -51,6 +52,8 @@
const respondsToLightDismiss = !dialog.open;
dialog.close();
// See if expectations match
let expectedReflectionWhileOpen = dialog.dataset.behavior;
let expectedReflectionWhileClosed = dialog.dataset.behavior;
switch (dialog.dataset.behavior) {
case 'any':
assert_true(respondsToEsc,'Dialog should respond to ESC');
Expand All @@ -64,11 +67,24 @@
assert_false(respondsToEsc,'Dialog should NOT respond to ESC');
assert_false(respondsToLightDismiss,'Dialog should NOT respond to light dismiss');
break;
case 'auto':
if (modal) {
assert_true(respondsToEsc,'Modal dialog in auto state should respond to ESC');
assert_false(respondsToLightDismiss,'Modal dialog in auto state should NOT respond to light dismiss');
expectedReflectionWhileOpen = 'closerequest';
} else {
assert_false(respondsToEsc,'Non-modal dialog in auto state should NOT respond to ESC');
assert_false(respondsToLightDismiss,'Non-modal dialog in auto state should NOT respond to light dismiss');
expectedReflectionWhileOpen = 'none';
}
expectedReflectionWhileClosed = 'none';
break;
default:
assert_notreached('Invalid expectation');
}
// Check reflection
assert_equals(dialog.closedBy,dialog.dataset.behavior,'Reflection should be limited to known values');
assert_equals(closedByReflectionWhileOpen,expectedReflectionWhileOpen,'Reflection should be limited to known values (open)');
assert_equals(dialog.closedBy,expectedReflectionWhileClosed,'Reflection should be limited to known values (closed)');
}, `closedby=${dialog.getAttribute('closedby')}, ${modal ? 'Modal' : 'Non-modal'}`);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<link rel=author href="mailto:masonf@chromium.org">
<link rel=help href="https://html.spec.whatwg.org/multipage/interactive-elements.html#the-dialog-element">
<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="/close-watcher/resources/helpers.js"></script>

<dialog>Dialog</dialog>

<script>
promise_test(async () => {
const dialog = document.querySelector('dialog');
assert_false(dialog.open);
dialog.show();
assert_true(dialog.open);
await sendEscKey();
assert_true(dialog.open,'Escape does not close a non-modal dialog');
dialog.close();
dialog.showModal();
assert_true(dialog.open);
await sendEscKey();
assert_false(dialog.open,'Escape does close a modal dialog');
},'Non-modal dialogs should not be cancelable via ESC');
</script>

0 comments on commit 7ef3aa7

Please sign in to comment.