Chromium Code Reviews| 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..7e6d12431b85bd564b265a771972dffc12b58f1a |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/editing/EditingCommandTest.cpp |
| @@ -0,0 +1,70 @@ |
| +// 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" |
| +#include "wtf/StringExtras.h" |
| + |
| +namespace blink { |
| + |
| +namespace { |
| + |
| +struct CommandNameEntry { |
| + const char* name; |
| + WebEditingCommandType type; |
| +}; |
| + |
| +#define EDITOR_COMMAND_MAP_DECLARATION const CommandNameEntry kCommandNameEntries[] = |
| +#define EDITOR_COMMAND_MAP(name, id) { name, WebEditingCommandType::id } |
| +#include "core/editing/commands/EditorCommandData.inc" // NOLINT(build/include_order) |
| +#undef EDITOR_COMMAND_MAP |
| +#undef EDITOR_COMMAND_MAP_DECLARATION |
| +// Test all commands except WebEditingCommandType::Invalid. |
| +static_assert(arraysize(kCommandNameEntries) + 1 == static_cast<int>(WebEditingCommandType::NumberOfCommandTypes), "must test all valid WebEditingCommandType"); |
|
yosin_UTC9
2016/03/30 01:50:51
s/<int>/<size_t>/
chongz
2016/03/30 15:25:40
Done.
|
| + |
| +} // 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."; |
|
yosin_UTC9
2016/03/30 01:50:51
s/i-1/i - 1/
We may want to have "<< i" to know w
chongz
2016/03/30 15:25:40
Done.
|
| +} |
| + |
| +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 |