OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/layout/LayoutBlockFlow.h" |
| 7 #include "core/layout/LayoutMultiColumnFlowThread.h" |
| 8 |
| 9 #include "core/layout/LayoutTestHelper.h" |
| 10 #include <gtest/gtest.h> |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class PaginationStrutTest : public RenderingTest { |
| 15 public: |
| 16 int strutForBox(const char* blockId) |
| 17 { |
| 18 Node* node = document().getElementById(blockId); |
| 19 if (!node || !node->layoutObject() || !node->layoutObject()->isBox()) |
| 20 return std::numeric_limits<int>::min(); |
| 21 LayoutBox* box = toLayoutBox(node->layoutObject()); |
| 22 return box->paginationStrut().toInt(); |
| 23 } |
| 24 |
| 25 int strutForLine(const char* containerId, int lineIndex) |
| 26 { |
| 27 Node* node = document().getElementById(containerId); |
| 28 if (!node || !node->layoutObject() || !node->layoutObject()->isLayoutBlo
ckFlow()) |
| 29 return std::numeric_limits<int>::min(); |
| 30 LayoutBlockFlow* block = toLayoutBlockFlow(node->layoutObject()); |
| 31 if (block->multiColumnFlowThread()) |
| 32 block = block->multiColumnFlowThread(); |
| 33 for (RootInlineBox* line = block->firstRootBox(); line; line = line->nex
tRootBox(), lineIndex--) { |
| 34 if (lineIndex) |
| 35 continue; |
| 36 return line->paginationStrut().toInt(); |
| 37 } |
| 38 return std::numeric_limits<int>::min(); |
| 39 } |
| 40 }; |
| 41 |
| 42 TEST_F(PaginationStrutTest, LineWithStrut) |
| 43 { |
| 44 setBodyInnerHTML( |
| 45 "<div id='paged' style='overflow:-webkit-paged-y; height:200px; line-hei
ght:150px;'>" |
| 46 " line1<br>" |
| 47 " line2<br>" |
| 48 "</div>"); |
| 49 EXPECT_EQ(0, strutForLine("paged", 0)); |
| 50 EXPECT_EQ(50, strutForLine("paged", 1)); |
| 51 } |
| 52 |
| 53 TEST_F(PaginationStrutTest, BlockWithStrut) |
| 54 { |
| 55 setBodyInnerHTML( |
| 56 "<div style='overflow:-webkit-paged-y; height:200px; line-height:150px;'
>" |
| 57 " <div id='block1'>line1</div>" |
| 58 " <div id='block2'>line2</div>" |
| 59 "</div>"); |
| 60 EXPECT_EQ(0, strutForBox("block1")); |
| 61 EXPECT_EQ(0, strutForLine("block1", 0)); |
| 62 EXPECT_EQ(50, strutForBox("block2")); |
| 63 EXPECT_EQ(0, strutForLine("block2", 0)); |
| 64 } |
| 65 |
| 66 TEST_F(PaginationStrutTest, FloatWithStrut) |
| 67 { |
| 68 setBodyInnerHTML( |
| 69 "<div style='overflow:-webkit-paged-y; height:200px; line-height:150px;'
>" |
| 70 " <div style='height:120px;'></div>" |
| 71 " <div id='float' style='float:left;'>line</div>" |
| 72 "</div>"); |
| 73 EXPECT_EQ(80, strutForBox("float")); |
| 74 EXPECT_EQ(0, strutForLine("float", 0)); |
| 75 } |
| 76 |
| 77 TEST_F(PaginationStrutTest, UnbreakableBlockWithStrut) |
| 78 { |
| 79 setBodyInnerHTML( |
| 80 "<style>img { display:block; width:100px; height:150px; outline:4px soli
d blue; padding:0; border:none; margin:0; }</style>" |
| 81 "<div style='overflow:-webkit-paged-y; height:200px;'>" |
| 82 " <img id='img1'>" |
| 83 " <img id='img2'>" |
| 84 "</div>"); |
| 85 EXPECT_EQ(0, strutForBox("img1")); |
| 86 EXPECT_EQ(50, strutForBox("img2")); |
| 87 } |
| 88 |
| 89 TEST_F(PaginationStrutTest, BreakBefore) |
| 90 { |
| 91 setBodyInnerHTML( |
| 92 "<div style='overflow:-webkit-paged-y; height:400px; line-height:50px;'>
" |
| 93 " <div id='block1'>line1</div>" |
| 94 " <div id='block2' style='-webkit-column-break-before:always;'>line2<
/div>" |
| 95 "</div>"); |
| 96 EXPECT_EQ(0, strutForBox("block1")); |
| 97 EXPECT_EQ(0, strutForLine("block1", 0)); |
| 98 EXPECT_EQ(350, strutForBox("block2")); |
| 99 EXPECT_EQ(0, strutForLine("block2", 0)); |
| 100 } |
| 101 |
| 102 TEST_F(PaginationStrutTest, BlockWithStrutPropagatedFromInnerBlock) |
| 103 { |
| 104 setBodyInnerHTML( |
| 105 "<div style='overflow:-webkit-paged-y; height:200px; line-height:150px;'
>" |
| 106 " <div id='block1'>line1</div>" |
| 107 " <div id='block2' style='padding-top:2px;'>" |
| 108 " <div id='innerBlock' style='padding-top:2px;'>line2</div>" |
| 109 " </div>" |
| 110 "</div>"); |
| 111 EXPECT_EQ(0, strutForBox("block1")); |
| 112 EXPECT_EQ(0, strutForLine("block1", 0)); |
| 113 EXPECT_EQ(50, strutForBox("block2")); |
| 114 EXPECT_EQ(0, strutForBox("innerBlock")); |
| 115 EXPECT_EQ(0, strutForLine("innerBlock", 0)); |
| 116 } |
| 117 |
| 118 TEST_F(PaginationStrutTest, BlockWithStrutPropagatedFromUnbreakableInnerBlock) |
| 119 { |
| 120 setBodyInnerHTML( |
| 121 "<div style='overflow:-webkit-paged-y; height:400px; line-height:150px;'
>" |
| 122 " <div id='block1'>line1</div>" |
| 123 " <div id='block2' style='padding-top:2px;'>" |
| 124 " <div id='innerBlock' style='padding-top:2px; -webkit-column-bre
ak-inside:avoid;'>" |
| 125 " line2<br>" |
| 126 " line3<br>" |
| 127 " </div>" |
| 128 " </div>" |
| 129 "</div>"); |
| 130 EXPECT_EQ(0, strutForBox("block1")); |
| 131 EXPECT_EQ(0, strutForLine("block1", 0)); |
| 132 EXPECT_EQ(250, strutForBox("block2")); |
| 133 EXPECT_EQ(0, strutForBox("innerBlock")); |
| 134 EXPECT_EQ(0, strutForLine("innerBlock", 0)); |
| 135 EXPECT_EQ(0, strutForLine("innerBlock", 1)); |
| 136 } |
| 137 |
| 138 TEST_F(PaginationStrutTest, InnerBlockWithBreakBefore) |
| 139 { |
| 140 setBodyInnerHTML( |
| 141 "<div style='overflow:-webkit-paged-y; height:200px; line-height:150px;'
>" |
| 142 " <div id='block1'>line1</div>" |
| 143 " <div id='block2' style='padding-top:2px;'>" |
| 144 " <div id='innerBlock' style='padding-top:2px; -webkit-column-bre
ak-before:always;'>line2</div>" |
| 145 " </div>" |
| 146 "</div>"); |
| 147 EXPECT_EQ(0, strutForBox("block1")); |
| 148 EXPECT_EQ(0, strutForLine("block1", 0)); |
| 149 EXPECT_EQ(0, strutForBox("block2")); |
| 150 EXPECT_EQ(48, strutForBox("innerBlock")); |
| 151 EXPECT_EQ(0, strutForLine("innerBlock", 0)); |
| 152 } |
| 153 |
| 154 } // namespace blink |
OLD | NEW |