зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1432864 - Run native focussing steps on interaction commands. r=automatedtester
Instead of generating custom focus events when interacting with elements, we can run the HTMLElement.focus() function will do the correct thing. Before this patch we only simulated focus events, whereas this patch will actually focus the element. MozReview-Commit-ID: IoBV2ngqOA5 --HG-- extra : rebase_source : c133a8ac7fc91dfa373a9d8adbc3f30d2441c46d
This commit is contained in:
Родитель
660c1092d4
Коммит
e8df6e360f
|
@ -1380,25 +1380,6 @@ event.sendEvent = function(eventType, el, modifiers = {}, opts = {}) {
|
|||
el.dispatchEvent(ev);
|
||||
};
|
||||
|
||||
event.focus = function(el, opts = {}) {
|
||||
opts.canBubble = opts.canBubble || true;
|
||||
let doc = el.ownerDocument || el.document;
|
||||
let win = doc.defaultView;
|
||||
|
||||
let ev = new win.FocusEvent(el);
|
||||
ev.initEvent("focus", opts.canBubble, true);
|
||||
el.dispatchEvent(ev);
|
||||
};
|
||||
|
||||
event.blur = function(el, {canBubble = true} = {}) {
|
||||
let doc = el.ownerDocument || el.document;
|
||||
let win = doc.defaultView;
|
||||
|
||||
let ev = new win.FocusEvent(el);
|
||||
ev.initEvent("blur", canBubble, true);
|
||||
el.dispatchEvent(ev);
|
||||
};
|
||||
|
||||
event.mouseover = function(el, modifiers = {}, opts = {}) {
|
||||
return event.sendEvent("mouseover", el, modifiers, opts);
|
||||
};
|
||||
|
|
|
@ -270,7 +270,7 @@ interaction.selectOption = function(el) {
|
|||
event.mouseover(containerEl);
|
||||
event.mousemove(containerEl);
|
||||
event.mousedown(containerEl);
|
||||
event.focus(containerEl);
|
||||
containerEl.focus();
|
||||
|
||||
if (!el.disabled) {
|
||||
// Clicking <option> in <select> should not be deselected if selected.
|
||||
|
@ -340,10 +340,10 @@ function clearContentEditableElement(el) {
|
|||
if (el.innerHTML === "") {
|
||||
return;
|
||||
}
|
||||
event.focus(el);
|
||||
el.focus();
|
||||
el.innerHTML = "";
|
||||
event.change(el);
|
||||
event.blur(el);
|
||||
el.blur();
|
||||
}
|
||||
|
||||
function clearResettableElement(el) {
|
||||
|
@ -366,10 +366,10 @@ function clearResettableElement(el) {
|
|||
return;
|
||||
}
|
||||
|
||||
event.focus(el);
|
||||
el.focus();
|
||||
el.value = "";
|
||||
event.change(el);
|
||||
event.blur(el);
|
||||
el.blur();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -491,7 +491,7 @@ interaction.uploadFile = async function(el, path) {
|
|||
event.mouseover(el);
|
||||
event.mousemove(el);
|
||||
event.mousedown(el);
|
||||
event.focus(el);
|
||||
el.focus();
|
||||
event.mouseup(el);
|
||||
event.click(el);
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
import pytest
|
||||
|
||||
from tests.support.asserts import assert_error, assert_success
|
||||
from tests.support.asserts import (
|
||||
assert_element_has_focus,
|
||||
assert_error,
|
||||
assert_success,
|
||||
)
|
||||
from tests.support.inline import inline
|
||||
|
||||
|
||||
|
@ -108,6 +112,7 @@ def test_input(session, type, value, default):
|
|||
assert "focus" in events
|
||||
assert "change" in events
|
||||
assert "blur" in events
|
||||
assert_element_has_focus(session.execute_script("return document.body"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("type",
|
||||
|
@ -262,6 +267,7 @@ def test_contenteditable(session):
|
|||
assert_success(response)
|
||||
assert element.property("innerHTML") == ""
|
||||
assert get_events(session) == ["focus", "change", "blur"]
|
||||
assert_element_has_focus(session.execute_script("return document.body"))
|
||||
|
||||
|
||||
|
||||
|
@ -274,6 +280,7 @@ def test_designmode(session):
|
|||
response = element_clear(session, element)
|
||||
assert_success(response)
|
||||
assert element.property("innerHTML") == "<br>"
|
||||
assert_element_has_focus(session.execute_script("return document.body"))
|
||||
|
||||
|
||||
def test_resettable_element_focus_when_empty(session):
|
||||
|
|
|
@ -137,3 +137,14 @@ def assert_same_element(session, a, b):
|
|||
pass
|
||||
|
||||
raise AssertionError(message)
|
||||
|
||||
|
||||
def assert_element_has_focus(target_element):
|
||||
session = target_element.session
|
||||
|
||||
active_element = session.execute_script("return document.activeElement")
|
||||
active_tag = active_element.property("localName")
|
||||
target_tag = target_element.property("localName")
|
||||
|
||||
assert active_element == target_element, (
|
||||
"Focussed element is <%s>, not <%s>" % (active_tag, target_tag))
|
||||
|
|
Загрузка…
Ссылка в новой задаче