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

Side by Side Diff: components/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
(Empty)
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.
4
5 #include "components/test_runner/mock_grammar_check.h"
6
7 #include <stddef.h>
8
9 #include <algorithm>
10
11 #include "base/logging.h"
12 #include "base/macros.h"
13 #include "components/test_runner/test_common.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
16
17 namespace test_runner {
18
19 bool MockGrammarCheck::CheckGrammarOfString(
20 const blink::WebString& text,
21 std::vector<blink::WebTextCheckingResult>* results) {
22 DCHECK(results);
23 base::string16 string_text = text.utf16();
24 if (std::find_if(string_text.begin(), string_text.end(), IsASCIIAlpha) ==
25 string_text.end())
26 return true;
27
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
30 // sentences that have grammatical errors.
31 static const struct {
32 const char* text;
33 int location;
34 int length;
35 } kGrammarErrors[] = {
36 {"I have a issue.", 7, 1},
37 {"I have an grape.", 7, 2},
38 {"I have an kiwi.", 7, 2},
39 {"I have an muscat.", 7, 2},
40 {"You has the right.", 4, 3},
41 {"apple orange zz.", 0, 16},
42 {"apple zz orange.", 0, 16},
43 {"apple,zz,orange.", 0, 16},
44 {"orange,zz,apple.", 0, 16},
45 {"the the adlj adaasj sdklj. there there", 4, 3},
46 {"the the adlj adaasj sdklj. there there", 33, 5},
47 {"zz apple orange.", 0, 16},
48 };
49 for (size_t i = 0; i < arraysize(kGrammarErrors); ++i) {
50 size_t offset = 0;
51 base::string16 error(
52 kGrammarErrors[i].text,
53 kGrammarErrors[i].text + strlen(kGrammarErrors[i].text));
54 while ((offset = string_text.find(error, offset)) != base::string16::npos) {
55 results->push_back(
56 blink::WebTextCheckingResult(blink::WebTextDecorationTypeGrammar,
57 offset + kGrammarErrors[i].location,
58 kGrammarErrors[i].length));
59 offset += kGrammarErrors[i].length;
60 }
61 }
62 return false;
63 }
64
65 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698