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 "core/layout/LayoutBox.h" | 5 #include "core/layout/LayoutBox.h" |
6 | 6 |
7 #include "core/html/HTMLElement.h" | 7 #include "core/html/HTMLElement.h" |
8 #include "core/layout/ImageQualityController.h" | 8 #include "core/layout/ImageQualityController.h" |
9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 class LayoutBoxTest : public RenderingTest { | 14 class LayoutBoxTest : public RenderingTest { |
15 }; | 15 }; |
16 | 16 |
17 TEST_F(LayoutBoxTest, BackgroundObscuredInRect) | 17 TEST_F(LayoutBoxTest, BackgroundObscuredInRect) |
18 { | 18 { |
19 setBodyInnerHTML("<style>.column { width: 295.4px; padding-left: 10.4px; } . white-background { background: red; position: relative; overflow: hidden; border -radius: 1px; }" | 19 setBodyInnerHTML("<style>.column { width: 295.4px; padding-left: 10.4px; } . white-background { background: red; position: relative; overflow: hidden; border -radius: 1px; }" |
20 ".black-background { height: 100px; background: black; color: white; } < /style>" | 20 ".black-background { height: 100px; background: black; color: white; } < /style>" |
21 "<div class='column'> <div> <div id='target' class='white-background'> < div class='black-background'></div> </div> </div> </div>"); | 21 "<div class='column'> <div> <div id='target' class='white-background'> < div class='black-background'></div> </div> </div> </div>"); |
22 LayoutObject* layoutObject = getLayoutObjectByElementId("target"); | 22 LayoutObject* layoutObject = getLayoutObjectByElementId("target"); |
23 ASSERT_TRUE(layoutObject); | 23 ASSERT_TRUE(layoutObject); |
24 ASSERT_TRUE(layoutObject->backgroundIsKnownToBeObscured()); | 24 ASSERT_TRUE(layoutObject->backgroundIsKnownToBeObscured()); |
25 } | 25 } |
26 | 26 |
27 TEST_F(LayoutBoxTest, BackgroundRect) | |
28 { | |
29 setBodyInnerHTML("<style>div { position: absolute; width: 100px; height: 100 px; padding: 10px; border: 10px solid black; overflow: scroll; }" | |
30 "#target1 { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUg ) border-box, green content-box;}" | |
31 "#target2 { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUg ) content-box, green local border-box;}" | |
32 "#target3 { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUg ) content-box, rgba(0, 255, 0, 0.5) border-box;}" | |
33 "#target4 { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUg ) content-box, green border-box multiply;}" | |
trchen
2016/08/17 01:22:55
The shorthand form doesn't seem to support backgro
| |
34 "#target5 { background: none border-box, green content-box;}" | |
35 "</style>" | |
36 "<div id='target1'></div>" | |
37 "<div id='target2'></div>" | |
38 "<div id='target3'></div>" | |
39 "<div id='target4'></div>" | |
40 "<div id='target5'></div>"); | |
41 | |
42 // #target1's opaque background color only fills the content box but its tra nslucent image extends to the borders. | |
43 LayoutBox* layoutBox = toLayoutBox(getLayoutObjectByElementId("target1")); | |
44 EXPECT_EQ(LayoutRect(20, 20, 100, 100), layoutBox->backgroundRect(Background KnownOpaqueRect)); | |
45 EXPECT_EQ(LayoutRect(0, 0, 140, 140), layoutBox->backgroundRect(BackgroundCl ipRect)); | |
46 | |
47 // #target2's background color is opaque but only fills the padding-box beca use it has local attachment. | |
48 // This eclipses the content-box image. | |
49 layoutBox = toLayoutBox(getLayoutObjectByElementId("target2")); | |
50 EXPECT_EQ(LayoutRect(10, 10, 120, 120), layoutBox->backgroundRect(Background KnownOpaqueRect)); | |
51 EXPECT_EQ(LayoutRect(10, 10, 120, 120), layoutBox->backgroundRect(Background ClipRect)); | |
52 | |
53 // #target3's background color is not opaque so we only have a clip rect. | |
54 layoutBox = toLayoutBox(getLayoutObjectByElementId("target3")); | |
55 EXPECT_TRUE(layoutBox->backgroundRect(BackgroundKnownOpaqueRect).isEmpty()); | |
56 EXPECT_EQ(LayoutRect(0, 0, 140, 140), layoutBox->backgroundRect(BackgroundCl ipRect)); | |
57 | |
58 // #target4's background color has a blend mode so it isn't opaque. | |
trchen
2016/08/17 01:22:55
Note: CSS backgrounds always create an isolated gr
| |
59 layoutBox = toLayoutBox(getLayoutObjectByElementId("target4")); | |
60 EXPECT_TRUE(layoutBox->backgroundRect(BackgroundKnownOpaqueRect).isEmpty()); | |
61 EXPECT_EQ(LayoutRect(0, 0, 140, 140), layoutBox->backgroundRect(BackgroundCl ipRect)); | |
62 | |
63 // #target5's solid background only covers the content-box but it has a "non e" background | |
64 // covering the border box. | |
65 layoutBox = toLayoutBox(getLayoutObjectByElementId("target5")); | |
66 EXPECT_EQ(LayoutRect(20, 20, 100, 100), layoutBox->backgroundRect(Background KnownOpaqueRect)); | |
67 EXPECT_EQ(LayoutRect(0, 0, 140, 140), layoutBox->backgroundRect(BackgroundCl ipRect)); | |
trchen
2016/08/17 01:22:55
This is surprising to me. I think it relies on the
| |
68 } | |
69 | |
27 } // namespace blink | 70 } // namespace blink |
OLD | NEW |