diff options
author | yosin <yosin@chromium.org> | 2016-03-23 02:13:46 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-23 09:15:35 +0000 |
commit | f0371cdb39e34540ebb9ea0daaa962976b551b56 (patch) | |
tree | 74e3ed72bd9767fbd192c25a0de7771631b70461 | |
parent | a82bdf8c0f978ea78873ccebf45ea64c3e0a7d94 (diff) | |
download | chromium_src-f0371cdb39e34540ebb9ea0daaa962976b551b56.zip chromium_src-f0371cdb39e34540ebb9ea0daaa962976b551b56.tar.gz chromium_src-f0371cdb39e34540ebb9ea0daaa962976b551b56.tar.bz2 |
Make Editor::tidyUpHTMLStructure() handles BODY element correctly
This patch makes |Editor::tidyUpHTMLStructure()| to handle BODY element
correctly when it is document element.
Before this patch, |Editor::tidyUpHTMLStructure()| attempt to move existing
BODY element itself, this patch checks this case and not to move it into
itself.
This patch also exports HEAD element to use in unit test and adds
"HTMLHeadElement.h" into GYPI file for sane.
BUG=595606
TEST=run_webkit_unittests --gtest_filter=EditorTest.tidyUpHTMLStructure*
Review URL: https://codereview.chromium.org/1828623002
Cr-Commit-Position: refs/heads/master@{#382811}
4 files changed, 71 insertions, 2 deletions
diff --git a/third_party/WebKit/Source/core/core.gypi b/third_party/WebKit/Source/core/core.gypi index ad94327..7be236f 100644 --- a/third_party/WebKit/Source/core/core.gypi +++ b/third_party/WebKit/Source/core/core.gypi @@ -2832,6 +2832,7 @@ 'html/HTMLHRElement.cpp', 'html/HTMLHRElement.h', 'html/HTMLHeadElement.cpp', + 'html/HTMLHeadElement.h', 'html/HTMLHeadingElement.cpp', 'html/HTMLHeadingElement.h', 'html/HTMLHtmlElement.cpp', @@ -3947,6 +3948,7 @@ 'editing/EditingTestBase.cpp', 'editing/EditingTestBase.h', 'editing/EditingUtilitiesTest.cpp', + 'editing/EditorTest.cpp', 'editing/FrameSelectionTest.cpp', 'editing/GranularityStrategyTest.cpp', 'editing/InputMethodControllerTest.cpp', diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp index 1ea22e3..6442a0e 100644 --- a/third_party/WebKit/Source/core/editing/Editor.cpp +++ b/third_party/WebKit/Source/core/editing/Editor.cpp @@ -1361,7 +1361,7 @@ void Editor::tidyUpHTMLStructure(Document& document) body = existingBody.release(); else body = HTMLBodyElement::create(document); - if (document.documentElement()) + if (document.documentElement() && body != document.documentElement()) body->appendChild(document.documentElement()); root->appendChild(body.release()); ASSERT(!document.documentElement()); diff --git a/third_party/WebKit/Source/core/editing/EditorTest.cpp b/third_party/WebKit/Source/core/editing/EditorTest.cpp new file mode 100644 index 0000000..b92e8a4 --- /dev/null +++ b/third_party/WebKit/Source/core/editing/EditorTest.cpp @@ -0,0 +1,66 @@ +// Copyright 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/Editor.h" + +#include "core/dom/Document.h" +#include "core/editing/EditingTestBase.h" +#include "core/html/HTMLBodyElement.h" +#include "core/html/HTMLDivElement.h" +#include "core/html/HTMLHeadElement.h" +#include "core/html/HTMLHtmlElement.h" + +namespace blink { + +class EditorTest : public EditingTestBase { +protected: + void makeDocumentEmpty(); +}; + +void EditorTest::makeDocumentEmpty() +{ + while (document().firstChild()) + document().removeChild(document().firstChild()); +} + +TEST_F(EditorTest, tidyUpHTMLStructureFromBody) +{ + RefPtrWillBeRawPtr<Element> body = HTMLBodyElement::create(document()); + makeDocumentEmpty(); + document().setDesignMode("on"); + document().appendChild(body); + Editor::tidyUpHTMLStructure(document()); + + EXPECT_TRUE(isHTMLHtmlElement(document().documentElement())); + EXPECT_EQ(body, document().body()); + EXPECT_EQ(document().documentElement(), body->parentNode()); +} + +TEST_F(EditorTest, tidyUpHTMLStructureFromDiv) +{ + RefPtrWillBeRawPtr<Element> div = HTMLDivElement::create(document()); + makeDocumentEmpty(); + document().setDesignMode("on"); + document().appendChild(div); + Editor::tidyUpHTMLStructure(document()); + + EXPECT_TRUE(isHTMLHtmlElement(document().documentElement())); + EXPECT_TRUE(isHTMLBodyElement(document().body())); + EXPECT_EQ(document().body(), div->parentNode()); +} + +TEST_F(EditorTest, tidyUpHTMLStructureFromHead) +{ + RefPtrWillBeRawPtr<Element> head = HTMLHeadElement::create(document()); + makeDocumentEmpty(); + document().setDesignMode("on"); + document().appendChild(head); + Editor::tidyUpHTMLStructure(document()); + + EXPECT_TRUE(isHTMLHtmlElement(document().documentElement())); + EXPECT_TRUE(isHTMLBodyElement(document().body())); + EXPECT_EQ(document().documentElement(), head->parentNode()); +} + +} // namespace blink diff --git a/third_party/WebKit/Source/core/html/HTMLHeadElement.h b/third_party/WebKit/Source/core/html/HTMLHeadElement.h index 15613dd..17f8651 100644 --- a/third_party/WebKit/Source/core/html/HTMLHeadElement.h +++ b/third_party/WebKit/Source/core/html/HTMLHeadElement.h @@ -24,11 +24,12 @@ #ifndef HTMLHeadElement_h #define HTMLHeadElement_h +#include "core/CoreExport.h" #include "core/html/HTMLElement.h" namespace blink { -class HTMLHeadElement final : public HTMLElement { +class CORE_EXPORT HTMLHeadElement final : public HTMLElement { DEFINE_WRAPPERTYPEINFO(); public: DECLARE_NODE_FACTORY(HTMLHeadElement); |