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

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

Issue 9368052: Removed WebTextCheckingResult legacy API use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another trial... Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc ('k') | no next file » | 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 "webkit/glue/webkit_glue.h" 5 #include "webkit/glue/webkit_glue.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/renderer/spellchecker/spellcheck.h" 13 #include "chrome/renderer/spellchecker/spellcheck.h"
14 #include "chrome/common/chrome_paths.h" 14 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/spellcheck_common.h" 15 #include "chrome/common/spellcheck_common.h"
16 #include "chrome/common/spellcheck_result.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h" 18
18 19
19 namespace { 20 namespace {
20 21
21 FilePath GetHunspellDirectory() { 22 FilePath GetHunspellDirectory() {
22 FilePath hunspell_directory; 23 FilePath hunspell_directory;
23 if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory)) 24 if (!PathService::Get(base::DIR_SOURCE_ROOT, &hunspell_directory))
24 return FilePath(); 25 return FilePath();
25 26
26 hunspell_directory = hunspell_directory.AppendASCII("third_party"); 27 hunspell_directory = hunspell_directory.AppendASCII("third_party");
27 hunspell_directory = hunspell_directory.AppendASCII("hunspell_dictionaries"); 28 hunspell_directory = hunspell_directory.AppendASCII("hunspell_dictionaries");
(...skipping 22 matching lines...) Expand all
50 51
51 virtual ~SpellCheckTest() { 52 virtual ~SpellCheckTest() {
52 } 53 }
53 54
54 SpellCheck* spell_check() { return spell_check_.get(); } 55 SpellCheck* spell_check() { return spell_check_.get(); }
55 56
56 #if !defined(OS_MACOSX) 57 #if !defined(OS_MACOSX)
57 protected: 58 protected:
58 void TestSpellCheckParagraph( 59 void TestSpellCheckParagraph(
59 const string16& input, 60 const string16& input,
60 const std::vector<WebKit::WebTextCheckingResult>& expected) { 61 const std::vector<SpellCheckResult>& expected) {
61 std::vector<WebKit::WebTextCheckingResult> results; 62 std::vector<SpellCheckResult> results;
62 spell_check()->SpellCheckParagraph(input, 63 spell_check()->SpellCheckParagraph(input,
63 0, 64 0,
64 &results); 65 &results);
65 66
66 EXPECT_EQ(results.size(), expected.size()); 67 EXPECT_EQ(results.size(), expected.size());
67 size_t size = std::min(results.size(), expected.size()); 68 size_t size = std::min(results.size(), expected.size());
68 for (size_t j = 0; j < size; ++j) { 69 for (size_t j = 0; j < size; ++j) {
69 EXPECT_EQ(results[j].type, WebKit::WebTextCheckingTypeSpelling); 70 EXPECT_EQ(results[j].type, SpellCheckResult::SPELLING);
70 EXPECT_EQ(results[j].location, expected[j].location); 71 EXPECT_EQ(results[j].location, expected[j].location);
71 EXPECT_EQ(results[j].length, expected[j].length); 72 EXPECT_EQ(results[j].length, expected[j].length);
72 } 73 }
73 } 74 }
74 #endif 75 #endif
75 76
76 private: 77 private:
77 scoped_ptr<SpellCheck> spell_check_; 78 scoped_ptr<SpellCheck> spell_check_;
78 }; 79 };
79 80
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 EXPECT_EQ(expected_autocorrect_word, autocorrect_word); 727 EXPECT_EQ(expected_autocorrect_word, autocorrect_word);
727 } 728 }
728 } 729 }
729 730
730 // Since SpellCheck::SpellCheckParagraph is not implemented on Mac, 731 // Since SpellCheck::SpellCheckParagraph is not implemented on Mac,
731 // we skip these SpellCheckParagraph tests on Mac. 732 // we skip these SpellCheckParagraph tests on Mac.
732 #if !defined(OS_MACOSX) 733 #if !defined(OS_MACOSX)
733 734
734 // Make sure SpellCheckParagraph does not crash if the input is empty. 735 // Make sure SpellCheckParagraph does not crash if the input is empty.
735 TEST_F(SpellCheckTest, SpellCheckParagraphEmptyParagraph) { 736 TEST_F(SpellCheckTest, SpellCheckParagraphEmptyParagraph) {
736 std::vector<WebKit::WebTextCheckingResult> expected; 737 std::vector<SpellCheckResult> expected;
737 TestSpellCheckParagraph(UTF8ToUTF16(""), expected); 738 TestSpellCheckParagraph(UTF8ToUTF16(""), expected);
738 } 739 }
739 740
740 // A simple test case having no misspellings. 741 // A simple test case having no misspellings.
741 TEST_F(SpellCheckTest, SpellCheckParagraphNoMisspellings) { 742 TEST_F(SpellCheckTest, SpellCheckParagraphNoMisspellings) {
742 const string16 text = UTF8ToUTF16("apple"); 743 const string16 text = UTF8ToUTF16("apple");
743 std::vector<WebKit::WebTextCheckingResult> expected; 744 std::vector<SpellCheckResult> expected;
744 TestSpellCheckParagraph(text, expected); 745 TestSpellCheckParagraph(text, expected);
745 } 746 }
746 747
747 // A simple test case having one misspelling. 748 // A simple test case having one misspelling.
748 TEST_F(SpellCheckTest, SpellCheckParagraphSingleMisspellings) { 749 TEST_F(SpellCheckTest, SpellCheckParagraphSingleMisspellings) {
749 const string16 text = UTF8ToUTF16("zz"); 750 const string16 text = UTF8ToUTF16("zz");
750 std::vector<WebKit::WebTextCheckingResult> expected; 751 std::vector<SpellCheckResult> expected;
751 expected.push_back(WebKit::WebTextCheckingResult( 752 expected.push_back(SpellCheckResult(
752 WebKit::WebTextCheckingTypeSpelling, 0, 2)); 753 SpellCheckResult::SPELLING, 0, 2));
753 754
754 TestSpellCheckParagraph(text, expected); 755 TestSpellCheckParagraph(text, expected);
755 } 756 }
756 757
757 // A simple test case having multiple misspellings. 758 // A simple test case having multiple misspellings.
758 TEST_F(SpellCheckTest, SpellCheckParagraphMultipleMisspellings) { 759 TEST_F(SpellCheckTest, SpellCheckParagraphMultipleMisspellings) {
759 const string16 text = UTF8ToUTF16("zz, zz"); 760 const string16 text = UTF8ToUTF16("zz, zz");
760 std::vector<WebKit::WebTextCheckingResult> expected; 761 std::vector<SpellCheckResult> expected;
761 expected.push_back(WebKit::WebTextCheckingResult( 762 expected.push_back(SpellCheckResult(
762 WebKit::WebTextCheckingTypeSpelling, 0, 2)); 763 SpellCheckResult::SPELLING, 0, 2));
763 expected.push_back(WebKit::WebTextCheckingResult( 764 expected.push_back(SpellCheckResult(
764 WebKit::WebTextCheckingTypeSpelling, 4, 2)); 765 SpellCheckResult::SPELLING, 4, 2));
765 766
766 TestSpellCheckParagraph(text, expected); 767 TestSpellCheckParagraph(text, expected);
767 } 768 }
768 769
769 // Make sure a relatively long (correct) sentence can be spellchecked. 770 // Make sure a relatively long (correct) sentence can be spellchecked.
770 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentence) { 771 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentence) {
771 std::vector<WebKit::WebTextCheckingResult> expected; 772 std::vector<SpellCheckResult> expected;
772 // The text is taken from US constitution preamble. 773 // The text is taken from US constitution preamble.
773 const string16 text = UTF8ToUTF16( 774 const string16 text = UTF8ToUTF16(
774 "We the people of the United States, in order to form a more perfect " 775 "We the people of the United States, in order to form a more perfect "
775 "union, establish justice, insure domestic tranquility, provide for " 776 "union, establish justice, insure domestic tranquility, provide for "
776 "the common defense, promote the general welfare, and secure the " 777 "the common defense, promote the general welfare, and secure the "
777 "blessings of liberty to ourselves and our posterity, do ordain and " 778 "blessings of liberty to ourselves and our posterity, do ordain and "
778 "establish this Constitution for the United States of America."); 779 "establish this Constitution for the United States of America.");
779 780
780 TestSpellCheckParagraph(text, expected); 781 TestSpellCheckParagraph(text, expected);
781 } 782 }
782 783
783 // Make sure all misspellings can be found in a relatively long sentence. 784 // Make sure all misspellings can be found in a relatively long sentence.
784 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentenceMultipleMisspellings) { 785 TEST_F(SpellCheckTest, SpellCheckParagraphLongSentenceMultipleMisspellings) {
785 std::vector<WebKit::WebTextCheckingResult> expected; 786 std::vector<SpellCheckResult> expected;
786 787
787 // All 'the' are converted to 'hte' in US consitition preamble. 788 // All 'the' are converted to 'hte' in US consitition preamble.
788 const string16 text = UTF8ToUTF16( 789 const string16 text = UTF8ToUTF16(
789 "We hte people of hte United States, in order to form a more perfect " 790 "We hte people of hte United States, in order to form a more perfect "
790 "union, establish justice, insure domestic tranquility, provide for " 791 "union, establish justice, insure domestic tranquility, provide for "
791 "hte common defense, promote hte general welfare, and secure hte " 792 "hte common defense, promote hte general welfare, and secure hte "
792 "blessings of liberty to ourselves and our posterity, do ordain and " 793 "blessings of liberty to ourselves and our posterity, do ordain and "
793 "establish this Constitution for hte United States of America."); 794 "establish this Constitution for hte United States of America.");
794 795
795 expected.push_back(WebKit::WebTextCheckingResult( 796 expected.push_back(SpellCheckResult(
796 WebKit::WebTextCheckingTypeSpelling, 3, 3)); 797 SpellCheckResult::SPELLING, 3, 3));
797 expected.push_back(WebKit::WebTextCheckingResult( 798 expected.push_back(SpellCheckResult(
798 WebKit::WebTextCheckingTypeSpelling, 17, 3)); 799 SpellCheckResult::SPELLING, 17, 3));
799 expected.push_back(WebKit::WebTextCheckingResult( 800 expected.push_back(SpellCheckResult(
800 WebKit::WebTextCheckingTypeSpelling, 135, 3)); 801 SpellCheckResult::SPELLING, 135, 3));
801 expected.push_back(WebKit::WebTextCheckingResult( 802 expected.push_back(SpellCheckResult(
802 WebKit::WebTextCheckingTypeSpelling, 163, 3)); 803 SpellCheckResult::SPELLING, 163, 3));
803 expected.push_back(WebKit::WebTextCheckingResult( 804 expected.push_back(SpellCheckResult(
804 WebKit::WebTextCheckingTypeSpelling, 195, 3)); 805 SpellCheckResult::SPELLING, 195, 3));
805 expected.push_back(WebKit::WebTextCheckingResult( 806 expected.push_back(SpellCheckResult(
806 WebKit::WebTextCheckingTypeSpelling, 298, 3)); 807 SpellCheckResult::SPELLING, 298, 3));
807 808
808 TestSpellCheckParagraph(text, expected); 809 TestSpellCheckParagraph(text, expected);
809 } 810 }
810 #endif 811 #endif
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698