Chromium Code Reviews| Index: Source/core/rendering/RenderObjectTest.cpp |
| diff --git a/Source/core/rendering/RenderObjectTest.cpp b/Source/core/rendering/RenderObjectTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9c8d16194d8fdd44a99a66f19f06a25b17c5de74 |
| --- /dev/null |
| +++ b/Source/core/rendering/RenderObjectTest.cpp |
| @@ -0,0 +1,140 @@ |
| +/* |
| + * Copyright (C) 2014 Google Inc. All rights reserved. |
|
leviw_travelin_and_unemployed
2014/06/26 21:39:02
Elliott was telling me there's a shorter header we
chrishtr
2014/06/27 00:49:31
http://www.chromium.org/blink/coding-style#TOC-Lic
Julien - ping for review
2014/06/29 02:01:39
Switched the header to the short version. Thanks f
|
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "core/rendering/RenderObject.h" |
| + |
| +#include "core/html/HTMLElement.h" |
| +#include "core/rendering/RenderView.h" |
| +#include "core/testing/DummyPageHolder.h" |
| +#include <gtest/gtest.h> |
| + |
| +using namespace WebCore; |
| + |
| +namespace { |
| + |
| +// Base class for RenderObject testing, it exposes some useful getter. |
| +class RenderObjectTest : public testing::Test { |
| +protected: |
| + virtual void SetUp() OVERRIDE |
| + { |
| + m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| + } |
| + |
| + Document& document() const { return m_pageHolder->document(); } |
| + RenderView& view() const { return *document().renderView(); } |
| + |
| + void setHtmlInnerHTML(const char*); |
| + |
| +private: |
| + OwnPtr<DummyPageHolder> m_pageHolder; |
| +}; |
| + |
| +void RenderObjectTest::setHtmlInnerHTML(const char* htmlContent) |
| +{ |
| + document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), ASSERT_NO_EXCEPTION); |
| + document().view()->updateLayoutAndStyleIfNeededRecursive(); |
| +} |
| + |
| +TEST_F(RenderObjectTest, DisplayNoneCreateObject) |
| +{ |
| + setHtmlInnerHTML("<html><body><div style='display:none'></div></body></html>"); |
|
esprehn
2014/06/27 08:15:33
This is not right, since you innerHTML the <html>
Julien - ping for review
2014/06/29 02:01:39
Fair enough. I updated the test to follow that. No
|
| + EXPECT_EQ(nullptr, document().body()->firstChild()->renderer()); |
| +} |
| + |
| +TEST_F(RenderObjectTest, DisplayBlockCreateObject) |
| +{ |
| + setHtmlInnerHTML("<html><body><foo style='display:block'></foo></body></html>"); |
| + RenderObject* renderer = document().body()->firstChild()->renderer(); |
| + EXPECT_NE(nullptr, renderer); |
| + EXPECT_TRUE(renderer->isRenderBlockFlow()); |
| +} |
| + |
| +TEST_F(RenderObjectTest, DisplayInlineBlockCreateObject) |
| +{ |
| + setHtmlInnerHTML("<html><body><foo style='display:inline-block'></foo></body></html>"); |
| + RenderObject* renderer = document().body()->firstChild()->renderer(); |
| + EXPECT_NE(nullptr, renderer); |
| + EXPECT_TRUE(renderer->isRenderBlockFlow()); |
| +} |
| + |
| + |
| + |
| +// Containing block test. |
| +TEST_F(RenderObjectTest, ContainingBlockRenderViewShouldBeNull) |
| +{ |
| + setHtmlInnerHTML("<html><body></body></html>"); |
| + EXPECT_EQ(nullptr, view().containingBlock()); |
| +} |
| + |
| +TEST_F(RenderObjectTest, ContainingBlockBodyShouldBeDocumentElement) |
| +{ |
| + setHtmlInnerHTML("<html><body></body></html>"); |
| + EXPECT_EQ(document().body()->renderer()->containingBlock(), document().documentElement()->renderer()); |
| +} |
| + |
| +TEST_F(RenderObjectTest, ContainingBlockDocumentElementShouldBeRenderView) |
| +{ |
| + setHtmlInnerHTML("<html><body></body></html>"); |
| + EXPECT_EQ(document().documentElement()->renderer()->containingBlock(), view()); |
| +} |
| + |
| +TEST_F(RenderObjectTest, ContainingBlockStaticRendererShouldBeParent) |
| +{ |
| + setHtmlInnerHTML("<html><body><foo style='position:static'></foo></body></html>"); |
| + RenderObject* bodyRenderer = document().body()->renderer(); |
| + RenderObject* renderer = bodyRenderer->slowFirstChild(); |
| + EXPECT_EQ(renderer->containingBlock(), bodyRenderer); |
| +} |
| + |
| +TEST_F(RenderObjectTest, ContainingBlockAbsoluteRendererShouldBeRenderView) |
| +{ |
| + setHtmlInnerHTML("<html><body><foo style='position:absolute'></foo></body></html>"); |
| + RenderObject* renderer = document().body()->renderer()->slowFirstChild(); |
| + EXPECT_EQ(renderer->containingBlock(), view()); |
| +} |
| + |
| +TEST_F(RenderObjectTest, ContainingBlockAbsoluteRendererShouldBeNonStaticlyPositionedBlockAncestor) |
| +{ |
| + setHtmlInnerHTML("<html><body><div style='position:relative'><bar style='position:absolute'></bar></div></body></html>"); |
| + RenderObject* containingBlockRenderer = document().body()->renderer()->slowFirstChild(); |
| + RenderObject* renderer = containingBlockRenderer->slowFirstChild(); |
| + EXPECT_EQ(renderer->containingBlock(), containingBlockRenderer); |
| +} |
| + |
| +TEST_F(RenderObjectTest, ContainingBlockAbsoluteRendererShouldNotBeNonStaticlyPositionedInlineAncestor) |
| +{ |
| + setHtmlInnerHTML("<html><body><span style='position:relative'><bar style='position:absolute'></bar></span></body></html>"); |
| + RenderObject* bodyRenderer = document().body()->renderer(); |
| + RenderObject* renderer = bodyRenderer->slowFirstChild()->slowFirstChild(); |
| + EXPECT_EQ(renderer->containingBlock(), bodyRenderer); |
| +} |
| + |
| +} // namespace |