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

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: Introducing |codePointCompareIgnoringASCIICase()| Created 4 years, 8 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..864b825c37db957fb705fc3f03c6ffd13259caa0
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/EditingCommandTest.cpp
@@ -0,0 +1,73 @@
+// 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 "core/editing/commands/EditorCommandNames.h"
+#include "public/platform/WebEditingCommandType.h"
+#include "wtf/StringExtras.h"
+
+namespace blink {
+
+namespace {
+
+struct CommandNameEntry {
+ const char* name;
+ WebEditingCommandType type;
+};
+
+const CommandNameEntry kCommandNameEntries[] = {
+#define V(name) { #name, WebEditingCommandType::name },
+ FOR_EACH_BLINK_EDITING_COMMAND_NAME(V)
+#undef V
+};
+// Test all commands except WebEditingCommandType::Invalid.
+static_assert(arraysize(kCommandNameEntries) + 1 == static_cast<size_t>(WebEditingCommandType::NumberOfCommandTypes), "must test all valid WebEditingCommandType");
+
+} // anonymous namespace
+
+class EditingCommandTest : public EditingTestBase {
+};
+
+TEST_F(EditingCommandTest, EditorCommandOrder)
+{
+ for (size_t i = 1; i < arraysize(kCommandNameEntries); ++i)
+ EXPECT_GT(0, strcasecmp(kCommandNameEntries[i - 1].name, kCommandNameEntries[i].name)) << "EDITOR_COMMAND_MAP must be case-folding ordered. Incorrect index:" << i;
+}
+
+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).lower());
+ EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << entry.name;
+ command = dummyEditor.createCommand(String(entry.name).upper());
+ 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
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698