OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/renderer/spellchecker/spellcheck.h" | |
17 #include "chrome/renderer/spellchecker/spellcheck_provider_test.h" | |
18 #include "components/spellcheck/common/spellcheck_common.h" | 16 #include "components/spellcheck/common/spellcheck_common.h" |
19 #include "components/spellcheck/common/spellcheck_result.h" | 17 #include "components/spellcheck/common/spellcheck_result.h" |
18 #include "components/spellcheck/renderer/spellcheck.h" | |
19 #include "components/spellcheck/renderer/spellcheck_provider_test.h" | |
20 #include "components/test_runner/test_common.h" | |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/WebString.h" | 22 #include "third_party/WebKit/public/platform/WebString.h" |
22 #include "third_party/WebKit/public/platform/WebVector.h" | 23 #include "third_party/WebKit/public/platform/WebVector.h" |
23 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 24 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 struct SpellcheckTestCase { | 28 struct SpellcheckTestCase { |
28 // A string of text for checking. | 29 // A string of text for checking. |
29 const wchar_t* input; | 30 const wchar_t* input; |
30 // The position and the length of the first misspelled word, if any. | 31 // The position and the length of the first misspelled word, if any. |
31 int expected_misspelling_start; | 32 int expected_misspelling_start; |
32 int expected_misspelling_length; | 33 int expected_misspelling_length; |
33 }; | 34 }; |
34 | 35 |
35 base::FilePath GetHunspellDirectory() { | 36 base::FilePath GetHunspellDirectory() { |
36 base::FilePath hunspell_directory; | 37 base::FilePath hunspell_directory; |
37 if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory)) | 38 if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory)) |
38 return base::FilePath(); | 39 return base::FilePath(); |
39 | 40 |
40 hunspell_directory = hunspell_directory.AppendASCII("third_party"); | 41 hunspell_directory = hunspell_directory.AppendASCII("third_party"); |
41 hunspell_directory = hunspell_directory.AppendASCII("hunspell_dictionaries"); | 42 hunspell_directory = hunspell_directory.AppendASCII("hunspell_dictionaries"); |
42 return hunspell_directory; | 43 return hunspell_directory; |
43 } | 44 } |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 class MultilingualSpellCheckTest : public testing::Test { | 48 class MultilingualSpellCheckTest : public testing::Test { |
48 public: | 49 public: |
49 MultilingualSpellCheckTest() {} | 50 MultilingualSpellCheckTest() { test_runner::EnsureBlinkInitialized(); } |
groby-ooo-7-16
2016/08/03 17:31:54
Why does this need blink initialized?
timvolodine
2016/08/03 19:12:30
if I don't do that I get a crash stack with someth
| |
50 | 51 |
51 void ReinitializeSpellCheck(const std::string& unsplit_languages) { | 52 void ReinitializeSpellCheck(const std::string& unsplit_languages) { |
52 spellcheck_ = new SpellCheck(); | 53 spellcheck_ = new SpellCheck(); |
53 provider_.reset(new TestingSpellCheckProvider(spellcheck_)); | 54 provider_.reset(new TestingSpellCheckProvider(spellcheck_)); |
54 InitializeSpellCheck(unsplit_languages); | 55 InitializeSpellCheck(unsplit_languages); |
55 } | 56 } |
56 | 57 |
57 void InitializeSpellCheck(const std::string& unsplit_languages) { | 58 void InitializeSpellCheck(const std::string& unsplit_languages) { |
58 base::FilePath hunspell_directory = GetHunspellDirectory(); | 59 base::FilePath hunspell_directory = GetHunspellDirectory(); |
59 EXPECT_FALSE(hunspell_directory.empty()); | 60 EXPECT_FALSE(hunspell_directory.empty()); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 base::WideToUTF16(kTestCases[i].expected_suggestions), | 248 base::WideToUTF16(kTestCases[i].expected_suggestions), |
248 base::string16(1, ','), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 249 base::string16(1, ','), base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
249 | 250 |
250 EXPECT_EQ(expected_suggestions.size(), suggestions.size()); | 251 EXPECT_EQ(expected_suggestions.size(), suggestions.size()); |
251 for (size_t j = 0; | 252 for (size_t j = 0; |
252 j < std::min(expected_suggestions.size(), suggestions.size()); j++) { | 253 j < std::min(expected_suggestions.size(), suggestions.size()); j++) { |
253 EXPECT_EQ(expected_suggestions[j], base::string16(suggestions[j])); | 254 EXPECT_EQ(expected_suggestions[j], base::string16(suggestions[j])); |
254 } | 255 } |
255 } | 256 } |
256 } | 257 } |
OLD | NEW |