/* * Copyright (C) 2012 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. 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. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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 "core/layout/LayoutTableRow.h" #include "build/build_config.h" #include "core/layout/LayoutTestHelper.h" namespace blink { namespace { class LayoutTableRowDeathTest : public RenderingTest { protected: virtual void SetUp() { RenderingTest::SetUp(); row_ = LayoutTableRow::CreateAnonymous(&GetDocument()); } virtual void TearDown() { row_->Destroy(); } LayoutTableRow* row_; }; TEST_F(LayoutTableRowDeathTest, CanSetRow) { static const unsigned kRowIndex = 10; row_->SetRowIndex(kRowIndex); EXPECT_EQ(kRowIndex, row_->RowIndex()); } TEST_F(LayoutTableRowDeathTest, CanSetRowToMaxRowIndex) { row_->SetRowIndex(kMaxRowIndex); EXPECT_EQ(kMaxRowIndex, row_->RowIndex()); } // Death tests don't work properly on Android. #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) TEST_F(LayoutTableRowDeathTest, CrashIfRowOverflowOnSetting) { ASSERT_DEATH(row_->SetRowIndex(kMaxRowIndex + 1), ""); } TEST_F(LayoutTableRowDeathTest, CrashIfSettingUnsetRowIndex) { ASSERT_DEATH(row_->SetRowIndex(kUnsetRowIndex), ""); } #endif class LayoutTableRowTest : public RenderingTest { protected: LayoutTableRow* GetRowByElementId(const char* id) { return ToLayoutTableRow(GetLayoutObjectByElementId(id)); } }; TEST_F(LayoutTableRowTest, BackgroundIsKnownToBeOpaqueWithLayerAndCollapsedBorder) { SetBodyInnerHTML( "" " " " " " " "
Cell
"); EXPECT_FALSE(GetRowByElementId("row")->BackgroundIsKnownToBeOpaqueInRect( LayoutRect(0, 0, 1, 1))); } TEST_F(LayoutTableRowTest, BackgroundIsKnownToBeOpaqueWithBorderSpacing) { SetBodyInnerHTML( "" " " "
Cell
"); EXPECT_FALSE(GetRowByElementId("row")->BackgroundIsKnownToBeOpaqueInRect( LayoutRect(0, 0, 1, 1))); } TEST_F(LayoutTableRowTest, BackgroundIsKnownToBeOpaqueWithEmptyCell) { SetBodyInnerHTML( "" " " " " "
Cell
CellCell
"); EXPECT_FALSE(GetRowByElementId("row")->BackgroundIsKnownToBeOpaqueInRect( LayoutRect(0, 0, 1, 1))); } TEST_F(LayoutTableRowTest, VisualOverflow) { // +---+---+---+ // | A | | | row1 // |---| B | |---+ // | D | | C | | row2 // |---|---| | E | // | F | | | | row3 // +---+ +---+---+ // Cell D has an outline which creates overflow. SetBodyInnerHTML( "" "" " " " " " " " " " " " " " " " " " " " " " " " " "
ABC
DE
F
"); auto* row1 = GetRowByElementId("row1"); EXPECT_EQ(LayoutRect(120, 0, 210, 320), row1->ContentsVisualOverflowRect()); EXPECT_EQ(LayoutRect(0, 0, 450, 320), row1->SelfVisualOverflowRect()); auto* row2 = GetRowByElementId("row2"); EXPECT_EQ(LayoutRect(0, -10, 440, 220), row2->ContentsVisualOverflowRect()); EXPECT_EQ(LayoutRect(0, 0, 450, 210), row2->SelfVisualOverflowRect()); auto* row3 = GetRowByElementId("row3"); EXPECT_EQ(LayoutRect(), row3->ContentsVisualOverflowRect()); EXPECT_EQ(LayoutRect(0, 0, 450, 100), row3->SelfVisualOverflowRect()); } TEST_F(LayoutTableRowTest, VisualOverflowWithCollapsedBorders) { SetBodyInnerHTML( "" "" " " " " " " " " "
"); auto* row = GetRowByElementId("row"); // The row's self visual overflow covers the collapsed borders. LayoutRect expected_self_visual_overflow = row->BorderBoxRect(); expected_self_visual_overflow.ExpandEdges(LayoutUnit(1), LayoutUnit(8), LayoutUnit(5), LayoutUnit(0)); EXPECT_EQ(expected_self_visual_overflow, row->SelfVisualOverflowRect()); // The row's visual overflow covers self visual overflow and visual overflows // of all cells. LayoutRect expected_visual_overflow = row->BorderBoxRect(); expected_visual_overflow.ExpandEdges(LayoutUnit(3), LayoutUnit(8), LayoutUnit(5), LayoutUnit(3)); EXPECT_EQ(expected_visual_overflow, row->VisualOverflowRect()); } TEST_F(LayoutTableRowTest, LayoutOverflow) { SetBodyInnerHTML( "" " " " " " " "
" "
" "
"); EXPECT_EQ(LayoutRect(0, 0, 150, 150), GetRowByElementId("row")->LayoutOverflowRect()); } } // anonymous namespace } // namespace blink