Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: content/shell/test_runner/mock_grammar_check.cc

Issue 2707183003: Move //components/test_runner back into //content/shell (Closed)
Patch Set: Trim DEPS Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/test_runner/mock_grammar_check.h" 5 #include "content/shell/test_runner/mock_grammar_check.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "components/test_runner/test_common.h" 13 #include "content/shell/test_runner/test_common.h"
14 #include "third_party/WebKit/public/platform/WebString.h" 14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" 15 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
16 16
17 namespace test_runner { 17 namespace test_runner {
18 18
19 bool MockGrammarCheck::CheckGrammarOfString( 19 bool MockGrammarCheck::CheckGrammarOfString(
20 const blink::WebString& text, 20 const blink::WebString& text,
21 std::vector<blink::WebTextCheckingResult>* results) { 21 std::vector<blink::WebTextCheckingResult>* results) {
22 DCHECK(results); 22 DCHECK(results);
23 base::string16 string_text = text.utf16(); 23 base::string16 string_text = text.utf16();
24 if (std::find_if(string_text.begin(), string_text.end(), IsASCIIAlpha) == 24 if (std::find_if(string_text.begin(), string_text.end(), IsASCIIAlpha) ==
25 string_text.end()) 25 string_text.end())
26 return true; 26 return true;
27 27
28 // Find matching grammatical errors from known ones. This function has to 28 // Find matching grammatical errors from known ones. This function has to
29 // check all errors because the given text may consist of two or more 29 // check all errors because the given text may consist of two or more
30 // sentences that have grammatical errors. 30 // sentences that have grammatical errors.
31 static const struct { 31 static const struct {
32 const char* text; 32 const char* text;
33 int location; 33 int location;
34 int length; 34 int length;
35 } kGrammarErrors[] = { 35 } kGrammarErrors[] = {
36 {"I have a issue.", 7, 1}, 36 {"I have a issue.", 7, 1},
37 {"I have an grape.", 7, 2}, 37 {"I have an grape.", 7, 2},
38 {"I have an kiwi.", 7, 2}, 38 {"I have an kiwi.", 7, 2},
39 {"I have an muscat.", 7, 2}, 39 {"I have an muscat.", 7, 2},
40 {"You has the right.", 4, 3}, 40 {"You has the right.", 4, 3},
41 {"apple orange zz.", 0, 16}, 41 {"apple orange zz.", 0, 16},
42 {"apple zz orange.", 0, 16}, 42 {"apple zz orange.", 0, 16},
43 {"apple,zz,orange.", 0, 16}, 43 {"apple,zz,orange.", 0, 16},
44 {"orange,zz,apple.", 0, 16}, 44 {"orange,zz,apple.", 0, 16},
45 {"the the adlj adaasj sdklj. there there", 4, 3}, 45 {"the the adlj adaasj sdklj. there there", 4, 3},
46 {"the the adlj adaasj sdklj. there there", 33, 5}, 46 {"the the adlj adaasj sdklj. there there", 33, 5},
47 {"zz apple orange.", 0, 16}, 47 {"zz apple orange.", 0, 16},
48 }; 48 };
49 for (size_t i = 0; i < arraysize(kGrammarErrors); ++i) { 49 for (size_t i = 0; i < arraysize(kGrammarErrors); ++i) {
50 size_t offset = 0; 50 size_t offset = 0;
51 base::string16 error( 51 base::string16 error(
52 kGrammarErrors[i].text, 52 kGrammarErrors[i].text,
53 kGrammarErrors[i].text + strlen(kGrammarErrors[i].text)); 53 kGrammarErrors[i].text + strlen(kGrammarErrors[i].text));
54 while ((offset = string_text.find(error, offset)) != base::string16::npos) { 54 while ((offset = string_text.find(error, offset)) != base::string16::npos) {
55 results->push_back( 55 results->push_back(blink::WebTextCheckingResult(
56 blink::WebTextCheckingResult(blink::WebTextDecorationTypeGrammar, 56 blink::WebTextDecorationTypeGrammar,
57 offset + kGrammarErrors[i].location, 57 offset + kGrammarErrors[i].location, kGrammarErrors[i].length));
58 kGrammarErrors[i].length));
59 offset += kGrammarErrors[i].length; 58 offset += kGrammarErrors[i].length;
60 } 59 }
61 } 60 }
62 return false; 61 return false;
63 } 62 }
64 63
65 } // namespace test_runner 64 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698