1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/renderer/test_runner/MockGrammarCheck.h"
9 #include "base/logging.h"
10 #include "content/shell/renderer/test_runner/TestCommon.h"
11 #include "third_party/WebKit/public/platform/WebCString.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
15 using namespace blink
;
20 bool MockGrammarCheck::checkGrammarOfString(const WebString
& text
, vector
<WebTextCheckingResult
>* results
)
23 base::string16 stringText
= text
;
24 if (find_if(stringText
.begin(), stringText
.end(), WebTestRunner::isASCIIAlpha
) == stringText
.end())
27 // Find matching grammatical errors from known ones. This function has to
28 // check all errors because the given text may consist of two or more
29 // sentences that have grammatical errors.
35 {"I have a issue.", 7, 1},
36 {"I have an grape.", 7, 2},
37 {"I have an kiwi.", 7, 2},
38 {"I have an muscat.", 7, 2},
39 {"You has the right.", 4, 3},
40 {"apple orange zz.", 0, 16},
41 {"apple zz orange.", 0, 16},
42 {"apple,zz,orange.", 0, 16},
43 {"orange,zz,apple.", 0, 16},
44 {"the the adlj adaasj sdklj. there there", 4, 3},
45 {"the the adlj adaasj sdklj. there there", 33, 5},
46 {"zz apple orange.", 0, 16},
48 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(grammarErrors
); ++i
) {
50 base::string16
error(grammarErrors
[i
].text
, grammarErrors
[i
].text
+ strlen(grammarErrors
[i
].text
));
51 while ((offset
= stringText
.find(error
, offset
)) != base::string16::npos
) {
52 results
->push_back(WebTextCheckingResult(WebTextDecorationTypeGrammar
, offset
+ grammarErrors
[i
].location
, grammarErrors
[i
].length
));
53 offset
+= grammarErrors
[i
].length
;
59 } // namespace content