Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: third_party/WebKit/LayoutTests/accessibility/set-selection-child-offset.html

Issue 2339093003: Support child-based node offsets when setting accessible selections (Closed)
Patch Set: More tests. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/accessibility/set-selection-child-offset.html
diff --git a/third_party/WebKit/LayoutTests/accessibility/set-selection-child-offset.html b/third_party/WebKit/LayoutTests/accessibility/set-selection-child-offset.html
new file mode 100644
index 0000000000000000000000000000000000000000..c779d57999a5ff27784d1388fd8608672ff0a320
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/accessibility/set-selection-child-offset.html
@@ -0,0 +1,132 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+
+<span id="span1">this is a<a id="link" href="#1">test</a></span>
+<span id="span2">of selection</span>
+
+<script>
+ var sel = null;
+ function updateSelectedRangeFromPage() {
+ sel = window.getSelection().getRangeAt(0);
+ }
+
+ // The accessibility tree contains a group with 3 children, select each.
+ test(function()
+ {
+ assert_not_equals(window.accessibilityController, undefined, 'This test requires accessibilityController');
+
+ var axGroup = accessibilityController.accessibleElementById("link").parentElement();
dmazzoni 2016/09/15 16:32:36 What element does this correspond to? Is it not sp
David Tseng 2016/09/15 18:34:28 The idea was to use an example where the ax tree r
+ assert_equals(axGroup.role, "AXRole: AXGroup");
+
+ // An insertion point before the first child.
+ axGroup.setSelection(axGroup, 0, axGroup, 0);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "");
+ assert_true(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.startOffset, 0);
+ assert_equals(sel.startContainer.textContent, "this is a");
+
+ // A straight-forward selection of the first child.
+ axGroup.setSelection(axGroup, 0, axGroup, 1);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "this is a");
+ assert_false(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.endContainer.constructor, Text);
+ assert_equals(sel.startOffset, 0);
+ assert_equals(sel.startContainer.textContent, "this is a");
+ assert_equals(sel.endOffset, 9);
+ assert_equals(sel.endContainer.textContent, "this is a");
+
+ // Another insertion point after the first child, before the second.
+ axGroup.setSelection(axGroup, 1, axGroup, 1);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "");
+ assert_true(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.startOffset, 9);
+ assert_equals(sel.startContainer.textContent, "this is a");
+
+ // A selection demonstrating ax can use child indicies to select whitespace only in the DOM (second child).
dmazzoni 2016/09/15 16:32:36 What do you mean by whitespace only in the DOM?
David Tseng 2016/09/15 18:34:28 Were you expecting a line break (either a node or
+ axGroup.setSelection(axGroup, 1, axGroup, 2);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "test\n");
+ assert_false(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.endContainer.constructor, Text);
+ assert_equals(sel.startOffset, 0);
+ assert_equals(sel.startContainer.textContent, "test");
+ // Assert the endContainer comes *after* the node above.
+ assert_equals(sel.endContainer.previousSibling.lastChild.lastChild, sel.startContainer);
dmazzoni 2016/09/15 16:32:36 I'm worried that this is really fragile and will b
David Tseng 2016/09/15 18:34:28 This is the DOM tree; what type of refactoring are
dmazzoni 2016/09/15 21:06:43 How about this: add comments next to the two types
+ assert_equals(sel.endOffset, 1);
+ assert_equals(sel.endContainer.textContent, "\n");
+
+ // Next, another insertion point between second and third child.
+ axGroup.setSelection(axGroup, 2, axGroup, 2);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "");
+ assert_true(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.startOffset, 1);
+ assert_equals(sel.startContainer.textContent, "\n");
+
+ // Select the third child.
+ axGroup.setSelection(axGroup, 2, axGroup, 3);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "of selection");
+ assert_false(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.endContainer.constructor, Text);
+ assert_equals(sel.startOffset, 0);
+ assert_equals(sel.startContainer.textContent, "of selection");
+ assert_equals(sel.endOffset, 12);
+ assert_equals(sel.endContainer.textContent, "of selection");
+
+ // Select the first and second children.
+ axGroup.setSelection(axGroup, 0, axGroup, 2);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "this is atest\n");
+ assert_false(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.endContainer.constructor, Text);
+ assert_equals(sel.startOffset, 0);
+ assert_equals(sel.startContainer.textContent, "this is a");
+ assert_equals(sel.endOffset, 1);
+ assert_equals(sel.endContainer.textContent, "\n");
+
+ // Select the second and third children.
+ axGroup.setSelection(axGroup, 1, axGroup, 3);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "test\nof selection");
+ assert_false(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.endContainer.constructor, Text);
+ assert_equals(sel.startOffset, 0);
+ assert_equals(sel.startContainer.textContent, "test");
+ assert_equals(sel.endOffset, 12);
+ assert_equals(sel.endContainer.textContent, "of selection");
+
+ // Select everything.
+ axGroup.setSelection(axGroup, 0, axGroup, 3);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "this is atest\nof selection");
+ assert_false(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.endContainer.constructor, Text);
+ assert_equals(sel.startOffset, 0);
+ assert_equals(sel.startContainer.textContent, "this is a");
+ assert_equals(sel.endOffset, 12);
+ assert_equals(sel.endContainer.textContent, "of selection");
+
+ // Last, the insertion point after third child.
+ axGroup.setSelection(axGroup, 3, axGroup, 3);
+ updateSelectedRangeFromPage();
+ assert_equals(sel.toString(), "");
+ assert_true(sel.collapsed);
+ assert_equals(sel.startContainer.constructor, Text);
+ assert_equals(sel.startOffset, 12);
+ assert_equals(sel.startContainer.textContent, "of selection");
+ }, "Select child node at index.");
+</script>

Powered by Google App Engine
This is Rietveld 408576698