| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/spellchecker/spellcheck_action.h" | 10 #include "chrome/browser/spellchecker/spellcheck_action.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 ASSERT_EQ(SpellcheckAction::TYPE_IGNORE, action.type); | 49 ASSERT_EQ(SpellcheckAction::TYPE_IGNORE, action.type); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST(SpellcheckActionTest, SerializeTest) { | 52 TEST(SpellcheckActionTest, SerializeTest) { |
| 53 static const size_t kNumTestCases = 7; | 53 static const size_t kNumTestCases = 7; |
| 54 static const struct { | 54 static const struct { |
| 55 SpellcheckAction action; | 55 SpellcheckAction action; |
| 56 std::string expected; | 56 std::string expected; |
| 57 } kTestCases[] = { | 57 } kTestCases[] = { |
| 58 { SpellcheckAction( | 58 { SpellcheckAction( |
| 59 SpellcheckAction::TYPE_ADD_TO_DICT, -1, ASCIIToUTF16("nothing")), | 59 SpellcheckAction::TYPE_ADD_TO_DICT, -1, |
| 60 base::ASCIIToUTF16("nothing")), |
| 60 "{\"actionType\": \"ADD_TO_DICT\"}" }, | 61 "{\"actionType\": \"ADD_TO_DICT\"}" }, |
| 61 { SpellcheckAction( | 62 { SpellcheckAction( |
| 62 SpellcheckAction::TYPE_IGNORE, -1, ASCIIToUTF16("nothing")), | 63 SpellcheckAction::TYPE_IGNORE, -1, base::ASCIIToUTF16("nothing")), |
| 63 "{\"actionType\": \"IGNORE\"}" }, | 64 "{\"actionType\": \"IGNORE\"}" }, |
| 64 { SpellcheckAction( | 65 { SpellcheckAction( |
| 65 SpellcheckAction::TYPE_IN_DICTIONARY, -1, ASCIIToUTF16("nothing")), | 66 SpellcheckAction::TYPE_IN_DICTIONARY, -1, |
| 67 base::ASCIIToUTF16("nothing")), |
| 66 "{\"actionType\": \"IN_DICTIONARY\"}" }, | 68 "{\"actionType\": \"IN_DICTIONARY\"}" }, |
| 67 { SpellcheckAction( | 69 { SpellcheckAction( |
| 68 SpellcheckAction::TYPE_MANUALLY_CORRECTED, -1, ASCIIToUTF16("hello")), | 70 SpellcheckAction::TYPE_MANUALLY_CORRECTED, -1, |
| 71 base::ASCIIToUTF16("hello")), |
| 69 "{\"actionTargetValue\": \"hello\"," | 72 "{\"actionTargetValue\": \"hello\"," |
| 70 "\"actionType\": \"MANUALLY_CORRECTED\"}" }, | 73 "\"actionType\": \"MANUALLY_CORRECTED\"}" }, |
| 71 { SpellcheckAction( | 74 { SpellcheckAction( |
| 72 SpellcheckAction::TYPE_NO_ACTION, -1, ASCIIToUTF16("nothing")), | 75 SpellcheckAction::TYPE_NO_ACTION, -1, base::ASCIIToUTF16("nothing")), |
| 73 "{\"actionType\": \"NO_ACTION\"}" }, | 76 "{\"actionType\": \"NO_ACTION\"}" }, |
| 74 { SpellcheckAction( | 77 { SpellcheckAction( |
| 75 SpellcheckAction::TYPE_PENDING, -1, ASCIIToUTF16("nothing")), | 78 SpellcheckAction::TYPE_PENDING, -1, base::ASCIIToUTF16("nothing")), |
| 76 "{\"actionType\": \"PENDING\"}" }, | 79 "{\"actionType\": \"PENDING\"}" }, |
| 77 { SpellcheckAction( | 80 { SpellcheckAction( |
| 78 SpellcheckAction::TYPE_PENDING_IGNORE, -1, ASCIIToUTF16("nothing")), | 81 SpellcheckAction::TYPE_PENDING_IGNORE, -1, |
| 82 base::ASCIIToUTF16("nothing")), |
| 79 "{\"actionType\": \"PENDING\"}" }, | 83 "{\"actionType\": \"PENDING\"}" }, |
| 80 { SpellcheckAction( | 84 { SpellcheckAction( |
| 81 SpellcheckAction::TYPE_SELECT, 42, ASCIIToUTF16("nothing")), | 85 SpellcheckAction::TYPE_SELECT, 42, base::ASCIIToUTF16("nothing")), |
| 82 "{\"actionTargetIndex\": 42, \"actionType\": \"SELECT\"}" }, | 86 "{\"actionTargetIndex\": 42, \"actionType\": \"SELECT\"}" }, |
| 83 }; | 87 }; |
| 84 for (size_t i = 0; i < kNumTestCases; ++i) { | 88 for (size_t i = 0; i < kNumTestCases; ++i) { |
| 85 scoped_ptr<base::DictionaryValue> serialized( | 89 scoped_ptr<base::DictionaryValue> serialized( |
| 86 kTestCases[i].action.Serialize()); | 90 kTestCases[i].action.Serialize()); |
| 87 scoped_ptr<base::Value> expected( | 91 scoped_ptr<base::Value> expected( |
| 88 base::JSONReader::Read(kTestCases[i].expected)); | 92 base::JSONReader::Read(kTestCases[i].expected)); |
| 89 EXPECT_TRUE(serialized->Equals(expected.get())); | 93 EXPECT_TRUE(serialized->Equals(expected.get())); |
| 90 } | 94 } |
| 91 } | 95 } |
| OLD | NEW |