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

Unified Diff: third_party/WebKit/Source/core/editing/EditingCommandTest.cpp

Issue 1841143002: Add enum class |WebEditingCommandType| for EditorCommand (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/EditingCommandTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/EditingCommandTest.cpp b/third_party/WebKit/Source/core/editing/EditingCommandTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..698d75b778b6778f8775574490ffc39014f4826a
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/EditingCommandTest.cpp
@@ -0,0 +1,197 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/editing/EditingTestBase.h"
+#include "core/editing/Editor.h"
+#include "public/platform/WebEditingCommandType.h"
+
+namespace blink {
+
+namespace {
+
+const struct CommandNameEntry {
dtapuska 2016/03/29 18:47:50 This table is duplicated.. Perhaps you can place i
+ const char* name;
+ WebEditingCommandType type;
+} kCommandNameEntries[] = {
+ { "AlignCenter", WebEditingCommandType::AlignCenter },
+ { "AlignJustified", WebEditingCommandType::AlignJustified },
+ { "AlignLeft", WebEditingCommandType::AlignLeft },
+ { "AlignRight", WebEditingCommandType::AlignRight },
+ { "BackColor", WebEditingCommandType::BackColor },
+ { "BackwardDelete", WebEditingCommandType::BackwardDelete },
+ { "Bold", WebEditingCommandType::Bold },
+ { "Copy", WebEditingCommandType::Copy },
+ { "CreateLink", WebEditingCommandType::CreateLink },
+ { "Cut", WebEditingCommandType::Cut },
+ { "DefaultParagraphSeparator", WebEditingCommandType::DefaultParagraphSeparator },
+ { "Delete", WebEditingCommandType::Delete },
+ { "DeleteBackward", WebEditingCommandType::DeleteBackward },
+ { "DeleteBackwardByDecomposingPreviousCharacter", WebEditingCommandType::DeleteBackwardByDecomposingPreviousCharacter },
+ { "DeleteForward", WebEditingCommandType::DeleteForward },
+ { "DeleteToBeginningOfLine", WebEditingCommandType::DeleteToBeginningOfLine },
+ { "DeleteToBeginningOfParagraph", WebEditingCommandType::DeleteToBeginningOfParagraph },
+ { "DeleteToEndOfLine", WebEditingCommandType::DeleteToEndOfLine },
+ { "DeleteToEndOfParagraph", WebEditingCommandType::DeleteToEndOfParagraph },
+ { "DeleteToMark", WebEditingCommandType::DeleteToMark },
+ { "DeleteWordBackward", WebEditingCommandType::DeleteWordBackward },
+ { "DeleteWordForward", WebEditingCommandType::DeleteWordForward },
+ { "FindString", WebEditingCommandType::FindString },
+ { "FontName", WebEditingCommandType::FontName },
+ { "FontSize", WebEditingCommandType::FontSize },
+ { "FontSizeDelta", WebEditingCommandType::FontSizeDelta },
+ { "ForeColor", WebEditingCommandType::ForeColor },
+ { "FormatBlock", WebEditingCommandType::FormatBlock },
+ { "ForwardDelete", WebEditingCommandType::ForwardDelete },
+ { "HiliteColor", WebEditingCommandType::HiliteColor },
+ { "IgnoreSpelling", WebEditingCommandType::IgnoreSpelling },
+ { "Indent", WebEditingCommandType::Indent },
+ { "InsertBacktab", WebEditingCommandType::InsertBacktab },
+ { "InsertHorizontalRule", WebEditingCommandType::InsertHorizontalRule },
+ { "InsertHTML", WebEditingCommandType::InsertHTML },
+ { "InsertImage", WebEditingCommandType::InsertImage },
+ { "InsertLineBreak", WebEditingCommandType::InsertLineBreak },
+ { "InsertNewline", WebEditingCommandType::InsertNewline },
+ { "InsertNewlineInQuotedContent", WebEditingCommandType::InsertNewlineInQuotedContent },
+ { "InsertOrderedList", WebEditingCommandType::InsertOrderedList },
+ { "InsertParagraph", WebEditingCommandType::InsertParagraph },
+ { "InsertTab", WebEditingCommandType::InsertTab },
+ { "InsertText", WebEditingCommandType::InsertText },
+ { "InsertUnorderedList", WebEditingCommandType::InsertUnorderedList },
+ { "Italic", WebEditingCommandType::Italic },
+ { "JustifyCenter", WebEditingCommandType::JustifyCenter },
+ { "JustifyFull", WebEditingCommandType::JustifyFull },
+ { "JustifyLeft", WebEditingCommandType::JustifyLeft },
+ { "JustifyNone", WebEditingCommandType::JustifyNone },
+ { "JustifyRight", WebEditingCommandType::JustifyRight },
+ { "MakeTextWritingDirectionLeftToRight", WebEditingCommandType::MakeTextWritingDirectionLeftToRight },
+ { "MakeTextWritingDirectionNatural", WebEditingCommandType::MakeTextWritingDirectionNatural },
+ { "MakeTextWritingDirectionRightToLeft", WebEditingCommandType::MakeTextWritingDirectionRightToLeft },
+ { "MoveBackward", WebEditingCommandType::MoveBackward },
+ { "MoveBackwardAndModifySelection", WebEditingCommandType::MoveBackwardAndModifySelection },
+ { "MoveDown", WebEditingCommandType::MoveDown },
+ { "MoveDownAndModifySelection", WebEditingCommandType::MoveDownAndModifySelection },
+ { "MoveForward", WebEditingCommandType::MoveForward },
+ { "MoveForwardAndModifySelection", WebEditingCommandType::MoveForwardAndModifySelection },
+ { "MoveLeft", WebEditingCommandType::MoveLeft },
+ { "MoveLeftAndModifySelection", WebEditingCommandType::MoveLeftAndModifySelection },
+ { "MovePageDown", WebEditingCommandType::MovePageDown },
+ { "MovePageDownAndModifySelection", WebEditingCommandType::MovePageDownAndModifySelection },
+ { "MovePageUp", WebEditingCommandType::MovePageUp },
+ { "MovePageUpAndModifySelection", WebEditingCommandType::MovePageUpAndModifySelection },
+ { "MoveParagraphBackward", WebEditingCommandType::MoveParagraphBackward },
+ { "MoveParagraphBackwardAndModifySelection", WebEditingCommandType::MoveParagraphBackwardAndModifySelection },
+ { "MoveParagraphForward", WebEditingCommandType::MoveParagraphForward },
+ { "MoveParagraphForwardAndModifySelection", WebEditingCommandType::MoveParagraphForwardAndModifySelection },
+ { "MoveRight", WebEditingCommandType::MoveRight },
+ { "MoveRightAndModifySelection", WebEditingCommandType::MoveRightAndModifySelection },
+ { "MoveToBeginningOfDocument", WebEditingCommandType::MoveToBeginningOfDocument },
+ { "MoveToBeginningOfDocumentAndModifySelection", WebEditingCommandType::MoveToBeginningOfDocumentAndModifySelection },
+ { "MoveToBeginningOfLine", WebEditingCommandType::MoveToBeginningOfLine },
+ { "MoveToBeginningOfLineAndModifySelection", WebEditingCommandType::MoveToBeginningOfLineAndModifySelection },
+ { "MoveToBeginningOfParagraph", WebEditingCommandType::MoveToBeginningOfParagraph },
+ { "MoveToBeginningOfParagraphAndModifySelection", WebEditingCommandType::MoveToBeginningOfParagraphAndModifySelection },
+ { "MoveToBeginningOfSentence", WebEditingCommandType::MoveToBeginningOfSentence },
+ { "MoveToBeginningOfSentenceAndModifySelection", WebEditingCommandType::MoveToBeginningOfSentenceAndModifySelection },
+ { "MoveToEndOfDocument", WebEditingCommandType::MoveToEndOfDocument },
+ { "MoveToEndOfDocumentAndModifySelection", WebEditingCommandType::MoveToEndOfDocumentAndModifySelection },
+ { "MoveToEndOfLine", WebEditingCommandType::MoveToEndOfLine },
+ { "MoveToEndOfLineAndModifySelection", WebEditingCommandType::MoveToEndOfLineAndModifySelection },
+ { "MoveToEndOfParagraph", WebEditingCommandType::MoveToEndOfParagraph },
+ { "MoveToEndOfParagraphAndModifySelection", WebEditingCommandType::MoveToEndOfParagraphAndModifySelection },
+ { "MoveToEndOfSentence", WebEditingCommandType::MoveToEndOfSentence },
+ { "MoveToEndOfSentenceAndModifySelection", WebEditingCommandType::MoveToEndOfSentenceAndModifySelection },
+ { "MoveToLeftEndOfLine", WebEditingCommandType::MoveToLeftEndOfLine },
+ { "MoveToLeftEndOfLineAndModifySelection", WebEditingCommandType::MoveToLeftEndOfLineAndModifySelection },
+ { "MoveToRightEndOfLine", WebEditingCommandType::MoveToRightEndOfLine },
+ { "MoveToRightEndOfLineAndModifySelection", WebEditingCommandType::MoveToRightEndOfLineAndModifySelection },
+ { "MoveUp", WebEditingCommandType::MoveUp },
+ { "MoveUpAndModifySelection", WebEditingCommandType::MoveUpAndModifySelection },
+ { "MoveWordBackward", WebEditingCommandType::MoveWordBackward },
+ { "MoveWordBackwardAndModifySelection", WebEditingCommandType::MoveWordBackwardAndModifySelection },
+ { "MoveWordForward", WebEditingCommandType::MoveWordForward },
+ { "MoveWordForwardAndModifySelection", WebEditingCommandType::MoveWordForwardAndModifySelection },
+ { "MoveWordLeft", WebEditingCommandType::MoveWordLeft },
+ { "MoveWordLeftAndModifySelection", WebEditingCommandType::MoveWordLeftAndModifySelection },
+ { "MoveWordRight", WebEditingCommandType::MoveWordRight },
+ { "MoveWordRightAndModifySelection", WebEditingCommandType::MoveWordRightAndModifySelection },
+ { "Outdent", WebEditingCommandType::Outdent },
+ { "OverWrite", WebEditingCommandType::OverWrite },
+ { "Paste", WebEditingCommandType::Paste },
+ { "PasteAndMatchStyle", WebEditingCommandType::PasteAndMatchStyle },
+ { "PasteGlobalSelection", WebEditingCommandType::PasteGlobalSelection },
+ { "Print", WebEditingCommandType::Print },
+ { "Redo", WebEditingCommandType::Redo },
+ { "RemoveFormat", WebEditingCommandType::RemoveFormat },
+ { "ScrollLineDown", WebEditingCommandType::ScrollLineDown },
+ { "ScrollLineUp", WebEditingCommandType::ScrollLineUp },
+ { "ScrollPageBackward", WebEditingCommandType::ScrollPageBackward },
+ { "ScrollPageForward", WebEditingCommandType::ScrollPageForward },
+ { "ScrollToBeginningOfDocument", WebEditingCommandType::ScrollToBeginningOfDocument },
+ { "ScrollToEndOfDocument", WebEditingCommandType::ScrollToEndOfDocument },
+ { "SelectAll", WebEditingCommandType::SelectAll },
+ { "SelectLine", WebEditingCommandType::SelectLine },
+ { "SelectParagraph", WebEditingCommandType::SelectParagraph },
+ { "SelectSentence", WebEditingCommandType::SelectSentence },
+ { "SelectToMark", WebEditingCommandType::SelectToMark },
+ { "SelectWord", WebEditingCommandType::SelectWord },
+ { "SetMark", WebEditingCommandType::SetMark },
+ { "Strikethrough", WebEditingCommandType::Strikethrough },
+ { "StyleWithCSS", WebEditingCommandType::StyleWithCSS },
+ { "Subscript", WebEditingCommandType::Subscript },
+ { "Superscript", WebEditingCommandType::Superscript },
+ { "SwapWithMark", WebEditingCommandType::SwapWithMark },
+ { "ToggleBold", WebEditingCommandType::ToggleBold },
+ { "ToggleItalic", WebEditingCommandType::ToggleItalic },
+ { "ToggleUnderline", WebEditingCommandType::ToggleUnderline },
+ { "Transpose", WebEditingCommandType::Transpose },
+ { "Underline", WebEditingCommandType::Underline },
+ { "Undo", WebEditingCommandType::Undo },
+ { "Unlink", WebEditingCommandType::Unlink },
+ { "Unscript", WebEditingCommandType::Unscript },
+ { "Unselect", WebEditingCommandType::Unselect },
+ { "UseCSS", WebEditingCommandType::UseCSS },
+ { "Yank", WebEditingCommandType::Yank },
+ { "YankAndSelect", WebEditingCommandType::YankAndSelect },
+};
+// Test all commands except WebEditingCommandType::Invalid.
+static_assert(arraysize(kCommandNameEntries) + 1 == static_cast<int>(WebEditingCommandType::NumberOfCommandTypes), "must test all valid WebEditingCommandType");
+
+} // anonymous namespace
+
+class EditingCommandTest : public EditingTestBase {
+};
+
+TEST_F(EditingCommandTest, CreateCommandFromString)
+{
+ Editor& dummyEditor = document().frame()->editor();
+ for (const auto& entry : kCommandNameEntries) {
+ Editor::Command command = dummyEditor.createCommand(entry.name);
+ EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << entry.name;
+ }
+}
+
+TEST_F(EditingCommandTest, CreateCommandFromStringCaseFolding)
+{
+ Editor& dummyEditor = document().frame()->editor();
+ for (const auto& entry : kCommandNameEntries) {
+ Editor::Command command = dummyEditor.createCommand(String(entry.name).foldCase());
+ EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << entry.name;
+ }
+}
+
+TEST_F(EditingCommandTest, CreateCommandFromInvalidString)
+{
+ const String kInvalidCommandName[] = {
+ "",
+ "iNvAlId",
+ "12345",
+ };
+ Editor& dummyEditor = document().frame()->editor();
+ for (const auto& commandName : kInvalidCommandName) {
+ Editor::Command command = dummyEditor.createCommand(commandName);
+ EXPECT_EQ(0, command.idForHistogram());
+ }
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698