OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1040 } else { | 1040 } else { |
1041 ASSERT_TRUE(scroll_layer); | 1041 ASSERT_TRUE(scroll_layer); |
1042 web_scroll_layer = scroll_layer->PlatformLayer(); | 1042 web_scroll_layer = scroll_layer->PlatformLayer(); |
1043 ASSERT_TRUE(web_scroll_layer->Scrollable()); | 1043 ASSERT_TRUE(web_scroll_layer->Scrollable()); |
1044 ASSERT_FALSE( | 1044 ASSERT_FALSE( |
1045 web_scroll_layer->MainThreadScrollingReasons() & | 1045 web_scroll_layer->MainThreadScrollingReasons() & |
1046 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); | 1046 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects); |
1047 } | 1047 } |
1048 } | 1048 } |
1049 | 1049 |
1050 class StyleRelatedMainThreadScrollingReasonTest | 1050 class NonCompositedMainThreadScrollingReasonTest |
1051 : public ScrollingCoordinatorTest { | 1051 : public ScrollingCoordinatorTest { |
1052 static const uint32_t kLCDTextRelatedReasons = | 1052 static const uint32_t kLCDTextRelatedReasons = |
1053 MainThreadScrollingReason::kHasOpacityAndLCDText | | 1053 MainThreadScrollingReason::kHasOpacityAndLCDText | |
1054 MainThreadScrollingReason::kHasTransformAndLCDText | | 1054 MainThreadScrollingReason::kHasTransformAndLCDText | |
1055 MainThreadScrollingReason::kBackgroundNotOpaqueInRectAndLCDText; | 1055 MainThreadScrollingReason::kBackgroundNotOpaqueInRectAndLCDText; |
1056 | 1056 |
1057 protected: | 1057 protected: |
1058 StyleRelatedMainThreadScrollingReasonTest() { | 1058 NonCompositedMainThreadScrollingReasonTest() { |
1059 RegisterMockedHttpURLLoad("two_scrollable_area.html"); | 1059 RegisterMockedHttpURLLoad("two_scrollable_area.html"); |
1060 NavigateTo(base_url_ + "two_scrollable_area.html"); | 1060 NavigateTo(base_url_ + "two_scrollable_area.html"); |
1061 } | 1061 } |
1062 void TestStyle(const std::string& target, const uint32_t reason) { | 1062 void TestNonCompositedReasons(const std::string& target, |
1063 const uint32_t reason) { | |
1063 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled( | 1064 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled( |
1064 false); | 1065 false); |
1065 Document* document = GetFrame()->GetDocument(); | 1066 Document* document = GetFrame()->GetDocument(); |
1066 Element* container = document->GetElementById("scroller1"); | 1067 Element* container = document->GetElementById("scroller1"); |
1067 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); | 1068 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); |
1068 container = document->GetElementById("scroller2"); | |
1069 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); | |
1070 ForceFullCompositingUpdate(); | 1069 ForceFullCompositingUpdate(); |
1071 | 1070 |
1071 PaintLayerScrollableArea* scrollable_area = | |
1072 ToLayoutBoxModelObject(container->GetLayoutObject()) | |
1073 ->GetScrollableArea(); | |
1074 ASSERT_TRUE(scrollable_area); | |
1075 ASSERT_TRUE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | |
1076 reason); | |
1077 | |
1078 Element* container_2 = document->GetElementById("scroller2"); | |
tdresser
2017/04/11 18:50:48
I think container2 would be more typical.
yigu
2017/04/11 21:28:11
Done.
| |
1079 PaintLayerScrollableArea* scrollable_area_2 = | |
1080 ToLayoutBoxModelObject(container_2->GetLayoutObject()) | |
1081 ->GetScrollableArea(); | |
1082 ASSERT_TRUE(scrollable_area_2); | |
1083 // Different scrollable area should remain unaffected. | |
1084 ASSERT_FALSE( | |
tdresser
2017/04/11 18:50:48
Many of the ASSERTs in this file should be EXPECTs
yigu
2017/04/11 21:28:11
Done.
| |
1085 scrollable_area_2->GetNonCompositedMainThreadScrollingReasons() & | |
1086 reason); | |
1087 | |
1072 FrameView* frame_view = GetFrame()->View(); | 1088 FrameView* frame_view = GetFrame()->View(); |
1073 ASSERT_TRUE(frame_view); | 1089 ASSERT_TRUE(frame_view); |
1074 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); | 1090 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); |
1075 | 1091 |
1076 // Remove the target attribute from one of the scrollers. | 1092 // Remove attribute from the scroller 1 would lead to scroll on impl. |
1077 // Still need to scroll on main thread. | |
1078 container = document->GetElementById("scroller1"); | |
1079 DCHECK(container); | |
1080 | |
1081 container->removeAttribute("class"); | 1093 container->removeAttribute("class"); |
1082 ForceFullCompositingUpdate(); | 1094 ForceFullCompositingUpdate(); |
1083 | 1095 |
1084 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); | 1096 ASSERT_FALSE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & |
1085 | 1097 reason); |
1086 // Remove attribute from the other scroller would lead to | |
1087 // scroll on impl. | |
1088 container = document->GetElementById("scroller2"); | |
1089 DCHECK(container); | |
1090 | |
1091 container->removeAttribute("class"); | |
1092 ForceFullCompositingUpdate(); | |
1093 | |
1094 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); | 1098 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); |
1095 | 1099 |
1096 // Add target attribute would again lead to scroll on main thread | 1100 // Add target attribute would again lead to scroll on main thread |
1097 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); | 1101 container->setAttribute("class", target.c_str(), ASSERT_NO_EXCEPTION); |
1098 ForceFullCompositingUpdate(); | 1102 ForceFullCompositingUpdate(); |
1099 | 1103 |
1100 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); | 1104 ASSERT_TRUE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & |
1105 reason); | |
1106 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); | |
1101 | 1107 |
1102 if ((reason & kLCDTextRelatedReasons) && | 1108 if ((reason & kLCDTextRelatedReasons) && |
1103 !(reason & ~kLCDTextRelatedReasons)) { | 1109 !(reason & ~kLCDTextRelatedReasons)) { |
1104 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled( | 1110 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled( |
1105 true); | 1111 true); |
1106 ForceFullCompositingUpdate(); | 1112 ForceFullCompositingUpdate(); |
1113 ASSERT_FALSE( | |
1114 scrollable_area->GetNonCompositedMainThreadScrollingReasons()); | |
1107 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons()); | 1115 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons()); |
1108 } | 1116 } |
1109 } | 1117 } |
1110 }; | 1118 }; |
1111 | 1119 |
1112 INSTANTIATE_TEST_CASE_P(All, | 1120 INSTANTIATE_TEST_CASE_P(All, |
1113 StyleRelatedMainThreadScrollingReasonTest, | 1121 NonCompositedMainThreadScrollingReasonTest, |
1114 ::testing::Bool()); | 1122 ::testing::Bool()); |
1115 | 1123 |
1116 // TODO(yigu): This test and all other style realted main thread scrolling | 1124 TEST_P(NonCompositedMainThreadScrollingReasonTest, TransparentTest) { |
1117 // reason tests below have been disabled due to https://crbug.com/701355. | 1125 TestNonCompositedReasons("transparent", |
1118 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_TransparentTest) { | 1126 MainThreadScrollingReason::kHasOpacityAndLCDText); |
1119 TestStyle("transparent", MainThreadScrollingReason::kHasOpacityAndLCDText); | |
1120 } | 1127 } |
1121 | 1128 |
1122 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_TransformTest) { | 1129 TEST_P(NonCompositedMainThreadScrollingReasonTest, TransformTest) { |
1123 TestStyle("transform", MainThreadScrollingReason::kHasTransformAndLCDText); | 1130 TestNonCompositedReasons("transform", |
1131 MainThreadScrollingReason::kHasTransformAndLCDText); | |
1124 } | 1132 } |
1125 | 1133 |
1126 TEST_P(StyleRelatedMainThreadScrollingReasonTest, | 1134 TEST_P(NonCompositedMainThreadScrollingReasonTest, BackgroundNotOpaqueTest) { |
1127 DISABLED_BackgroundNotOpaqueTest) { | 1135 TestNonCompositedReasons( |
1128 TestStyle("background-not-opaque", | 1136 "background-not-opaque", |
1129 MainThreadScrollingReason::kBackgroundNotOpaqueInRectAndLCDText); | 1137 MainThreadScrollingReason::kBackgroundNotOpaqueInRectAndLCDText); |
1130 } | 1138 } |
1131 | 1139 |
1132 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_BorderRadiusTest) { | 1140 TEST_P(NonCompositedMainThreadScrollingReasonTest, BorderRadiusTest) { |
1133 TestStyle("border-radius", MainThreadScrollingReason::kHasBorderRadius); | 1141 TestNonCompositedReasons("border-radius", |
1142 MainThreadScrollingReason::kHasBorderRadius); | |
1134 } | 1143 } |
1135 | 1144 |
1136 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_ClipTest) { | 1145 TEST_P(NonCompositedMainThreadScrollingReasonTest, ClipTest) { |
1137 TestStyle("clip", MainThreadScrollingReason::kHasClipRelatedProperty); | 1146 TestNonCompositedReasons("clip", |
1147 MainThreadScrollingReason::kHasClipRelatedProperty); | |
1138 } | 1148 } |
1139 | 1149 |
1140 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_ClipPathTest) { | 1150 TEST_P(NonCompositedMainThreadScrollingReasonTest, ClipPathTest) { |
1141 uint32_t reason = MainThreadScrollingReason::kHasClipRelatedProperty; | 1151 uint32_t clip_reason = MainThreadScrollingReason::kHasClipRelatedProperty; |
1142 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled(false); | 1152 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled(false); |
1143 Document* document = GetFrame()->GetDocument(); | 1153 Document* document = GetFrame()->GetDocument(); |
1144 // Test ancestor with ClipPath | 1154 // Test ancestor with ClipPath |
1145 Element* element = document->body(); | 1155 Element* element = document->body(); |
1146 DCHECK(element); | 1156 DCHECK(element); |
1147 element->setAttribute(HTMLNames::styleAttr, | 1157 element->setAttribute(HTMLNames::styleAttr, |
1148 "clip-path:circle(115px at 20px 20px);"); | 1158 "clip-path:circle(115px at 20px 20px);"); |
1159 Element* container = document->getElementById("scroller1"); | |
1160 DCHECK(container); | |
1149 ForceFullCompositingUpdate(); | 1161 ForceFullCompositingUpdate(); |
1150 | 1162 |
1163 PaintLayerScrollableArea* scrollable_area = | |
1164 ToLayoutBoxModelObject(container->GetLayoutObject())->GetScrollableArea(); | |
1165 ASSERT_TRUE(scrollable_area); | |
1166 ASSERT_TRUE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & | |
1167 clip_reason); | |
1168 | |
1151 FrameView* frame_view = GetFrame()->View(); | 1169 FrameView* frame_view = GetFrame()->View(); |
1152 ASSERT_TRUE(frame_view); | 1170 ASSERT_TRUE(frame_view); |
1153 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); | 1171 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & clip_reason); |
1154 | 1172 |
1155 // Remove clip path from ancestor. | 1173 // Remove clip path from ancestor. |
1156 element->removeAttribute(HTMLNames::styleAttr); | 1174 element->removeAttribute(HTMLNames::styleAttr); |
1157 ForceFullCompositingUpdate(); | 1175 ForceFullCompositingUpdate(); |
1158 | 1176 |
1159 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); | 1177 ASSERT_FALSE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & |
1178 clip_reason); | |
1179 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & clip_reason); | |
1160 | 1180 |
1161 // Test descendant with ClipPath | 1181 // Test descendant with ClipPath |
1162 element = document->GetElementById("content1"); | 1182 element = document->GetElementById("content1"); |
1163 DCHECK(element); | 1183 DCHECK(element); |
1164 element->setAttribute(HTMLNames::styleAttr, | 1184 element->setAttribute(HTMLNames::styleAttr, |
1165 "clip-path:circle(115px at 20px 20px);"); | 1185 "clip-path:circle(115px at 20px 20px);"); |
1166 ForceFullCompositingUpdate(); | 1186 ForceFullCompositingUpdate(); |
1167 ASSERT_TRUE(frame_view->GetMainThreadScrollingReasons() & reason); | 1187 ASSERT_TRUE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & |
1188 clip_reason); | |
1189 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & clip_reason); | |
1168 | 1190 |
1169 // Remove clip path from descendant. | 1191 // Remove clip path from descendant. |
1170 element->removeAttribute(HTMLNames::styleAttr); | 1192 element->removeAttribute(HTMLNames::styleAttr); |
1171 ForceFullCompositingUpdate(); | 1193 ForceFullCompositingUpdate(); |
1172 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & reason); | 1194 ASSERT_FALSE(scrollable_area->GetNonCompositedMainThreadScrollingReasons() & |
1195 clip_reason); | |
1196 ASSERT_FALSE(frame_view->GetMainThreadScrollingReasons() & clip_reason); | |
1173 } | 1197 } |
1174 | 1198 |
1175 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_LCDTextEnabledTest) { | 1199 TEST_P(NonCompositedMainThreadScrollingReasonTest, LCDTextEnabledTest) { |
1176 TestStyle("transparent border-radius", | 1200 TestNonCompositedReasons("transparent border-radius", |
1177 MainThreadScrollingReason::kHasOpacityAndLCDText | | 1201 MainThreadScrollingReason::kHasOpacityAndLCDText | |
1178 MainThreadScrollingReason::kHasBorderRadius); | 1202 MainThreadScrollingReason::kHasBorderRadius); |
1179 } | 1203 } |
1180 | 1204 |
1181 TEST_P(StyleRelatedMainThreadScrollingReasonTest, DISABLED_BoxShadowTest) { | 1205 TEST_P(NonCompositedMainThreadScrollingReasonTest, BoxShadowTest) { |
1182 TestStyle("box-shadow", | 1206 TestNonCompositedReasons( |
1183 MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer); | 1207 "box-shadow", MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer); |
1208 } | |
1209 | |
1210 TEST_P(NonCompositedMainThreadScrollingReasonTest, | |
1211 CompositedWithLCDTextRelatedReasonsTest) { | |
1212 // With "will-change:transform" we composite elements with | |
1213 // LCDTextRelatedReasons only. For elements with other | |
1214 // NonCompositedReasons, we don't create scrollingLayer for their | |
1215 // CompositedLayerMapping therefore they don't get composited. | |
1216 GetWebViewImpl()->GetSettings()->SetPreferCompositingToLCDTextEnabled(false); | |
1217 Document* document = GetFrame()->GetDocument(); | |
1218 Element* container = document->getElementById("scroller1"); | |
1219 DCHECK(container); | |
1220 container->setAttribute("class", "composited transparent", | |
1221 ASSERT_NO_EXCEPTION); | |
1222 ForceFullCompositingUpdate(); | |
1223 | |
1224 PaintLayerScrollableArea* scrollable_area = | |
1225 ToLayoutBoxModelObject(container->GetLayoutObject())->GetScrollableArea(); | |
1226 ASSERT_TRUE(scrollable_area); | |
1227 ASSERT_FALSE(scrollable_area->GetNonCompositedMainThreadScrollingReasons()); | |
1228 | |
1229 Element* container_2 = document->getElementById("scroller2"); | |
1230 DCHECK(container_2); | |
1231 container_2->setAttribute("class", "composited border-radius", | |
1232 ASSERT_NO_EXCEPTION); | |
1233 ForceFullCompositingUpdate(); | |
1234 PaintLayerScrollableArea* scrollable_area_2 = | |
1235 ToLayoutBoxModelObject(container_2->GetLayoutObject()) | |
1236 ->GetScrollableArea(); | |
1237 ASSERT_TRUE(scrollable_area_2); | |
1238 ASSERT_TRUE(scrollable_area_2->GetNonCompositedMainThreadScrollingReasons() & | |
1239 MainThreadScrollingReason::kHasBorderRadius); | |
1184 } | 1240 } |
1185 | 1241 |
1186 } // namespace blink | 1242 } // namespace blink |
OLD | NEW |