Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="../resources/testharness.js"></script> | |
| 3 <script src="../resources/testharnessreport.js"></script> | |
| 4 | |
| 5 <span id="span1">this is a<a id="link" href="#1">test</a></span> | |
| 6 <span id="span2">of selection</span> | |
| 7 | |
| 8 <script> | |
| 9 var sel = null; | |
| 10 function updateSelectedRangeFromPage() { | |
| 11 sel = window.getSelection().getRangeAt(0); | |
| 12 } | |
| 13 | |
| 14 // The accessibility tree contains a group with 3 children, select each. | |
| 15 test(function() | |
| 16 { | |
| 17 assert_not_equals(window.accessibilityController, undefined, 'This test requires accessibilityController'); | |
| 18 | |
| 19 var axGroup = accessibilityController.accessibleElementById("link").pare ntElement(); | |
|
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
| |
| 20 assert_equals(axGroup.role, "AXRole: AXGroup"); | |
| 21 | |
| 22 // An insertion point before the first child. | |
| 23 axGroup.setSelection(axGroup, 0, axGroup, 0); | |
| 24 updateSelectedRangeFromPage(); | |
| 25 assert_equals(sel.toString(), ""); | |
| 26 assert_true(sel.collapsed); | |
| 27 assert_equals(sel.startContainer.constructor, Text); | |
| 28 assert_equals(sel.startOffset, 0); | |
| 29 assert_equals(sel.startContainer.textContent, "this is a"); | |
| 30 | |
| 31 // A straight-forward selection of the first child. | |
| 32 axGroup.setSelection(axGroup, 0, axGroup, 1); | |
| 33 updateSelectedRangeFromPage(); | |
| 34 assert_equals(sel.toString(), "this is a"); | |
| 35 assert_false(sel.collapsed); | |
| 36 assert_equals(sel.startContainer.constructor, Text); | |
| 37 assert_equals(sel.endContainer.constructor, Text); | |
| 38 assert_equals(sel.startOffset, 0); | |
| 39 assert_equals(sel.startContainer.textContent, "this is a"); | |
| 40 assert_equals(sel.endOffset, 9); | |
| 41 assert_equals(sel.endContainer.textContent, "this is a"); | |
| 42 | |
| 43 // Another insertion point after the first child, before the second. | |
| 44 axGroup.setSelection(axGroup, 1, axGroup, 1); | |
| 45 updateSelectedRangeFromPage(); | |
| 46 assert_equals(sel.toString(), ""); | |
| 47 assert_true(sel.collapsed); | |
| 48 assert_equals(sel.startContainer.constructor, Text); | |
| 49 assert_equals(sel.startOffset, 9); | |
| 50 assert_equals(sel.startContainer.textContent, "this is a"); | |
| 51 | |
| 52 // A selection demonstrating ax can use child indicies to select whitesp ace 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
| |
| 53 axGroup.setSelection(axGroup, 1, axGroup, 2); | |
| 54 updateSelectedRangeFromPage(); | |
| 55 assert_equals(sel.toString(), "test\n"); | |
| 56 assert_false(sel.collapsed); | |
| 57 assert_equals(sel.startContainer.constructor, Text); | |
| 58 assert_equals(sel.endContainer.constructor, Text); | |
| 59 assert_equals(sel.startOffset, 0); | |
| 60 assert_equals(sel.startContainer.textContent, "test"); | |
| 61 // Assert the endContainer comes *after* the node above. | |
| 62 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
| |
| 63 assert_equals(sel.endOffset, 1); | |
| 64 assert_equals(sel.endContainer.textContent, "\n"); | |
| 65 | |
| 66 // Next, another insertion point between second and third child. | |
| 67 axGroup.setSelection(axGroup, 2, axGroup, 2); | |
| 68 updateSelectedRangeFromPage(); | |
| 69 assert_equals(sel.toString(), ""); | |
| 70 assert_true(sel.collapsed); | |
| 71 assert_equals(sel.startContainer.constructor, Text); | |
| 72 assert_equals(sel.startOffset, 1); | |
| 73 assert_equals(sel.startContainer.textContent, "\n"); | |
| 74 | |
| 75 // Select the third child. | |
| 76 axGroup.setSelection(axGroup, 2, axGroup, 3); | |
| 77 updateSelectedRangeFromPage(); | |
| 78 assert_equals(sel.toString(), "of selection"); | |
| 79 assert_false(sel.collapsed); | |
| 80 assert_equals(sel.startContainer.constructor, Text); | |
| 81 assert_equals(sel.endContainer.constructor, Text); | |
| 82 assert_equals(sel.startOffset, 0); | |
| 83 assert_equals(sel.startContainer.textContent, "of selection"); | |
| 84 assert_equals(sel.endOffset, 12); | |
| 85 assert_equals(sel.endContainer.textContent, "of selection"); | |
| 86 | |
| 87 // Select the first and second children. | |
| 88 axGroup.setSelection(axGroup, 0, axGroup, 2); | |
| 89 updateSelectedRangeFromPage(); | |
| 90 assert_equals(sel.toString(), "this is atest\n"); | |
| 91 assert_false(sel.collapsed); | |
| 92 assert_equals(sel.startContainer.constructor, Text); | |
| 93 assert_equals(sel.endContainer.constructor, Text); | |
| 94 assert_equals(sel.startOffset, 0); | |
| 95 assert_equals(sel.startContainer.textContent, "this is a"); | |
| 96 assert_equals(sel.endOffset, 1); | |
| 97 assert_equals(sel.endContainer.textContent, "\n"); | |
| 98 | |
| 99 // Select the second and third children. | |
| 100 axGroup.setSelection(axGroup, 1, axGroup, 3); | |
| 101 updateSelectedRangeFromPage(); | |
| 102 assert_equals(sel.toString(), "test\nof selection"); | |
| 103 assert_false(sel.collapsed); | |
| 104 assert_equals(sel.startContainer.constructor, Text); | |
| 105 assert_equals(sel.endContainer.constructor, Text); | |
| 106 assert_equals(sel.startOffset, 0); | |
| 107 assert_equals(sel.startContainer.textContent, "test"); | |
| 108 assert_equals(sel.endOffset, 12); | |
| 109 assert_equals(sel.endContainer.textContent, "of selection"); | |
| 110 | |
| 111 // Select everything. | |
| 112 axGroup.setSelection(axGroup, 0, axGroup, 3); | |
| 113 updateSelectedRangeFromPage(); | |
| 114 assert_equals(sel.toString(), "this is atest\nof selection"); | |
| 115 assert_false(sel.collapsed); | |
| 116 assert_equals(sel.startContainer.constructor, Text); | |
| 117 assert_equals(sel.endContainer.constructor, Text); | |
| 118 assert_equals(sel.startOffset, 0); | |
| 119 assert_equals(sel.startContainer.textContent, "this is a"); | |
| 120 assert_equals(sel.endOffset, 12); | |
| 121 assert_equals(sel.endContainer.textContent, "of selection"); | |
| 122 | |
| 123 // Last, the insertion point after third child. | |
| 124 axGroup.setSelection(axGroup, 3, axGroup, 3); | |
| 125 updateSelectedRangeFromPage(); | |
| 126 assert_equals(sel.toString(), ""); | |
| 127 assert_true(sel.collapsed); | |
| 128 assert_equals(sel.startContainer.constructor, Text); | |
| 129 assert_equals(sel.startOffset, 12); | |
| 130 assert_equals(sel.startContainer.textContent, "of selection"); | |
| 131 }, "Select child node at index."); | |
| 132 </script> | |
| OLD | NEW |