| OLD | NEW |
| 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 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 mainFrameLocal->loader().load( | 1157 mainFrameLocal->loader().load( |
| 1158 FrameLoadRequest(nullptr, FrameLoader::resourceRequestFromHistoryItem(it
em1.get(), WebCachePolicy::UseProtocolCachePolicy)), | 1158 FrameLoadRequest(nullptr, FrameLoader::resourceRequestFromHistoryItem(it
em1.get(), WebCachePolicy::UseProtocolCachePolicy)), |
| 1159 FrameLoadTypeBackForward, item1.get(), HistorySameDocumentLoad); | 1159 FrameLoadTypeBackForward, item1.get(), HistorySameDocumentLoad); |
| 1160 mainFrameLocal->loader().load( | 1160 mainFrameLocal->loader().load( |
| 1161 FrameLoadRequest(nullptr, FrameLoader::resourceRequestFromHistoryItem(it
em3.get(), WebCachePolicy::UseProtocolCachePolicy)), | 1161 FrameLoadRequest(nullptr, FrameLoader::resourceRequestFromHistoryItem(it
em3.get(), WebCachePolicy::UseProtocolCachePolicy)), |
| 1162 FrameLoadTypeBackForward, item3.get(), HistorySameDocumentLoad); | 1162 FrameLoadTypeBackForward, item3.get(), HistorySameDocumentLoad); |
| 1163 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 1163 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
| 1164 EXPECT_GT(webViewImpl->mainFrame()->scrollOffset().height, 2000); | 1164 EXPECT_GT(webViewImpl->mainFrame()->scrollOffset().height, 2000); |
| 1165 } | 1165 } |
| 1166 | 1166 |
| 1167 // Tests that we restore scroll and scale *after* the fullscreen styles are |
| 1168 // removed and the page is laid out. http://crbug.com/625683. |
| 1169 TEST_F(WebViewTest, FullscreenResetScrollAndScaleFullscreenStyles) |
| 1170 { |
| 1171 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1172 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("fullscreen_
style.html")); |
| 1173 WebViewImpl* webViewImpl = |
| 1174 m_webViewHelper.initializeAndLoad(m_baseURL + "fullscreen_style.html"); |
| 1175 webViewImpl->resize(WebSize(800, 600)); |
| 1176 webViewImpl->updateAllLifecyclePhases(); |
| 1177 |
| 1178 // Scroll the page down. |
| 1179 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 2000)); |
| 1180 ASSERT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
| 1181 |
| 1182 // Enter fullscreen. |
| 1183 Element* element = static_cast<Element*>( |
| 1184 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")
); |
| 1185 webViewImpl->enterFullScreenForElement(element); |
| 1186 webViewImpl->didEnterFullscreen(); |
| 1187 webViewImpl->updateAllLifecyclePhases(); |
| 1188 |
| 1189 // Sanity-check. There should be no scrolling possible. |
| 1190 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 1191 ASSERT_EQ(0, webViewImpl->mainFrameImpl()->frameView()->maximumScrollPositio
n().y()); |
| 1192 |
| 1193 // Confirm that after exiting and doing a layout, the scroll and scale |
| 1194 // parameters are reset. The page sets display: none on overflowing elements |
| 1195 // while in fullscreen so if we try to restore before the style and layout |
| 1196 // is applied the offsets will be clamped. |
| 1197 webViewImpl->didExitFullscreen(); |
| 1198 EXPECT_TRUE(webViewImpl->mainFrameImpl()->frameView()->needsLayout()); |
| 1199 webViewImpl->updateAllLifecyclePhases(); |
| 1200 |
| 1201 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
| 1202 } |
| 1203 |
| 1204 // Tests that exiting and immediately reentering fullscreen doesn't cause the |
| 1205 // scroll and scale restoration to occur when we enter fullscreen again. |
| 1206 TEST_F(WebViewTest, FullscreenResetScrollAndScaleExitAndReenter) |
| 1207 { |
| 1208 URLTestHelpers::registerMockedURLFromBaseURL( |
| 1209 WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("fullscreen_
style.html")); |
| 1210 WebViewImpl* webViewImpl = |
| 1211 m_webViewHelper.initializeAndLoad(m_baseURL + "fullscreen_style.html"); |
| 1212 webViewImpl->resize(WebSize(800, 600)); |
| 1213 webViewImpl->updateAllLifecyclePhases(); |
| 1214 |
| 1215 // Scroll the page down. |
| 1216 webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 2000)); |
| 1217 ASSERT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
| 1218 |
| 1219 // Enter fullscreen. |
| 1220 Element* element = static_cast<Element*>( |
| 1221 webViewImpl->mainFrame()->document().getElementById("fullscreenElement")
); |
| 1222 webViewImpl->enterFullScreenForElement(element); |
| 1223 webViewImpl->didEnterFullscreen(); |
| 1224 webViewImpl->updateAllLifecyclePhases(); |
| 1225 |
| 1226 // Sanity-check. There should be no scrolling possible. |
| 1227 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 1228 ASSERT_EQ(0, webViewImpl->mainFrameImpl()->frameView()->maximumScrollPositio
n().y()); |
| 1229 |
| 1230 // Exit and, without performing a layout, reenter fullscreen again. We |
| 1231 // shouldn't try to restore the scroll and scale values when we layout to |
| 1232 // enter fullscreen. |
| 1233 webViewImpl->exitFullScreenForElement(element); |
| 1234 webViewImpl->didExitFullscreen(); |
| 1235 webViewImpl->enterFullScreenForElement(element); |
| 1236 webViewImpl->didEnterFullscreen(); |
| 1237 webViewImpl->updateAllLifecyclePhases(); |
| 1238 |
| 1239 // Sanity-check. There should be no scrolling possible. |
| 1240 ASSERT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 1241 ASSERT_EQ(0, webViewImpl->mainFrameImpl()->frameView()->maximumScrollPositio
n().y()); |
| 1242 |
| 1243 // When we exit now, we should restore the original scroll value. |
| 1244 webViewImpl->exitFullScreenForElement(element); |
| 1245 webViewImpl->didExitFullscreen(); |
| 1246 webViewImpl->updateAllLifecyclePhases(); |
| 1247 |
| 1248 EXPECT_EQ(2000, webViewImpl->mainFrame()->scrollOffset().height); |
| 1249 } |
| 1250 |
| 1167 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) | 1251 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) |
| 1168 { | 1252 { |
| 1169 FrameTestHelpers::TestWebViewClient client; | |
| 1170 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); | 1253 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); |
| 1171 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html", true, 0, &client); | 1254 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); |
| 1172 webViewImpl->resize(WebSize(100, 150)); | 1255 webViewImpl->resize(WebSize(100, 150)); |
| 1173 webViewImpl->updateAllLifecyclePhases(); | 1256 webViewImpl->updateAllLifecyclePhases(); |
| 1174 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 1257 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
| 1175 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 1258 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 1176 | 1259 |
| 1177 // Make the page scale and scroll with the given paremeters. | 1260 // Make the page scale and scroll with the given paremeters. |
| 1178 webViewImpl->setPageScaleFactor(2.0f); | 1261 webViewImpl->setPageScaleFactor(2.0f); |
| 1179 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); | 1262 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); |
| 1180 webViewImpl->setVisualViewportOffset(WebFloatPoint(12, 20)); | 1263 webViewImpl->setVisualViewportOffset(WebFloatPoint(12, 20)); |
| 1181 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 1264 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 1182 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); | 1265 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); |
| 1183 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); | 1266 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); |
| 1184 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); | 1267 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); |
| 1185 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); | 1268 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); |
| 1186 | 1269 |
| 1187 Element* element = static_cast<Element*>(webViewImpl->mainFrame()->document(
).body()); | 1270 Element* element = static_cast<Element*>(webViewImpl->mainFrame()->document(
).body()); |
| 1188 webViewImpl->enterFullScreenForElement(element); | 1271 webViewImpl->enterFullScreenForElement(element); |
| 1189 webViewImpl->didEnterFullscreen(); | 1272 webViewImpl->didEnterFullscreen(); |
| 1190 | 1273 |
| 1191 // Page scale factor must be 1.0 during fullscreen for elements to be sized | 1274 // Page scale factor must be 1.0 during fullscreen for elements to be sized |
| 1192 // properly. | 1275 // properly. |
| 1193 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); | 1276 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); |
| 1194 | 1277 |
| 1195 // Make sure fullscreen nesting doesn't disrupt scroll/scale saving. | 1278 // Make sure fullscreen nesting doesn't disrupt scroll/scale saving. |
| 1196 Element* otherElement = static_cast<Element*>(webViewImpl->mainFrame()->docu
ment().head()); | 1279 Element* otherElement = static_cast<Element*>(webViewImpl->mainFrame()->docu
ment().head()); |
| 1197 webViewImpl->enterFullScreenForElement(otherElement); | 1280 webViewImpl->enterFullScreenForElement(otherElement); |
| 1198 | 1281 |
| 1199 // Confirm that exiting fullscreen restores the parameters. | 1282 // Confirm that exiting fullscreen restores the parameters. |
| 1283 webViewImpl->exitFullScreenForElement(element); |
| 1200 webViewImpl->didExitFullscreen(); | 1284 webViewImpl->didExitFullscreen(); |
| 1285 webViewImpl->updateAllLifecyclePhases(); |
| 1286 |
| 1201 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 1287 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 1202 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); | 1288 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); |
| 1203 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); | 1289 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); |
| 1204 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); | 1290 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); |
| 1205 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); | 1291 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); |
| 1206 | |
| 1207 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | |
| 1208 } | 1292 } |
| 1209 | 1293 |
| 1210 class PrintWebViewClient : public FrameTestHelpers::TestWebViewClient { | 1294 class PrintWebViewClient : public FrameTestHelpers::TestWebViewClient { |
| 1211 public: | 1295 public: |
| 1212 PrintWebViewClient() | 1296 PrintWebViewClient() |
| 1213 : m_printCalled(false) | 1297 : m_printCalled(false) |
| 1214 { | 1298 { |
| 1215 } | 1299 } |
| 1216 | 1300 |
| 1217 // WebViewClient methods | 1301 // WebViewClient methods |
| (...skipping 1908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3126 frame->setAutofillClient(&client); | 3210 frame->setAutofillClient(&client); |
| 3127 webView->setInitialFocus(false); | 3211 webView->setInitialFocus(false); |
| 3128 | 3212 |
| 3129 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel
lo").c_str()))); | 3213 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel
lo").c_str()))); |
| 3130 EXPECT_EQ(1, client.textChangesFromUserGesture()); | 3214 EXPECT_EQ(1, client.textChangesFromUserGesture()); |
| 3131 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | 3215 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); |
| 3132 frame->setAutofillClient(0); | 3216 frame->setAutofillClient(0); |
| 3133 } | 3217 } |
| 3134 | 3218 |
| 3135 } // namespace blink | 3219 } // namespace blink |
| OLD | NEW |