зеркало из https://github.com/mozilla/gecko-dev.git
Bug 918940 - Part a: Make HTMLInputElement::SetSelectionRange fire select event asynchronously per spec. r=ehsan
This commit is contained in:
Родитель
f2eb0ae894
Коммит
ecc69f1db7
|
@ -4523,12 +4523,10 @@ HTMLInputElement::SetSelectionRange(int32_t aSelectionStart,
|
|||
aRv = textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd, dir);
|
||||
if (!aRv.Failed()) {
|
||||
aRv = textControlFrame->ScrollSelectionIntoView();
|
||||
nsRefPtr<nsAsyncDOMEvent> event =
|
||||
new nsAsyncDOMEvent(this, NS_LITERAL_STRING("select"), true, false);
|
||||
event->PostDOMEvent();
|
||||
}
|
||||
|
||||
nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(this),
|
||||
NS_LITERAL_STRING("select"), true,
|
||||
false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850364
|
|||
}
|
||||
ok(opThrows, msg + " should throw NotSupportedError");
|
||||
}
|
||||
|
||||
|
||||
var numOfSelectCalls = 0, expectedNumOfSelectCalls = 0;
|
||||
//Supported types should not throw
|
||||
for (i = 0; i < SupportedTypes.length; ++i) {
|
||||
opThrows = false;
|
||||
|
@ -73,14 +74,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850364
|
|||
} catch (ex) {
|
||||
opThrows = true;
|
||||
}
|
||||
is(opThrows, false, msg + " should not throw NotSupportedError");
|
||||
is(opThrows, false, msg + " should not throw NotSupportedError");
|
||||
|
||||
elem.addEventListener("select", function (aEvent) {
|
||||
ok(true, "select event should be fired for "+ msg);
|
||||
ok(true, "select event should be fired for " + aEvent.target.id);
|
||||
if (++numOfSelectCalls == expectedNumOfSelectCalls) {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}, false);
|
||||
|
||||
elem.addEventListener("input", function (aEvent) {
|
||||
ok(false, "input event should NOT be fired for " + msg);
|
||||
ok(false, "input event should NOT be fired for " + aEvent.target.id);
|
||||
}, false);
|
||||
|
||||
//test setRange(replacement)
|
||||
|
@ -91,7 +95,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850364
|
|||
is(elem.selectionStart, 1, msg + ".selectionStart == 1");
|
||||
is(elem.selectionEnd, 4, msg + ".selectionEnd == 4");
|
||||
elem.setRangeText("mnk");
|
||||
is(elem.value, "0mnk6789ABCDEF", msg + ".value == \"0mnk6789ABCDEF\"");
|
||||
is(elem.value, "0mnk6789ABCDEF", msg + ".value == \"0mnk6789ABCDEF\"");
|
||||
expectedNumOfSelectCalls += 3;
|
||||
|
||||
//test SetRange(replacement, start, end, mode) with start > end
|
||||
try {
|
||||
|
@ -99,43 +104,50 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850364
|
|||
} catch (ex) {
|
||||
opThrows = (ex.name == "IndexSizeError" && ex.code == DOMException.INDEX_SIZE_ERR);
|
||||
}
|
||||
is(opThrows, true, msg + " should throw IndexSizeError");
|
||||
is(opThrows, true, msg + " should throw IndexSizeError");
|
||||
expectedNumOfSelectCalls += 1;
|
||||
|
||||
//test SelectionMode 'select'
|
||||
elem.value = "0123456789ABCDEF";
|
||||
elem.setRangeText("xyz", 4, 9, "select");
|
||||
is(elem.value, "0123xyz9ABCDEF", msg + ".value == \"0123xyz9ABCDEF\"");
|
||||
is(elem.selectionStart, 4, msg + ".selectionStart == 4, with \"select\"");
|
||||
is(elem.selectionEnd, 7, msg + ".selectionEnd == 7, with \"select\"");
|
||||
is(elem.selectionEnd, 7, msg + ".selectionEnd == 7, with \"select\"");
|
||||
expectedNumOfSelectCalls += 1;
|
||||
|
||||
elem.setRangeText("pqm", 6, 25, "select");
|
||||
is(elem.value, "0123xypqm", msg + ".value == \"0123xypqm\"");
|
||||
is(elem.selectionStart, 6, msg + ".selectionStart == 6, with \"select\"");
|
||||
is(elem.selectionEnd, 9, msg + ".selectionEnd == 9, with \"select\"");
|
||||
is(elem.selectionEnd, 9, msg + ".selectionEnd == 9, with \"select\"");
|
||||
expectedNumOfSelectCalls += 1;
|
||||
|
||||
//test SelectionMode 'start'
|
||||
elem.value = "0123456789ABCDEF";
|
||||
elem.setRangeText("xyz", 4, 9, "start");
|
||||
is(elem.value, "0123xyz9ABCDEF", msg + ".value == \"0123xyz9ABCDEF\"");
|
||||
is(elem.selectionStart, 4, msg + ".selectionStart == 4, with \"start\"");
|
||||
is(elem.selectionEnd, 4, msg + ".selectionEnd == 4, with \"start\"");
|
||||
is(elem.selectionEnd, 4, msg + ".selectionEnd == 4, with \"start\"");
|
||||
expectedNumOfSelectCalls += 1;
|
||||
|
||||
elem.setRangeText("pqm", 6, 25, "start");
|
||||
is(elem.value, "0123xypqm", msg + ".value == \"0123xypqm\"");
|
||||
is(elem.selectionStart, 6, msg + ".selectionStart == 6, with \"start\"");
|
||||
is(elem.selectionEnd, 6, msg + ".selectionEnd == 6, with \"start\"");
|
||||
is(elem.selectionEnd, 6, msg + ".selectionEnd == 6, with \"start\"");
|
||||
expectedNumOfSelectCalls += 1;
|
||||
|
||||
//test SelectionMode 'end'
|
||||
elem.value = "0123456789ABCDEF";
|
||||
elem.setRangeText("xyz", 4, 9, "end");
|
||||
is(elem.value, "0123xyz9ABCDEF", msg + ".value == \"0123xyz9ABCDEF\"");
|
||||
is(elem.selectionStart, 7, msg + ".selectionStart == 7, with \"end\"");
|
||||
is(elem.selectionEnd, 7, msg + ".selectionEnd == 7, with \"end\"");
|
||||
is(elem.selectionEnd, 7, msg + ".selectionEnd == 7, with \"end\"");
|
||||
expectedNumOfSelectCalls += 1;
|
||||
|
||||
elem.setRangeText("pqm", 6, 25, "end");
|
||||
is(elem.value, "0123xypqm", msg + ".value == \"0123xypqm\"");
|
||||
is(elem.selectionStart, 9, msg + ".selectionStart == 9, with \"end\"");
|
||||
is(elem.selectionEnd, 9, msg + ".selectionEnd == 9, with \"end\"");
|
||||
is(elem.selectionEnd, 9, msg + ".selectionEnd == 9, with \"end\"");
|
||||
expectedNumOfSelectCalls += 1;
|
||||
|
||||
//test SelectionMode 'preserve' (default)
|
||||
|
||||
|
@ -145,7 +157,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850364
|
|||
elem.setRangeText("Z", 1, 2, "preserve");
|
||||
is(elem.value, "0Z23456789", msg + ".value == \"0Z23456789\"");
|
||||
is(elem.selectionStart, 6, msg + ".selectionStart == 6, with \"preserve\"");
|
||||
is(elem.selectionEnd, 9, msg + ".selectionEnd == 9, with \"preserve\"");
|
||||
is(elem.selectionEnd, 9, msg + ".selectionEnd == 9, with \"preserve\"");
|
||||
expectedNumOfSelectCalls += 2;
|
||||
|
||||
//subcase: selection{Start|End} < end
|
||||
elem.value = "0123456789";
|
||||
|
@ -153,7 +166,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850364
|
|||
elem.setRangeText("QRST", 2, 9, "preserve");
|
||||
is(elem.value, "01QRST9", msg + ".value == \"01QRST9\"");
|
||||
is(elem.selectionStart, 2, msg + ".selectionStart == 2, with \"preserve\"");
|
||||
is(elem.selectionEnd, 6, msg + ".selectionEnd == 6, with \"preserve\"");
|
||||
is(elem.selectionEnd, 6, msg + ".selectionEnd == 6, with \"preserve\"");
|
||||
expectedNumOfSelectCalls += 2;
|
||||
|
||||
//subcase: selectionStart > end, selectionEnd < end
|
||||
elem.value = "0123456789";
|
||||
|
@ -161,7 +175,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850364
|
|||
elem.setRangeText("QRST", 1, 5);
|
||||
is(elem.value, "0QRST56789", msg + ".value == \"0QRST56789\"");
|
||||
is(elem.selectionStart, 1, msg + ".selectionStart == 1, with \"default\"");
|
||||
is(elem.selectionEnd, 5, msg + ".selectionEnd == 5, with \"default\"");
|
||||
is(elem.selectionEnd, 5, msg + ".selectionEnd == 5, with \"default\"");
|
||||
expectedNumOfSelectCalls += 2;
|
||||
|
||||
//subcase: selectionStart < end, selectionEnd > end
|
||||
elem.value = "0123456789";
|
||||
|
@ -169,10 +184,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=850364
|
|||
elem.setRangeText("QRST", 2, 6);
|
||||
is(elem.value, "01QRST6789", msg + ".value == \"01QRST6789\"");
|
||||
is(elem.selectionStart, 2, msg + ".selectionStart == 2, with \"default\"");
|
||||
is(elem.selectionEnd, 9, msg + ".selectionEnd == 9, with \"default\"");
|
||||
is(elem.selectionEnd, 9, msg + ".selectionEnd == 9, with \"default\"");
|
||||
expectedNumOfSelectCalls += 2;
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
addLoadEvent(TestInputs);
|
||||
|
|
Загрузка…
Ссылка в новой задаче