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

Unified Diff: components/spellcheck/renderer/spellcheck_unittest2.cc

Issue 2891763003: [WIP, DONOTCOMMIT] Test case for multi-result spellcheck (Closed)
Patch Set: Proposed fix Created 3 years, 7 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: components/spellcheck/renderer/spellcheck_unittest2.cc
diff --git a/components/spellcheck/renderer/spellcheck_unittest2.cc b/components/spellcheck/renderer/spellcheck_unittest2.cc
new file mode 100644
index 0000000000000000000000000000000000000000..652f32e74fa42ee7225f126a2852fb930a05d479
--- /dev/null
+++ b/components/spellcheck/renderer/spellcheck_unittest2.cc
@@ -0,0 +1,69 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/spellcheck/renderer/spellcheck.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "components/spellcheck/common/spellcheck_result.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+#include "third_party/WebKit/public/platform/WebVector.h"
+#include "third_party/WebKit/public/web/WebTextCheckingResult.h"
+
+class SpellCheckTest : public testing::Test {
+ public:
+ SpellCheckTest() {}
+
+ // Helper function to add a result via UTF8. 'Cause I'm lazy.
+ void AddReplacement(const std::string& replacement) {
+ if (chrome_results_.empty()) {
+ chrome_results_.push_back(SpellCheckResult(
+ SpellCheckResult::SPELLING, 0, replacement.size() + 2,
+ base::UTF8ToUTF16(replacement)));
+ } else {
+ chrome_results_.back().replacements.push_back(
+ base::UTF8ToUTF16(replacement));
+ }
+ }
+
+ std::vector<SpellCheckResult> chrome_results_;
+ SpellCheck spellcheck_;
+};
+
+TEST_F(SpellCheckTest, MultiResultTest) {
+ blink::WebVector<blink::WebTextCheckingResult> blink_results;
+
+ const base::char16 kApostrophe = 0x27;
+ const base::char16 kRightSingleQuotationMark = 0x2019;
+
+ // The text to be checked contains a "typographic" apostrophe.
+ std::string original_text = "mark's";
+ base::string16 typographic_text = base::UTF8ToUTF16(original_text);
+ std::replace(typographic_text.begin(), typographic_text.end(), kApostrophe,
+ kRightSingleQuotationMark);
+
+ // The results contain...
+ // ... a "fixed" version without apostrophe
+ AddReplacement("marks");
+ // ... a version that has just the apostrophe flipped back
+ AddReplacement(original_text);
+ // ... and a completely different word.
+ AddReplacement("markus");
+
+ // Let's test that!
+ spellcheck_.CreateTextCheckingResults(SpellCheck::DO_NOT_MODIFY, 0,
+ typographic_text, chrome_results_,
+ &blink_results);
+
+ // We expect back two results, the "fixed" non-apostrophe one, and the
+ // different word. The apostrophe flip should be ignored.
+ ASSERT_EQ(1U, blink_results.size());
+ ASSERT_EQ(2U, blink_results[0].replacements.size());
+ // First replacement is left intact.
+ EXPECT_EQ(chrome_results_[0].replacements[0],
+ blink_results[0].replacements[0].Utf16());
+ // Second replacement is skipped, third replacement is left intact.
+ EXPECT_EQ(chrome_results_[0].replacements[2],
+ blink_results[0].replacements[1].Utf16());
+}
« no previous file with comments | « components/spellcheck/renderer/spellcheck_unittest.cc ('k') | content/shell/test_runner/mock_spell_check.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698