Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * 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
| |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "core/rendering/RenderObject.h" | |
| 33 | |
| 34 #include "core/html/HTMLElement.h" | |
| 35 #include "core/rendering/RenderView.h" | |
| 36 #include "core/testing/DummyPageHolder.h" | |
| 37 #include <gtest/gtest.h> | |
| 38 | |
| 39 using namespace WebCore; | |
| 40 | |
| 41 namespace { | |
| 42 | |
| 43 // Base class for RenderObject testing, it exposes some useful getter. | |
| 44 class RenderObjectTest : public testing::Test { | |
| 45 protected: | |
| 46 virtual void SetUp() OVERRIDE | |
| 47 { | |
| 48 m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); | |
| 49 } | |
| 50 | |
| 51 Document& document() const { return m_pageHolder->document(); } | |
| 52 RenderView& view() const { return *document().renderView(); } | |
| 53 | |
| 54 void setHtmlInnerHTML(const char*); | |
| 55 | |
| 56 private: | |
| 57 OwnPtr<DummyPageHolder> m_pageHolder; | |
| 58 }; | |
| 59 | |
| 60 void RenderObjectTest::setHtmlInnerHTML(const char* htmlContent) | |
| 61 { | |
| 62 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS SERT_NO_EXCEPTION); | |
| 63 document().view()->updateLayoutAndStyleIfNeededRecursive(); | |
| 64 } | |
| 65 | |
| 66 TEST_F(RenderObjectTest, DisplayNoneCreateObject) | |
| 67 { | |
| 68 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
| |
| 69 EXPECT_EQ(nullptr, document().body()->firstChild()->renderer()); | |
| 70 } | |
| 71 | |
| 72 TEST_F(RenderObjectTest, DisplayBlockCreateObject) | |
| 73 { | |
| 74 setHtmlInnerHTML("<html><body><foo style='display:block'></foo></body></html >"); | |
| 75 RenderObject* renderer = document().body()->firstChild()->renderer(); | |
| 76 EXPECT_NE(nullptr, renderer); | |
| 77 EXPECT_TRUE(renderer->isRenderBlockFlow()); | |
| 78 } | |
| 79 | |
| 80 TEST_F(RenderObjectTest, DisplayInlineBlockCreateObject) | |
| 81 { | |
| 82 setHtmlInnerHTML("<html><body><foo style='display:inline-block'></foo></body ></html>"); | |
| 83 RenderObject* renderer = document().body()->firstChild()->renderer(); | |
| 84 EXPECT_NE(nullptr, renderer); | |
| 85 EXPECT_TRUE(renderer->isRenderBlockFlow()); | |
| 86 } | |
| 87 | |
| 88 | |
| 89 | |
| 90 // Containing block test. | |
| 91 TEST_F(RenderObjectTest, ContainingBlockRenderViewShouldBeNull) | |
| 92 { | |
| 93 setHtmlInnerHTML("<html><body></body></html>"); | |
| 94 EXPECT_EQ(nullptr, view().containingBlock()); | |
| 95 } | |
| 96 | |
| 97 TEST_F(RenderObjectTest, ContainingBlockBodyShouldBeDocumentElement) | |
| 98 { | |
| 99 setHtmlInnerHTML("<html><body></body></html>"); | |
| 100 EXPECT_EQ(document().body()->renderer()->containingBlock(), document().docum entElement()->renderer()); | |
| 101 } | |
| 102 | |
| 103 TEST_F(RenderObjectTest, ContainingBlockDocumentElementShouldBeRenderView) | |
| 104 { | |
| 105 setHtmlInnerHTML("<html><body></body></html>"); | |
| 106 EXPECT_EQ(document().documentElement()->renderer()->containingBlock(), view( )); | |
| 107 } | |
| 108 | |
| 109 TEST_F(RenderObjectTest, ContainingBlockStaticRendererShouldBeParent) | |
| 110 { | |
| 111 setHtmlInnerHTML("<html><body><foo style='position:static'></foo></body></ht ml>"); | |
| 112 RenderObject* bodyRenderer = document().body()->renderer(); | |
| 113 RenderObject* renderer = bodyRenderer->slowFirstChild(); | |
| 114 EXPECT_EQ(renderer->containingBlock(), bodyRenderer); | |
| 115 } | |
| 116 | |
| 117 TEST_F(RenderObjectTest, ContainingBlockAbsoluteRendererShouldBeRenderView) | |
| 118 { | |
| 119 setHtmlInnerHTML("<html><body><foo style='position:absolute'></foo></body></ html>"); | |
| 120 RenderObject* renderer = document().body()->renderer()->slowFirstChild(); | |
| 121 EXPECT_EQ(renderer->containingBlock(), view()); | |
| 122 } | |
| 123 | |
| 124 TEST_F(RenderObjectTest, ContainingBlockAbsoluteRendererShouldBeNonStaticlyPosit ionedBlockAncestor) | |
| 125 { | |
| 126 setHtmlInnerHTML("<html><body><div style='position:relative'><bar style='pos ition:absolute'></bar></div></body></html>"); | |
| 127 RenderObject* containingBlockRenderer = document().body()->renderer()->slowF irstChild(); | |
| 128 RenderObject* renderer = containingBlockRenderer->slowFirstChild(); | |
| 129 EXPECT_EQ(renderer->containingBlock(), containingBlockRenderer); | |
| 130 } | |
| 131 | |
| 132 TEST_F(RenderObjectTest, ContainingBlockAbsoluteRendererShouldNotBeNonStaticlyPo sitionedInlineAncestor) | |
| 133 { | |
| 134 setHtmlInnerHTML("<html><body><span style='position:relative'><bar style='po sition:absolute'></bar></span></body></html>"); | |
| 135 RenderObject* bodyRenderer = document().body()->renderer(); | |
| 136 RenderObject* renderer = bodyRenderer->slowFirstChild()->slowFirstChild(); | |
| 137 EXPECT_EQ(renderer->containingBlock(), bodyRenderer); | |
| 138 } | |
| 139 | |
| 140 } // namespace | |
| OLD | NEW |