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 #include "wtf/StringExtras.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 struct CommandNameEntry { | |
| 15 const char* name; | |
| 16 WebEditingCommandType type; | |
| 17 }; | |
| 18 | |
| 19 #define EDITOR_COMMAND_MAP_DECLARATION const CommandNameEntry kCommandNameEntrie s[] = | |
| 20 #define EDITOR_COMMAND_MAP(name, id) { name, WebEditingCommandType::id } | |
| 21 #include "core/editing/commands/EditorCommandData.inc" // NOLINT(build/include_o rder) | |
| 22 #undef EDITOR_COMMAND_MAP | |
| 23 #undef EDITOR_COMMAND_MAP_DECLARATION | |
| 24 // Test all commands except WebEditingCommandType::Invalid. | |
| 25 static_assert(arraysize(kCommandNameEntries) + 1 == static_cast<int>(WebEditingC ommandType::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.
| |
| 26 | |
| 27 } // anonymous namespace | |
| 28 | |
| 29 class EditingCommandTest : public EditingTestBase { | |
| 30 }; | |
| 31 | |
| 32 TEST_F(EditingCommandTest, EditorCommandOrder) | |
| 33 { | |
| 34 for (size_t i = 1; i < arraysize(kCommandNameEntries); ++i) | |
| 35 EXPECT_GT(0, strcasecmp(kCommandNameEntries[i-1].name, kCommandNameEntri es[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.
| |
| 36 } | |
| 37 | |
| 38 TEST_F(EditingCommandTest, CreateCommandFromString) | |
| 39 { | |
| 40 Editor& dummyEditor = document().frame()->editor(); | |
| 41 for (const auto& entry : kCommandNameEntries) { | |
| 42 Editor::Command command = dummyEditor.createCommand(entry.name); | |
| 43 EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << ent ry.name; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 TEST_F(EditingCommandTest, CreateCommandFromStringCaseFolding) | |
| 48 { | |
| 49 Editor& dummyEditor = document().frame()->editor(); | |
| 50 for (const auto& entry : kCommandNameEntries) { | |
| 51 Editor::Command command = dummyEditor.createCommand(String(entry.name).f oldCase()); | |
| 52 EXPECT_EQ(static_cast<int>(entry.type), command.idForHistogram()) << ent ry.name; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 TEST_F(EditingCommandTest, CreateCommandFromInvalidString) | |
| 57 { | |
| 58 const String kInvalidCommandName[] = { | |
| 59 "", | |
| 60 "iNvAlId", | |
| 61 "12345", | |
| 62 }; | |
| 63 Editor& dummyEditor = document().frame()->editor(); | |
| 64 for (const auto& commandName : kInvalidCommandName) { | |
| 65 Editor::Command command = dummyEditor.createCommand(commandName); | |
| 66 EXPECT_EQ(0, command.idForHistogram()); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 } // namespace blink | |
| OLD | NEW |