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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/spellcheck/renderer/spellcheck.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/spellcheck/common/spellcheck_result.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/platform/WebVector.h"
12 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
13
14 class SpellCheckTest : public testing::Test {
15 public:
16 SpellCheckTest() {}
17
18 // Helper function to add a result via UTF8. 'Cause I'm lazy.
19 void AddReplacement(const std::string& replacement) {
20 if (chrome_results_.empty()) {
21 chrome_results_.push_back(SpellCheckResult(
22 SpellCheckResult::SPELLING, 0, replacement.size() + 2,
23 base::UTF8ToUTF16(replacement)));
24 } else {
25 chrome_results_.back().replacements.push_back(
26 base::UTF8ToUTF16(replacement));
27 }
28 }
29
30 std::vector<SpellCheckResult> chrome_results_;
31 SpellCheck spellcheck_;
32 };
33
34 TEST_F(SpellCheckTest, MultiResultTest) {
35 blink::WebVector<blink::WebTextCheckingResult> blink_results;
36
37 const base::char16 kApostrophe = 0x27;
38 const base::char16 kRightSingleQuotationMark = 0x2019;
39
40 // The text to be checked contains a "typographic" apostrophe.
41 std::string original_text = "mark's";
42 base::string16 typographic_text = base::UTF8ToUTF16(original_text);
43 std::replace(typographic_text.begin(), typographic_text.end(), kApostrophe,
44 kRightSingleQuotationMark);
45
46 // The results contain...
47 // ... a "fixed" version without apostrophe
48 AddReplacement("marks");
49 // ... a version that has just the apostrophe flipped back
50 AddReplacement(original_text);
51 // ... and a completely different word.
52 AddReplacement("markus");
53
54 // Let's test that!
55 spellcheck_.CreateTextCheckingResults(SpellCheck::DO_NOT_MODIFY, 0,
56 typographic_text, chrome_results_,
57 &blink_results);
58
59 // We expect back two results, the "fixed" non-apostrophe one, and the
60 // different word. The apostrophe flip should be ignored.
61 ASSERT_EQ(1U, blink_results.size());
62 ASSERT_EQ(2U, blink_results[0].replacements.size());
63 // First replacement is left intact.
64 EXPECT_EQ(chrome_results_[0].replacements[0],
65 blink_results[0].replacements[0].Utf16());
66 // Second replacement is skipped, third replacement is left intact.
67 EXPECT_EQ(chrome_results_[0].replacements[2],
68 blink_results[0].replacements[1].Utf16());
69 }
OLDNEW
« 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