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.
7 #include "base/json/json_reader.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "chrome/browser/spellchecker/spellcheck_action.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(SpellcheckActionTest
, FinalActionsTest
) {
14 static const SpellcheckAction::SpellcheckActionType kFinalActions
[] = {
15 SpellcheckAction::TYPE_ADD_TO_DICT
,
16 SpellcheckAction::TYPE_IGNORE
,
17 SpellcheckAction::TYPE_IN_DICTIONARY
,
18 SpellcheckAction::TYPE_MANUALLY_CORRECTED
,
19 SpellcheckAction::TYPE_NO_ACTION
,
20 SpellcheckAction::TYPE_SELECT
,
22 SpellcheckAction action
;
23 for (size_t i
= 0; i
< arraysize(kFinalActions
); ++i
) {
24 action
.type
= kFinalActions
[i
];
25 ASSERT_TRUE(action
.IsFinal());
29 TEST(SpellcheckActionTest
, PendingActionsTest
) {
30 static const SpellcheckAction::SpellcheckActionType kPendingActions
[] = {
31 SpellcheckAction::TYPE_PENDING
,
32 SpellcheckAction::TYPE_PENDING_IGNORE
,
34 SpellcheckAction action
;
35 for (size_t i
= 0; i
< arraysize(kPendingActions
); ++i
) {
36 action
.type
= kPendingActions
[i
];
37 ASSERT_FALSE(action
.IsFinal());
41 TEST(SpellcheckActionTest
, FinalizeTest
) {
42 SpellcheckAction action
;
43 action
.type
= SpellcheckAction::TYPE_PENDING
;
45 ASSERT_EQ(SpellcheckAction::TYPE_NO_ACTION
, action
.type
);
47 action
.type
= SpellcheckAction::TYPE_PENDING_IGNORE
;
49 ASSERT_EQ(SpellcheckAction::TYPE_IGNORE
, action
.type
);
52 TEST(SpellcheckActionTest
, SerializeTest
) {
53 static const size_t kNumTestCases
= 7;
55 SpellcheckAction action
;
59 SpellcheckAction::TYPE_ADD_TO_DICT
, -1,
60 base::ASCIIToUTF16("nothing")),
61 "{\"actionType\": \"ADD_TO_DICT\"}" },
63 SpellcheckAction::TYPE_IGNORE
, -1, base::ASCIIToUTF16("nothing")),
64 "{\"actionType\": \"IGNORE\"}" },
66 SpellcheckAction::TYPE_IN_DICTIONARY
, -1,
67 base::ASCIIToUTF16("nothing")),
68 "{\"actionType\": \"IN_DICTIONARY\"}" },
70 SpellcheckAction::TYPE_MANUALLY_CORRECTED
, -1,
71 base::ASCIIToUTF16("hello")),
72 "{\"actionTargetValue\": \"hello\","
73 "\"actionType\": \"MANUALLY_CORRECTED\"}" },
75 SpellcheckAction::TYPE_NO_ACTION
, -1, base::ASCIIToUTF16("nothing")),
76 "{\"actionType\": \"NO_ACTION\"}" },
78 SpellcheckAction::TYPE_PENDING
, -1, base::ASCIIToUTF16("nothing")),
79 "{\"actionType\": \"PENDING\"}" },
81 SpellcheckAction::TYPE_PENDING_IGNORE
, -1,
82 base::ASCIIToUTF16("nothing")),
83 "{\"actionType\": \"PENDING\"}" },
85 SpellcheckAction::TYPE_SELECT
, 42, base::ASCIIToUTF16("nothing")),
86 "{\"actionTargetIndex\": 42, \"actionType\": \"SELECT\"}" },
88 for (size_t i
= 0; i
< kNumTestCases
; ++i
) {
89 scoped_ptr
<base::DictionaryValue
> serialized(
90 kTestCases
[i
].action
.Serialize());
91 scoped_ptr
<base::Value
> expected(
92 base::JSONReader::Read(kTestCases
[i
].expected
));
93 EXPECT_TRUE(serialized
->Equals(expected
.get()));