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

Unified Diff: third_party/WebKit/Source/core/editing/commands/CompositeEditCommandTest.cpp

Issue 2631133002: Make CompositeEditCommand::insertNodeBefore() to update layout for hasEditableStyle() (Closed)
Patch Set: 2017-01-16T20:09:30 Created 3 years, 11 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/commands/CompositeEditCommandTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommandTest.cpp b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommandTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9980ae51547738f68a9bc5f88111153d8fa24101
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommandTest.cpp
@@ -0,0 +1,103 @@
+// Copyright 2017 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/commands/CompositeEditCommand.h"
+
+#include "core/css/StylePropertySet.h"
+#include "core/dom/Document.h"
+#include "core/editing/EditingTestBase.h"
+#include "core/editing/FrameSelection.h"
+#include "core/frame/LocalFrame.h"
+
+namespace blink {
+
+namespace {
+
+class SampleCommand final : public CompositeEditCommand {
+ public:
+ SampleCommand(Document&);
+
+ void insertNodeBefore(
+ Node*,
+ Node* refChild,
+ EditingState*,
+ ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
+
+ // CompositeEditCommand member implementations
+ void doApply(EditingState*) final {}
+ InputEvent::InputType inputType() const final {
+ return InputEvent::InputType::None;
+ }
+};
+
+SampleCommand::SampleCommand(Document& document)
+ : CompositeEditCommand(document) {}
+
+void SampleCommand::insertNodeBefore(
+ Node* insertChild,
+ Node* refChild,
+ EditingState* editingState,
+ ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable) {
+ CompositeEditCommand::insertNodeBefore(insertChild, refChild, editingState,
+ shouldAssumeContentIsAlwaysEditable);
+}
+
+} // namespace
+
+class CompositeEditCommandTest : public EditingTestBase {};
+
+TEST_F(CompositeEditCommandTest, insertNodeBefore) {
+ setBodyContent("<div contenteditable><b></b></div>");
+ SampleCommand& sample = *new SampleCommand(document());
yoichio 2017/01/18 02:29:17 Why do you use reference than simple pointer?
yosin_UTC9 2017/01/18 03:44:14 Short form of SampleCommand* const sample = new Sa
+ Node* insertChild = document().createTextNode("foo");
+ Element* refChild = document().querySelector("b");
+ Element* div = document().querySelector("div");
+
+ EditingState editingState;
+ sample.insertNodeBefore(insertChild, refChild, &editingState);
+ EXPECT_FALSE(editingState.isAborted());
+ EXPECT_EQ("foo<b></b>", div->innerHTML());
+}
+
+TEST_F(CompositeEditCommandTest, insertNodeBeforeInUneditable) {
+ setBodyContent("<div><b></b></div>");
+ SampleCommand& sample = *new SampleCommand(document());
+ Node* insertChild = document().createTextNode("foo");
+ Element* refChild = document().querySelector("b");
+
+ EditingState editingState;
+ sample.insertNodeBefore(insertChild, refChild, &editingState);
+ EXPECT_TRUE(editingState.isAborted());
+}
+
+TEST_F(CompositeEditCommandTest, insertNodeBeforeDisconnectedNode) {
+ setBodyContent("<div><b></b></div>");
+ SampleCommand& sample = *new SampleCommand(document());
+ Node* insertChild = document().createTextNode("foo");
+ Element* refChild = document().querySelector("b");
+ Element* div = document().querySelector("div");
+ div->remove();
+
+ EditingState editingState;
+ sample.insertNodeBefore(insertChild, refChild, &editingState);
+ EXPECT_FALSE(editingState.isAborted());
+ EXPECT_EQ("<b></b>", div->innerHTML())
+ << "InsertNodeBeforeCommand does nothing for disconnected node";
+}
+
+TEST_F(CompositeEditCommandTest, insertNodeBeforeWithDirtyLayoutTree) {
+ setBodyContent("<div><b></b></div>");
+ SampleCommand& sample = *new SampleCommand(document());
+ Node* insertChild = document().createTextNode("foo");
+ Element* refChild = document().querySelector("b");
+ Element* div = document().querySelector("div");
+ div->setAttribute(HTMLNames::contenteditableAttr, "true");
+
+ EditingState editingState;
+ sample.insertNodeBefore(insertChild, refChild, &editingState);
+ EXPECT_FALSE(editingState.isAborted());
+ EXPECT_EQ("foo<b></b>", div->innerHTML());
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698