1 description("Tests find going both forward and backwards in small and large documents.");
3 var selection
= getSelection();
5 function testFind(subjectString
, pattern
, backwards
)
7 var textNode
= document
.createTextNode(subjectString
);
8 document
.body
.appendChild(textNode
);
9 selection
.removeAllRanges();
11 var afterTextNodeRange
= document
.createRange();
12 afterTextNodeRange
.setStartAfter(textNode
);
13 afterTextNodeRange
.setEndAfter(textNode
);
14 selection
.addRange(afterTextNodeRange
);
16 var beforeTextNodeRange
= document
.createRange();
17 beforeTextNodeRange
.setStartBefore(textNode
);
18 beforeTextNodeRange
.setEndBefore(textNode
);
19 selection
.addRange(beforeTextNodeRange
);
22 if (!find(pattern
, false, backwards
))
24 else if (selection
.rangeCount
!= 1)
25 result
= "internal inconsistency";
27 var resultRange
= selection
.getRangeAt(0);
28 if (resultRange
.startContainer
!== textNode
|| resultRange
.endContainer
!== textNode
)
31 result
= resultRange
.startOffset
+ ", " + resultRange
.endOffset
;
33 document
.body
.removeChild(textNode
);
40 var manyCharacters
= "1234567890"
41 for (i
= 0; i
< 10; ++i
)
42 manyCharacters
+= manyCharacters
;
43 var tenThousandCharacters
= manyCharacters
.substring(0, 10000);
45 shouldBe("testFind('abc', 'a', forward)", "'0, 1'");
46 shouldBe("testFind('abc', 'b', forward)", "'1, 2'");
47 shouldBe("testFind('abc', 'c', forward)", "'2, 3'");
48 shouldBe("testFind('abc', 'a', backward)", "'0, 1'");
49 shouldBe("testFind('abc', 'b', backward)", "'1, 2'");
50 shouldBe("testFind('abc', 'c', backward)", "'2, 3'");
51 shouldBe("testFind(tenThousandCharacters + 'abc' + tenThousandCharacters, 'a', forward)", "'10000, 10001'");
52 shouldBe("testFind(tenThousandCharacters + 'abc' + tenThousandCharacters, 'b', forward)", "'10001, 10002'");
53 shouldBe("testFind(tenThousandCharacters + 'abc' + tenThousandCharacters, 'c', forward)", "'10002, 10003'");
54 shouldBe("testFind(tenThousandCharacters + 'abc' + tenThousandCharacters, 'a', backward)", "'10000, 10001'");
55 shouldBe("testFind(tenThousandCharacters + 'abc' + tenThousandCharacters, 'b', backward)", "'10001, 10002'");
56 shouldBe("testFind(tenThousandCharacters + 'abc' + tenThousandCharacters, 'c', backward)", "'10002, 10003'");
57 shouldBe("testFind('abcabc', 'a', forward)", "'0, 1'");
58 shouldBe("testFind('abcabc', 'b', forward)", "'1, 2'");
59 shouldBe("testFind('abcabc', 'c', forward)", "'2, 3'");
60 shouldBe("testFind('abcabc', 'a', backward)", "'3, 4'");
61 shouldBe("testFind('abcabc', 'b', backward)", "'4, 5'");
62 shouldBe("testFind('abcabc', 'c', backward)", "'5, 6'");
63 shouldBe("testFind(tenThousandCharacters + 'abcabc' + tenThousandCharacters, 'a', forward)", "'10000, 10001'");
64 shouldBe("testFind(tenThousandCharacters + 'abcabc' + tenThousandCharacters, 'b', forward)", "'10001, 10002'");
65 shouldBe("testFind(tenThousandCharacters + 'abcabc' + tenThousandCharacters, 'c', forward)", "'10002, 10003'");
66 shouldBe("testFind(tenThousandCharacters + 'abcabc' + tenThousandCharacters, 'a', backward)", "'10003, 10004'");
67 shouldBe("testFind(tenThousandCharacters + 'abcabc' + tenThousandCharacters, 'b', backward)", "'10004, 10005'");
68 shouldBe("testFind(tenThousandCharacters + 'abcabc' + tenThousandCharacters, 'c', backward)", "'10005, 10006'");