зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 18c139fe8859 (bug 1675894) for selectionchange.tentative.html failures CLOSED TREE
This commit is contained in:
Родитель
a8b38a9593
Коммит
007e18402d
|
@ -2098,19 +2098,10 @@ void TextControlState::SetSelectionRange(
|
|||
|
||||
if (changed) {
|
||||
// It sure would be nice if we had an existing Element* or so to work with.
|
||||
RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(
|
||||
mTextCtrlElement, eFormSelect, CanBubble::eYes);
|
||||
RefPtr<AsyncEventDispatcher> asyncDispatcher =
|
||||
new AsyncEventDispatcher(mTextCtrlElement, u"select"_ns,
|
||||
CanBubble::eYes, ChromeOnlyDispatch::eNo);
|
||||
asyncDispatcher->PostDOMEvent();
|
||||
|
||||
// SelectionChangeEventDispatcher covers this when !IsSelectionCached().
|
||||
// XXX(krosylight): Shouldn't it fire before select event?
|
||||
// Currently Gecko and Blink both fire selectionchange after select.
|
||||
if (IsSelectionCached() &&
|
||||
StaticPrefs::dom_select_events_textcontrols_enabled()) {
|
||||
asyncDispatcher = new AsyncEventDispatcher(
|
||||
mTextCtrlElement, eSelectionChange, CanBubble::eNo);
|
||||
asyncDispatcher->PostDOMEvent();
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
|
|
|
@ -16,11 +16,7 @@
|
|||
|
||||
<script>
|
||||
class SelectionChangeCollector {
|
||||
/**
|
||||
* @param {HTMLElement} target
|
||||
*/
|
||||
constructor(target) {
|
||||
this.target = target;
|
||||
this.events = [];
|
||||
target.addEventListener("selectionchange", ev => {
|
||||
this.events.push(ev);
|
||||
|
@ -32,139 +28,165 @@
|
|||
}
|
||||
|
||||
const data = {
|
||||
collectors: [
|
||||
new SelectionChangeCollector(input),
|
||||
new SelectionChangeCollector(input.cloneNode()),
|
||||
new SelectionChangeCollector(textarea),
|
||||
new SelectionChangeCollector(textarea.cloneNode(true)),
|
||||
],
|
||||
input: new SelectionChangeCollector(input),
|
||||
textarea: new SelectionChangeCollector(textarea),
|
||||
async initialize() {
|
||||
for (const collector of this.collectors) {
|
||||
collector.target.blur();
|
||||
collector.target.setSelectionRange(0, 0);
|
||||
}
|
||||
input.blur();
|
||||
textarea.blur();
|
||||
input.selectionStart = input.selectionEnd = 0;
|
||||
textarea.selectionStart = textarea.selectionEnd = 0;
|
||||
await this.spin();
|
||||
for (const collector of this.collectors) {
|
||||
collector.clear();
|
||||
}
|
||||
this.input.clear();
|
||||
this.textarea.clear();
|
||||
},
|
||||
spin() {
|
||||
return new Promise(setTimeout);
|
||||
},
|
||||
async assert_empty_spin() {
|
||||
// firing selectionchange must be asynchronous
|
||||
for (const collector of this.collectors) {
|
||||
assert_equals(collector.events.length, 0);
|
||||
}
|
||||
assert_equals(this.input.events.length, 0);
|
||||
assert_equals(this.textarea.events.length, 0);
|
||||
await this.spin();
|
||||
}
|
||||
};
|
||||
|
||||
for (const collector of data.collectors) {
|
||||
const target = collector.target;
|
||||
const name = `the ${!target.parentNode ? "disconnected " : ""}${target.localName} element`;
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
textarea.selectionStart = 1;
|
||||
|
||||
target.selectionStart = 1;
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 1);
|
||||
}, "Modifying selectionStart value of the textarea element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 1);
|
||||
}, `Modifying selectionStart value of ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
textarea.selectionEnd = 1;
|
||||
|
||||
target.selectionEnd = 1;
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 1);
|
||||
}, "Modifying selectionEnd value of the textarea element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 1);
|
||||
}, `Modifying selectionEnd value of ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
textarea.setSelectionRange(0, 4);
|
||||
|
||||
target.setSelectionRange(0, 4);
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 1);
|
||||
}, "Calling setSelectionRange() on the textarea element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 1);
|
||||
}, `Calling setSelectionRange() on ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
input.select();
|
||||
|
||||
target.select();
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.input.events.length, 1);
|
||||
}, "Calling select() on the input element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 1);
|
||||
}, `Calling select() on ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
textarea.select();
|
||||
|
||||
target.selectionStart = 0;
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 1);
|
||||
}, "Calling select() on the textarea element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 0);
|
||||
}, `Setting initial zero selectionStart value on ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
input.selectionStart = 0;
|
||||
|
||||
target.selectionStart = 2;
|
||||
target.selectionStart = 2;
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.input.events.length, 0);
|
||||
}, "Setting initial zero selectionStart value on the input element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 1);
|
||||
}, `Setting the same selectionStart value twice on ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
input.selectionEnd = 0;
|
||||
|
||||
target.selectionEnd = 0;
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.input.events.length, 0);
|
||||
}, "Setting initial zero selectionEnd value on the input element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 0);
|
||||
}, `Setting initial zero selectionEnd value on ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
textarea.selectionStart = 0;
|
||||
|
||||
target.selectionEnd = 2;
|
||||
target.selectionEnd = 2;
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 0);
|
||||
}, "Setting initial zero selectionStart value on the textarea element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 1);
|
||||
}, `Setting the same selectionEnd value twice on ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
textarea.selectionStart = 2;
|
||||
textarea.selectionStart = 2;
|
||||
|
||||
target.setSelectionRange(0, 0);
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 1);
|
||||
}, "Setting the same selectionStart value twice on the textarea element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 0);
|
||||
}, `Setting initial zero selection range on ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
textarea.selectionEnd = 0;
|
||||
|
||||
target.setSelectionRange(3, 3);
|
||||
target.setSelectionRange(3, 3);
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 0);
|
||||
}, "Setting initial zero selectionEnd value on the textarea element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 1);
|
||||
}, `Setting the same selection range twice on ${name}`);
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
textarea.selectionEnd = 2;
|
||||
textarea.selectionEnd = 2;
|
||||
|
||||
target.select();
|
||||
target.select();
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 1);
|
||||
}, "Setting the same selectionEnd value twice on the textarea element");
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(collector.events.length, 1);
|
||||
}, `Calling select() twice on ${name}`);
|
||||
}
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
textarea.setSelectionRange(0, 0);
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 0);
|
||||
}, "Setting initial zero selection range on the textarea element");
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
textarea.setSelectionRange(3, 3);
|
||||
textarea.setSelectionRange(3, 3);
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 1);
|
||||
}, "Setting the same selection range twice on the textarea element");
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
input.select();
|
||||
input.select();
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.input.events.length, 1);
|
||||
}, "Calling select() twice on the input element");
|
||||
|
||||
promise_test(async () => {
|
||||
await data.initialize();
|
||||
|
||||
textarea.select();
|
||||
textarea.select();
|
||||
|
||||
await data.assert_empty_spin();
|
||||
assert_equals(data.textarea.events.length, 1);
|
||||
}, "Calling select() twice on the textarea element");
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче