Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2096633002: Adds scroll position/scale emulation to DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add C++ tests, clamp visual viewport position. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 #include "bindings/core/v8/V8Document.h" 33 #include "bindings/core/v8/V8Document.h"
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/Element.h" 35 #include "core/dom/Element.h"
36 #include "core/editing/FrameSelection.h" 36 #include "core/editing/FrameSelection.h"
37 #include "core/editing/InputMethodController.h" 37 #include "core/editing/InputMethodController.h"
38 #include "core/editing/markers/DocumentMarkerController.h" 38 #include "core/editing/markers/DocumentMarkerController.h"
39 #include "core/frame/EventHandlerRegistry.h" 39 #include "core/frame/EventHandlerRegistry.h"
40 #include "core/frame/FrameHost.h" 40 #include "core/frame/FrameHost.h"
41 #include "core/frame/FrameView.h" 41 #include "core/frame/FrameView.h"
42 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
43 #include "core/frame/PageScaleConstraints.h"
44 #include "core/frame/PageScaleConstraintsSet.h"
43 #include "core/frame/Settings.h" 45 #include "core/frame/Settings.h"
44 #include "core/frame/VisualViewport.h" 46 #include "core/frame/VisualViewport.h"
45 #include "core/html/HTMLDocument.h" 47 #include "core/html/HTMLDocument.h"
46 #include "core/html/HTMLIFrameElement.h" 48 #include "core/html/HTMLIFrameElement.h"
47 #include "core/html/HTMLInputElement.h" 49 #include "core/html/HTMLInputElement.h"
48 #include "core/html/HTMLTextAreaElement.h" 50 #include "core/html/HTMLTextAreaElement.h"
49 #include "core/layout/LayoutView.h" 51 #include "core/layout/LayoutView.h"
50 #include "core/loader/DocumentLoader.h" 52 #include "core/loader/DocumentLoader.h"
51 #include "core/loader/FrameLoadRequest.h" 53 #include "core/loader/FrameLoadRequest.h"
52 #include "core/page/Page.h" 54 #include "core/page/Page.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 #include "public/web/mac/WebSubstringUtil.h" 105 #include "public/web/mac/WebSubstringUtil.h"
104 #endif 106 #endif
105 107
106 using blink::FrameTestHelpers::loadFrame; 108 using blink::FrameTestHelpers::loadFrame;
107 using blink::URLTestHelpers::toKURL; 109 using blink::URLTestHelpers::toKURL;
108 using blink::URLTestHelpers::registerMockedURLLoad; 110 using blink::URLTestHelpers::registerMockedURLLoad;
109 using blink::testing::runPendingTasks; 111 using blink::testing::runPendingTasks;
110 112
111 namespace blink { 113 namespace blink {
112 114
115 #define EXPECT_POINT_EQ(expected, actual) \
116 do { \
117 EXPECT_DOUBLE_EQ((expected).x(), (actual).x()); \
118 EXPECT_DOUBLE_EQ((expected).y(), (actual).y()); \
119 } while (false)
120
121 #define EXPECT_SIZE_EQ(expected, actual) \
122 do { \
123 EXPECT_DOUBLE_EQ((expected).width(), (actual).width()); \
124 EXPECT_DOUBLE_EQ((expected).height(), (actual).height()); \
125 } while (false)
126
127 #define EXPECT_SCROLL_AND_SCALE(expectedScrollPosition, expectedVisualPosition, expectedScale, frameView, visualViewport) \
128 do { \
129 EXPECT_POINT_EQ(expectedScrollPosition, frameView->scrollPositionDouble( )); \
130 EXPECT_POINT_EQ(expectedScrollPosition, frameView->scrollAnimator().curr entPosition()); \
131 EXPECT_POINT_EQ(expectedVisualPosition, visualViewport->scrollPositionDo uble()); \
132 EXPECT_POINT_EQ(expectedVisualPosition, visualViewport->scrollAnimator() .currentPosition()); \
133 EXPECT_EQ(expectedScale, visualViewport->scale()); \
134 } while (false)
135
113 enum HorizontalScrollbarState { 136 enum HorizontalScrollbarState {
114 NoHorizontalScrollbar, 137 NoHorizontalScrollbar,
115 VisibleHorizontalScrollbar, 138 VisibleHorizontalScrollbar,
116 }; 139 };
117 140
118 enum VerticalScrollbarState { 141 enum VerticalScrollbarState {
119 NoVerticalScrollbar, 142 NoVerticalScrollbar,
120 VisibleVerticalScrollbar, 143 VisibleVerticalScrollbar,
121 }; 144 };
122 145
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 webView->setInitialFocus(false); 1083 webView->setInitialFocus(false);
1061 frame->setEditableSelectionOffsets(4, 10); 1084 frame->setEditableSelectionOffsets(4, 10);
1062 EXPECT_TRUE(webView->isSelectionAnchorFirst()); 1085 EXPECT_TRUE(webView->isSelectionAnchorFirst());
1063 WebRect anchor; 1086 WebRect anchor;
1064 WebRect focus; 1087 WebRect focus;
1065 webView->selectionBounds(anchor, focus); 1088 webView->selectionBounds(anchor, focus);
1066 frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y)) ; 1089 frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y)) ;
1067 EXPECT_FALSE(webView->isSelectionAnchorFirst()); 1090 EXPECT_FALSE(webView->isSelectionAnchorFirst());
1068 } 1091 }
1069 1092
1093 TEST_F(WebViewTest, DeviceEmulationOverridesMoveAndZoomViewports)
1094 {
1095 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
1096 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
1097 webViewImpl->resize(WebSize(100, 150));
1098 webViewImpl->resizeVisualViewport(WebSize(50, 75));
1099
1100 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
1101 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie wport();
1102 WebDeviceEmulationParams params;
1103
1104 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1105
1106 // Scroll position override moves layout viewport.
1107 params.scrollPosition = WebPoint(100, 100);
1108 params.visualViewportPosition = WebFloatPoint(-1, -1);
1109 params.visualViewportScale = 0;
1110 webViewImpl->enableDeviceEmulation(params);
1111 EXPECT_FALSE(frameView->layoutPending());
1112 EXPECT_FALSE(frameView->needsLayout());
1113 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.0, frame View, visualViewport);
1114
1115 params.scrollPosition = WebPoint(50, 50);
1116 webViewImpl->enableDeviceEmulation(params);
1117 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameVi ew, visualViewport);
1118
1119 webViewImpl->disableDeviceEmulation();
1120 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1121
1122 // Visual viewport scroll position override moves visual viewport.
1123 params.scrollPosition = WebPoint(-1, -1);
1124 params.visualViewportPosition = WebFloatPoint(50, 50);
1125 params.visualViewportScale = 0;
1126 webViewImpl->enableDeviceEmulation(params);
1127 EXPECT_FALSE(frameView->layoutPending());
1128 EXPECT_FALSE(frameView->needsLayout());
1129 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(50, 50), 1.0, frameVi ew, visualViewport);
1130
1131 params.visualViewportPosition = WebFloatPoint(25, 25);
1132 webViewImpl->enableDeviceEmulation(params);
1133 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameVi ew, visualViewport);
1134
1135 webViewImpl->disableDeviceEmulation();
1136 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1137
1138 // Page scale override zooms into page.
1139 params.scrollPosition = WebPoint(-1, -1);
1140 params.visualViewportPosition = WebFloatPoint(-1, -1);
1141 params.visualViewportScale = 2;
1142 webViewImpl->enableDeviceEmulation(params);
1143 // Scale override is enforced via constraints, which require a layout.
1144 EXPECT_TRUE(frameView->layoutPending());
1145 EXPECT_TRUE(frameView->needsLayout());
1146 frameView->layout();
bokan 2016/07/11 13:52:10 I would use webViewImpl->updateAllLifecyclePhases,
Eric Seckler 2016/07/11 16:37:13 Done.
1147 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView , visualViewport);
1148
1149 params.visualViewportScale = 1.5;
1150 webViewImpl->enableDeviceEmulation(params);
1151 EXPECT_TRUE(frameView->layoutPending());
1152 EXPECT_TRUE(frameView->needsLayout());
1153 frameView->layout();
1154 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.5, frameView , visualViewport);
1155
1156 webViewImpl->disableDeviceEmulation();
1157 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
bokan 2016/07/11 13:52:10 Should we also expect needsLayout/layoutPending he
Eric Seckler 2016/07/11 16:37:13 Theoretically yes, but disableDeviceEmulation() pe
1158
1159 // Combined override of all factors repositions and scales viewports.
1160 params.scrollPosition = WebPoint(100, 100);
1161 params.visualViewportPosition = WebFloatPoint(50, 50);
1162 params.visualViewportScale = 2;
1163 webViewImpl->enableDeviceEmulation(params);
1164 EXPECT_TRUE(frameView->layoutPending());
1165 EXPECT_TRUE(frameView->needsLayout());
1166 frameView->layout();
1167 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(50, 50), 2.0, fra meView, visualViewport);
1168
1169 params.scrollPosition = WebPoint(50, 50);
1170 params.visualViewportPosition = WebFloatPoint(25, 25);
1171 params.visualViewportScale = 1.5;
1172 webViewImpl->enableDeviceEmulation(params);
1173 EXPECT_TRUE(frameView->layoutPending());
1174 EXPECT_TRUE(frameView->needsLayout());
1175 frameView->layout();
1176 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frame View, visualViewport);
1177
1178 webViewImpl->disableDeviceEmulation();
1179 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1180 }
1181
1182 TEST_F(WebViewTest, DeviceEmulationOverridesFixScaleAndScrollPositions)
1183 {
1184 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
1185 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
1186 webViewImpl->resize(WebSize(100, 150));
1187 webViewImpl->resizeVisualViewport(WebSize(50, 75));
1188
1189 // We don't want to have to service animations for the test.
1190 webViewImpl->settings()->setEnableScrollAnimator(false);
1191
1192 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
1193 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie wport();
1194 ScrollableArea* rootScroller = frameView->getScrollableArea();
1195 WebDeviceEmulationParams params;
1196
1197 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1198
1199 // Empty overrides allow scrolling and zooming.
1200 params.scrollPosition = WebPoint(-1, -1);
1201 params.visualViewportPosition = WebFloatPoint(-1, -1);
1202 params.visualViewportScale = 0;
1203 webViewImpl->enableDeviceEmulation(params);
1204 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1205
1206 frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, Scro llBehaviorInstant);
1207 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.0, frame View, visualViewport);
1208 visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, S crollBehaviorInstant);
1209 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(50, 50), 1.0, fra meView, visualViewport);
1210 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).did Scroll());
1211 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.0, frame View, visualViewport);
1212 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).did Scroll());
1213 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameVi ew, visualViewport);
1214 webViewImpl->setPageScaleFactor(2.0);
1215 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 2.0, frameVi ew, visualViewport);
1216
1217 webViewImpl->disableDeviceEmulation();
1218 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1219
1220 // Override of scroll position fixes layout viewport, but not visual one.
1221 params.scrollPosition = WebPoint(50, 50);
1222 params.visualViewportPosition = WebFloatPoint(-1, -1);
1223 params.visualViewportScale = 0;
1224 webViewImpl->enableDeviceEmulation(params);
1225 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameVi ew, visualViewport);
1226
1227 frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, Scro llBehaviorInstant);
1228 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameVi ew, visualViewport);
1229 visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, S crollBehaviorInstant);
1230 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(50, 50), 1.0, frame View, visualViewport);
1231 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).did Scroll());
1232 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameVi ew, visualViewport);
1233 EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).di dScroll());
1234 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameVi ew, visualViewport);
1235 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(1000, 1000)).d idScroll());
1236 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(50, 75), 1.0, frame View, visualViewport);
1237 webViewImpl->setPageScaleFactor(2.0);
1238 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(50, 75), 2.0, frame View, visualViewport);
1239
1240 webViewImpl->disableDeviceEmulation();
1241 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1242
1243 // Override of visual position fixes visual viewport, but not layout one.
1244 params.scrollPosition = WebPoint(-1, -1);
1245 params.visualViewportPosition = WebFloatPoint(25, 25);
1246 params.visualViewportScale = 0;
1247 webViewImpl->enableDeviceEmulation(params);
1248 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameVi ew, visualViewport);
1249
1250 frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, Scro llBehaviorInstant);
1251 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(25, 25), 1.0, fra meView, visualViewport);
1252 visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, S crollBehaviorInstant);
1253 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(25, 25), 1.0, fra meView, visualViewport);
1254 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-100, -100)).d idScroll());
1255 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameVi ew, visualViewport);
1256 EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).di dScroll());
1257 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameVi ew, visualViewport);
1258 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(1000, 1000)).d idScroll());
1259 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 150), DoublePoint(25, 25), 1.0, fra meView, visualViewport);
1260 webViewImpl->setPageScaleFactor(2.0);
1261 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 150), DoublePoint(25, 25), 2.0, fra meView, visualViewport);
1262
1263 webViewImpl->disableDeviceEmulation();
1264 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1265
1266 // Scroll position: override of one coordinate doesn't fix other one.
1267 params.scrollPosition = WebPoint(-1, 50);
1268 params.visualViewportPosition = WebFloatPoint(-1, -1);
1269 params.visualViewportScale = 0;
1270 webViewImpl->enableDeviceEmulation(params);
1271 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 50), DoublePoint(0, 0), 1.0, frameVie w, visualViewport);
1272
1273 frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, Scro llBehaviorInstant);
1274 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 50), DoublePoint(0, 0), 1.0, frameV iew, visualViewport);
1275 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-100, -100)).d idScroll());
1276 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 50), DoublePoint(0, 0), 1.0, frameVie w, visualViewport);
1277
1278 params.scrollPosition = WebPoint(50, -1);
1279 webViewImpl->enableDeviceEmulation(params);
1280 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.0, frameVi ew, visualViewport);
1281 frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, Scro llBehaviorInstant);
1282 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 100), DoublePoint(0, 0), 1.0, frameV iew, visualViewport);
1283 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-100, -100)).d idScroll());
1284 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 0), DoublePoint(0, 0), 1.0, frameVie w, visualViewport);
1285
1286 webViewImpl->disableDeviceEmulation();
1287 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1288
1289 // Visual position: override of one coordinate doesn't fix other one.
1290 params.scrollPosition = WebPoint(-1, -1);
1291 params.visualViewportPosition = WebFloatPoint(-1, 25);
1292 params.visualViewportScale = 0;
1293 webViewImpl->enableDeviceEmulation(params);
1294 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 25), 1.0, frameVie w, visualViewport);
1295
1296 visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, S crollBehaviorInstant);
1297 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(50, 25), 1.0, frameVi ew, visualViewport);
1298 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).did Scroll());
1299 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 25), 1.0, frameVie w, visualViewport);
1300
1301 params.visualViewportPosition = WebFloatPoint(25, -1);
1302 webViewImpl->enableDeviceEmulation(params);
1303 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 25), 1.0, frameVi ew, visualViewport);
1304 visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, S crollBehaviorInstant);
1305 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 50), 1.0, frameVi ew, visualViewport);
1306 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).did Scroll());
1307 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(25, 0), 1.0, frameVie w, visualViewport);
1308
1309 webViewImpl->disableDeviceEmulation();
1310 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1311
1312 // Scale change is ignored when scale is overridden, but scrolls work.
1313 params.scrollPosition = WebPoint(-1, -1);
1314 params.visualViewportPosition = WebFloatPoint(-1, -1);
1315 params.visualViewportScale = 1.5;
1316 webViewImpl->enableDeviceEmulation(params);
1317 frameView->layout();
1318 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.5, frameView , visualViewport);
1319
1320 frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, Scro llBehaviorInstant);
1321 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.5, frame View, visualViewport);
1322 visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, S crollBehaviorInstant);
1323 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(50, 50), 1.5, fra meView, visualViewport);
1324 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).did Scroll());
1325 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 100), DoublePoint(0, 0), 1.5, frame View, visualViewport);
1326 EXPECT_TRUE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).did Scroll());
1327 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.5, frameVi ew, visualViewport);
1328 webViewImpl->setPageScaleFactor(2.0);
1329 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(0, 0), 1.5, frameVi ew, visualViewport);
1330
1331 webViewImpl->disableDeviceEmulation();
1332 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1333
1334 // Scrolling is ignored when both scroll positions are fixed, but not zoom.
1335 params.scrollPosition = WebPoint(50, 50);
1336 params.visualViewportPosition = WebFloatPoint(25, 25);
1337 params.visualViewportScale = 0;
1338 webViewImpl->enableDeviceEmulation(params);
1339 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frame View, visualViewport);
1340
1341 frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, Scro llBehaviorInstant);
1342 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frame View, visualViewport);
1343 visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, S crollBehaviorInstant);
1344 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frame View, visualViewport);
1345 EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).di dScroll());
1346 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frame View, visualViewport);
1347 EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(1000, 1000)). didScroll());
1348 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.0, frame View, visualViewport);
1349 webViewImpl->setPageScaleFactor(2.0);
1350 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 2.0, frame View, visualViewport);
1351
1352 webViewImpl->disableDeviceEmulation();
1353 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1354
1355 // Both scrolling and scale changes are ignored when they are all fixed.
1356 params.scrollPosition = WebPoint(50, 50);
1357 params.visualViewportPosition = WebFloatPoint(25, 25);
1358 params.visualViewportScale = 1.5;
1359 webViewImpl->enableDeviceEmulation(params);
1360 frameView->layout();
1361 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frame View, visualViewport);
1362
1363 frameView->setScrollPosition(DoublePoint(100, 100), ProgrammaticScroll, Scro llBehaviorInstant);
1364 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frame View, visualViewport);
1365 visualViewport->setScrollPosition(DoublePoint(50, 50), ProgrammaticScroll, S crollBehaviorInstant);
1366 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frame View, visualViewport);
1367 EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(-50, -50)).di dScroll());
1368 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frame View, visualViewport);
1369 EXPECT_FALSE(rootScroller->userScroll(ScrollByPixel, FloatSize(1000, 1000)). didScroll());
1370 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frame View, visualViewport);
1371 webViewImpl->setPageScaleFactor(2.0);
1372 EXPECT_SCROLL_AND_SCALE(DoublePoint(50, 50), DoublePoint(25, 25), 1.5, frame View, visualViewport);
1373
1374 webViewImpl->disableDeviceEmulation();
1375 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1376 }
1377
1378 TEST_F(WebViewTest, DeviceEmulationScrollOverridesAreClamped)
1379 {
1380 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
1381 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
1382 webViewImpl->resize(WebSize(100, 150));
1383 webViewImpl->resizeVisualViewport(WebSize(50, 75));
1384
1385 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
1386 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie wport();
1387 WebDeviceEmulationParams params;
1388
1389 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1390
1391 // Scroll position override is clamped to maximum.
1392 params.scrollPosition = WebPoint(1000, 1000);
1393 params.visualViewportPosition = WebFloatPoint(-1, -1);
1394 params.visualViewportScale = 0;
1395 webViewImpl->enableDeviceEmulation(params);
1396 EXPECT_SCROLL_AND_SCALE(DoublePoint(100, 150), DoublePoint(0, 0), 1.0, frame View, visualViewport);
1397
1398 webViewImpl->disableDeviceEmulation();
1399 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1400
1401 // Viewport scroll position override is clamped to maximum.
1402 params.scrollPosition = WebPoint(-1, -1);
1403 params.visualViewportPosition = WebFloatPoint(1000, 1000);
1404 params.visualViewportScale = 0;
1405 webViewImpl->enableDeviceEmulation(params);
1406 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(50, 75), 1.0, frameVi ew, visualViewport);
1407
1408 webViewImpl->disableDeviceEmulation();
1409 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1410 }
1411
1412 TEST_F(WebViewTest, DeviceEmulationDisablesAndRestoresThreadedScrolling)
1413 {
1414 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
1415 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
1416 webViewImpl->resize(WebSize(100, 150));
1417 webViewImpl->resizeVisualViewport(WebSize(50, 75));
1418
1419 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
1420 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie wport();
1421 WebDeviceEmulationParams params;
1422
1423 EXPECT_TRUE(webViewImpl->page()->settings().threadedScrollingEnabled());
1424
1425 // Setting scroll override disables threaded scrolling and sets main thread
1426 // scrolling reasons.
1427 params.scrollPosition = WebPoint(0, 0);
1428 params.visualViewportPosition = WebFloatPoint(0, 0);
1429 webViewImpl->enableDeviceEmulation(params);
1430 EXPECT_FALSE(webViewImpl->page()->settings().threadedScrollingEnabled());
1431 webViewImpl->updateAllLifecyclePhases();
1432 EXPECT_TRUE(frameView->layerForScrolling()->platformLayer()->shouldScrollOnM ainThread());
1433 EXPECT_TRUE(visualViewport->layerForScrolling()->platformLayer()->shouldScro llOnMainThread());
1434
1435 // Clearing override restores original setting.
1436 webViewImpl->disableDeviceEmulation();
1437 EXPECT_TRUE(webViewImpl->page()->settings().threadedScrollingEnabled());
1438 webViewImpl->updateAllLifecyclePhases();
1439 EXPECT_FALSE(frameView->layerForScrolling()->platformLayer()->shouldScrollOn MainThread());
1440 EXPECT_FALSE(visualViewport->layerForScrolling()->platformLayer()->shouldScr ollOnMainThread());
1441
1442 // Updating scroll override does not override stored default.
1443 params.scrollPosition = WebPoint(0, 0);
1444 params.visualViewportPosition = WebFloatPoint(0, 0);
1445 webViewImpl->enableDeviceEmulation(params);
1446 params.scrollPosition = WebPoint(100, 100);
1447 webViewImpl->enableDeviceEmulation(params);
1448 EXPECT_FALSE(webViewImpl->page()->settings().threadedScrollingEnabled());
1449 webViewImpl->updateAllLifecyclePhases();
1450 EXPECT_TRUE(frameView->layerForScrolling()->platformLayer()->shouldScrollOnM ainThread());
1451 EXPECT_TRUE(visualViewport->layerForScrolling()->platformLayer()->shouldScro llOnMainThread());
1452
1453 webViewImpl->disableDeviceEmulation();
1454 EXPECT_TRUE(webViewImpl->page()->settings().threadedScrollingEnabled());
1455 webViewImpl->updateAllLifecyclePhases();
1456 EXPECT_FALSE(frameView->layerForScrolling()->platformLayer()->shouldScrollOn MainThread());
1457 EXPECT_FALSE(visualViewport->layerForScrolling()->platformLayer()->shouldScr ollOnMainThread());
1458 }
1459
1460 TEST_F(WebViewTest, DeviceEmulationScaleOverrideDoesNotAffectMainFrameSize)
1461 {
1462 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
1463 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
1464 webViewImpl->resize(WebSize(100, 150));
1465 webViewImpl->resizeVisualViewport(WebSize(50, 75));
1466
1467 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
1468 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie wport();
1469 WebDeviceEmulationParams params;
1470
1471 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1472
1473 // Main frame size is normally calculated by dividing by minimum scale.
1474 // Since scale override changes minimum scale, we need to ensure that the
1475 // calculated main frame size does not change.
1476 IntSize expectedSize = webViewImpl->mainFrameSize();
1477 params.visualViewportScale = 2.0;
1478 webViewImpl->enableDeviceEmulation(params);
1479 frameView->layout();
1480 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView , visualViewport);
1481 EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize());
1482
1483 webViewImpl->disableDeviceEmulation();
1484 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1485 EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize());
1486
1487 // Same behavior for non-default minimum scale.
1488 webViewImpl->setDefaultPageScaleLimits(0.25, 5.0);
1489 frameView->layout();
1490 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 0.25, frameVie w, visualViewport);
1491 expectedSize = webViewImpl->mainFrameSize();
1492 params.visualViewportScale = 2.0;
1493 webViewImpl->enableDeviceEmulation(params);
1494 frameView->layout();
1495 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView , visualViewport);
1496 EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize());
bokan 2016/07/11 13:52:10 Maybe add a resize while the override is in place
Eric Seckler 2016/07/11 16:37:13 Done.
1497
1498 webViewImpl->disableDeviceEmulation();
1499 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 0.25, frameVie w, visualViewport);
1500 EXPECT_SIZE_EQ(expectedSize, webViewImpl->mainFrameSize());
1501 }
1502
1503 TEST_F(WebViewTest, DeviceEmulationScaleOverrideSetsAndRestoresPageScaleConstrai nts)
1504 {
1505 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
1506 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
1507 webViewImpl->resize(WebSize(100, 150));
1508 webViewImpl->resizeVisualViewport(WebSize(50, 75));
1509
1510 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view();
1511 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie wport();
1512 WebDeviceEmulationParams params;
1513
1514 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1515 PageScaleConstraints originalConstraints(1.0, 0.5, 2.0);
1516 webViewImpl->page()->frameHost().setUserAgentPageScaleConstraints(originalCo nstraints);
1517 frameView->layout();
1518 EXPECT_EQ(originalConstraints.initialScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().initialScale);
1519 EXPECT_EQ(originalConstraints.minimumScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().minimumScale);
1520 EXPECT_EQ(originalConstraints.maximumScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().maximumScale);
1521
1522 // Setting and clearing scale override restores original user-agent page
1523 // scale constraints setting.
1524 params.visualViewportScale = 3.0;
1525 webViewImpl->enableDeviceEmulation(params);
1526 frameView->layout();
1527 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 3.0, frameView , visualViewport);
1528 EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints() .initialScale);
1529 EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints() .minimumScale);
1530 EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints() .maximumScale);
1531
1532 params.visualViewportScale = 0;
1533 webViewImpl->enableDeviceEmulation(params);
1534 frameView->layout();
1535 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 2.0, frameView , visualViewport);
1536 EXPECT_EQ(originalConstraints.initialScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().initialScale);
1537 EXPECT_EQ(originalConstraints.minimumScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().minimumScale);
1538 EXPECT_EQ(originalConstraints.maximumScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().maximumScale);
1539
1540 // Same behavior for disabling emulation after scale override.
1541 params.visualViewportScale = 3.0;
1542 webViewImpl->enableDeviceEmulation(params);
1543 frameView->layout();
1544 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 3.0, frameView , visualViewport);
1545 EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints() .initialScale);
1546 EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints() .minimumScale);
1547 EXPECT_EQ(3.0, webViewImpl->pageScaleConstraintsSet().userAgentConstraints() .maximumScale);
1548
1549 webViewImpl->disableDeviceEmulation();
1550 EXPECT_SCROLL_AND_SCALE(DoublePoint(0, 0), DoublePoint(0, 0), 1.0, frameView , visualViewport);
1551 EXPECT_EQ(originalConstraints.initialScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().initialScale);
1552 EXPECT_EQ(originalConstraints.minimumScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().minimumScale);
1553 EXPECT_EQ(originalConstraints.maximumScale, webViewImpl->pageScaleConstraint sSet().userAgentConstraints().maximumScale);
1554 }
1555
1070 TEST_F(WebViewTest, ExitingDeviceEmulationResetsPageScale) 1556 TEST_F(WebViewTest, ExitingDeviceEmulationResetsPageScale)
1071 { 1557 {
1072 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html")); 1558 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("200-by-300.html"));
1073 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html"); 1559 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20 0-by-300.html");
1074 webViewImpl->resize(WebSize(200, 300)); 1560 webViewImpl->resize(WebSize(200, 300));
1075 1561
1076 float pageScaleExpected = webViewImpl->pageScaleFactor(); 1562 float pageScaleExpected = webViewImpl->pageScaleFactor();
1077 1563
1078 WebDeviceEmulationParams params; 1564 WebDeviceEmulationParams params;
1079 params.screenPosition = WebDeviceEmulationParams::Desktop; 1565 params.screenPosition = WebDeviceEmulationParams::Desktop;
(...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after
3132 frame->setAutofillClient(&client); 3618 frame->setAutofillClient(&client);
3133 webView->setInitialFocus(false); 3619 webView->setInitialFocus(false);
3134 3620
3135 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel lo").c_str()))); 3621 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel lo").c_str())));
3136 EXPECT_EQ(1, client.textChangesFromUserGesture()); 3622 EXPECT_EQ(1, client.textChangesFromUserGesture());
3137 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); 3623 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
3138 frame->setAutofillClient(0); 3624 frame->setAutofillClient(0);
3139 } 3625 }
3140 3626
3141 } // namespace blink 3627 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/public/web/WebDeviceEmulationParams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698