| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016 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 "core/editing/EditingTestBase.h" |
| 6 #include "core/editing/Editor.h" |
| 7 #include "core/editing/commands/EditorCommandNames.h" |
| 8 #include "public/platform/WebEditingCommandType.h" |
| 9 #include "wtf/StringExtras.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 namespace { |
| 14 |
| 15 struct CommandNameEntry { |
| 16 const char* name; |
| 17 WebEditingCommandType type; |
| 18 }; |
| 19 |
| 20 const CommandNameEntry kCommandNameEntries[] = { |
| 21 #define V(name) { #name, WebEditingCommandType::name }, |
| 22 FOR_EACH_BLINK_EDITING_COMMAND_NAME(V) |
| 23 #undef V |
| 24 }; |
| 25 // Test all commands except WebEditingCommandType::Invalid. |
| 26 static_assert(arraysize(kCommandNameEntries) + 1 == static_cast<size_t>(WebEditi
ngCommandType::NumberOfCommandTypes), "must test all valid WebEditingCommandType
"); |
| 27 |
| 28 } // anonymous namespace |
| 29 |
| 30 class EditingCommandTest : public EditingTestBase { |
| 31 }; |
| 32 |
| 33 TEST_F(EditingCommandTest, EditorCommandOrder) |
| 34 { |
| 35 for (size_t i = 1; i < arraysize(kCommandNameEntries); ++i) |
| 36 EXPECT_GT(0, strcasecmp(kCommandNameEntries[i - 1].name, kCommandNameEnt
ries[i].name)) << "EDITOR_COMMAND_MAP must be case-folding ordered. Incorrect in
dex:" << i; |
| 37 } |
| 38 |
| 39 TEST_F(EditingCommandTest, CreateCommandFromString) |
| 40 { |
| 41 Editor& dummyEditor = document().frame()->editor(); |
| 42 for (const auto& entry : kCommandNameEntries) { |
| 43 Editor::Command command = dummyEditor.createCommand(entry.name); |
| 44 EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << ent
ry.name; |
| 45 } |
| 46 } |
| 47 |
| 48 TEST_F(EditingCommandTest, CreateCommandFromStringCaseFolding) |
| 49 { |
| 50 Editor& dummyEditor = document().frame()->editor(); |
| 51 for (const auto& entry : kCommandNameEntries) { |
| 52 Editor::Command command = dummyEditor.createCommand(String(entry.name).l
ower()); |
| 53 EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << ent
ry.name; |
| 54 command = dummyEditor.createCommand(String(entry.name).upper()); |
| 55 EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << ent
ry.name; |
| 56 } |
| 57 } |
| 58 |
| 59 TEST_F(EditingCommandTest, CreateCommandFromInvalidString) |
| 60 { |
| 61 const String kInvalidCommandName[] = { |
| 62 "", |
| 63 "iNvAlId", |
| 64 "12345", |
| 65 }; |
| 66 Editor& dummyEditor = document().frame()->editor(); |
| 67 for (const auto& commandName : kInvalidCommandName) { |
| 68 Editor::Command command = dummyEditor.createCommand(commandName); |
| 69 EXPECT_EQ(0, command.idForHistogram()); |
| 70 } |
| 71 } |
| 72 |
| 73 } // namespace blink |
| OLD | NEW |