Chromium Code Reviews| 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 "public/platform/WebEditingCommandType.h" | |
| 8 | |
| 9 namespace blink { | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 const struct CommandNameEntry { | |
|
dtapuska
2016/03/29 18:47:50
This table is duplicated.. Perhaps you can place i
| |
| 14 const char* name; | |
| 15 WebEditingCommandType type; | |
| 16 } kCommandNameEntries[] = { | |
| 17 { "AlignCenter", WebEditingCommandType::AlignCenter }, | |
| 18 { "AlignJustified", WebEditingCommandType::AlignJustified }, | |
| 19 { "AlignLeft", WebEditingCommandType::AlignLeft }, | |
| 20 { "AlignRight", WebEditingCommandType::AlignRight }, | |
| 21 { "BackColor", WebEditingCommandType::BackColor }, | |
| 22 { "BackwardDelete", WebEditingCommandType::BackwardDelete }, | |
| 23 { "Bold", WebEditingCommandType::Bold }, | |
| 24 { "Copy", WebEditingCommandType::Copy }, | |
| 25 { "CreateLink", WebEditingCommandType::CreateLink }, | |
| 26 { "Cut", WebEditingCommandType::Cut }, | |
| 27 { "DefaultParagraphSeparator", WebEditingCommandType::DefaultParagraphSepara tor }, | |
| 28 { "Delete", WebEditingCommandType::Delete }, | |
| 29 { "DeleteBackward", WebEditingCommandType::DeleteBackward }, | |
| 30 { "DeleteBackwardByDecomposingPreviousCharacter", WebEditingCommandType::Del eteBackwardByDecomposingPreviousCharacter }, | |
| 31 { "DeleteForward", WebEditingCommandType::DeleteForward }, | |
| 32 { "DeleteToBeginningOfLine", WebEditingCommandType::DeleteToBeginningOfLine }, | |
| 33 { "DeleteToBeginningOfParagraph", WebEditingCommandType::DeleteToBeginningOf Paragraph }, | |
| 34 { "DeleteToEndOfLine", WebEditingCommandType::DeleteToEndOfLine }, | |
| 35 { "DeleteToEndOfParagraph", WebEditingCommandType::DeleteToEndOfParagraph }, | |
| 36 { "DeleteToMark", WebEditingCommandType::DeleteToMark }, | |
| 37 { "DeleteWordBackward", WebEditingCommandType::DeleteWordBackward }, | |
| 38 { "DeleteWordForward", WebEditingCommandType::DeleteWordForward }, | |
| 39 { "FindString", WebEditingCommandType::FindString }, | |
| 40 { "FontName", WebEditingCommandType::FontName }, | |
| 41 { "FontSize", WebEditingCommandType::FontSize }, | |
| 42 { "FontSizeDelta", WebEditingCommandType::FontSizeDelta }, | |
| 43 { "ForeColor", WebEditingCommandType::ForeColor }, | |
| 44 { "FormatBlock", WebEditingCommandType::FormatBlock }, | |
| 45 { "ForwardDelete", WebEditingCommandType::ForwardDelete }, | |
| 46 { "HiliteColor", WebEditingCommandType::HiliteColor }, | |
| 47 { "IgnoreSpelling", WebEditingCommandType::IgnoreSpelling }, | |
| 48 { "Indent", WebEditingCommandType::Indent }, | |
| 49 { "InsertBacktab", WebEditingCommandType::InsertBacktab }, | |
| 50 { "InsertHorizontalRule", WebEditingCommandType::InsertHorizontalRule }, | |
| 51 { "InsertHTML", WebEditingCommandType::InsertHTML }, | |
| 52 { "InsertImage", WebEditingCommandType::InsertImage }, | |
| 53 { "InsertLineBreak", WebEditingCommandType::InsertLineBreak }, | |
| 54 { "InsertNewline", WebEditingCommandType::InsertNewline }, | |
| 55 { "InsertNewlineInQuotedContent", WebEditingCommandType::InsertNewlineInQuot edContent }, | |
| 56 { "InsertOrderedList", WebEditingCommandType::InsertOrderedList }, | |
| 57 { "InsertParagraph", WebEditingCommandType::InsertParagraph }, | |
| 58 { "InsertTab", WebEditingCommandType::InsertTab }, | |
| 59 { "InsertText", WebEditingCommandType::InsertText }, | |
| 60 { "InsertUnorderedList", WebEditingCommandType::InsertUnorderedList }, | |
| 61 { "Italic", WebEditingCommandType::Italic }, | |
| 62 { "JustifyCenter", WebEditingCommandType::JustifyCenter }, | |
| 63 { "JustifyFull", WebEditingCommandType::JustifyFull }, | |
| 64 { "JustifyLeft", WebEditingCommandType::JustifyLeft }, | |
| 65 { "JustifyNone", WebEditingCommandType::JustifyNone }, | |
| 66 { "JustifyRight", WebEditingCommandType::JustifyRight }, | |
| 67 { "MakeTextWritingDirectionLeftToRight", WebEditingCommandType::MakeTextWrit ingDirectionLeftToRight }, | |
| 68 { "MakeTextWritingDirectionNatural", WebEditingCommandType::MakeTextWritingD irectionNatural }, | |
| 69 { "MakeTextWritingDirectionRightToLeft", WebEditingCommandType::MakeTextWrit ingDirectionRightToLeft }, | |
| 70 { "MoveBackward", WebEditingCommandType::MoveBackward }, | |
| 71 { "MoveBackwardAndModifySelection", WebEditingCommandType::MoveBackwardAndMo difySelection }, | |
| 72 { "MoveDown", WebEditingCommandType::MoveDown }, | |
| 73 { "MoveDownAndModifySelection", WebEditingCommandType::MoveDownAndModifySele ction }, | |
| 74 { "MoveForward", WebEditingCommandType::MoveForward }, | |
| 75 { "MoveForwardAndModifySelection", WebEditingCommandType::MoveForwardAndModi fySelection }, | |
| 76 { "MoveLeft", WebEditingCommandType::MoveLeft }, | |
| 77 { "MoveLeftAndModifySelection", WebEditingCommandType::MoveLeftAndModifySele ction }, | |
| 78 { "MovePageDown", WebEditingCommandType::MovePageDown }, | |
| 79 { "MovePageDownAndModifySelection", WebEditingCommandType::MovePageDownAndMo difySelection }, | |
| 80 { "MovePageUp", WebEditingCommandType::MovePageUp }, | |
| 81 { "MovePageUpAndModifySelection", WebEditingCommandType::MovePageUpAndModify Selection }, | |
| 82 { "MoveParagraphBackward", WebEditingCommandType::MoveParagraphBackward }, | |
| 83 { "MoveParagraphBackwardAndModifySelection", WebEditingCommandType::MovePara graphBackwardAndModifySelection }, | |
| 84 { "MoveParagraphForward", WebEditingCommandType::MoveParagraphForward }, | |
| 85 { "MoveParagraphForwardAndModifySelection", WebEditingCommandType::MoveParag raphForwardAndModifySelection }, | |
| 86 { "MoveRight", WebEditingCommandType::MoveRight }, | |
| 87 { "MoveRightAndModifySelection", WebEditingCommandType::MoveRightAndModifySe lection }, | |
| 88 { "MoveToBeginningOfDocument", WebEditingCommandType::MoveToBeginningOfDocum ent }, | |
| 89 { "MoveToBeginningOfDocumentAndModifySelection", WebEditingCommandType::Move ToBeginningOfDocumentAndModifySelection }, | |
| 90 { "MoveToBeginningOfLine", WebEditingCommandType::MoveToBeginningOfLine }, | |
| 91 { "MoveToBeginningOfLineAndModifySelection", WebEditingCommandType::MoveToBe ginningOfLineAndModifySelection }, | |
| 92 { "MoveToBeginningOfParagraph", WebEditingCommandType::MoveToBeginningOfPara graph }, | |
| 93 { "MoveToBeginningOfParagraphAndModifySelection", WebEditingCommandType::Mov eToBeginningOfParagraphAndModifySelection }, | |
| 94 { "MoveToBeginningOfSentence", WebEditingCommandType::MoveToBeginningOfSente nce }, | |
| 95 { "MoveToBeginningOfSentenceAndModifySelection", WebEditingCommandType::Move ToBeginningOfSentenceAndModifySelection }, | |
| 96 { "MoveToEndOfDocument", WebEditingCommandType::MoveToEndOfDocument }, | |
| 97 { "MoveToEndOfDocumentAndModifySelection", WebEditingCommandType::MoveToEndO fDocumentAndModifySelection }, | |
| 98 { "MoveToEndOfLine", WebEditingCommandType::MoveToEndOfLine }, | |
| 99 { "MoveToEndOfLineAndModifySelection", WebEditingCommandType::MoveToEndOfLin eAndModifySelection }, | |
| 100 { "MoveToEndOfParagraph", WebEditingCommandType::MoveToEndOfParagraph }, | |
| 101 { "MoveToEndOfParagraphAndModifySelection", WebEditingCommandType::MoveToEnd OfParagraphAndModifySelection }, | |
| 102 { "MoveToEndOfSentence", WebEditingCommandType::MoveToEndOfSentence }, | |
| 103 { "MoveToEndOfSentenceAndModifySelection", WebEditingCommandType::MoveToEndO fSentenceAndModifySelection }, | |
| 104 { "MoveToLeftEndOfLine", WebEditingCommandType::MoveToLeftEndOfLine }, | |
| 105 { "MoveToLeftEndOfLineAndModifySelection", WebEditingCommandType::MoveToLeft EndOfLineAndModifySelection }, | |
| 106 { "MoveToRightEndOfLine", WebEditingCommandType::MoveToRightEndOfLine }, | |
| 107 { "MoveToRightEndOfLineAndModifySelection", WebEditingCommandType::MoveToRig htEndOfLineAndModifySelection }, | |
| 108 { "MoveUp", WebEditingCommandType::MoveUp }, | |
| 109 { "MoveUpAndModifySelection", WebEditingCommandType::MoveUpAndModifySelectio n }, | |
| 110 { "MoveWordBackward", WebEditingCommandType::MoveWordBackward }, | |
| 111 { "MoveWordBackwardAndModifySelection", WebEditingCommandType::MoveWordBackw ardAndModifySelection }, | |
| 112 { "MoveWordForward", WebEditingCommandType::MoveWordForward }, | |
| 113 { "MoveWordForwardAndModifySelection", WebEditingCommandType::MoveWordForwar dAndModifySelection }, | |
| 114 { "MoveWordLeft", WebEditingCommandType::MoveWordLeft }, | |
| 115 { "MoveWordLeftAndModifySelection", WebEditingCommandType::MoveWordLeftAndMo difySelection }, | |
| 116 { "MoveWordRight", WebEditingCommandType::MoveWordRight }, | |
| 117 { "MoveWordRightAndModifySelection", WebEditingCommandType::MoveWordRightAnd ModifySelection }, | |
| 118 { "Outdent", WebEditingCommandType::Outdent }, | |
| 119 { "OverWrite", WebEditingCommandType::OverWrite }, | |
| 120 { "Paste", WebEditingCommandType::Paste }, | |
| 121 { "PasteAndMatchStyle", WebEditingCommandType::PasteAndMatchStyle }, | |
| 122 { "PasteGlobalSelection", WebEditingCommandType::PasteGlobalSelection }, | |
| 123 { "Print", WebEditingCommandType::Print }, | |
| 124 { "Redo", WebEditingCommandType::Redo }, | |
| 125 { "RemoveFormat", WebEditingCommandType::RemoveFormat }, | |
| 126 { "ScrollLineDown", WebEditingCommandType::ScrollLineDown }, | |
| 127 { "ScrollLineUp", WebEditingCommandType::ScrollLineUp }, | |
| 128 { "ScrollPageBackward", WebEditingCommandType::ScrollPageBackward }, | |
| 129 { "ScrollPageForward", WebEditingCommandType::ScrollPageForward }, | |
| 130 { "ScrollToBeginningOfDocument", WebEditingCommandType::ScrollToBeginningOfD ocument }, | |
| 131 { "ScrollToEndOfDocument", WebEditingCommandType::ScrollToEndOfDocument }, | |
| 132 { "SelectAll", WebEditingCommandType::SelectAll }, | |
| 133 { "SelectLine", WebEditingCommandType::SelectLine }, | |
| 134 { "SelectParagraph", WebEditingCommandType::SelectParagraph }, | |
| 135 { "SelectSentence", WebEditingCommandType::SelectSentence }, | |
| 136 { "SelectToMark", WebEditingCommandType::SelectToMark }, | |
| 137 { "SelectWord", WebEditingCommandType::SelectWord }, | |
| 138 { "SetMark", WebEditingCommandType::SetMark }, | |
| 139 { "Strikethrough", WebEditingCommandType::Strikethrough }, | |
| 140 { "StyleWithCSS", WebEditingCommandType::StyleWithCSS }, | |
| 141 { "Subscript", WebEditingCommandType::Subscript }, | |
| 142 { "Superscript", WebEditingCommandType::Superscript }, | |
| 143 { "SwapWithMark", WebEditingCommandType::SwapWithMark }, | |
| 144 { "ToggleBold", WebEditingCommandType::ToggleBold }, | |
| 145 { "ToggleItalic", WebEditingCommandType::ToggleItalic }, | |
| 146 { "ToggleUnderline", WebEditingCommandType::ToggleUnderline }, | |
| 147 { "Transpose", WebEditingCommandType::Transpose }, | |
| 148 { "Underline", WebEditingCommandType::Underline }, | |
| 149 { "Undo", WebEditingCommandType::Undo }, | |
| 150 { "Unlink", WebEditingCommandType::Unlink }, | |
| 151 { "Unscript", WebEditingCommandType::Unscript }, | |
| 152 { "Unselect", WebEditingCommandType::Unselect }, | |
| 153 { "UseCSS", WebEditingCommandType::UseCSS }, | |
| 154 { "Yank", WebEditingCommandType::Yank }, | |
| 155 { "YankAndSelect", WebEditingCommandType::YankAndSelect }, | |
| 156 }; | |
| 157 // Test all commands except WebEditingCommandType::Invalid. | |
| 158 static_assert(arraysize(kCommandNameEntries) + 1 == static_cast<int>(WebEditingC ommandType::NumberOfCommandTypes), "must test all valid WebEditingCommandType"); | |
| 159 | |
| 160 } // anonymous namespace | |
| 161 | |
| 162 class EditingCommandTest : public EditingTestBase { | |
| 163 }; | |
| 164 | |
| 165 TEST_F(EditingCommandTest, CreateCommandFromString) | |
| 166 { | |
| 167 Editor& dummyEditor = document().frame()->editor(); | |
| 168 for (const auto& entry : kCommandNameEntries) { | |
| 169 Editor::Command command = dummyEditor.createCommand(entry.name); | |
| 170 EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << ent ry.name; | |
| 171 } | |
| 172 } | |
| 173 | |
| 174 TEST_F(EditingCommandTest, CreateCommandFromStringCaseFolding) | |
| 175 { | |
| 176 Editor& dummyEditor = document().frame()->editor(); | |
| 177 for (const auto& entry : kCommandNameEntries) { | |
| 178 Editor::Command command = dummyEditor.createCommand(String(entry.name).f oldCase()); | |
| 179 EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << ent ry.name; | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 TEST_F(EditingCommandTest, CreateCommandFromInvalidString) | |
| 184 { | |
| 185 const String kInvalidCommandName[] = { | |
| 186 "", | |
| 187 "iNvAlId", | |
| 188 "12345", | |
| 189 }; | |
| 190 Editor& dummyEditor = document().frame()->editor(); | |
| 191 for (const auto& commandName : kInvalidCommandName) { | |
| 192 Editor::Command command = dummyEditor.createCommand(commandName); | |
| 193 EXPECT_EQ(0, command.idForHistogram()); | |
| 194 } | |
| 195 } | |
| 196 | |
| 197 } // namespace blink | |
| OLD | NEW |