haikuwebkit/LayoutTests/accessibility/mac/replace-text-with-range-val...

108 lines
4.1 KiB
HTML
Raw Permalink Normal View History

AX: accessibilityReplaceRange:withText: doesn't post an AXValueChanged notification like when typing with kb https://bugs.webkit.org/show_bug.cgi?id=208332 <rdar://problem/58489685> Patch by Canhai Chen <canhai_chen@apple.com> on 2020-03-11 Reviewed by Chris Fleizach. Source/WebCore: When accessibilityReplaceRange:withText: is called to insert or replace text, there should be a AXValueChanged notification posted with the correct user info to notify the AX client that the text value has been changed with detailed info about the change. Post a notification in Editor::replaceSelectionWithFragment for EditAction::Insert edit type with replaced text and selection. Add a new test for text replacement value change notification in editable div, text input, and textarea, including direct text insertion and replace-and-insert. Test: accessibility/mac/replace-text-with-range-value-change-notification.html * editing/Editor.cpp: (WebCore::Editor::replaceSelectionWithFragment): * editing/ReplaceSelectionCommand.h: (WebCore::ReplaceSelectionCommand::documentFragmentPlainText const): LayoutTests: Test text replacement value change notification in editable div, text input, and textarea, including direct text insertion and replace-and-insert. * accessibility/mac/replace-text-with-range-value-change-notification-expected.txt: Added. * accessibility/mac/replace-text-with-range-value-change-notification.html: Added. Canonical link: https://commits.webkit.org/221875@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@258303 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-03-12 01:22:09 +00:00
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="../../editing/editing.js"></script>
<script src="value-change/value-change-helpers.js"></script>
</head>
<body id="body">
<div id="content">
<div id="content-editable-div" contenteditable="true" role="textbox"></div>
<input id="text" type="text" value="">
<textarea id="textarea"></textarea>
</div>
<p id="description"></p>
<div id="console"></div>
<script>
description("This tests that when we are calling the replace with range API to insert or replace text, value change notifications are posted as expected with correct user info data.");
var webArea = 0;
var count = 0;
var resultIndex = -1;
var actualChangeTypes = [];
var actualChangeValues = [];
var actualEditTypes = [];
var expectedValues = [];
function notificationCallback(notification, userInfo) {
if (notification == "AXValueChanged") {
actualChangeTypes[count] = userInfo["AXTextStateChangeType"];
var changes = userInfo["AXTextChangeValues"];
if (changes && changes.length == 1) {
var change = changes[0];
actualChangeValues[count] = change["AXTextChangeValue"];
actualEditTypes[count] = stringForEditType(change["AXTextEditType"])
} else if (changes && changes.length == 2) {
var change1 = changes[0];
var change2 = changes[1];
actualChangeValues[count] = [change1["AXTextChangeValue"], change2["AXTextChangeValue"]];
actualEditTypes[count] = [stringForEditType(change1["AXTextEditType"]), stringForEditType(change2["AXTextEditType"])];
}
count++;
var expectedCount = 6;
if (count == expectedCount) {
shouldBeInsert("Apple");
shouldBeInsertReplace("Apple", "Pie");
shouldBeInsert("Banana");
shouldBeInsertReplace("Banana", "Ice-cream");
shouldBeInsert("Cat");
shouldBeInsertReplace("Cat", "Dog");
webArea.removeNotificationListener();
finishJSTest();
}
}
}
if (window.accessibilityController) {
jsTestIsAsync = true;
accessibilityController.enableEnhancedAccessibility(true);
webArea = accessibilityController.rootElement.childAtIndex(0);
var addedNotification = webArea.addNotificationListener(notificationCallback);
shouldBe("addedNotification", "true");
var axContentEditableDiv = accessibilityController.accessibleElementById("content-editable-div");
var contentEditableDiv = document.getElementById("content-editable-div");
contentEditableDiv.focus();
shouldBeTrue("axContentEditableDiv.replaceTextInRange('Apple', 0, 0)");
shouldBe("axContentEditableDiv.stringValue", "'AXValue: Apple'");
shouldBeTrue("axContentEditableDiv.replaceTextInRange('Pie', 0, 5)");
shouldBe("axContentEditableDiv.stringValue", "'AXValue: Pie'");
contentEditableDiv.blur();
var axText = accessibilityController.accessibleElementById("text");
var text = document.getElementById("text");
text.focus();
shouldBeTrue("axText.replaceTextInRange('Banana', 0, 0)");
shouldBe("axText.stringValue", "'AXValue: Banana'");
shouldBeTrue("axText.replaceTextInRange('Ice-cream', 0, 6)");
shouldBe("axText.stringValue", "'AXValue: Ice-cream'");
text.blur();
var axTextarea = accessibilityController.accessibleElementById("textarea");
var textarea = document.getElementById("textarea");
textarea.focus();
shouldBeTrue("axTextarea.replaceTextInRange('Cat', 0, 0)");
shouldBe("axTextarea.stringValue", "'AXValue: Cat'");
shouldBeTrue("axTextarea.replaceTextInRange('Dog', 0, 3)");
shouldBe("axTextarea.stringValue", "'AXValue: Dog'");
textarea.blur();
document.getElementById("content").style.visibility = "hidden";
}
</script>
</body>
</html>