Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NavigationAPI: don't reset focus if focus changed before the transiti…
…on completes https://github.com/WICG/navigation-api#focus-management says: "However, this focus reset will not take place if the user or developer has manually changed focus while the promise was settling, and that element is still visible and focusable." We weren't currently handling the case where the focus was changed while the promise was settling. Bug: 1183545 Change-Id: I96636a2cd06cecf1f680b476190e2fa14731b05b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3566413 Reviewed-by: Mason Freed <masonf@chromium.org> Commit-Queue: Nate Chapin <japhet@chromium.org> Cr-Commit-Position: refs/heads/main@{#990087}
- Loading branch information
1 parent
53ca258
commit b537dd6
Showing
11 changed files
with
227 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
third_party/blink/renderer/core/dom/focused_element_change_observer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_DOM_FOCUSED_ELEMENT_CHANGE_OBSERVER_H_ | ||
#define THIRD_PARTY_BLINK_RENDERER_CORE_DOM_FOCUSED_ELEMENT_CHANGE_OBSERVER_H_ | ||
|
||
#include "third_party/blink/renderer/platform/heap/garbage_collected.h" | ||
|
||
namespace blink { | ||
|
||
class FocusedElementChangeObserver : public GarbageCollectedMixin { | ||
public: | ||
virtual void DidChangeFocus() = 0; | ||
}; | ||
|
||
} // namespace blink | ||
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_DOM_FOCUSED_ELEMENT_CHANGE_OBSERVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...nal/wpt/navigation-api/focus-reset/change-focus-again-in-blur-during-transitionWhile.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<script> | ||
promise_test(async t => { | ||
let transitionWhile_resolve; | ||
navigation.addEventListener("navigate", e => { | ||
e.transitionWhile(new Promise(resolve => transitionWhile_resolve = resolve), | ||
{ focusReset: "after-transition" }); | ||
}, { once: true }); | ||
|
||
const button = document.body.appendChild(document.createElement("button")); | ||
const button2 = document.body.appendChild(document.createElement("button")); | ||
button2.tabIndex = 0; | ||
t.add_cleanup(() => { | ||
button.remove(); | ||
button2.remove(); | ||
}); | ||
|
||
assert_equals(document.activeElement, document.body, "Start on body"); | ||
button.focus(); | ||
assert_equals(document.activeElement, button, "focus() worked"); | ||
|
||
const finished = navigation.navigate("#1").finished; | ||
button.onblur = () => button2.focus(); | ||
button.blur(); | ||
assert_equals(document.activeElement, button2, "focus() in blur worked"); | ||
|
||
transitionWhile_resolve(); | ||
await finished; | ||
assert_equals(document.activeElement, button2, "Focus was not reset after the transition"); | ||
}, ""); | ||
</script> | ||
</body> |
36 changes: 36 additions & 0 deletions
36
...l/wpt/navigation-api/focus-reset/change-focus-back-to-origial-during-transitionWhile.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<script> | ||
promise_test(async t => { | ||
let transitionWhile_resolve; | ||
navigation.addEventListener("navigate", e => { | ||
e.transitionWhile(new Promise(resolve => transitionWhile_resolve = resolve), | ||
{ focusReset: "after-transition" }); | ||
}, { once: true }); | ||
|
||
const button = document.body.appendChild(document.createElement("button")); | ||
const button2 = document.body.appendChild(document.createElement("button")); | ||
button2.tabIndex = 0; | ||
t.add_cleanup(() => { | ||
button.remove(); | ||
button2.remove(); | ||
}); | ||
|
||
assert_equals(document.activeElement, document.body, "Start on body"); | ||
button.focus(); | ||
assert_equals(document.activeElement, button, "focus() worked"); | ||
|
||
const finished = navigation.navigate("#1").finished; | ||
button2.focus(); | ||
assert_equals(document.activeElement, button2, "focus() worked"); | ||
button.focus(); | ||
assert_equals(document.activeElement, button, "focus() worked"); | ||
|
||
transitionWhile_resolve(); | ||
await finished; | ||
assert_equals(document.activeElement, button, "Focus was not reset after the transition"); | ||
}, ""); | ||
</script> | ||
</body> |
34 changes: 34 additions & 0 deletions
34
...eb_tests/external/wpt/navigation-api/focus-reset/change-focus-during-transitionWhile.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<script> | ||
promise_test(async t => { | ||
let transitionWhile_resolve; | ||
navigation.addEventListener("navigate", e => { | ||
e.transitionWhile(new Promise(resolve => transitionWhile_resolve = resolve), | ||
{ focusReset: "after-transition" }); | ||
}, { once: true }); | ||
|
||
const button = document.body.appendChild(document.createElement("button")); | ||
const button2 = document.body.appendChild(document.createElement("button")); | ||
button2.tabIndex = 0; | ||
t.add_cleanup(() => { | ||
button.remove(); | ||
button2.remove(); | ||
}); | ||
|
||
assert_equals(document.activeElement, document.body, "Start on body"); | ||
button.focus(); | ||
assert_equals(document.activeElement, button, "focus() worked"); | ||
|
||
const finished = navigation.navigate("#1").finished; | ||
button2.focus(); | ||
assert_equals(document.activeElement, button2, "focus() worked"); | ||
|
||
transitionWhile_resolve(); | ||
await finished; | ||
assert_equals(document.activeElement, button2, "Focus was not reset after the transition"); | ||
}, ""); | ||
</script> | ||
</body> |
39 changes: 39 additions & 0 deletions
39
...ernal/wpt/navigation-api/focus-reset/change-focus-then-remove-during-transitionWhile.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!doctype html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<script> | ||
promise_test(async t => { | ||
let transitionWhile_resolve; | ||
navigation.addEventListener("navigate", e => { | ||
e.transitionWhile(new Promise(resolve => transitionWhile_resolve = resolve), { focusReset: "after-transition" }); | ||
}, { once: true }); | ||
|
||
const button = document.body.appendChild(document.createElement("button")); | ||
const button2 = document.body.appendChild(document.createElement("button")); | ||
button2.tabIndex = 0; | ||
t.add_cleanup(() => { | ||
button.remove(); | ||
button2.remove(); | ||
}); | ||
|
||
assert_equals(document.activeElement, document.body, "Start on body"); | ||
button.focus(); | ||
assert_equals(document.activeElement, button, "focus() worked"); | ||
|
||
const finished = navigation.navigate("#1").finished; | ||
|
||
let onfocus_called = false; | ||
document.body.onfocus = onfocus_called = true; | ||
button.remove(); | ||
assert_equals(document.activeElement, document.body, "Removing the element reset focus"); | ||
assert_true(onfocus_called); | ||
|
||
document.body.onfocus = t.unreached_func("onfocus shouldn't fire a second time due to focus reset"); | ||
transitionWhile_resolve(); | ||
await finished; | ||
assert_equals(document.activeElement, document.body, "Focus remains on document.body after promise fulfills"); | ||
await new Promise(resolve => t.step_timeout(resolve, 10)); | ||
}, ""); | ||
</script> | ||
</body> |