OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/renderer/test_runner/MockGrammarCheck.h" | 5 #include "content/shell/renderer/test_runner/MockGrammarCheck.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "content/shell/renderer/test_runner/TestCommon.h" | 9 #include "content/shell/renderer/test_runner/TestCommon.h" |
10 #include "third_party/WebKit/public/platform/WebCString.h" | 10 #include "third_party/WebKit/public/platform/WebCString.h" |
11 #include "third_party/WebKit/public/platform/WebString.h" | 11 #include "third_party/WebKit/public/platform/WebString.h" |
12 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 12 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
13 | 13 |
14 using namespace blink; | 14 using namespace blink; |
15 using namespace std; | 15 using namespace std; |
16 | 16 |
17 namespace WebTestRunner { | 17 namespace WebTestRunner { |
18 | 18 |
19 bool MockGrammarCheck::checkGrammarOfString(const WebString& text, vector<WebTex
tCheckingResult>* results) | 19 bool MockGrammarCheck::checkGrammarOfString(const WebString& text, vector<WebTex
tCheckingResult>* results) |
20 { | 20 { |
21 BLINK_ASSERT(results); | 21 BLINK_ASSERT(results); |
22 string16 stringText = text; | 22 base::string16 stringText = text; |
23 if (find_if(stringText.begin(), stringText.end(), isASCIIAlpha) == stringTex
t.end()) | 23 if (find_if(stringText.begin(), stringText.end(), isASCIIAlpha) == stringTex
t.end()) |
24 return true; | 24 return true; |
25 | 25 |
26 // Find matching grammatical errors from known ones. This function has to | 26 // Find matching grammatical errors from known ones. This function has to |
27 // check all errors because the given text may consist of two or more | 27 // check all errors because the given text may consist of two or more |
28 // sentences that have grammatical errors. | 28 // sentences that have grammatical errors. |
29 static const struct { | 29 static const struct { |
30 const char* text; | 30 const char* text; |
31 int location; | 31 int location; |
32 int length; | 32 int length; |
33 } grammarErrors[] = { | 33 } grammarErrors[] = { |
34 {"I have a issue.", 7, 1}, | 34 {"I have a issue.", 7, 1}, |
35 {"I have an grape.", 7, 2}, | 35 {"I have an grape.", 7, 2}, |
36 {"I have an kiwi.", 7, 2}, | 36 {"I have an kiwi.", 7, 2}, |
37 {"I have an muscat.", 7, 2}, | 37 {"I have an muscat.", 7, 2}, |
38 {"You has the right.", 4, 3}, | 38 {"You has the right.", 4, 3}, |
39 {"apple orange zz.", 0, 16}, | 39 {"apple orange zz.", 0, 16}, |
40 {"apple zz orange.", 0, 16}, | 40 {"apple zz orange.", 0, 16}, |
41 {"apple,zz,orange.", 0, 16}, | 41 {"apple,zz,orange.", 0, 16}, |
42 {"orange,zz,apple.", 0, 16}, | 42 {"orange,zz,apple.", 0, 16}, |
43 {"the the adlj adaasj sdklj. there there", 4, 3}, | 43 {"the the adlj adaasj sdklj. there there", 4, 3}, |
44 {"the the adlj adaasj sdklj. there there", 33, 5}, | 44 {"the the adlj adaasj sdklj. there there", 33, 5}, |
45 {"zz apple orange.", 0, 16}, | 45 {"zz apple orange.", 0, 16}, |
46 }; | 46 }; |
47 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(grammarErrors); ++i) { | 47 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(grammarErrors); ++i) { |
48 size_t offset = 0; | 48 size_t offset = 0; |
49 string16 error(grammarErrors[i].text, grammarErrors[i].text + strlen(gra
mmarErrors[i].text)); | 49 base::string16 error(grammarErrors[i].text, grammarErrors[i].text + strl
en(grammarErrors[i].text)); |
50 while ((offset = stringText.find(error, offset)) != string16::npos) { | 50 while ((offset = stringText.find(error, offset)) != base::string16::npos
) { |
51 results->push_back(WebTextCheckingResult(WebTextDecorationTypeGramma
r, offset + grammarErrors[i].location, grammarErrors[i].length)); | 51 results->push_back(WebTextCheckingResult(WebTextDecorationTypeGramma
r, offset + grammarErrors[i].location, grammarErrors[i].length)); |
52 offset += grammarErrors[i].length; | 52 offset += grammarErrors[i].length; |
53 } | 53 } |
54 } | 54 } |
55 return false; | 55 return false; |
56 } | 56 } |
57 | 57 |
58 } | 58 } |
OLD | NEW |