blob: bb3c86cfc8a97a0c6c87e790b553f809f5a897f2 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body id="body">
<div role="textbox" tabindex=0 id="textbox" contenteditable=true>
<p>one two three. four five six.</p>
<p>seven eight nine.</p>
</div>
<p id="description"></p>
<div id="console"></div>
<div id="notifications"></div>
<script>
description("This tests selection change notifications user info data.");
var AXTextStateChangeTypeSelectionMove = 2;
var AXTextStateChangeTypeSelectionExtend = AXTextStateChangeTypeSelectionMove + 1;
var AXTextSelectionDirectionBeginning = 1;
var AXTextSelectionDirectionEnd = AXTextSelectionDirectionBeginning + 1;
var AXTextSelectionDirectionPrevious = AXTextSelectionDirectionEnd + 1;
var AXTextSelectionDirectionNext = AXTextSelectionDirectionPrevious + 1;
var AXTextSelectionGranularityCharacter = 1;
var AXTextSelectionGranularityWord = AXTextSelectionGranularityCharacter + 1;
var AXTextSelectionGranularityLine = AXTextSelectionGranularityWord + 1;
var AXTextSelectionGranularitySentence = AXTextSelectionGranularityLine + 1;
var AXTextSelectionGranularityParagraph = AXTextSelectionGranularitySentence + 1;
var AXTextSelectionGranularityDocument = AXTextSelectionGranularityParagraph + 2;
var gran = ["character", "word", "sentence", "line", "paragraph", "lineboundary", "sentenceboundary", "paragraphboundary", "documentboundary"];
var webArea = 0;
var count = 0;
var results = [];
var resultIndex = 0;
function notificationCallback(notification, userInfo) {
if (notification == "AXSelectedTextChanged") {
count++;
if (userInfo)
results.push(userInfo);
if (count == gran.length * 4) {
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityCharacter");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityCharacter");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionPrevious");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityWord");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityWord");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionPrevious");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularitySentence");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularitySentence");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionPrevious");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityLine");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityLine");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionPrevious");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityParagraph");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityParagraph");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionPrevious");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityLine");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionEnd");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityLine");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionBeginning");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularitySentence");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionEnd");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularitySentence");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionBeginning");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityParagraph");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionEnd");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityParagraph");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionBeginning");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityDocument");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionEnd");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionMove");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityDocument");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionBeginning");
resultIndex++;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityCharacter");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex += 2;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityWord");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex += 2;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularitySentence");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex += 2;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityLine");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex += 2;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityParagraph");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionNext");
resultIndex += 2;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityLine");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionEnd");
resultIndex += 2;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularitySentence");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionEnd");
resultIndex += 2;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityParagraph");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionEnd");
resultIndex += 2;
shouldBe("results[resultIndex][\"AXTextStateChangeType\"]", "AXTextStateChangeTypeSelectionExtend");
shouldBe("results[resultIndex][\"AXTextSelectionGranularity\"]", "AXTextSelectionGranularityDocument");
shouldBe("results[resultIndex][\"AXTextSelectionDirection\"]", "AXTextSelectionDirectionEnd");
webArea.removeNotificationListener();
finishJSTest();
}
}
}
if (window.accessibilityController) {
jsTestIsAsync = true;
accessibilityController.enableEnhancedAccessibility(true);
webArea = accessibilityController.rootElement.childAtIndex(0);
var addedNotification = webArea.addNotificationListener(notificationCallback);
shouldBe("addedNotification", "true");
textbox = document.getElementById("textbox");
// Trigger selection changes.
var s = window.getSelection();
function focusTextBox() {
return new Promise(function(resolve, reject) {
setTimeout(() => {
textbox.focus();
resolve();
}, 0);
});
}
function moveSelection(direction, granularity) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
s.modify("move", direction, granularity);
resolve();
}, 0);
});
}
function extendSelection(granularity) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
s.modify("extend", "forward", granularity);
resolve();
}, 0);
});
}
function resetPosition() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
s = window.getSelection();
s.setPosition(textbox, 0);
resolve();
}, 0);
});
}
(async function() {
await focusTextBox();
await resetPosition();
await moveSelection("forward", gran[0]);
await moveSelection("backward", gran[0]);
await moveSelection("forward", gran[1]);
await moveSelection("backward", gran[1]);
await moveSelection("forward", gran[2]);
await moveSelection("backward", gran[2]);
await moveSelection("forward", gran[3]);
await moveSelection("backward", gran[3]);
await moveSelection("forward", gran[4]);
await moveSelection("backward", gran[4]);
await moveSelection("forward", gran[5]);
await moveSelection("backward", gran[5]);
await moveSelection("forward", gran[6]);
await moveSelection("backward", gran[6]);
await moveSelection("forward", gran[7]);
await moveSelection("backward", gran[7]);
await moveSelection("forward", gran[8]);
await moveSelection("backward", gran[8]);
await resetPosition();
await extendSelection(gran[0]);
await resetPosition();
await extendSelection(gran[1]);
await resetPosition();
await extendSelection(gran[2]);
await resetPosition();
await extendSelection(gran[3]);
await resetPosition();
await extendSelection(gran[4]);
await resetPosition();
await extendSelection(gran[5]);
await resetPosition();
await extendSelection(gran[6]);
await resetPosition();
await extendSelection(gran[7]);
await resetPosition();
await extendSelection(gran[8]);
})();
}
</script>
</body>
</html>