| OLD | NEW |
| (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 /* |
| 6 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions are |
| 10 * met: |
| 11 * |
| 12 * * Redistributions of source code must retain the above copyright |
| 13 * notice, this list of conditions and the following disclaimer. |
| 14 * * Redistributions in binary form must reproduce the above |
| 15 * copyright notice, this list of conditions and the following disclaimer |
| 16 * in the documentation and/or other materials provided with the |
| 17 * distribution. |
| 18 * * Neither the name of Google Inc. nor the names of its |
| 19 * contributors may be used to endorse or promote products derived from |
| 20 * this software without specific prior written permission. |
| 21 * |
| 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 */ |
| 34 |
| 35 #include "content/test/layout_tests/runner/MockGrammarCheck.h" |
| 36 |
| 37 #include <algorithm> |
| 38 |
| 39 #include "content/test/layout_tests/runner/TestCommon.h" |
| 40 #include "third_party/WebKit/public/platform/WebCString.h" |
| 41 #include "third_party/WebKit/public/platform/WebString.h" |
| 42 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
| 43 |
| 44 using namespace blink; |
| 45 using namespace std; |
| 46 |
| 47 namespace WebTestRunner { |
| 48 |
| 49 bool MockGrammarCheck::checkGrammarOfString(const WebString& text, vector<WebTex
tCheckingResult>* results) |
| 50 { |
| 51 BLINK_ASSERT(results); |
| 52 string16 stringText = text; |
| 53 if (find_if(stringText.begin(), stringText.end(), isASCIIAlpha) == stringTex
t.end()) |
| 54 return true; |
| 55 |
| 56 // Find matching grammatical errors from known ones. This function has to |
| 57 // check all errors because the given text may consist of two or more |
| 58 // sentences that have grammatical errors. |
| 59 static const struct { |
| 60 const char* text; |
| 61 int location; |
| 62 int length; |
| 63 } grammarErrors[] = { |
| 64 {"I have a issue.", 7, 1}, |
| 65 {"I have an grape.", 7, 2}, |
| 66 {"I have an kiwi.", 7, 2}, |
| 67 {"I have an muscat.", 7, 2}, |
| 68 {"You has the right.", 4, 3}, |
| 69 {"apple orange zz.", 0, 16}, |
| 70 {"apple zz orange.", 0, 16}, |
| 71 {"apple,zz,orange.", 0, 16}, |
| 72 {"orange,zz,apple.", 0, 16}, |
| 73 {"the the adlj adaasj sdklj. there there", 4, 3}, |
| 74 {"the the adlj adaasj sdklj. there there", 33, 5}, |
| 75 {"zz apple orange.", 0, 16}, |
| 76 }; |
| 77 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(grammarErrors); ++i) { |
| 78 size_t offset = 0; |
| 79 string16 error(grammarErrors[i].text, grammarErrors[i].text + strlen(gra
mmarErrors[i].text)); |
| 80 while ((offset = stringText.find(error, offset)) != string16::npos) { |
| 81 results->push_back(WebTextCheckingResult(WebTextDecorationTypeGramma
r, offset + grammarErrors[i].location, grammarErrors[i].length)); |
| 82 offset += grammarErrors[i].length; |
| 83 } |
| 84 } |
| 85 return false; |
| 86 } |
| 87 |
| 88 } |
| OLD | NEW |