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

Unified Diff: chrome/renderer/spellchecker/spellcheck_unittest.cc

Issue 1092243002: Handle typographical apostrophe with spelling service client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ozone and mac Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/spellchecker/spellcheck_unittest.cc
diff --git a/chrome/renderer/spellchecker/spellcheck_unittest.cc b/chrome/renderer/spellchecker/spellcheck_unittest.cc
index f82ac8034560ddbc72df9369e471a6f01f130d01..e3c71707147a122012b2fac451523788a2a386e6 100644
--- a/chrome/renderer/spellchecker/spellcheck_unittest.cc
+++ b/chrome/renderer/spellchecker/spellcheck_unittest.cc
@@ -16,6 +16,8 @@
#include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
#include "third_party/WebKit/public/web/WebTextCheckingResult.h"
+#define TYPOGRAPHICAL_APOSTROPHE L"\x2019"
groby-ooo-7-16 2015/04/25 00:19:02 Eeeeeeeek. I suppose we need the define, but... ee
please use gerrit instead 2015/06/17 03:52:07 Ack
+
namespace {
base::FilePath GetHunspellDirectory() {
@@ -79,6 +81,10 @@ class SpellCheckTest : public testing::Test {
base::ASCIIToUTF16(word), tag);
}
+ bool IsValidContraction(const base::string16& word, int tag) {
+ return spell_check_->spellcheck_.IsValidContraction(word, tag);
+ }
+
#if !defined(OS_MACOSX)
protected:
void TestSpellCheckParagraph(
@@ -201,7 +207,7 @@ TEST_F(SpellCheckTest, SpellCheckStrings_EN_US) {
// A valid English contraction
{L"isn't", true},
// A valid English contraction with a typographical apostrophe.
- {L"isn\x2019t", true},
+ {L"isn" TYPOGRAPHICAL_APOSTROPHE L"t", true},
// A valid English word enclosed with underscores.
{L"_hello_", true},
@@ -1140,7 +1146,7 @@ TEST_F(SpellCheckTest, CreateTextCheckingResults) {
text,
spellcheck_results,
&textcheck_results);
- EXPECT_EQ(spellcheck_results.size(), textcheck_results.size());
+ ASSERT_EQ(spellcheck_results.size(), textcheck_results.size());
EXPECT_EQ(blink::WebTextDecorationTypeSpelling,
textcheck_results[0].decoration);
EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location);
@@ -1160,12 +1166,78 @@ TEST_F(SpellCheckTest, CreateTextCheckingResults) {
text,
spellcheck_results,
&textcheck_results);
- EXPECT_EQ(spellcheck_results.size(), textcheck_results.size());
+ ASSERT_EQ(spellcheck_results.size(), textcheck_results.size());
EXPECT_EQ(blink::WebTextDecorationTypeGrammar,
textcheck_results[0].decoration);
EXPECT_EQ(spellcheck_results[0].location, textcheck_results[0].location);
EXPECT_EQ(spellcheck_results[0].length, textcheck_results[0].length);
}
+
+ // Verify that the SpellCheck preserves the original apostrophe type in the
+ // checked text, regardless of the type of apostrophe the browser returns.
+ {
+ base::string16 text = base::WideToUTF16(
+ L"Ik've havn" TYPOGRAPHICAL_APOSTROPHE L"t ni'n"
+ TYPOGRAPHICAL_APOSTROPHE L"out-s I've I" TYPOGRAPHICAL_APOSTROPHE
+ L"ve");
+ std::vector<SpellCheckResult> spellcheck_results;
+
+ // All typewriter apostrophe results.
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 0, 5, base::WideToUTF16(L"I've")));
groby-ooo-7-16 2015/04/25 00:19:02 UTF8ToUTF16 is enough here. No need to go wide cha
please use gerrit instead 2015/06/17 03:52:07 Done.
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 6, 6, base::WideToUTF16(L"haven't")));
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 13, 10, base::WideToUTF16(L"in'n'out's")));
+
+ // Replacements that differ only by apostrophe type should be ignored.
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 24, 4, base::WideToUTF16(L"I've")));
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 29, 4, base::WideToUTF16(L"I've")));
+
+ // All typographical apostrophe results.
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 0, 5,
+ base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")));
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 6, 6,
+ base::WideToUTF16(L"haven" TYPOGRAPHICAL_APOSTROPHE L"t")));
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 13, 10, base::WideToUTF16(
+ L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"out"
+ TYPOGRAPHICAL_APOSTROPHE L"s")));
+
+ // Replacements that differ only by apostrophe type should be ignored.
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 24, 4,
+ base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")));
+ spellcheck_results.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 29, 4,
+ base::WideToUTF16(L"I" TYPOGRAPHICAL_APOSTROPHE L"ve")));
+
+ blink::WebVector<blink::WebTextCheckingResult> textcheck_results;
+ spell_check()->CreateTextCheckingResults(SpellCheck::USE_NATIVE_CHECKER,
+ 0,
+ text,
+ spellcheck_results,
+ &textcheck_results);
+
+ static const wchar_t* kExpectedReplacements[] = {
+ L"I've",
+ L"haven" TYPOGRAPHICAL_APOSTROPHE L"t",
+ L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out's",
+ L"I've",
+ L"haven" TYPOGRAPHICAL_APOSTROPHE L"t",
+ L"in'n" TYPOGRAPHICAL_APOSTROPHE L"out" TYPOGRAPHICAL_APOSTROPHE L"s",
+ };
+
+ ASSERT_EQ(arraysize(kExpectedReplacements), textcheck_results.size());
+ for (size_t i = 0; i < arraysize(kExpectedReplacements); ++i) {
+ EXPECT_EQ(base::WideToUTF16(kExpectedReplacements[i]),
+ textcheck_results[i].replacement);
+ }
+ }
}
#endif
@@ -1373,3 +1445,24 @@ TEST_F(SpellCheckTest, LogicalSuggestions) {
EXPECT_EQ(suggestions[0], base::ASCIIToUTF16(kTestCases[i].suggestion));
}
}
+
+// Words with apostrophes should be valid contractions.
+TEST_F(SpellCheckTest, IsValidContraction) {
+ static const char* kLanguages[] = {
+ "en-AU",
+ "en-CA",
+ "en-GB",
+ "en-US",
+ };
+
+ static const wchar_t* kWords[] = {
+ L"in'n'out",
+ L"in" TYPOGRAPHICAL_APOSTROPHE L"n" TYPOGRAPHICAL_APOSTROPHE L"out",
+ };
+
+ for (size_t i = 0; i < arraysize(kLanguages); ++i) {
+ ReinitializeSpellCheck(kLanguages[i]);
+ for (size_t j = 0; j < arraysize(kWords); ++j)
+ EXPECT_TRUE(IsValidContraction(base::WideToUTF16(kWords[j]), 0));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698