Don't preload rarely seen large images
[chromium-blink-merge.git] / components / test_runner / mock_grammar_check.cc
blob26f318f9e8214e5072f93b8e2f36add9f2180414
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 "components/test_runner/mock_grammar_check.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "components/test_runner/test_common.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 namespace test_runner {
17 bool MockGrammarCheck::CheckGrammarOfString(
18 const blink::WebString& text,
19 std::vector<blink::WebTextCheckingResult>* results) {
20 DCHECK(results);
21 base::string16 string_text = text;
22 if (std::find_if(string_text.begin(), string_text.end(), IsASCIIAlpha) ==
23 string_text.end())
24 return true;
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
28 // sentences that have grammatical errors.
29 static const struct {
30 const char* text;
31 int location;
32 int length;
33 } kGrammarErrors[] = {
34 {"I have a issue.", 7, 1},
35 {"I have an grape.", 7, 2},
36 {"I have an kiwi.", 7, 2},
37 {"I have an muscat.", 7, 2},
38 {"You has the right.", 4, 3},
39 {"apple orange zz.", 0, 16},
40 {"apple zz orange.", 0, 16},
41 {"apple,zz,orange.", 0, 16},
42 {"orange,zz,apple.", 0, 16},
43 {"the the adlj adaasj sdklj. there there", 4, 3},
44 {"the the adlj adaasj sdklj. there there", 33, 5},
45 {"zz apple orange.", 0, 16},
47 for (size_t i = 0; i < arraysize(kGrammarErrors); ++i) {
48 size_t offset = 0;
49 base::string16 error(
50 kGrammarErrors[i].text,
51 kGrammarErrors[i].text + strlen(kGrammarErrors[i].text));
52 while ((offset = string_text.find(error, offset)) != base::string16::npos) {
53 results->push_back(
54 blink::WebTextCheckingResult(blink::WebTextDecorationTypeGrammar,
55 offset + kGrammarErrors[i].location,
56 kGrammarErrors[i].length));
57 offset += kGrammarErrors[i].length;
60 return false;
63 } // namespace test_runner