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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 #ifndef NDEBUG | 67 #ifndef NDEBUG |
| 68 #define TRACE_DISPLAY_ITEMS(i, expected, actual) \ | 68 #define TRACE_DISPLAY_ITEMS(i, expected, actual) \ |
| 69 String trace = String::format("%d: ", (int)i) + "Expected: " + (expected).as DebugString() + " Actual: " + (actual).asDebugString(); \ | 69 String trace = String::format("%d: ", (int)i) + "Expected: " + (expected).as DebugString() + " Actual: " + (actual).asDebugString(); \ |
| 70 SCOPED_TRACE(trace.utf8().data()); | 70 SCOPED_TRACE(trace.utf8().data()); |
| 71 #else | 71 #else |
| 72 #define TRACE_DISPLAY_ITEMS(i, expected, actual) | 72 #define TRACE_DISPLAY_ITEMS(i, expected, actual) |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 #define EXPECT_DISPLAY_LIST(actual, expectedSize, ...) \ | 75 #define EXPECT_DISPLAY_LIST_BASE(actual, expectedSize, ...) \ |
| 76 do { \ | 76 do { \ |
| 77 EXPECT_EQ((size_t)expectedSize, actual.size()); \ | 77 EXPECT_EQ((size_t)expectedSize, actual.size()); \ |
| 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_RED_FILL_IN_DEBUG(actual, expectedSizeWithoutFi ll, ...) \ | |
| 90 EXPECT_DISPLAY_LIST_BASE( \ | |
| 91 actual, expectedSizeWithoutFill + 1, \ | |
| 92 TestDisplayItem(*document().layoutView()->layer()->graphicsLayerBacking( ), DisplayItem::DebugRedFill), \ | |
| 93 __VA_ARGS__) | |
| 94 #else | |
| 95 #define EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG EXPECT_DISPLAY_LIST_BASE | |
| 96 #endif | |
| 97 | |
| 88 TEST_F(DisplayItemListPaintTest, FullDocumentPaintingWithCaret) | 98 TEST_F(DisplayItemListPaintTest, FullDocumentPaintingWithCaret) |
| 89 { | 99 { |
| 90 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'> XYZ</div>"); | 100 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'> XYZ</div>"); |
| 91 document().page()->focusController().setActive(true); | 101 document().page()->focusController().setActive(true); |
| 92 document().page()->focusController().setFocused(true); | 102 document().page()->focusController().setFocused(true); |
| 93 LayoutView& layoutView = *document().layoutView(); | 103 LayoutView& layoutView = *document().layoutView(); |
| 94 DeprecatedPaintLayer& rootLayer = *layoutView.layer(); | |
| 95 Element& div = *toElement(document().body()->firstChild()); | 104 Element& div = *toElement(document().body()->firstChild()); |
| 96 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje ct(); | 105 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje ct(); |
| 97 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject( ))->firstTextBox(); | 106 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject( ))->firstTextBox(); |
| 98 | 107 |
| 99 GraphicsContext context(&rootDisplayItemList()); | 108 document().view()->updateAllLifecyclePhases(); |
|
chrishtr
2015/08/13 21:33:16
Add new v2 tests rather than editing existing ones
pdr.
2015/08/14 00:10:29
These edits aren't changes to the test, they are f
| |
| 100 DeprecatedPaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 8 00, 600), GlobalPaintNormalPhase, LayoutSize()); | |
| 101 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); | |
| 102 rootDisplayItemList().commitNewDisplayItems(); | |
| 103 | 109 |
| 104 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 2, | 110 EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(rootDisplayItemList().displayItem s(), 2, |
| 105 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), | 111 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), |
| 106 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground))); | 112 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground))); |
| 107 | 113 |
| 108 div.focus(); | 114 div.focus(); |
| 109 document().view()->updateAllLifecyclePhases(); | 115 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 | 116 |
| 116 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 3, | 117 EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(rootDisplayItemList().displayItem s(), 3, |
| 117 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), | 118 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), |
| 118 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), | 119 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), |
| 119 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New! | 120 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New! |
| 120 } | 121 } |
| 121 | 122 |
| 122 TEST_F(DisplayItemListPaintTest, InlineRelayout) | 123 TEST_F(DisplayItemListPaintTest, InlineRelayout) |
| 123 { | 124 { |
| 124 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA A BBBBBBBBBB</div>"); | 125 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA A BBBBBBBBBB</div>"); |
| 125 LayoutView& layoutView = *document().layoutView(); | 126 LayoutView& layoutView = *document().layoutView(); |
| 126 DeprecatedPaintLayer& rootLayer = *layoutView.layer(); | |
| 127 Element& div = *toElement(document().body()->firstChild()); | 127 Element& div = *toElement(document().body()->firstChild()); |
| 128 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo utObject()); | 128 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo utObject()); |
| 129 LayoutText& text = *toLayoutText(divBlock.firstChild()); | 129 LayoutText& text = *toLayoutText(divBlock.firstChild()); |
| 130 InlineTextBox& firstTextBox = *text.firstTextBox(); | 130 InlineTextBox& firstTextBox = *text.firstTextBox(); |
| 131 DisplayItemClient firstTextBoxDisplayItemClient = firstTextBox.displayItemCl ient(); | |
| 132 | 131 |
| 133 GraphicsContext context(&rootDisplayItemList()); | 132 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 | 133 |
| 138 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 2, | 134 EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(rootDisplayItemList().displayItem s(), 2, |
| 139 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), | 135 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), |
| 140 TestDisplayItem(firstTextBox, DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground))); | 136 TestDisplayItem(firstTextBox, DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground))); |
| 141 | 137 |
| 142 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px"); | 138 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px"); |
| 143 document().view()->updateAllLifecyclePhases(); | 139 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 | 140 |
| 150 LayoutText& newText = *toLayoutText(divBlock.firstChild()); | 141 LayoutText& newText = *toLayoutText(divBlock.firstChild()); |
| 151 InlineTextBox& newFirstTextBox = *newText.firstTextBox(); | 142 InlineTextBox& newFirstTextBox = *newText.firstTextBox(); |
| 152 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox(); | 143 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox(); |
| 153 | 144 |
| 154 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 5, | 145 EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(rootDisplayItemList().displayItem s(), 5, |
| 155 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), | 146 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), |
| 156 TestDisplayItem(divBlock, DisplayItem::paintPhaseToBeginSubtreeType(Pain tPhaseForeground)), | 147 TestDisplayItem(divBlock, DisplayItem::paintPhaseToBeginSubtreeType(Pain tPhaseForeground)), |
| 157 TestDisplayItem(newFirstTextBox, DisplayItem::paintPhaseToDrawingType(Pa intPhaseForeground)), | 148 TestDisplayItem(newFirstTextBox, DisplayItem::paintPhaseToDrawingType(Pa intPhaseForeground)), |
| 158 TestDisplayItem(secondTextBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), | 149 TestDisplayItem(secondTextBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), |
| 159 TestDisplayItem(divBlock, DisplayItem::paintPhaseToEndSubtreeType(PaintP haseForeground))); | 150 TestDisplayItem(divBlock, DisplayItem::paintPhaseToEndSubtreeType(PaintP haseForeground))); |
| 160 } | 151 } |
| 161 | 152 |
| 162 } // namespace blink | 153 } // namespace blink |
| OLD | NEW |