Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/editing_test.extjs |
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/editing_test.extjs b/chrome/browser/resources/chromeos/chromevox/cvox2/background/editing_test.extjs |
index af6ebc8eb60eb98f0d9435a65d9ffbca794a8040..2def23f3a3285c573ed596a84073012220b46e9a 100644 |
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/editing_test.extjs |
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/editing_test.extjs |
@@ -554,3 +554,102 @@ TEST_F('EditingTest', 'EditableLineEquality', function() { |
assertFalse(e1.equals(e2)); |
}); |
}); |
+ |
+TEST_F('EditingTest', 'EditableLineStrictEquality', function() { |
+ this.runWithLoadedTree(function() {/*! |
+ <div contenteditable role="textbox"> |
+ <p style="word-spacing:100000px">this is a test</p> |
+ <p>hello <b>world</b></p> |
+ </div> |
+ */}, function(root) { |
+ var thisIsATest = root.findAll({role: RoleType.PARAGRAPH})[0].firstChild; |
+ var hello = root.findAll({role: RoleType.PARAGRAPH})[1].firstChild; |
+ var world = root.findAll({role: RoleType.PARAGRAPH})[1].lastChild; |
+ |
+ // The same position -- sanity check. |
+ var e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 0); |
+ assertEquals('this ', e1.text); |
+ assertTrue(e1.equalsStrict(e1)); |
+ |
+ // Offset into the same soft line. |
+ var e2 = new editing.EditableLine(thisIsATest, 1, thisIsATest, 1); |
+ assertFalse(e1.equalsStrict(e2)); |
+ |
+ // Boundary. |
+ e2 = new editing.EditableLine(thisIsATest, 4, thisIsATest, 4); |
+ assertFalse(e1.equalsStrict(e2)); |
+ |
+ // Offsets into different soft lines. |
+ e2 = new editing.EditableLine(thisIsATest, 5, thisIsATest, 5); |
+ assertEquals('is ', e2.text); |
+ assertFalse(e1.equalsStrict(e2)); |
+ |
+ // Sanity check; second soft line. |
+ assertTrue(e2.equalsStrict(e2)); |
+ |
+ // Different offsets into second soft line. |
+ e1 = new editing.EditableLine(thisIsATest, 6, thisIsATest, 6); |
+ assertFalse(e1.equalsStrict(e2)); |
+ |
+ // Boundary. |
+ e1 = new editing.EditableLine(thisIsATest, 7, thisIsATest, 7); |
+ assertFalse(e1.equalsStrict(e2)); |
+ |
+ // Cross into new paragraph. |
+ e2 = new editing.EditableLine(hello, 0, hello, 0); |
+ assertEquals('hello world', e2.text); |
+ assertFalse(e1.equalsStrict(e2)); |
+ |
+ // On same node, with multi-static text line. |
+ e1 = new editing.EditableLine(hello, 1, hello, 1); |
+ assertFalse(e1.equalsStrict(e2)); |
+ |
+ // On same node, with multi-static text line; boundary. |
+ e1 = new editing.EditableLine(hello, 5, hello, 5); |
+ assertFalse(e1.equalsStrict(e2)); |
+ }); |
+}); |
+ |
+TEST_F('EditingTest', 'EditableLineBaseLineAnchorOrFocus', function() { |
+ this.runWithLoadedTree(function() {/*! |
+ <div contenteditable role="textbox"> |
+ <p style="word-spacing:100000px">this is a test</p> |
+ <p>hello <b>world</b></p> |
+ </div> |
+ */}, function(root) { |
+ var thisIsATest = root.findAll({role: RoleType.PARAGRAPH})[0].firstChild; |
+ var hello = root.findAll({role: RoleType.PARAGRAPH})[1].firstChild; |
+ var world = root.findAll({role: RoleType.PARAGRAPH})[1].lastChild; |
+ |
+ // The same position -- sanity check. |
+ var e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 0, true); |
+ assertEquals('this ', e1.text); |
+ |
+ // Offsets into different soft lines; base on focus (default). |
+ e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 6); |
+ assertEquals('is ', e1.text); |
+ // Notice that the offset is truncated at the beginning of the line. |
+ assertEquals(0, e1.startOffset); |
+// Notice that the end offset is properly retained. |
dmazzoni
2017/06/21 06:22:08
nit: indent
David Tseng
2017/06/21 16:58:28
Done.
|
+ assertEquals(1, e1.endOffset); |
+ |
+ // Offsets into different soft lines; base on anchor. |
+ e1 = new editing.EditableLine(thisIsATest, 0, thisIsATest, 6, true); |
+ assertEquals('this ', e1.text); |
+ assertEquals(0, e1.startOffset); |
+// Notice that the end offset is truncated up to the end of line. |
dmazzoni
2017/06/21 06:22:08
nit: indent
David Tseng
2017/06/21 16:58:28
Done (hmm git cl format didn't catch this).
|
+ assertEquals(5, e1.endOffset); |
+ |
+ // Across paragraph dselection with base line on focus. |
dmazzoni
2017/06/21 06:22:08
nit: dselection -> selection, and again below
David Tseng
2017/06/21 16:58:28
Done.
|
+ e1 = new editing.EditableLine(thisIsATest, 5, hello, 2); |
+ assertEquals('hello world', e1.text); |
+ assertEquals(0, e1.startOffset); |
+ assertEquals(2, e1.endOffset); |
+ |
+ // Across paragraph dselection with base line on anchor. |
+ e1 = new editing.EditableLine(thisIsATest, 5, hello, 2, true); |
+ assertEquals('is ', e1.text); |
+ assertEquals(0, e1.startOffset); |
+ assertEquals(3, e1.endOffset); |
+ }) |
+}); |