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

Side by Side Diff: chrome/browser/spellchecker/misspelling_unittest.cc

Issue 2244083002: Componentize spellcheck [4]: spellcheck/browser and android java-side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 // Unit tests for |Misspelling| object.
6
7 #include "chrome/browser/spellchecker/misspelling.h"
8
9 #include "base/json/json_reader.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 TEST(MisspellingTest, SerializeTest) {
15 Misspelling misspelling;
16 misspelling.context = base::ASCIIToUTF16("How doe sit know");
17 misspelling.location = 4;
18 misspelling.length = 7;
19 misspelling.timestamp = base::Time::FromJsTime(42);
20 misspelling.hash = 9001;
21 misspelling.suggestions.push_back(base::ASCIIToUTF16("does it"));
22
23 std::unique_ptr<base::Value> expected = base::JSONReader::Read(
24 "{\"originalText\": \"How doe sit know\","
25 "\"misspelledStart\": 4,"
26 "\"misspelledLength\": 7,"
27 "\"timestamp\": \"42\","
28 "\"suggestionId\":\"9001\","
29 "\"suggestions\": [\"does it\"],"
30 "\"userActions\": [{\"actionType\": \"PENDING\"}]}");
31
32 std::unique_ptr<base::DictionaryValue> serialized(
33 SerializeMisspelling(misspelling));
34 EXPECT_TRUE(serialized->Equals(expected.get()));
35 }
36
37 TEST(MisspellingTest, GetMisspelledStringTest) {
38 Misspelling misspelling;
39 misspelling.context = base::ASCIIToUTF16("How doe sit know");
40 misspelling.location = 4;
41 misspelling.length = 7;
42 EXPECT_EQ(base::ASCIIToUTF16("doe sit"), GetMisspelledString(misspelling));
43
44 misspelling.length = 0;
45 EXPECT_EQ(base::string16(), GetMisspelledString(misspelling));
46
47 misspelling.location = misspelling.context.length();
48 misspelling.length = 7;
49 EXPECT_EQ(base::string16(), GetMisspelledString(misspelling));
50
51 misspelling.location = misspelling.context.length() + 1;
52 EXPECT_EQ(base::string16(), GetMisspelledString(misspelling));
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698