4 function canFind(target
, specimen
)
6 getSelection().empty();
7 document
.body
.innerHTML
= specimen
;
8 document
.execCommand("FindString", false, target
);
9 var result
= getSelection().rangeCount
!= 0;
10 getSelection().empty();
16 if (window
.testRunner
)
17 testRunner
.dumpAsText();
21 var nbsp
= String
.fromCharCode(0xA0);
23 var message
= "FAILURE:";
25 if (canFind("", "a b")) {
27 message
+= " Was able to find the empty string.";
30 if (!canFind(" ", "a b")) {
32 message
+= " Cannot find space.";
35 if (canFind(" ", "a b")) {
37 message
+= " Two spaces are matching even though they should be collapsed.";
40 if (!canFind(" ", "<pre>a b</pre>")) {
42 message
+= " Cannot find two spaces in a <pre> element.";
45 if (!canFind(" ", "a b")) {
47 message
+= " Cannot find an &nbsp; when searching for a space.";
50 if (!canFind(" ", "a b")) {
52 message
+= " Cannot find a space followed by &nbsp; when searching for two spaces.";
55 if (!canFind(" ", "a b")) {
57 message
+= " Cannot find an &nbsp; followed by a space when searching for two spaces.";
60 if (!canFind(nbsp
, "a b")) {
62 message
+= " Cannot find space.";
65 if (canFind(nbsp
+ nbsp
, "a b")) {
67 message
+= " Two spaces are matching even though they should be collapsed.";
70 if (!canFind(nbsp
+ nbsp
, "<pre>a b</pre>")) {
72 message
+= " Cannot find two spaces in a <pre> element.";
75 if (!canFind(nbsp
, "a b")) {
77 message
+= " Cannot find an &nbsp; when searching for a space.";
80 if (!canFind(nbsp
+ nbsp
, "a b")) {
82 message
+= " Cannot find a space followed by &nbsp; when searching for two spaces.";
85 if (!canFind(nbsp
+ nbsp
, "a b")) {
87 message
+= " Cannot find an &nbsp; followed by a space when searching for two spaces.";
91 message
= "SUCCESS: Found all the spaces as expected.";
93 document
.body
.innerHTML
= message
;
97 <body onload=
"runTests()"></body>