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

Side by Side Diff: chrome/renderer/spellchecker/spellcheck_unittest.cc

Issue 2177343002: Componentize spellcheck [2]: move common/ files to component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move message generator to component Created 4 years, 4 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
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_provider_test.cc ('k') | components/spellcheck.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/spellchecker/spellcheck.h" 5 #include "chrome/renderer/spellchecker/spellcheck.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "chrome/common/spellcheck_common.h"
22 #include "chrome/common/spellcheck_result.h"
23 #include "chrome/renderer/spellchecker/hunspell_engine.h" 21 #include "chrome/renderer/spellchecker/hunspell_engine.h"
24 #include "chrome/renderer/spellchecker/spellcheck_language.h" 22 #include "chrome/renderer/spellchecker/spellcheck_language.h"
23 #include "components/spellcheck/common/spellcheck_common.h"
24 #include "components/spellcheck/common/spellcheck_result.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "third_party/WebKit/public/platform/WebVector.h" 26 #include "third_party/WebKit/public/platform/WebVector.h"
27 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" 27 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
28 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" 28 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
29 29
30 #define TYPOGRAPHICAL_APOSTROPHE L"\x2019" 30 #define TYPOGRAPHICAL_APOSTROPHE L"\x2019"
31 31
32 namespace { 32 namespace {
33 const int kNoOffset = 0; 33 const int kNoOffset = 0;
34 const int kNoTag = 0; 34 const int kNoTag = 0;
(...skipping 27 matching lines...) Expand all
62 } 62 }
63 63
64 bool InitializeIfNeeded() { 64 bool InitializeIfNeeded() {
65 return spell_check()->InitializeIfNeeded(); 65 return spell_check()->InitializeIfNeeded();
66 } 66 }
67 67
68 void InitializeSpellCheck(const std::string& language) { 68 void InitializeSpellCheck(const std::string& language) {
69 base::FilePath hunspell_directory = GetHunspellDirectory(); 69 base::FilePath hunspell_directory = GetHunspellDirectory();
70 EXPECT_FALSE(hunspell_directory.empty()); 70 EXPECT_FALSE(hunspell_directory.empty());
71 base::File file( 71 base::File file(
72 chrome::spellcheck_common::GetVersionedFileName(language, 72 spellcheck::GetVersionedFileName(language, hunspell_directory),
73 hunspell_directory),
74 base::File::FLAG_OPEN | base::File::FLAG_READ); 73 base::File::FLAG_OPEN | base::File::FLAG_READ);
75 #if defined(OS_MACOSX) 74 #if defined(OS_MACOSX)
76 // TODO(groby): Forcing spellcheck to use hunspell, even on OSX. 75 // TODO(groby): Forcing spellcheck to use hunspell, even on OSX.
77 // Instead, tests should exercise individual spelling engines. 76 // Instead, tests should exercise individual spelling engines.
78 spell_check_->languages_.push_back(new SpellcheckLanguage()); 77 spell_check_->languages_.push_back(new SpellcheckLanguage());
79 spell_check_->languages_.front()->platform_spelling_engine_.reset( 78 spell_check_->languages_.front()->platform_spelling_engine_.reset(
80 new HunspellEngine); 79 new HunspellEngine);
81 spell_check_->languages_.front()->Init(std::move(file), language); 80 spell_check_->languages_.front()->Init(std::move(file), language);
82 #else 81 #else
83 spell_check_->AddSpellcheckLanguage(std::move(file), language); 82 spell_check_->AddSpellcheckLanguage(std::move(file), language);
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 EXPECT_FALSE(compare_result == 0) << kTestCases[t].suggestion << 1359 EXPECT_FALSE(compare_result == 0) << kTestCases[t].suggestion <<
1361 " in " << kTestCases[i].locale; 1360 " in " << kTestCases[i].locale;
1362 } 1361 }
1363 } 1362 }
1364 } 1363 }
1365 } 1364 }
1366 1365
1367 // Check that the correct dictionary files are checked in. 1366 // Check that the correct dictionary files are checked in.
1368 TEST_F(SpellCheckTest, DictionaryFiles) { 1367 TEST_F(SpellCheckTest, DictionaryFiles) {
1369 std::vector<std::string> spellcheck_languages; 1368 std::vector<std::string> spellcheck_languages;
1370 chrome::spellcheck_common::SpellCheckLanguages(&spellcheck_languages); 1369 spellcheck::SpellCheckLanguages(&spellcheck_languages);
1371 EXPECT_FALSE(spellcheck_languages.empty()); 1370 EXPECT_FALSE(spellcheck_languages.empty());
1372 1371
1373 base::FilePath hunspell = GetHunspellDirectory(); 1372 base::FilePath hunspell = GetHunspellDirectory();
1374 for (size_t i = 0; i < spellcheck_languages.size(); ++i) { 1373 for (size_t i = 0; i < spellcheck_languages.size(); ++i) {
1375 base::FilePath dict = chrome::spellcheck_common::GetVersionedFileName( 1374 base::FilePath dict =
1376 spellcheck_languages[i], hunspell); 1375 spellcheck::GetVersionedFileName(spellcheck_languages[i], hunspell);
1377 EXPECT_TRUE(base::PathExists(dict)) << dict.value() << " not found"; 1376 EXPECT_TRUE(base::PathExists(dict)) << dict.value() << " not found";
1378 } 1377 }
1379 } 1378 }
1380 1379
1381 // TODO(groby): Add a test for hunspell itself, when MAXWORDLEN is exceeded. 1380 // TODO(groby): Add a test for hunspell itself, when MAXWORDLEN is exceeded.
1382 TEST_F(SpellCheckTest, SpellingEngine_CheckSpelling) { 1381 TEST_F(SpellCheckTest, SpellingEngine_CheckSpelling) {
1383 static const struct { 1382 static const struct {
1384 const char* word; 1383 const char* word;
1385 bool expected_result; 1384 bool expected_result;
1386 } kTestCases[] = { 1385 } kTestCases[] = {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 FillSuggestions(suggestions_list, &suggestion_results); 1486 FillSuggestions(suggestions_list, &suggestion_results);
1488 ASSERT_EQ(1U, suggestion_results.size()); 1487 ASSERT_EQ(1U, suggestion_results.size());
1489 EXPECT_EQ(base::ASCIIToUTF16("foo"), suggestion_results[0]); 1488 EXPECT_EQ(base::ASCIIToUTF16("foo"), suggestion_results[0]);
1490 } 1489 }
1491 1490
1492 TEST_F(SpellCheckTest, FillSuggestions_OneLanguageManySuggestions) { 1491 TEST_F(SpellCheckTest, FillSuggestions_OneLanguageManySuggestions) {
1493 std::vector<std::vector<base::string16>> suggestions_list; 1492 std::vector<std::vector<base::string16>> suggestions_list;
1494 std::vector<base::string16> suggestion_results; 1493 std::vector<base::string16> suggestion_results;
1495 1494
1496 suggestions_list.resize(1); 1495 suggestions_list.resize(1);
1497 for (int i = 0; i < chrome::spellcheck_common::kMaxSuggestions + 2; ++i) 1496 for (int i = 0; i < spellcheck::kMaxSuggestions + 2; ++i)
1498 suggestions_list[0].push_back(base::ASCIIToUTF16(base::IntToString(i))); 1497 suggestions_list[0].push_back(base::ASCIIToUTF16(base::IntToString(i)));
1499 1498
1500 FillSuggestions(suggestions_list, &suggestion_results); 1499 FillSuggestions(suggestions_list, &suggestion_results);
1501 ASSERT_EQ(static_cast<size_t>(chrome::spellcheck_common::kMaxSuggestions), 1500 ASSERT_EQ(static_cast<size_t>(spellcheck::kMaxSuggestions),
1502 suggestion_results.size()); 1501 suggestion_results.size());
1503 for (int i = 0; i < chrome::spellcheck_common::kMaxSuggestions; ++i) 1502 for (int i = 0; i < spellcheck::kMaxSuggestions; ++i)
1504 EXPECT_EQ(base::ASCIIToUTF16(base::IntToString(i)), suggestion_results[i]); 1503 EXPECT_EQ(base::ASCIIToUTF16(base::IntToString(i)), suggestion_results[i]);
1505 } 1504 }
1506 1505
1507 TEST_F(SpellCheckTest, FillSuggestions_RemoveDuplicates) { 1506 TEST_F(SpellCheckTest, FillSuggestions_RemoveDuplicates) {
1508 std::vector<std::vector<base::string16>> suggestions_list; 1507 std::vector<std::vector<base::string16>> suggestions_list;
1509 std::vector<base::string16> suggestion_results; 1508 std::vector<base::string16> suggestion_results;
1510 1509
1511 suggestions_list.resize(2); 1510 suggestions_list.resize(2);
1512 for (size_t i = 0; i < 2; ++i) { 1511 for (size_t i = 0; i < 2; ++i) {
1513 suggestions_list[i].push_back(base::ASCIIToUTF16("foo")); 1512 suggestions_list[i].push_back(base::ASCIIToUTF16("foo"));
(...skipping 15 matching lines...) Expand all
1529 suggestions_list.resize(2); 1528 suggestions_list.resize(2);
1530 for (size_t i = 0; i < 2; ++i) { 1529 for (size_t i = 0; i < 2; ++i) {
1531 std::string prefix = base::IntToString(i); 1530 std::string prefix = base::IntToString(i);
1532 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "foo")); 1531 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "foo"));
1533 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "bar")); 1532 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "bar"));
1534 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "baz")); 1533 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "baz"));
1535 } 1534 }
1536 1535
1537 // Yes, this test assumes kMaxSuggestions is 5. If it isn't, the test needs 1536 // Yes, this test assumes kMaxSuggestions is 5. If it isn't, the test needs
1538 // to be updated accordingly. 1537 // to be updated accordingly.
1539 ASSERT_EQ(5, chrome::spellcheck_common::kMaxSuggestions); 1538 ASSERT_EQ(5, spellcheck::kMaxSuggestions);
1540 FillSuggestions(suggestions_list, &suggestion_results); 1539 FillSuggestions(suggestions_list, &suggestion_results);
1541 ASSERT_EQ(5U, suggestion_results.size()); 1540 ASSERT_EQ(5U, suggestion_results.size());
1542 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); 1541 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]);
1543 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); 1542 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]);
1544 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[2]); 1543 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[2]);
1545 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[3]); 1544 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[3]);
1546 EXPECT_EQ(base::ASCIIToUTF16("0baz"), suggestion_results[4]); 1545 EXPECT_EQ(base::ASCIIToUTF16("0baz"), suggestion_results[4]);
1547 } 1546 }
1548 1547
1549 TEST_F(SpellCheckTest, FillSuggestions_ThreeLanguages) { 1548 TEST_F(SpellCheckTest, FillSuggestions_ThreeLanguages) {
1550 std::vector<std::vector<base::string16>> suggestions_list; 1549 std::vector<std::vector<base::string16>> suggestions_list;
1551 std::vector<base::string16> suggestion_results; 1550 std::vector<base::string16> suggestion_results;
1552 1551
1553 suggestions_list.resize(3); 1552 suggestions_list.resize(3);
1554 for (size_t i = 0; i < 3; ++i) { 1553 for (size_t i = 0; i < 3; ++i) {
1555 std::string prefix = base::IntToString(i); 1554 std::string prefix = base::IntToString(i);
1556 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "foo")); 1555 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "foo"));
1557 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "bar")); 1556 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "bar"));
1558 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "baz")); 1557 suggestions_list[i].push_back(base::ASCIIToUTF16(prefix + "baz"));
1559 } 1558 }
1560 1559
1561 // Yes, this test assumes kMaxSuggestions is 5. If it isn't, the test needs 1560 // Yes, this test assumes kMaxSuggestions is 5. If it isn't, the test needs
1562 // to be updated accordingly. 1561 // to be updated accordingly.
1563 ASSERT_EQ(5, chrome::spellcheck_common::kMaxSuggestions); 1562 ASSERT_EQ(5, spellcheck::kMaxSuggestions);
1564 FillSuggestions(suggestions_list, &suggestion_results); 1563 FillSuggestions(suggestions_list, &suggestion_results);
1565 ASSERT_EQ(5U, suggestion_results.size()); 1564 ASSERT_EQ(5U, suggestion_results.size());
1566 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]); 1565 EXPECT_EQ(base::ASCIIToUTF16("0foo"), suggestion_results[0]);
1567 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]); 1566 EXPECT_EQ(base::ASCIIToUTF16("1foo"), suggestion_results[1]);
1568 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]); 1567 EXPECT_EQ(base::ASCIIToUTF16("2foo"), suggestion_results[2]);
1569 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]); 1568 EXPECT_EQ(base::ASCIIToUTF16("0bar"), suggestion_results[3]);
1570 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]); 1569 EXPECT_EQ(base::ASCIIToUTF16("1bar"), suggestion_results[4]);
1571 } 1570 }
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_provider_test.cc ('k') | components/spellcheck.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698