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

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

Issue 2159283003: [WIP][DO NOT LAND] Componentize spellcheck Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 #include "chrome/browser/spellchecker/spellcheck_action.h"
6
7 #include <stddef.h>
8
9 #include <memory>
10 #include <string>
11
12 #include "base/json/json_reader.h"
13 #include "base/macros.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 TEST(SpellcheckActionTest, FinalActionsTest) {
19 static const SpellcheckAction::SpellcheckActionType kFinalActions[] = {
20 SpellcheckAction::TYPE_ADD_TO_DICT,
21 SpellcheckAction::TYPE_IGNORE,
22 SpellcheckAction::TYPE_IN_DICTIONARY,
23 SpellcheckAction::TYPE_MANUALLY_CORRECTED,
24 SpellcheckAction::TYPE_NO_ACTION,
25 SpellcheckAction::TYPE_SELECT,
26 };
27 SpellcheckAction action;
28 for (size_t i = 0; i < arraysize(kFinalActions); ++i) {
29 action.set_type(kFinalActions[i]);
30 ASSERT_TRUE(action.IsFinal());
31 }
32 }
33
34 TEST(SpellcheckActionTest, PendingActionsTest) {
35 static const SpellcheckAction::SpellcheckActionType kPendingActions[] = {
36 SpellcheckAction::TYPE_PENDING,
37 SpellcheckAction::TYPE_PENDING_IGNORE,
38 };
39 SpellcheckAction action;
40 for (size_t i = 0; i < arraysize(kPendingActions); ++i) {
41 action.set_type(kPendingActions[i]);
42 ASSERT_FALSE(action.IsFinal());
43 }
44 }
45
46 TEST(SpellcheckActionTest, FinalizeTest) {
47 SpellcheckAction action;
48 action.set_type(SpellcheckAction::TYPE_PENDING);
49 action.Finalize();
50 ASSERT_EQ(SpellcheckAction::TYPE_NO_ACTION, action.type());
51
52 action.set_type(SpellcheckAction::TYPE_PENDING_IGNORE);
53 action.Finalize();
54 ASSERT_EQ(SpellcheckAction::TYPE_IGNORE, action.type());
55 }
56
57 TEST(SpellcheckActionTest, SerializeTest) {
58 static const size_t kNumTestCases = 7;
59 static const struct {
60 SpellcheckAction action;
61 std::string expected;
62 } kTestCases[] = {
63 { SpellcheckAction(
64 SpellcheckAction::TYPE_ADD_TO_DICT, -1,
65 base::ASCIIToUTF16("nothing")),
66 "{\"actionType\": \"ADD_TO_DICT\"}" },
67 { SpellcheckAction(
68 SpellcheckAction::TYPE_IGNORE, -1, base::ASCIIToUTF16("nothing")),
69 "{\"actionType\": \"IGNORE\"}" },
70 { SpellcheckAction(
71 SpellcheckAction::TYPE_IN_DICTIONARY, -1,
72 base::ASCIIToUTF16("nothing")),
73 "{\"actionType\": \"IN_DICTIONARY\"}" },
74 { SpellcheckAction(
75 SpellcheckAction::TYPE_MANUALLY_CORRECTED, -1,
76 base::ASCIIToUTF16("hello")),
77 "{\"actionTargetValue\": \"hello\","
78 "\"actionType\": \"MANUALLY_CORRECTED\"}" },
79 { SpellcheckAction(
80 SpellcheckAction::TYPE_NO_ACTION, -1, base::ASCIIToUTF16("nothing")),
81 "{\"actionType\": \"NO_ACTION\"}" },
82 { SpellcheckAction(
83 SpellcheckAction::TYPE_PENDING, -1, base::ASCIIToUTF16("nothing")),
84 "{\"actionType\": \"PENDING\"}" },
85 { SpellcheckAction(
86 SpellcheckAction::TYPE_PENDING_IGNORE, -1,
87 base::ASCIIToUTF16("nothing")),
88 "{\"actionType\": \"PENDING\"}" },
89 { SpellcheckAction(
90 SpellcheckAction::TYPE_SELECT, 42, base::ASCIIToUTF16("nothing")),
91 "{\"actionTargetIndex\": 42, \"actionType\": \"SELECT\"}" },
92 };
93 for (size_t i = 0; i < kNumTestCases; ++i) {
94 std::unique_ptr<base::DictionaryValue> serialized(
95 kTestCases[i].action.Serialize());
96 std::unique_ptr<base::Value> expected =
97 base::JSONReader::Read(kTestCases[i].expected);
98 EXPECT_TRUE(serialized->Equals(expected.get()));
99 }
100 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_action.cc ('k') | chrome/browser/spellchecker/spellcheck_custom_dictionary.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698