(In reply to Emilio Cobos Álvarez (:emilio) from comment #7)
It reports both because you're using
originalTarget, which isn't retargeted to the shadow root. The event isn't dispatched to outside of the shadow tree when the
target are in the same shadow tree.
By saying that I'm using originalTarget did you mean advanceFocusIntoSubtree call or something else? It seems I don't explicitly using originalTarget anywhere but for logging inside of event listeners.
That's not equivalent to the pre-existing code (and the code from the try run in comment 4) which does
advanceFocusIntoSubtree moves to the next focus target if there's nothing in that subtree that is focusable, which can probably explain what you're seeing. Do you see the same with
You're right. I have replaced defaultButton.focus() on advanceFocusIntoSubtree() for experimenting while was investigating failures. It indeed helps. Thanks a lot!
I now have another failure though on step10 where dialog itself is expected to be focused . The dialog  has noinitialfocus button and thus dialog is expected to grab the focus itself. Since commandDispatcher.focusedElement is null, then dialog calls advanceFocusIntoSubtree what makes the noinitialfocus button focused, then advanceFocusIntoSubtree is called for noinitialfocus button which keeps it focused, and thus blur() is called at the end . After that the focus goes nowhere. I suppose that blur() is expected to move the focus to dialog itself. Is it about right?