Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/paint/DisplayItemList.h" | 6 #include "platform/graphics/paint/DisplayItemList.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutTestHelper.h" | 8 #include "core/layout/LayoutTestHelper.h" |
| 9 #include "core/layout/LayoutText.h" | 9 #include "core/layout/LayoutText.h" |
| 10 #include "core/layout/LayoutView.h" | 10 #include "core/layout/LayoutView.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 if (expectedSize != actual.size()) \ | 78 if (expectedSize != actual.size()) \ |
| 79 break; \ | 79 break; \ |
| 80 const TestDisplayItem expected[] = { __VA_ARGS__ }; \ | 80 const TestDisplayItem expected[] = { __VA_ARGS__ }; \ |
| 81 for (size_t index = 0; index < std::min<size_t>(actual.size(), expectedS ize); index++) { \ | 81 for (size_t index = 0; index < std::min<size_t>(actual.size(), expectedS ize); index++) { \ |
| 82 TRACE_DISPLAY_ITEMS(index, expected[index], actual[index]); \ | 82 TRACE_DISPLAY_ITEMS(index, expected[index], actual[index]); \ |
| 83 EXPECT_EQ(expected[index].client(), actual[index].client()); \ | 83 EXPECT_EQ(expected[index].client(), actual[index].client()); \ |
| 84 EXPECT_EQ(expected[index].type(), actual[index].type()); \ | 84 EXPECT_EQ(expected[index].type(), actual[index].type()); \ |
| 85 } \ | 85 } \ |
| 86 } while (false); | 86 } while (false); |
| 87 | 87 |
| 88 #ifndef NDEBUG | |
| 89 #define EXPECT_DISPLAY_LIST_WITH_DEBUG_ONLY_RED_FILL(actual, expectedSizeWithout Fill, ...) \ | |
| 90 do { \ | |
| 91 EXPECT_EQ((size_t)expectedSizeWithoutFill + 1, actual.size()); \ | |
| 92 if (expectedSizeWithoutFill + 1 != actual.size()) \ | |
| 93 break; \ | |
| 94 EXPECT_EQ(DisplayItem::DebugRedFill, actual[0].type()); \ | |
| 95 const TestDisplayItem expected[] = { __VA_ARGS__ }; \ | |
| 96 for (size_t index = 1; index < std::min<size_t>(actual.size(), expectedS izeWithoutFill + 1); index++) { \ | |
| 97 TRACE_DISPLAY_ITEMS(index, expected[index - 1], actual[index]); \ | |
| 98 EXPECT_EQ(expected[index - 1].client(), actual[index].client()); \ | |
| 99 EXPECT_EQ(expected[index - 1].type(), actual[index].type()); \ | |
| 100 } \ | |
| 101 } while (false); | |
| 102 #else | |
| 103 #define EXPECT_DISPLAY_LIST_WITH_DEBUG_ONLY_RED_FILL(actual, expectedSize, ...) \ | |
| 104 do { \ | |
| 105 EXPECT_EQ((size_t)expectedSize, actual.size()); \ | |
| 106 if (expectedSize != actual.size()) \ | |
| 107 break; \ | |
| 108 const TestDisplayItem expected[] = { __VA_ARGS__ }; \ | |
| 109 for (size_t index = 0; index < std::min<size_t>(actual.size(), expectedS ize); index++) { \ | |
| 110 TRACE_DISPLAY_ITEMS(index, expected[index], actual[index]); \ | |
| 111 EXPECT_EQ(expected[index].client(), actual[index].client()); \ | |
| 112 EXPECT_EQ(expected[index].type(), actual[index].type()); \ | |
| 113 } \ | |
| 114 } while (false); | |
| 115 #endif | |
|
Xianzhu
2015/08/13 17:03:58
Would the following work?
75s/EXPECT_DISPLAY_LIST
pdr.
2015/08/13 20:55:00
Good idea, done.
| |
| 116 | |
| 88 TEST_F(DisplayItemListPaintTest, FullDocumentPaintingWithCaret) | 117 TEST_F(DisplayItemListPaintTest, FullDocumentPaintingWithCaret) |
| 89 { | 118 { |
| 90 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'> XYZ</div>"); | 119 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'> XYZ</div>"); |
| 91 document().page()->focusController().setActive(true); | 120 document().page()->focusController().setActive(true); |
| 92 document().page()->focusController().setFocused(true); | 121 document().page()->focusController().setFocused(true); |
| 93 LayoutView& layoutView = *document().layoutView(); | 122 LayoutView& layoutView = *document().layoutView(); |
| 94 DeprecatedPaintLayer& rootLayer = *layoutView.layer(); | |
| 95 Element& div = *toElement(document().body()->firstChild()); | 123 Element& div = *toElement(document().body()->firstChild()); |
| 96 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje ct(); | 124 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje ct(); |
| 97 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject( ))->firstTextBox(); | 125 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject( ))->firstTextBox(); |
| 98 | 126 |
| 99 GraphicsContext context(&rootDisplayItemList()); | 127 document().view()->updateAllLifecyclePhases(); |
| 100 DeprecatedPaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 8 00, 600), GlobalPaintNormalPhase, LayoutSize()); | |
| 101 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); | |
| 102 rootDisplayItemList().commitNewDisplayItems(); | |
| 103 | 128 |
| 104 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 2, | 129 EXPECT_DISPLAY_LIST_WITH_DEBUG_ONLY_RED_FILL(rootDisplayItemList().displayIt ems(), 2, |
| 105 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), | 130 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), |
| 106 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground))); | 131 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground))); |
| 107 | 132 |
| 108 div.focus(); | 133 div.focus(); |
| 109 document().view()->updateAllLifecyclePhases(); | 134 document().view()->updateAllLifecyclePhases(); |
| 110 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(layoutView.displayItemC lient())); | |
| 111 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(divLayoutObject.displa yItemClient())); | |
| 112 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(textInlineBox.displayIt emClient())); | |
| 113 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); | |
| 114 rootDisplayItemList().commitNewDisplayItems(); | |
| 115 | 135 |
| 116 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 3, | 136 EXPECT_DISPLAY_LIST_WITH_DEBUG_ONLY_RED_FILL(rootDisplayItemList().displayIt ems(), 3, |
| 117 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), | 137 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), |
| 118 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), | 138 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), |
| 119 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New! | 139 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New! |
| 120 } | 140 } |
| 121 | 141 |
| 122 TEST_F(DisplayItemListPaintTest, InlineRelayout) | 142 TEST_F(DisplayItemListPaintTest, InlineRelayout) |
| 123 { | 143 { |
| 124 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA A BBBBBBBBBB</div>"); | 144 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA A BBBBBBBBBB</div>"); |
| 125 LayoutView& layoutView = *document().layoutView(); | 145 LayoutView& layoutView = *document().layoutView(); |
| 126 DeprecatedPaintLayer& rootLayer = *layoutView.layer(); | |
| 127 Element& div = *toElement(document().body()->firstChild()); | 146 Element& div = *toElement(document().body()->firstChild()); |
| 128 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo utObject()); | 147 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo utObject()); |
| 129 LayoutText& text = *toLayoutText(divBlock.firstChild()); | 148 LayoutText& text = *toLayoutText(divBlock.firstChild()); |
| 130 InlineTextBox& firstTextBox = *text.firstTextBox(); | 149 InlineTextBox& firstTextBox = *text.firstTextBox(); |
| 131 DisplayItemClient firstTextBoxDisplayItemClient = firstTextBox.displayItemCl ient(); | |
| 132 | 150 |
| 133 GraphicsContext context(&rootDisplayItemList()); | 151 document().view()->updateAllLifecyclePhases(); |
| 134 DeprecatedPaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 8 00, 600), GlobalPaintNormalPhase, LayoutSize()); | |
| 135 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); | |
| 136 rootDisplayItemList().commitNewDisplayItems(); | |
| 137 | 152 |
| 138 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 2, | 153 EXPECT_DISPLAY_LIST_WITH_DEBUG_ONLY_RED_FILL(rootDisplayItemList().displayIt ems(), 2, |
| 139 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), | 154 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), |
| 140 TestDisplayItem(firstTextBox, DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground))); | 155 TestDisplayItem(firstTextBox, DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground))); |
| 141 | 156 |
| 142 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px"); | 157 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px"); |
| 143 document().view()->updateAllLifecyclePhases(); | 158 document().view()->updateAllLifecyclePhases(); |
| 144 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(layoutView.displayItemC lient())); | |
| 145 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(divBlock.displayItemCl ient())); | |
| 146 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(firstTextBoxDisplayIte mClient)); | |
| 147 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); | |
| 148 rootDisplayItemList().commitNewDisplayItems(); | |
| 149 | 159 |
| 150 LayoutText& newText = *toLayoutText(divBlock.firstChild()); | 160 LayoutText& newText = *toLayoutText(divBlock.firstChild()); |
| 151 InlineTextBox& newFirstTextBox = *newText.firstTextBox(); | 161 InlineTextBox& newFirstTextBox = *newText.firstTextBox(); |
| 152 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox(); | 162 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox(); |
| 153 | 163 |
| 154 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 5, | 164 EXPECT_DISPLAY_LIST_WITH_DEBUG_ONLY_RED_FILL(rootDisplayItemList().displayIt ems(), 5, |
| 155 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), | 165 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), |
| 156 TestDisplayItem(divBlock, DisplayItem::paintPhaseToBeginSubtreeType(Pain tPhaseForeground)), | 166 TestDisplayItem(divBlock, DisplayItem::paintPhaseToBeginSubtreeType(Pain tPhaseForeground)), |
| 157 TestDisplayItem(newFirstTextBox, DisplayItem::paintPhaseToDrawingType(Pa intPhaseForeground)), | 167 TestDisplayItem(newFirstTextBox, DisplayItem::paintPhaseToDrawingType(Pa intPhaseForeground)), |
| 158 TestDisplayItem(secondTextBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), | 168 TestDisplayItem(secondTextBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), |
| 159 TestDisplayItem(divBlock, DisplayItem::paintPhaseToEndSubtreeType(PaintP haseForeground))); | 169 TestDisplayItem(divBlock, DisplayItem::paintPhaseToEndSubtreeType(PaintP haseForeground))); |
| 160 } | 170 } |
| 161 | 171 |
| 162 } // namespace blink | 172 } // namespace blink |
| OLD | NEW |