| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 return m_layerTreeView.get(); | 127 return m_layerTreeView.get(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 FakeWebFrameClient m_fakeWebFrameClient; | 130 FakeWebFrameClient m_fakeWebFrameClient; |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 OwnPtr<WebLayerTreeView> m_layerTreeView; | 133 OwnPtr<WebLayerTreeView> m_layerTreeView; |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 class WebFrameTest : public testing::Test { | 136 class WebFrameTest : public testing::Test { |
| 137 public: | 137 protected: |
| 138 WebFrameTest() | 138 WebFrameTest() |
| 139 : m_baseURL("http://www.test.com/") | 139 : m_baseURL("http://www.test.com/") |
| 140 , m_chromeURL("chrome://") | 140 , m_chromeURL("chrome://") |
| 141 , m_webView(0) | |
| 142 { | 141 { |
| 143 } | 142 } |
| 144 | 143 |
| 145 virtual ~WebFrameTest() | 144 virtual ~WebFrameTest() |
| 146 { | 145 { |
| 147 if (m_webView) | |
| 148 m_webView->close(); | |
| 149 } | |
| 150 | |
| 151 virtual void TearDown() | |
| 152 { | |
| 153 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 146 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 154 } | 147 } |
| 155 | 148 |
| 156 void registerMockedHttpURLLoad(const std::string& fileName) | 149 void registerMockedHttpURLLoad(const std::string& fileName) |
| 157 { | 150 { |
| 158 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); | 151 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); |
| 159 } | 152 } |
| 160 | 153 |
| 161 void registerMockedChromeURLLoad(const std::string& fileName) | 154 void registerMockedChromeURLLoad(const std::string& fileName) |
| 162 { | 155 { |
| 163 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_chrom
eURL.c_str()), WebString::fromUTF8(fileName.c_str())); | 156 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_chrom
eURL.c_str()), WebString::fromUTF8(fileName.c_str())); |
| 164 } | 157 } |
| 165 | 158 |
| 166 void createCompositingWebView() | 159 static void configueCompositingWebView(WebSettings* settings) |
| 167 { | 160 { |
| 168 m_fakeCompositingWebViewClient = adoptPtr(new FakeCompositingWebViewClie
nt()); | 161 settings->setForceCompositingMode(true); |
| 169 m_webView = WebView::create(m_fakeCompositingWebViewClient.get()); | 162 settings->setAcceleratedCompositingEnabled(true); |
| 170 m_webView->settings()->setJavaScriptEnabled(true); | 163 settings->setAcceleratedCompositingForFixedPositionEnabled(true); |
| 171 m_webView->settings()->setForceCompositingMode(true); | 164 settings->setAcceleratedCompositingForOverflowScrollEnabled(true); |
| 172 m_webView->settings()->setAcceleratedCompositingEnabled(true); | 165 settings->setAcceleratedCompositingForScrollableFramesEnabled(true); |
| 173 m_webView->settings()->setAcceleratedCompositingForFixedPositionEnabled(
true); | 166 settings->setCompositedScrollingForFramesEnabled(true); |
| 174 m_webView->settings()->setAcceleratedCompositingForOverflowScrollEnabled
(true); | 167 settings->setFixedPositionCreatesStackingContext(true); |
| 175 m_webView->settings()->setAcceleratedCompositingForScrollableFramesEnabl
ed(true); | |
| 176 m_webView->settings()->setCompositedScrollingForFramesEnabled(true); | |
| 177 m_webView->settings()->setFixedPositionCreatesStackingContext(true); | |
| 178 m_webView->initializeMainFrame(&m_fakeCompositingWebViewClient->m_fakeWe
bFrameClient); | |
| 179 } | 168 } |
| 180 | 169 |
| 181 protected: | 170 void initializeTextSelectionWebView(const std::string& url, FrameTestHelpers
::WebViewHelper* webViewHelper) |
| 182 WebViewImpl* webViewImpl() const { return toWebViewImpl(m_webView); } | 171 { |
| 172 webViewHelper->initializeAndLoad(url, true); |
| 173 webViewHelper->webView()->settings()->setDefaultFontSize(12); |
| 174 webViewHelper->webView()->enableFixedLayoutMode(false); |
| 175 webViewHelper->webView()->resize(WebSize(640, 480)); |
| 176 } |
| 183 | 177 |
| 184 std::string m_baseURL; | 178 std::string m_baseURL; |
| 185 std::string m_chromeURL; | 179 std::string m_chromeURL; |
| 186 OwnPtr<FakeCompositingWebViewClient> m_fakeCompositingWebViewClient; | |
| 187 | |
| 188 WebView* m_webView; | |
| 189 }; | 180 }; |
| 190 | 181 |
| 191 class UseMockScrollbarSettings { | 182 class UseMockScrollbarSettings { |
| 192 public: | 183 public: |
| 193 UseMockScrollbarSettings() | 184 UseMockScrollbarSettings() |
| 194 { | 185 { |
| 195 WebCore::Settings::setMockScrollbarsEnabled(true); | 186 WebCore::Settings::setMockScrollbarsEnabled(true); |
| 196 WebCore::RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); | 187 WebCore::RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); |
| 197 EXPECT_TRUE(WebCore::ScrollbarTheme::theme()->usesOverlayScrollbars()); | 188 EXPECT_TRUE(WebCore::ScrollbarTheme::theme()->usesOverlayScrollbars()); |
| 198 } | 189 } |
| 199 | 190 |
| 200 ~UseMockScrollbarSettings() | 191 ~UseMockScrollbarSettings() |
| 201 { | 192 { |
| 202 WebCore::Settings::setMockScrollbarsEnabled(false); | 193 WebCore::Settings::setMockScrollbarsEnabled(false); |
| 203 WebCore::RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); | 194 WebCore::RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); |
| 204 } | 195 } |
| 205 }; | 196 }; |
| 206 | 197 |
| 207 TEST_F(WebFrameTest, ContentText) | 198 TEST_F(WebFrameTest, ContentText) |
| 208 { | 199 { |
| 209 registerMockedHttpURLLoad("iframes_test.html"); | 200 registerMockedHttpURLLoad("iframes_test.html"); |
| 210 registerMockedHttpURLLoad("visible_iframe.html"); | 201 registerMockedHttpURLLoad("visible_iframe.html"); |
| 211 registerMockedHttpURLLoad("invisible_iframe.html"); | 202 registerMockedHttpURLLoad("invisible_iframe.html"); |
| 212 registerMockedHttpURLLoad("zero_sized_iframe.html"); | 203 registerMockedHttpURLLoad("zero_sized_iframe.html"); |
| 213 | 204 |
| 214 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframes_test
.html"); | 205 FrameTestHelpers::WebViewHelper webViewHelper; |
| 206 webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html"); |
| 215 | 207 |
| 216 // Now retrieve the frames text and test it only includes visible elements. | 208 // Now retrieve the frames text and test it only includes visible elements. |
| 217 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024
).utf8().data()); | 209 std::string content = std::string(webViewHelper.webView()->mainFrame()->cont
entAsText(1024).utf8().data()); |
| 218 EXPECT_NE(std::string::npos, content.find(" visible paragraph")); | 210 EXPECT_NE(std::string::npos, content.find(" visible paragraph")); |
| 219 EXPECT_NE(std::string::npos, content.find(" visible iframe")); | 211 EXPECT_NE(std::string::npos, content.find(" visible iframe")); |
| 220 EXPECT_EQ(std::string::npos, content.find(" invisible pararaph")); | 212 EXPECT_EQ(std::string::npos, content.find(" invisible pararaph")); |
| 221 EXPECT_EQ(std::string::npos, content.find(" invisible iframe")); | 213 EXPECT_EQ(std::string::npos, content.find(" invisible iframe")); |
| 222 EXPECT_EQ(std::string::npos, content.find("iframe with zero size")); | 214 EXPECT_EQ(std::string::npos, content.find("iframe with zero size")); |
| 223 } | 215 } |
| 224 | 216 |
| 225 TEST_F(WebFrameTest, FrameForEnteredContext) | 217 TEST_F(WebFrameTest, FrameForEnteredContext) |
| 226 { | 218 { |
| 227 registerMockedHttpURLLoad("iframes_test.html"); | 219 registerMockedHttpURLLoad("iframes_test.html"); |
| 228 registerMockedHttpURLLoad("visible_iframe.html"); | 220 registerMockedHttpURLLoad("visible_iframe.html"); |
| 229 registerMockedHttpURLLoad("invisible_iframe.html"); | 221 registerMockedHttpURLLoad("invisible_iframe.html"); |
| 230 registerMockedHttpURLLoad("zero_sized_iframe.html"); | 222 registerMockedHttpURLLoad("zero_sized_iframe.html"); |
| 231 | 223 |
| 232 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframes_test
.html", true); | 224 FrameTestHelpers::WebViewHelper webViewHelper; |
| 225 webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html", true); |
| 233 | 226 |
| 234 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 227 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 235 EXPECT_EQ(m_webView->mainFrame(), | 228 EXPECT_EQ(webViewHelper.webView()->mainFrame(), WebFrame::frameForContext(we
bViewHelper.webView()->mainFrame()->mainWorldScriptContext())); |
| 236 WebFrame::frameForContext( | 229 EXPECT_EQ(webViewHelper.webView()->mainFrame()->firstChild(), WebFrame::fram
eForContext(webViewHelper.webView()->mainFrame()->firstChild()->mainWorldScriptC
ontext())); |
| 237 m_webView->mainFrame()->mainWorldScriptContext())); | |
| 238 EXPECT_EQ(m_webView->mainFrame()->firstChild(), | |
| 239 WebFrame::frameForContext( | |
| 240 m_webView->mainFrame()->firstChild()->mainWorldScriptContext()
)); | |
| 241 } | 230 } |
| 242 | 231 |
| 243 TEST_F(WebFrameTest, FormWithNullFrame) | 232 TEST_F(WebFrameTest, FormWithNullFrame) |
| 244 { | 233 { |
| 245 registerMockedHttpURLLoad("form.html"); | 234 registerMockedHttpURLLoad("form.html"); |
| 246 | 235 |
| 247 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "form.html"); | 236 FrameTestHelpers::WebViewHelper webViewHelper; |
| 237 webViewHelper.initializeAndLoad(m_baseURL + "form.html"); |
| 248 | 238 |
| 249 WebVector<WebFormElement> forms; | 239 WebVector<WebFormElement> forms; |
| 250 m_webView->mainFrame()->document().forms(forms); | 240 webViewHelper.webView()->mainFrame()->document().forms(forms); |
| 251 m_webView->close(); | 241 webViewHelper.reset(); |
| 252 m_webView = 0; | |
| 253 | 242 |
| 254 EXPECT_EQ(forms.size(), 1U); | 243 EXPECT_EQ(forms.size(), 1U); |
| 255 | 244 |
| 256 // This test passes if this doesn't crash. | 245 // This test passes if this doesn't crash. |
| 257 WebSearchableFormData searchableDataForm(forms[0]); | 246 WebSearchableFormData searchableDataForm(forms[0]); |
| 258 } | 247 } |
| 259 | 248 |
| 260 TEST_F(WebFrameTest, ChromePageJavascript) | 249 TEST_F(WebFrameTest, ChromePageJavascript) |
| 261 { | 250 { |
| 262 registerMockedChromeURLLoad("history.html"); | 251 registerMockedChromeURLLoad("history.html"); |
| 263 | 252 |
| 264 // Pass true to enable JavaScript. | 253 // Pass true to enable JavaScript. |
| 265 m_webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.ht
ml", true); | 254 FrameTestHelpers::WebViewHelper webViewHelper; |
| 255 webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true); |
| 266 | 256 |
| 267 // Try to run JS against the chrome-style URL. | 257 // Try to run JS against the chrome-style URL. |
| 268 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.bod
y.appendChild(document.createTextNode('Clobbered'))"); | 258 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.appendChild(document.createTextNode('Clobbered'))"); |
| 269 | 259 |
| 270 // Required to see any updates in contentAsText. | 260 // Required to see any updates in contentAsText. |
| 271 m_webView->layout(); | 261 webViewHelper.webView()->layout(); |
| 272 | 262 |
| 273 // Now retrieve the frame's text and ensure it was modified by running javas
cript. | 263 // Now retrieve the frame's text and ensure it was modified by running javas
cript. |
| 274 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024
).utf8().data()); | 264 std::string content = std::string(webViewHelper.webView()->mainFrame()->cont
entAsText(1024).utf8().data()); |
| 275 EXPECT_NE(std::string::npos, content.find("Clobbered")); | 265 EXPECT_NE(std::string::npos, content.find("Clobbered")); |
| 276 } | 266 } |
| 277 | 267 |
| 278 TEST_F(WebFrameTest, ChromePageNoJavascript) | 268 TEST_F(WebFrameTest, ChromePageNoJavascript) |
| 279 { | 269 { |
| 280 registerMockedChromeURLLoad("history.html"); | 270 registerMockedChromeURLLoad("history.html"); |
| 281 | 271 |
| 282 /// Pass true to enable JavaScript. | 272 /// Pass true to enable JavaScript. |
| 283 m_webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.ht
ml", true); | 273 FrameTestHelpers::WebViewHelper webViewHelper; |
| 274 webViewHelper.initializeAndLoad(m_chromeURL + "history.html", true); |
| 284 | 275 |
| 285 // Try to run JS against the chrome-style URL after prohibiting it. | 276 // Try to run JS against the chrome-style URL after prohibiting it. |
| 286 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome"); | 277 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome"); |
| 287 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.bod
y.appendChild(document.createTextNode('Clobbered'))"); | 278 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.appendChild(document.createTextNode('Clobbered'))"); |
| 288 | 279 |
| 289 // Required to see any updates in contentAsText. | 280 // Required to see any updates in contentAsText. |
| 290 m_webView->layout(); | 281 webViewHelper.webView()->layout(); |
| 291 | 282 |
| 292 // Now retrieve the frame's text and ensure it wasn't modified by running ja
vascript. | 283 // Now retrieve the frame's text and ensure it wasn't modified by running ja
vascript. |
| 293 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024
).utf8().data()); | 284 std::string content = std::string(webViewHelper.webView()->mainFrame()->cont
entAsText(1024).utf8().data()); |
| 294 EXPECT_EQ(std::string::npos, content.find("Clobbered")); | 285 EXPECT_EQ(std::string::npos, content.find("Clobbered")); |
| 295 } | 286 } |
| 296 | 287 |
| 297 TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) | 288 TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) |
| 298 { | 289 { |
| 299 registerMockedHttpURLLoad("postmessage_test.html"); | 290 registerMockedHttpURLLoad("postmessage_test.html"); |
| 300 | 291 |
| 301 // Pass true to enable JavaScript. | 292 // Pass true to enable JavaScript. |
| 302 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "postmessage_
test.html", true); | 293 FrameTestHelpers::WebViewHelper webViewHelper; |
| 294 webViewHelper.initializeAndLoad(m_baseURL + "postmessage_test.html", true); |
| 303 | 295 |
| 304 // Send a message with the correct origin. | 296 // Send a message with the correct origin. |
| 305 WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(toKURL(m_baseURL))
); | 297 WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(toKURL(m_baseURL))
); |
| 306 WebDOMEvent event = m_webView->mainFrame()->document().createEvent("MessageE
vent"); | 298 WebDOMEvent event = webViewHelper.webView()->mainFrame()->document().createE
vent("MessageEvent"); |
| 307 WebDOMMessageEvent message = event.to<WebDOMMessageEvent>(); | 299 WebDOMMessageEvent message = event.to<WebDOMMessageEvent>(); |
| 308 WebSerializedScriptValue data(WebSerializedScriptValue::fromString("foo")); | 300 WebSerializedScriptValue data(WebSerializedScriptValue::fromString("foo")); |
| 309 message.initMessageEvent("message", false, false, data, "http://origin.com",
0, ""); | 301 message.initMessageEvent("message", false, false, data, "http://origin.com",
0, ""); |
| 310 m_webView->mainFrame()->dispatchMessageEventWithOriginCheck(correctOrigin, m
essage); | 302 webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(co
rrectOrigin, message); |
| 311 | 303 |
| 312 // Send another message with incorrect origin. | 304 // Send another message with incorrect origin. |
| 313 WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(toKURL(m_chromeU
RL))); | 305 WebSecurityOrigin incorrectOrigin(WebSecurityOrigin::create(toKURL(m_chromeU
RL))); |
| 314 m_webView->mainFrame()->dispatchMessageEventWithOriginCheck(incorrectOrigin,
message); | 306 webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(in
correctOrigin, message); |
| 315 | 307 |
| 316 // Required to see any updates in contentAsText. | 308 // Required to see any updates in contentAsText. |
| 317 m_webView->layout(); | 309 webViewHelper.webView()->layout(); |
| 318 | 310 |
| 319 // Verify that only the first addition is in the body of the page. | 311 // Verify that only the first addition is in the body of the page. |
| 320 std::string content = std::string(m_webView->mainFrame()->contentAsText(1024
).utf8().data()); | 312 std::string content = std::string(webViewHelper.webView()->mainFrame()->cont
entAsText(1024).utf8().data()); |
| 321 EXPECT_NE(std::string::npos, content.find("Message 1.")); | 313 EXPECT_NE(std::string::npos, content.find("Message 1.")); |
| 322 EXPECT_EQ(std::string::npos, content.find("Message 2.")); | 314 EXPECT_EQ(std::string::npos, content.find("Message 2.")); |
| 323 } | 315 } |
| 324 | 316 |
| 325 class FixedLayoutTestWebViewClient : public WebViewClient { | 317 class FixedLayoutTestWebViewClient : public WebViewClient { |
| 326 public: | 318 public: |
| 327 virtual WebScreenInfo screenInfo() OVERRIDE { return m_screenInfo; } | 319 virtual WebScreenInfo screenInfo() OVERRIDE { return m_screenInfo; } |
| 328 | 320 |
| 329 WebScreenInfo m_screenInfo; | 321 WebScreenInfo m_screenInfo; |
| 330 }; | 322 }; |
| 331 | 323 |
| 332 TEST_F(WebFrameTest, FrameViewNeedsLayoutOnFixedLayoutResize) | 324 TEST_F(WebFrameTest, FrameViewNeedsLayoutOnFixedLayoutResize) |
| 333 { | 325 { |
| 334 registerMockedHttpURLLoad("fixed_layout.html"); | 326 registerMockedHttpURLLoad("fixed_layout.html"); |
| 335 | 327 |
| 336 FixedLayoutTestWebViewClient client; | 328 FixedLayoutTestWebViewClient client; |
| 337 int viewportWidth = 640; | 329 int viewportWidth = 640; |
| 338 int viewportHeight = 480; | 330 int viewportHeight = 480; |
| 339 | 331 |
| 340 // Make sure we initialize to minimum scale, even if the window size | 332 // Make sure we initialize to minimum scale, even if the window size |
| 341 // only becomes available after the load begins. | 333 // only becomes available after the load begins. |
| 342 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 334 FrameTestHelpers::WebViewHelper webViewHelper; |
| 343 m_webView->enableFixedLayoutMode(true); | 335 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 344 m_webView->settings()->setViewportEnabled(true); | 336 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 345 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 337 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 346 m_webView->layout(); | 338 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 339 webViewHelper.webView()->layout(); |
| 347 | 340 |
| 348 webViewImpl()->mainFrameImpl()->frameView()->setFixedLayoutSize(WebCore::Int
Size(100, 100)); | 341 webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->setFixedLayoutSiz
e(WebCore::IntSize(100, 100)); |
| 349 EXPECT_TRUE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); | 342 EXPECT_TRUE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needs
Layout()); |
| 350 | 343 |
| 351 int prevLayoutCount = webViewImpl()->mainFrameImpl()->frameView()->layoutCou
nt(); | 344 int prevLayoutCount = webViewHelper.webViewImpl()->mainFrameImpl()->frameVie
w()->layoutCount(); |
| 352 webViewImpl()->mainFrameImpl()->frameView()->setFrameRect(WebCore::IntRect(0
, 0, 641, 481)); | 345 webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->setFrameRect(WebC
ore::IntRect(0, 0, 641, 481)); |
| 353 EXPECT_EQ(prevLayoutCount, webViewImpl()->mainFrameImpl()->frameView()->layo
utCount()); | 346 EXPECT_EQ(prevLayoutCount, webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView()->layoutCount()); |
| 354 | 347 |
| 355 webViewImpl()->layout(); | 348 webViewHelper.webViewImpl()->layout(); |
| 356 } | 349 } |
| 357 | 350 |
| 358 TEST_F(WebFrameTest, ChangeInFixedLayoutTriggersTextAutosizingRecalculate) | 351 TEST_F(WebFrameTest, ChangeInFixedLayoutTriggersTextAutosizingRecalculate) |
| 359 { | 352 { |
| 360 registerMockedHttpURLLoad("fixed_layout.html"); | 353 registerMockedHttpURLLoad("fixed_layout.html"); |
| 361 | 354 |
| 362 FixedLayoutTestWebViewClient client; | 355 FixedLayoutTestWebViewClient client; |
| 363 int viewportWidth = 640; | 356 int viewportWidth = 640; |
| 364 int viewportHeight = 480; | 357 int viewportHeight = 480; |
| 365 | 358 |
| 366 // Make sure we initialize to minimum scale, even if the window size | 359 // Make sure we initialize to minimum scale, even if the window size |
| 367 // only becomes available after the load begins. | 360 // only becomes available after the load begins. |
| 368 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 361 FrameTestHelpers::WebViewHelper webViewHelper; |
| 369 m_webView->enableFixedLayoutMode(true); | 362 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 370 m_webView->settings()->setViewportEnabled(true); | 363 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 364 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 371 | 365 |
| 372 WebCore::Document* document = webViewImpl()->page()->mainFrame()->document()
; | 366 WebCore::Document* document = webViewHelper.webViewImpl()->page()->mainFrame
()->document(); |
| 373 document->settings()->setTextAutosizingEnabled(true); | 367 document->settings()->setTextAutosizingEnabled(true); |
| 374 EXPECT_TRUE(document->settings()->textAutosizingEnabled()); | 368 EXPECT_TRUE(document->settings()->textAutosizingEnabled()); |
| 375 webViewImpl()->resize(WebSize(viewportWidth, viewportHeight)); | 369 webViewHelper.webViewImpl()->resize(WebSize(viewportWidth, viewportHeight)); |
| 376 webViewImpl()->layout(); | 370 webViewHelper.webViewImpl()->layout(); |
| 377 | 371 |
| 378 WebCore::RenderObject* renderer = document->renderer(); | 372 WebCore::RenderObject* renderer = document->renderer(); |
| 379 bool multiplierSetAtLeastOnce = false; | 373 bool multiplierSetAtLeastOnce = false; |
| 380 while (renderer) { | 374 while (renderer) { |
| 381 if (renderer->style()) { | 375 if (renderer->style()) { |
| 382 renderer->style()->setTextAutosizingMultiplier(2); | 376 renderer->style()->setTextAutosizingMultiplier(2); |
| 383 EXPECT_EQ(2, renderer->style()->textAutosizingMultiplier()); | 377 EXPECT_EQ(2, renderer->style()->textAutosizingMultiplier()); |
| 384 multiplierSetAtLeastOnce = true; | 378 multiplierSetAtLeastOnce = true; |
| 385 } | 379 } |
| 386 renderer = renderer->nextInPreOrder(); | 380 renderer = renderer->nextInPreOrder(); |
| 387 } | 381 } |
| 388 EXPECT_TRUE(multiplierSetAtLeastOnce); | 382 EXPECT_TRUE(multiplierSetAtLeastOnce); |
| 389 | 383 |
| 390 WebCore::ViewportArguments arguments = document->viewportArguments(); | 384 WebCore::ViewportArguments arguments = document->viewportArguments(); |
| 391 // Choose a width that's not going match the viewport width of the loaded do
cument. | 385 // Choose a width that's not going match the viewport width of the loaded do
cument. |
| 392 arguments.minWidth = WebCore::Length(100, WebCore::Fixed); | 386 arguments.minWidth = WebCore::Length(100, WebCore::Fixed); |
| 393 arguments.maxWidth = WebCore::Length(100, WebCore::Fixed); | 387 arguments.maxWidth = WebCore::Length(100, WebCore::Fixed); |
| 394 webViewImpl()->updatePageDefinedPageScaleConstraints(arguments); | 388 webViewHelper.webViewImpl()->updatePageDefinedPageScaleConstraints(arguments
); |
| 395 | 389 |
| 396 bool multiplierCheckedAtLeastOnce = false; | 390 bool multiplierCheckedAtLeastOnce = false; |
| 397 renderer = document->renderer(); | 391 renderer = document->renderer(); |
| 398 while (renderer) { | 392 while (renderer) { |
| 399 if (renderer->style()) { | 393 if (renderer->style()) { |
| 400 EXPECT_EQ(1, renderer->style()->textAutosizingMultiplier()); | 394 EXPECT_EQ(1, renderer->style()->textAutosizingMultiplier()); |
| 401 multiplierCheckedAtLeastOnce = true; | 395 multiplierCheckedAtLeastOnce = true; |
| 402 } | 396 } |
| 403 renderer = renderer->nextInPreOrder(); | 397 renderer = renderer->nextInPreOrder(); |
| 404 } | 398 } |
| 405 EXPECT_TRUE(multiplierCheckedAtLeastOnce); | 399 EXPECT_TRUE(multiplierCheckedAtLeastOnce); |
| 406 } | 400 } |
| 407 | 401 |
| 408 TEST_F(WebFrameTest, FixedLayoutSizeStopsResizeFromChangingLayoutSize) | 402 TEST_F(WebFrameTest, FixedLayoutSizeStopsResizeFromChangingLayoutSize) |
| 409 { | 403 { |
| 410 registerMockedHttpURLLoad("fixed_layout.html"); | 404 registerMockedHttpURLLoad("fixed_layout.html"); |
| 411 | 405 |
| 412 int viewportWidth = 640; | 406 int viewportWidth = 640; |
| 413 int viewportHeight = 480; | 407 int viewportHeight = 480; |
| 414 | 408 |
| 415 int fixedLayoutWidth = viewportWidth / 2; | 409 int fixedLayoutWidth = viewportWidth / 2; |
| 416 int fixedLayoutHeight = viewportHeight / 2; | 410 int fixedLayoutHeight = viewportHeight / 2; |
| 417 | 411 |
| 418 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html"); | 412 FrameTestHelpers::WebViewHelper webViewHelper; |
| 419 m_webView->enableFixedLayoutMode(true); | 413 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html"); |
| 420 m_webView->settings()->setViewportEnabled(true); | 414 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 421 m_webView->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedLayoutHeight)); | 415 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 422 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 416 webViewHelper.webView()->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedL
ayoutHeight)); |
| 423 m_webView->layout(); | 417 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 418 webViewHelper.webView()->layout(); |
| 424 | 419 |
| 425 EXPECT_EQ(fixedLayoutWidth, m_webView->fixedLayoutSize().width); | 420 EXPECT_EQ(fixedLayoutWidth, webViewHelper.webView()->fixedLayoutSize().width
); |
| 426 EXPECT_EQ(fixedLayoutHeight, m_webView->fixedLayoutSize().height); | 421 EXPECT_EQ(fixedLayoutHeight, webViewHelper.webView()->fixedLayoutSize().heig
ht); |
| 427 } | 422 } |
| 428 | 423 |
| 429 TEST_F(WebFrameTest, FixedLayoutSizePreventsResizeFromChangingPageScale) | 424 TEST_F(WebFrameTest, FixedLayoutSizePreventsResizeFromChangingPageScale) |
| 430 { | 425 { |
| 431 registerMockedHttpURLLoad("fixed_layout.html"); | 426 registerMockedHttpURLLoad("fixed_layout.html"); |
| 432 | 427 |
| 433 int viewportWidth = 640; | 428 int viewportWidth = 640; |
| 434 int viewportHeight = 480; | 429 int viewportHeight = 480; |
| 435 | 430 |
| 436 int fixedLayoutWidth = viewportWidth / 2; | 431 int fixedLayoutWidth = viewportWidth / 2; |
| 437 int fixedLayoutHeight = viewportHeight / 2; | 432 int fixedLayoutHeight = viewportHeight / 2; |
| 438 | 433 |
| 439 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html"); | 434 FrameTestHelpers::WebViewHelper webViewHelper; |
| 440 m_webView->enableFixedLayoutMode(true); | 435 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html"); |
| 441 m_webView->settings()->setViewportEnabled(true); | 436 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 442 m_webView->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedLayoutHeight)); | 437 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 443 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 438 webViewHelper.webView()->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedL
ayoutHeight)); |
| 444 m_webView->layout(); | 439 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 445 float pageScaleFactor = m_webView->pageScaleFactor(); | 440 webViewHelper.webView()->layout(); |
| 441 float pageScaleFactor = webViewHelper.webView()->pageScaleFactor(); |
| 446 | 442 |
| 447 m_webView->resize(WebSize(viewportWidth * 2, viewportHeight * 2)); | 443 webViewHelper.webView()->resize(WebSize(viewportWidth * 2, viewportHeight *
2)); |
| 448 | 444 |
| 449 EXPECT_EQ(pageScaleFactor, m_webView->pageScaleFactor()); | 445 EXPECT_EQ(pageScaleFactor, webViewHelper.webView()->pageScaleFactor()); |
| 450 } | 446 } |
| 451 | 447 |
| 452 TEST_F(WebFrameTest, FixedLayoutSizePreventsLayoutFromChangingPageScale) | 448 TEST_F(WebFrameTest, FixedLayoutSizePreventsLayoutFromChangingPageScale) |
| 453 { | 449 { |
| 454 registerMockedHttpURLLoad("fixed_layout.html"); | 450 registerMockedHttpURLLoad("fixed_layout.html"); |
| 455 | 451 |
| 456 int viewportWidth = 640; | 452 int viewportWidth = 640; |
| 457 int viewportHeight = 480; | 453 int viewportHeight = 480; |
| 458 | 454 |
| 459 int fixedLayoutWidth = viewportWidth * 2; | 455 int fixedLayoutWidth = viewportWidth * 2; |
| 460 int fixedLayoutHeight = viewportHeight * 2; | 456 int fixedLayoutHeight = viewportHeight * 2; |
| 461 | 457 |
| 462 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html"); | 458 FrameTestHelpers::WebViewHelper webViewHelper; |
| 463 m_webView->enableFixedLayoutMode(true); | 459 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html"); |
| 464 m_webView->settings()->setViewportEnabled(true); | 460 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 465 m_webView->setFixedLayoutSize(WebSize(viewportWidth, viewportHeight)); | 461 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 466 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 462 webViewHelper.webView()->setFixedLayoutSize(WebSize(viewportWidth, viewportH
eight)); |
| 467 m_webView->layout(); | 463 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 468 float pageScaleFactor = m_webView->pageScaleFactor(); | 464 webViewHelper.webView()->layout(); |
| 465 float pageScaleFactor = webViewHelper.webView()->pageScaleFactor(); |
| 469 | 466 |
| 470 m_webView->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedLayoutHeight)); | 467 webViewHelper.webView()->setFixedLayoutSize(WebSize(fixedLayoutWidth, fixedL
ayoutHeight)); |
| 471 m_webView->layout(); | 468 webViewHelper.webView()->layout(); |
| 472 | 469 |
| 473 EXPECT_EQ(pageScaleFactor, m_webView->pageScaleFactor()); | 470 EXPECT_EQ(pageScaleFactor, webViewHelper.webView()->pageScaleFactor()); |
| 474 } | 471 } |
| 475 | 472 |
| 476 TEST_F(WebFrameTest, PreferredSizeAndContentSizeReportedCorrectlyWithZeroHeightF
ixedLayout) | 473 TEST_F(WebFrameTest, PreferredSizeAndContentSizeReportedCorrectlyWithZeroHeightF
ixedLayout) |
| 477 { | 474 { |
| 478 registerMockedHttpURLLoad("200-by-300.html"); | 475 registerMockedHttpURLLoad("200-by-300.html"); |
| 479 | 476 |
| 480 int windowWidth = 100; | 477 int windowWidth = 100; |
| 481 int windowHeight = 100; | 478 int windowHeight = 100; |
| 482 int viewportWidth = 100; | 479 int viewportWidth = 100; |
| 483 int viewportHeight = 0; | 480 int viewportHeight = 0; |
| 484 int divWidth = 200; | 481 int divWidth = 200; |
| 485 int divHeight = 300; | 482 int divHeight = 300; |
| 486 | 483 |
| 487 FixedLayoutTestWebViewClient client; | 484 FixedLayoutTestWebViewClient client; |
| 488 client.m_screenInfo.deviceScaleFactor = 1; | 485 client.m_screenInfo.deviceScaleFactor = 1; |
| 489 | 486 |
| 490 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "200-by-300.h
tml", true, 0, &client); | 487 FrameTestHelpers::WebViewHelper webViewHelper; |
| 491 m_webView->enableFixedLayoutMode(true); | 488 webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html", true, 0, &cli
ent); |
| 492 m_webView->settings()->setViewportEnabled(true); | 489 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 493 m_webView->resize(WebSize(windowWidth, windowHeight)); | 490 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 494 m_webView->setFixedLayoutSize(WebSize(viewportWidth, viewportHeight)); | 491 webViewHelper.webView()->resize(WebSize(windowWidth, windowHeight)); |
| 495 m_webView->layout(); | 492 webViewHelper.webView()->setFixedLayoutSize(WebSize(viewportWidth, viewportH
eight)); |
| 493 webViewHelper.webView()->layout(); |
| 496 | 494 |
| 497 EXPECT_EQ(divWidth, m_webView->mainFrame()->contentsSize().width); | 495 EXPECT_EQ(divWidth, webViewHelper.webView()->mainFrame()->contentsSize().wid
th); |
| 498 EXPECT_EQ(divHeight, m_webView->mainFrame()->contentsSize().height); | 496 EXPECT_EQ(divHeight, webViewHelper.webView()->mainFrame()->contentsSize().he
ight); |
| 499 | 497 |
| 500 EXPECT_EQ(divWidth, m_webView->contentsPreferredMinimumSize().width); | 498 EXPECT_EQ(divWidth, webViewHelper.webView()->contentsPreferredMinimumSize().
width); |
| 501 EXPECT_EQ(divHeight, m_webView->contentsPreferredMinimumSize().height); | 499 EXPECT_EQ(divHeight, webViewHelper.webView()->contentsPreferredMinimumSize()
.height); |
| 502 } | 500 } |
| 503 | 501 |
| 504 TEST_F(WebFrameTest, DisablingFixedLayoutSizeSetsCorrectLayoutSize) | 502 TEST_F(WebFrameTest, DisablingFixedLayoutSizeSetsCorrectLayoutSize) |
| 505 { | 503 { |
| 506 registerMockedHttpURLLoad("no_viewport_tag.html"); | 504 registerMockedHttpURLLoad("no_viewport_tag.html"); |
| 507 | 505 |
| 508 FixedLayoutTestWebViewClient client; | 506 FixedLayoutTestWebViewClient client; |
| 509 client.m_screenInfo.deviceScaleFactor = 1; | 507 client.m_screenInfo.deviceScaleFactor = 1; |
| 510 int viewportWidth = 640; | 508 int viewportWidth = 640; |
| 511 int viewportHeight = 480; | 509 int viewportHeight = 480; |
| 512 | 510 |
| 513 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_viewport_
tag.html", true, 0, &client); | 511 FrameTestHelpers::WebViewHelper webViewHelper; |
| 514 m_webView->settings()->setSupportDeprecatedTargetDensityDPI(true); | 512 webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0,
&client); |
| 515 m_webView->enableFixedLayoutMode(true); | 513 webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDPI(tr
ue); |
| 516 m_webView->settings()->setUseWideViewport(true); | 514 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 517 m_webView->settings()->setViewportEnabled(true); | 515 webViewHelper.webView()->settings()->setUseWideViewport(true); |
| 518 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 516 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 517 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 519 | 518 |
| 520 m_webView->setFixedLayoutSize(WebSize(viewportWidth, viewportHeight)); | 519 webViewHelper.webView()->setFixedLayoutSize(WebSize(viewportWidth, viewportH
eight)); |
| 521 EXPECT_TRUE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); | 520 EXPECT_TRUE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needs
Layout()); |
| 522 m_webView->layout(); | 521 webViewHelper.webView()->layout(); |
| 523 EXPECT_EQ(viewportWidth, webViewImpl()->mainFrameImpl()->frameView()->conten
tsSize().width()); | 522 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame
View()->contentsSize().width()); |
| 524 | 523 |
| 525 m_webView->setFixedLayoutSize(WebSize(0, 0)); | 524 webViewHelper.webView()->setFixedLayoutSize(WebSize(0, 0)); |
| 526 EXPECT_TRUE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); | 525 EXPECT_TRUE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->needs
Layout()); |
| 527 m_webView->layout(); | 526 webViewHelper.webView()->layout(); |
| 528 EXPECT_EQ(980, webViewImpl()->mainFrameImpl()->frameView()->contentsSize().w
idth()); | 527 EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->co
ntentsSize().width()); |
| 529 } | 528 } |
| 530 | 529 |
| 531 TEST_F(WebFrameTest, DeviceScaleFactorUsesDefaultWithoutViewportTag) | 530 TEST_F(WebFrameTest, DeviceScaleFactorUsesDefaultWithoutViewportTag) |
| 532 { | 531 { |
| 533 registerMockedHttpURLLoad("no_viewport_tag.html"); | 532 registerMockedHttpURLLoad("no_viewport_tag.html"); |
| 534 | 533 |
| 535 int viewportWidth = 640; | 534 int viewportWidth = 640; |
| 536 int viewportHeight = 480; | 535 int viewportHeight = 480; |
| 537 | 536 |
| 538 FixedLayoutTestWebViewClient client; | 537 FixedLayoutTestWebViewClient client; |
| 539 client.m_screenInfo.deviceScaleFactor = 2; | 538 client.m_screenInfo.deviceScaleFactor = 2; |
| 540 | 539 |
| 541 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_viewport_
tag.html", true, 0, &client); | 540 FrameTestHelpers::WebViewHelper webViewHelper; |
| 541 webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0,
&client); |
| 542 | 542 |
| 543 m_webView->settings()->setViewportEnabled(true); | 543 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 544 m_webView->enableFixedLayoutMode(true); | 544 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 545 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 545 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 546 m_webView->layout(); | 546 webViewHelper.webView()->layout(); |
| 547 | 547 |
| 548 EXPECT_EQ(2, m_webView->deviceScaleFactor()); | 548 EXPECT_EQ(2, webViewHelper.webView()->deviceScaleFactor()); |
| 549 | 549 |
| 550 // Device scale factor should be independent of page scale. | 550 // Device scale factor should be independent of page scale. |
| 551 m_webView->setPageScaleFactorLimits(1, 2); | 551 webViewHelper.webView()->setPageScaleFactorLimits(1, 2); |
| 552 m_webView->setPageScaleFactorPreservingScrollOffset(0.5); | 552 webViewHelper.webView()->setPageScaleFactorPreservingScrollOffset(0.5); |
| 553 m_webView->layout(); | 553 webViewHelper.webView()->layout(); |
| 554 EXPECT_EQ(1, m_webView->pageScaleFactor()); | 554 EXPECT_EQ(1, webViewHelper.webView()->pageScaleFactor()); |
| 555 | 555 |
| 556 // Force the layout to happen before leaving the test. | 556 // Force the layout to happen before leaving the test. |
| 557 m_webView->mainFrame()->contentAsText(1024).utf8(); | 557 webViewHelper.webView()->mainFrame()->contentAsText(1024).utf8(); |
| 558 } | 558 } |
| 559 | 559 |
| 560 TEST_F(WebFrameTest, FixedLayoutInitializeAtMinimumScale) | 560 TEST_F(WebFrameTest, FixedLayoutInitializeAtMinimumScale) |
| 561 { | 561 { |
| 562 UseMockScrollbarSettings mockScrollbarSettings; | 562 UseMockScrollbarSettings mockScrollbarSettings; |
| 563 | 563 |
| 564 registerMockedHttpURLLoad("fixed_layout.html"); | 564 registerMockedHttpURLLoad("fixed_layout.html"); |
| 565 | 565 |
| 566 FixedLayoutTestWebViewClient client; | 566 FixedLayoutTestWebViewClient client; |
| 567 client.m_screenInfo.deviceScaleFactor = 1; | 567 client.m_screenInfo.deviceScaleFactor = 1; |
| 568 int viewportWidth = 640; | 568 int viewportWidth = 640; |
| 569 int viewportHeight = 480; | 569 int viewportHeight = 480; |
| 570 | 570 |
| 571 // Make sure we initialize to minimum scale, even if the window size | 571 // Make sure we initialize to minimum scale, even if the window size |
| 572 // only becomes available after the load begins. | 572 // only becomes available after the load begins. |
| 573 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 573 FrameTestHelpers::WebViewHelper webViewHelper; |
| 574 m_webView->enableFixedLayoutMode(true); | 574 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 575 m_webView->settings()->setViewportEnabled(true); | 575 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 576 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 576 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 577 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 577 | 578 |
| 578 int defaultFixedLayoutWidth = 980; | 579 int defaultFixedLayoutWidth = 980; |
| 579 float minimumPageScaleFactor = viewportWidth / (float) defaultFixedLayoutWid
th; | 580 float minimumPageScaleFactor = viewportWidth / (float) defaultFixedLayoutWid
th; |
| 580 EXPECT_EQ(minimumPageScaleFactor, m_webView->pageScaleFactor()); | 581 EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->pageScaleFactor()
); |
| 581 EXPECT_EQ(minimumPageScaleFactor, m_webView->minimumPageScaleFactor()); | 582 EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->minimumPageScaleF
actor()); |
| 582 | 583 |
| 583 // Assume the user has pinch zoomed to page scale factor 2. | 584 // Assume the user has pinch zoomed to page scale factor 2. |
| 584 float userPinchPageScaleFactor = 2; | 585 float userPinchPageScaleFactor = 2; |
| 585 m_webView->setPageScaleFactorPreservingScrollOffset(userPinchPageScaleFactor
); | 586 webViewHelper.webView()->setPageScaleFactorPreservingScrollOffset(userPinchP
ageScaleFactor); |
| 586 m_webView->layout(); | 587 webViewHelper.webView()->layout(); |
| 587 | 588 |
| 588 // Make sure we don't reset to initial scale if the page continues to load. | 589 // Make sure we don't reset to initial scale if the page continues to load. |
| 589 bool isNewNavigation; | 590 bool isNewNavigation; |
| 590 webViewImpl()->didCommitLoad(&isNewNavigation, false); | 591 webViewHelper.webViewImpl()->didCommitLoad(&isNewNavigation, false); |
| 591 webViewImpl()->didChangeContentsSize(); | 592 webViewHelper.webViewImpl()->didChangeContentsSize(); |
| 592 EXPECT_EQ(userPinchPageScaleFactor, m_webView->pageScaleFactor()); | 593 EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor
()); |
| 593 | 594 |
| 594 // Make sure we don't reset to initial scale if the viewport size changes. | 595 // Make sure we don't reset to initial scale if the viewport size changes. |
| 595 m_webView->resize(WebSize(viewportWidth, viewportHeight + 100)); | 596 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight + 100)
); |
| 596 EXPECT_EQ(userPinchPageScaleFactor, m_webView->pageScaleFactor()); | 597 EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor
()); |
| 597 } | 598 } |
| 598 | 599 |
| 599 TEST_F(WebFrameTest, WideDocumentInitializeAtMinimumScale) | 600 TEST_F(WebFrameTest, WideDocumentInitializeAtMinimumScale) |
| 600 { | 601 { |
| 601 UseMockScrollbarSettings mockScrollbarSettings; | 602 UseMockScrollbarSettings mockScrollbarSettings; |
| 602 | 603 |
| 603 registerMockedHttpURLLoad("wide_document.html"); | 604 registerMockedHttpURLLoad("wide_document.html"); |
| 604 | 605 |
| 605 FixedLayoutTestWebViewClient client; | 606 FixedLayoutTestWebViewClient client; |
| 606 client.m_screenInfo.deviceScaleFactor = 1; | 607 client.m_screenInfo.deviceScaleFactor = 1; |
| 607 int viewportWidth = 640; | 608 int viewportWidth = 640; |
| 608 int viewportHeight = 480; | 609 int viewportHeight = 480; |
| 609 | 610 |
| 610 // Make sure we initialize to minimum scale, even if the window size | 611 // Make sure we initialize to minimum scale, even if the window size |
| 611 // only becomes available after the load begins. | 612 // only becomes available after the load begins. |
| 612 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "wide_documen
t.html", true, 0, &client); | 613 FrameTestHelpers::WebViewHelper webViewHelper; |
| 613 m_webView->enableFixedLayoutMode(true); | 614 webViewHelper.initializeAndLoad(m_baseURL + "wide_document.html", true, 0, &
client); |
| 614 m_webView->settings()->setViewportEnabled(true); | 615 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 615 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 616 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 617 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 616 | 618 |
| 617 int wideDocumentWidth = 1500; | 619 int wideDocumentWidth = 1500; |
| 618 float minimumPageScaleFactor = viewportWidth / (float) wideDocumentWidth; | 620 float minimumPageScaleFactor = viewportWidth / (float) wideDocumentWidth; |
| 619 EXPECT_EQ(minimumPageScaleFactor, m_webView->pageScaleFactor()); | 621 EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->pageScaleFactor()
); |
| 620 EXPECT_EQ(minimumPageScaleFactor, m_webView->minimumPageScaleFactor()); | 622 EXPECT_EQ(minimumPageScaleFactor, webViewHelper.webView()->minimumPageScaleF
actor()); |
| 621 | 623 |
| 622 // Assume the user has pinch zoomed to page scale factor 2. | 624 // Assume the user has pinch zoomed to page scale factor 2. |
| 623 float userPinchPageScaleFactor = 2; | 625 float userPinchPageScaleFactor = 2; |
| 624 m_webView->setPageScaleFactorPreservingScrollOffset(userPinchPageScaleFactor
); | 626 webViewHelper.webView()->setPageScaleFactorPreservingScrollOffset(userPinchP
ageScaleFactor); |
| 625 m_webView->layout(); | 627 webViewHelper.webView()->layout(); |
| 626 | 628 |
| 627 // Make sure we don't reset to initial scale if the page continues to load. | 629 // Make sure we don't reset to initial scale if the page continues to load. |
| 628 bool isNewNavigation; | 630 bool isNewNavigation; |
| 629 webViewImpl()->didCommitLoad(&isNewNavigation, false); | 631 webViewHelper.webViewImpl()->didCommitLoad(&isNewNavigation, false); |
| 630 webViewImpl()->didChangeContentsSize(); | 632 webViewHelper.webViewImpl()->didChangeContentsSize(); |
| 631 EXPECT_EQ(userPinchPageScaleFactor, m_webView->pageScaleFactor()); | 633 EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor
()); |
| 632 | 634 |
| 633 // Make sure we don't reset to initial scale if the viewport size changes. | 635 // Make sure we don't reset to initial scale if the viewport size changes. |
| 634 m_webView->resize(WebSize(viewportWidth, viewportHeight + 100)); | 636 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight + 100)
); |
| 635 EXPECT_EQ(userPinchPageScaleFactor, m_webView->pageScaleFactor()); | 637 EXPECT_EQ(userPinchPageScaleFactor, webViewHelper.webView()->pageScaleFactor
()); |
| 636 } | 638 } |
| 637 | 639 |
| 638 TEST_F(WebFrameTest, setLoadWithOverviewModeToFalse) | 640 TEST_F(WebFrameTest, setLoadWithOverviewModeToFalse) |
| 639 { | 641 { |
| 640 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); | 642 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); |
| 641 | 643 |
| 642 FixedLayoutTestWebViewClient client; | 644 FixedLayoutTestWebViewClient client; |
| 643 client.m_screenInfo.deviceScaleFactor = 1; | 645 client.m_screenInfo.deviceScaleFactor = 1; |
| 644 int viewportWidth = 640; | 646 int viewportWidth = 640; |
| 645 int viewportHeight = 480; | 647 int viewportHeight = 480; |
| 646 | 648 |
| 647 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-aut
o-initial-scale.html", true, 0, &client); | 649 FrameTestHelpers::WebViewHelper webViewHelper; |
| 648 m_webView->enableFixedLayoutMode(true); | 650 webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.htm
l", true, 0, &client); |
| 649 m_webView->settings()->setViewportEnabled(true); | 651 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 650 m_webView->settings()->setWideViewportQuirkEnabled(true); | 652 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 651 m_webView->settings()->setLoadWithOverviewMode(false); | 653 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 652 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 654 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false); |
| 655 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 653 | 656 |
| 654 // The page must be displayed at 100% zoom. | 657 // The page must be displayed at 100% zoom. |
| 655 EXPECT_EQ(1.0f, m_webView->pageScaleFactor()); | 658 EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor()); |
| 656 } | 659 } |
| 657 | 660 |
| 658 TEST_F(WebFrameTest, SetLoadWithOverviewModeToFalseAndNoWideViewport) | 661 TEST_F(WebFrameTest, SetLoadWithOverviewModeToFalseAndNoWideViewport) |
| 659 { | 662 { |
| 660 registerMockedHttpURLLoad("large-div.html"); | 663 registerMockedHttpURLLoad("large-div.html"); |
| 661 | 664 |
| 662 FixedLayoutTestWebViewClient client; | 665 FixedLayoutTestWebViewClient client; |
| 663 client.m_screenInfo.deviceScaleFactor = 1; | 666 client.m_screenInfo.deviceScaleFactor = 1; |
| 664 int viewportWidth = 640; | 667 int viewportWidth = 640; |
| 665 int viewportHeight = 480; | 668 int viewportHeight = 480; |
| 666 | 669 |
| 667 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "large-div.ht
ml", true, 0, &client); | 670 FrameTestHelpers::WebViewHelper webViewHelper; |
| 668 m_webView->enableFixedLayoutMode(true); | 671 webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &clie
nt); |
| 669 m_webView->settings()->setViewportEnabled(true); | 672 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 670 m_webView->settings()->setLoadWithOverviewMode(false); | 673 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 671 m_webView->settings()->setWideViewportQuirkEnabled(true); | 674 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false); |
| 672 m_webView->settings()->setUseWideViewport(false); | 675 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 673 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 676 webViewHelper.webView()->settings()->setUseWideViewport(false); |
| 677 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 674 | 678 |
| 675 // The page must be displayed at 100% zoom, despite that it hosts a wide div
element. | 679 // The page must be displayed at 100% zoom, despite that it hosts a wide div
element. |
| 676 EXPECT_EQ(1.0f, m_webView->pageScaleFactor()); | 680 EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor()); |
| 677 } | 681 } |
| 678 | 682 |
| 679 TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidth) | 683 TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidth) |
| 680 { | 684 { |
| 681 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); | 685 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); |
| 682 | 686 |
| 683 FixedLayoutTestWebViewClient client; | 687 FixedLayoutTestWebViewClient client; |
| 684 client.m_screenInfo.deviceScaleFactor = 1; | 688 client.m_screenInfo.deviceScaleFactor = 1; |
| 685 int viewportWidth = 640; | 689 int viewportWidth = 640; |
| 686 int viewportHeight = 480; | 690 int viewportHeight = 480; |
| 687 | 691 |
| 688 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-aut
o-initial-scale.html", true, 0, &client); | 692 FrameTestHelpers::WebViewHelper webViewHelper; |
| 689 m_webView->enableFixedLayoutMode(true); | 693 webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.htm
l", true, 0, &client); |
| 690 m_webView->settings()->setViewportEnabled(true); | 694 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 691 m_webView->settings()->setWideViewportQuirkEnabled(true); | 695 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 692 m_webView->settings()->setUseWideViewport(false); | 696 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 693 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 697 webViewHelper.webView()->settings()->setUseWideViewport(false); |
| 698 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 694 | 699 |
| 695 // The page sets viewport width to 3000, but with UseWideViewport == false i
s must be ignored. | 700 // The page sets viewport width to 3000, but with UseWideViewport == false i
s must be ignored. |
| 696 EXPECT_EQ(viewportWidth, webViewImpl()->mainFrameImpl()->frameView()->conten
tsSize().width()); | 701 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame
View()->contentsSize().width()); |
| 697 EXPECT_EQ(viewportHeight, webViewImpl()->mainFrameImpl()->frameView()->conte
ntsSize().height()); | 702 EXPECT_EQ(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->fram
eView()->contentsSize().height()); |
| 698 } | 703 } |
| 699 | 704 |
| 700 TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidthButAccountsScale) | 705 TEST_F(WebFrameTest, NoWideViewportIgnoresPageViewportWidthButAccountsScale) |
| 701 { | 706 { |
| 702 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); | 707 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); |
| 703 | 708 |
| 704 FixedLayoutTestWebViewClient client; | 709 FixedLayoutTestWebViewClient client; |
| 705 client.m_screenInfo.deviceScaleFactor = 1; | 710 client.m_screenInfo.deviceScaleFactor = 1; |
| 706 int viewportWidth = 640; | 711 int viewportWidth = 640; |
| 707 int viewportHeight = 480; | 712 int viewportHeight = 480; |
| 708 | 713 |
| 709 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-wid
e-2x-initial-scale.html", true, 0, &client); | 714 FrameTestHelpers::WebViewHelper webViewHelper; |
| 710 m_webView->enableFixedLayoutMode(true); | 715 webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.
html", true, 0, &client); |
| 711 m_webView->settings()->setViewportEnabled(true); | 716 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 712 m_webView->settings()->setWideViewportQuirkEnabled(true); | 717 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 713 m_webView->settings()->setUseWideViewport(false); | 718 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 714 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 719 webViewHelper.webView()->settings()->setUseWideViewport(false); |
| 720 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 715 | 721 |
| 716 // The page sets viewport width to 3000, but with UseWideViewport == false i
s must be ignored. | 722 // The page sets viewport width to 3000, but with UseWideViewport == false i
s must be ignored. |
| 717 // While the initial scale specified by the page must be accounted. | 723 // While the initial scale specified by the page must be accounted. |
| 718 EXPECT_EQ(viewportWidth / 2, webViewImpl()->mainFrameImpl()->frameView()->co
ntentsSize().width()); | 724 EXPECT_EQ(viewportWidth / 2, webViewHelper.webViewImpl()->mainFrameImpl()->f
rameView()->contentsSize().width()); |
| 719 EXPECT_EQ(viewportHeight / 2, webViewImpl()->mainFrameImpl()->frameView()->c
ontentsSize().height()); | 725 EXPECT_EQ(viewportHeight / 2, webViewHelper.webViewImpl()->mainFrameImpl()->
frameView()->contentsSize().height()); |
| 720 } | 726 } |
| 721 | 727 |
| 722 TEST_F(WebFrameTest, WideViewportSetsTo980WithoutViewportTag) | 728 TEST_F(WebFrameTest, WideViewportSetsTo980WithoutViewportTag) |
| 723 { | 729 { |
| 724 registerMockedHttpURLLoad("no_viewport_tag.html"); | 730 registerMockedHttpURLLoad("no_viewport_tag.html"); |
| 725 | 731 |
| 726 FixedLayoutTestWebViewClient client; | 732 FixedLayoutTestWebViewClient client; |
| 727 client.m_screenInfo.deviceScaleFactor = 1; | 733 client.m_screenInfo.deviceScaleFactor = 1; |
| 728 int viewportWidth = 640; | 734 int viewportWidth = 640; |
| 729 int viewportHeight = 480; | 735 int viewportHeight = 480; |
| 730 | 736 |
| 731 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_viewport_
tag.html", true, 0, &client); | 737 FrameTestHelpers::WebViewHelper webViewHelper; |
| 732 m_webView->enableFixedLayoutMode(true); | 738 webViewHelper.initializeAndLoad(m_baseURL + "no_viewport_tag.html", true, 0,
&client); |
| 733 m_webView->settings()->setWideViewportQuirkEnabled(true); | 739 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 734 m_webView->settings()->setUseWideViewport(true); | 740 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 735 m_webView->settings()->setViewportEnabled(true); | 741 webViewHelper.webView()->settings()->setUseWideViewport(true); |
| 736 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 742 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 743 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 737 | 744 |
| 738 EXPECT_EQ(980, webViewImpl()->mainFrameImpl()->frameView()->contentsSize().w
idth()); | 745 EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->co
ntentsSize().width()); |
| 739 EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewImpl()->mainFrameIm
pl()->frameView()->contentsSize().height()); | 746 EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewHelper.webViewImpl(
)->mainFrameImpl()->frameView()->contentsSize().height()); |
| 740 } | 747 } |
| 741 | 748 |
| 742 TEST_F(WebFrameTest, NoWideViewportAndHeightInMeta) | 749 TEST_F(WebFrameTest, NoWideViewportAndHeightInMeta) |
| 743 { | 750 { |
| 744 registerMockedHttpURLLoad("viewport-height-1000.html"); | 751 registerMockedHttpURLLoad("viewport-height-1000.html"); |
| 745 | 752 |
| 746 FixedLayoutTestWebViewClient client; | 753 FixedLayoutTestWebViewClient client; |
| 747 client.m_screenInfo.deviceScaleFactor = 1; | 754 client.m_screenInfo.deviceScaleFactor = 1; |
| 748 int viewportWidth = 640; | 755 int viewportWidth = 640; |
| 749 int viewportHeight = 480; | 756 int viewportHeight = 480; |
| 750 | 757 |
| 751 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-hei
ght-1000.html", true, 0, &client); | 758 FrameTestHelpers::WebViewHelper webViewHelper; |
| 752 m_webView->enableFixedLayoutMode(true); | 759 webViewHelper.initializeAndLoad(m_baseURL + "viewport-height-1000.html", tru
e, 0, &client); |
| 753 m_webView->settings()->setWideViewportQuirkEnabled(true); | 760 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 754 m_webView->settings()->setUseWideViewport(false); | 761 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 755 m_webView->settings()->setViewportEnabled(true); | 762 webViewHelper.webView()->settings()->setUseWideViewport(false); |
| 756 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 763 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 764 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 757 | 765 |
| 758 EXPECT_EQ(viewportWidth, webViewImpl()->mainFrameImpl()->frameView()->conten
tsSize().width()); | 766 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame
View()->contentsSize().width()); |
| 759 } | 767 } |
| 760 | 768 |
| 761 TEST_F(WebFrameTest, WideViewportSetsTo980WithAutoWidth) | 769 TEST_F(WebFrameTest, WideViewportSetsTo980WithAutoWidth) |
| 762 { | 770 { |
| 763 registerMockedHttpURLLoad("viewport-2x-initial-scale.html"); | 771 registerMockedHttpURLLoad("viewport-2x-initial-scale.html"); |
| 764 | 772 |
| 765 FixedLayoutTestWebViewClient client; | 773 FixedLayoutTestWebViewClient client; |
| 766 client.m_screenInfo.deviceScaleFactor = 1; | 774 client.m_screenInfo.deviceScaleFactor = 1; |
| 767 int viewportWidth = 640; | 775 int viewportWidth = 640; |
| 768 int viewportHeight = 480; | 776 int viewportHeight = 480; |
| 769 | 777 |
| 770 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-2x-
initial-scale.html", true, 0, &client); | 778 FrameTestHelpers::WebViewHelper webViewHelper; |
| 771 m_webView->enableFixedLayoutMode(true); | 779 webViewHelper.initializeAndLoad(m_baseURL + "viewport-2x-initial-scale.html"
, true, 0, &client); |
| 772 m_webView->settings()->setWideViewportQuirkEnabled(true); | 780 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 773 m_webView->settings()->setUseWideViewport(true); | 781 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 774 m_webView->settings()->setViewportEnabled(true); | 782 webViewHelper.webView()->settings()->setUseWideViewport(true); |
| 775 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 783 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 784 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 776 | 785 |
| 777 EXPECT_EQ(980, webViewImpl()->mainFrameImpl()->frameView()->contentsSize().w
idth()); | 786 EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->co
ntentsSize().width()); |
| 778 EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewImpl()->mainFrameIm
pl()->frameView()->contentsSize().height()); | 787 EXPECT_EQ(980.0 / viewportWidth * viewportHeight, webViewHelper.webViewImpl(
)->mainFrameImpl()->frameView()->contentsSize().height()); |
| 779 } | 788 } |
| 780 | 789 |
| 781 TEST_F(WebFrameTest, PageViewportInitialScaleOverridesLoadWithOverviewMode) | 790 TEST_F(WebFrameTest, PageViewportInitialScaleOverridesLoadWithOverviewMode) |
| 782 { | 791 { |
| 783 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); | 792 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); |
| 784 | 793 |
| 785 FixedLayoutTestWebViewClient client; | 794 FixedLayoutTestWebViewClient client; |
| 786 client.m_screenInfo.deviceScaleFactor = 1; | 795 client.m_screenInfo.deviceScaleFactor = 1; |
| 787 int viewportWidth = 640; | 796 int viewportWidth = 640; |
| 788 int viewportHeight = 480; | 797 int viewportHeight = 480; |
| 789 | 798 |
| 790 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-wid
e-2x-initial-scale.html", true, 0, &client); | 799 FrameTestHelpers::WebViewHelper webViewHelper; |
| 791 m_webView->enableFixedLayoutMode(true); | 800 webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.
html", true, 0, &client); |
| 792 m_webView->settings()->setViewportEnabled(true); | 801 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 793 m_webView->settings()->setLoadWithOverviewMode(false); | 802 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 794 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 803 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false); |
| 804 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 795 | 805 |
| 796 // The page must be displayed at 200% zoom, as specified in its viewport met
a tag. | 806 // The page must be displayed at 200% zoom, as specified in its viewport met
a tag. |
| 797 EXPECT_EQ(2.0f, m_webView->pageScaleFactor()); | 807 EXPECT_EQ(2.0f, webViewHelper.webView()->pageScaleFactor()); |
| 798 } | 808 } |
| 799 | 809 |
| 800 TEST_F(WebFrameTest, setInitialPageScaleFactorPermanently) | 810 TEST_F(WebFrameTest, setInitialPageScaleFactorPermanently) |
| 801 { | 811 { |
| 802 UseMockScrollbarSettings mockScrollbarSettings; | 812 UseMockScrollbarSettings mockScrollbarSettings; |
| 803 | 813 |
| 804 registerMockedHttpURLLoad("fixed_layout.html"); | 814 registerMockedHttpURLLoad("fixed_layout.html"); |
| 805 | 815 |
| 806 FixedLayoutTestWebViewClient client; | 816 FixedLayoutTestWebViewClient client; |
| 807 client.m_screenInfo.deviceScaleFactor = 1; | 817 client.m_screenInfo.deviceScaleFactor = 1; |
| 808 float enforcedPageScaleFactor = 2.0f; | 818 float enforcedPageScaleFactor = 2.0f; |
| 809 | 819 |
| 810 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 820 FrameTestHelpers::WebViewHelper webViewHelper; |
| 811 m_webView->settings()->setWideViewportQuirkEnabled(true); | 821 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 812 m_webView->settings()->setLoadWithOverviewMode(false); | 822 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 813 m_webView->setInitialPageScaleOverride(enforcedPageScaleFactor); | 823 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false); |
| 814 m_webView->enableFixedLayoutMode(true); | 824 webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScaleFactor
); |
| 815 m_webView->settings()->setViewportEnabled(true); | 825 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 816 m_webView->layout(); | 826 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 827 webViewHelper.webView()->layout(); |
| 817 | 828 |
| 818 EXPECT_EQ(enforcedPageScaleFactor, m_webView->pageScaleFactor()); | 829 EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor(
)); |
| 819 | 830 |
| 820 int viewportWidth = 640; | 831 int viewportWidth = 640; |
| 821 int viewportHeight = 480; | 832 int viewportHeight = 480; |
| 822 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 833 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 823 m_webView->layout(); | 834 webViewHelper.webView()->layout(); |
| 824 | 835 |
| 825 EXPECT_EQ(enforcedPageScaleFactor, m_webView->pageScaleFactor()); | 836 EXPECT_EQ(enforcedPageScaleFactor, webViewHelper.webView()->pageScaleFactor(
)); |
| 826 | 837 |
| 827 m_webView->setInitialPageScaleOverride(-1); | 838 webViewHelper.webView()->setInitialPageScaleOverride(-1); |
| 828 m_webView->layout(); | 839 webViewHelper.webView()->layout(); |
| 829 EXPECT_EQ(1.0, m_webView->pageScaleFactor()); | 840 EXPECT_EQ(1.0, webViewHelper.webView()->pageScaleFactor()); |
| 830 } | 841 } |
| 831 | 842 |
| 832 TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesLoadWithOverviewMod
e) | 843 TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesLoadWithOverviewMod
e) |
| 833 { | 844 { |
| 834 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); | 845 registerMockedHttpURLLoad("viewport-auto-initial-scale.html"); |
| 835 | 846 |
| 836 FixedLayoutTestWebViewClient client; | 847 FixedLayoutTestWebViewClient client; |
| 837 client.m_screenInfo.deviceScaleFactor = 1; | 848 client.m_screenInfo.deviceScaleFactor = 1; |
| 838 int viewportWidth = 640; | 849 int viewportWidth = 640; |
| 839 int viewportHeight = 480; | 850 int viewportHeight = 480; |
| 840 float enforcedPageScalePactor = 0.5f; | 851 float enforcedPageScalePactor = 0.5f; |
| 841 | 852 |
| 842 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-aut
o-initial-scale.html", true, 0, &client); | 853 FrameTestHelpers::WebViewHelper webViewHelper; |
| 843 m_webView->enableFixedLayoutMode(true); | 854 webViewHelper.initializeAndLoad(m_baseURL + "viewport-auto-initial-scale.htm
l", true, 0, &client); |
| 844 m_webView->settings()->setViewportEnabled(true); | 855 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 845 m_webView->settings()->setLoadWithOverviewMode(false); | 856 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 846 m_webView->setInitialPageScaleOverride(enforcedPageScalePactor); | 857 webViewHelper.webView()->settings()->setLoadWithOverviewMode(false); |
| 847 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 858 webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScalePactor
); |
| 859 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 848 | 860 |
| 849 EXPECT_EQ(enforcedPageScalePactor, m_webView->pageScaleFactor()); | 861 EXPECT_EQ(enforcedPageScalePactor, webViewHelper.webView()->pageScaleFactor(
)); |
| 850 } | 862 } |
| 851 | 863 |
| 852 TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesPageViewportInitial
Scale) | 864 TEST_F(WebFrameTest, PermanentInitialPageScaleFactorOverridesPageViewportInitial
Scale) |
| 853 { | 865 { |
| 854 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); | 866 registerMockedHttpURLLoad("viewport-wide-2x-initial-scale.html"); |
| 855 | 867 |
| 856 FixedLayoutTestWebViewClient client; | 868 FixedLayoutTestWebViewClient client; |
| 857 client.m_screenInfo.deviceScaleFactor = 1; | 869 client.m_screenInfo.deviceScaleFactor = 1; |
| 858 int viewportWidth = 640; | 870 int viewportWidth = 640; |
| 859 int viewportHeight = 480; | 871 int viewportHeight = 480; |
| 860 float enforcedPageScalePactor = 0.5f; | 872 float enforcedPageScalePactor = 0.5f; |
| 861 | 873 |
| 862 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-wid
e-2x-initial-scale.html", true, 0, &client); | 874 FrameTestHelpers::WebViewHelper webViewHelper; |
| 863 m_webView->enableFixedLayoutMode(true); | 875 webViewHelper.initializeAndLoad(m_baseURL + "viewport-wide-2x-initial-scale.
html", true, 0, &client); |
| 864 m_webView->settings()->setViewportEnabled(true); | 876 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 865 m_webView->setInitialPageScaleOverride(enforcedPageScalePactor); | 877 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 866 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 878 webViewHelper.webView()->setInitialPageScaleOverride(enforcedPageScalePactor
); |
| 879 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 867 | 880 |
| 868 EXPECT_EQ(enforcedPageScalePactor, m_webView->pageScaleFactor()); | 881 EXPECT_EQ(enforcedPageScalePactor, webViewHelper.webView()->pageScaleFactor(
)); |
| 869 } | 882 } |
| 870 | 883 |
| 871 TEST_F(WebFrameTest, WideViewportInitialScaleDoesNotExpandFixedLayoutWidth) | 884 TEST_F(WebFrameTest, WideViewportInitialScaleDoesNotExpandFixedLayoutWidth) |
| 872 { | 885 { |
| 873 registerMockedHttpURLLoad("viewport-device-0.5x-initial-scale.html"); | 886 registerMockedHttpURLLoad("viewport-device-0.5x-initial-scale.html"); |
| 874 | 887 |
| 875 FixedLayoutTestWebViewClient client; | 888 FixedLayoutTestWebViewClient client; |
| 876 client.m_screenInfo.deviceScaleFactor = 1; | 889 client.m_screenInfo.deviceScaleFactor = 1; |
| 877 int viewportWidth = 640; | 890 int viewportWidth = 640; |
| 878 int viewportHeight = 480; | 891 int viewportHeight = 480; |
| 879 | 892 |
| 880 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport-dev
ice-0.5x-initial-scale.html", true, 0, &client); | 893 FrameTestHelpers::WebViewHelper webViewHelper; |
| 881 m_webView->enableFixedLayoutMode(true); | 894 webViewHelper.initializeAndLoad(m_baseURL + "viewport-device-0.5x-initial-sc
ale.html", true, 0, &client); |
| 882 m_webView->settings()->setViewportEnabled(true); | 895 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 883 m_webView->settings()->setWideViewportQuirkEnabled(true); | 896 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 884 m_webView->settings()->setUseWideViewport(true); | 897 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 885 m_webView->settings()->setViewportMetaLayoutSizeQuirk(true); | 898 webViewHelper.webView()->settings()->setUseWideViewport(true); |
| 886 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 899 webViewHelper.webView()->settings()->setViewportMetaLayoutSizeQuirk(true); |
| 900 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 887 | 901 |
| 888 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); | 902 EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frame
View()->fixedLayoutSize().width()); |
| 889 EXPECT_EQ(viewportWidth, webViewImpl->mainFrameImpl()->frameView()->fixedLay
outSize().width()); | |
| 890 } | 903 } |
| 891 | 904 |
| 892 TEST_F(WebFrameTest, ZeroValuesQuirk) | 905 TEST_F(WebFrameTest, ZeroValuesQuirk) |
| 893 { | 906 { |
| 894 registerMockedHttpURLLoad("viewport-zero-values.html"); | 907 registerMockedHttpURLLoad("viewport-zero-values.html"); |
| 895 | 908 |
| 896 FixedLayoutTestWebViewClient client; | 909 FixedLayoutTestWebViewClient client; |
| 897 client.m_screenInfo.deviceScaleFactor = 1; | 910 client.m_screenInfo.deviceScaleFactor = 1; |
| 898 int viewportWidth = 640; | 911 int viewportWidth = 640; |
| 899 int viewportHeight = 480; | 912 int viewportHeight = 480; |
| 900 | 913 |
| 901 m_webView = FrameTestHelpers::createWebView(true, 0, &client); | 914 FrameTestHelpers::WebViewHelper webViewHelper; |
| 902 m_webView->enableFixedLayoutMode(true); | 915 webViewHelper.initialize(true, 0, &client); |
| 903 m_webView->settings()->setViewportEnabled(true); | 916 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 904 m_webView->settings()->setViewportMetaZeroValuesQuirk(true); | 917 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 905 m_webView->settings()->setWideViewportQuirkEnabled(true); | 918 webViewHelper.webView()->settings()->setViewportMetaZeroValuesQuirk(true); |
| 906 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "viewport-ze
ro-values.html"); | 919 webViewHelper.webView()->settings()->setWideViewportQuirkEnabled(true); |
| 920 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL
+ "viewport-zero-values.html"); |
| 907 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 921 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 908 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 922 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 909 | 923 |
| 910 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); | 924 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(webViewHelper.webView()
); |
| 911 EXPECT_EQ(viewportWidth, webViewImpl->mainFrameImpl()->frameView()->fixedLay
outSize().width()); | 925 EXPECT_EQ(viewportWidth, webViewImpl->mainFrameImpl()->frameView()->fixedLay
outSize().width()); |
| 912 EXPECT_EQ(1.0f, m_webView->pageScaleFactor()); | 926 EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor()); |
| 913 | 927 |
| 914 m_webView->settings()->setUseWideViewport(true); | 928 webViewHelper.webView()->settings()->setUseWideViewport(true); |
| 915 m_webView->layout(); | 929 webViewHelper.webView()->layout(); |
| 916 EXPECT_EQ(viewportWidth, webViewImpl->mainFrameImpl()->frameView()->fixedLay
outSize().width()); | 930 EXPECT_EQ(viewportWidth, webViewImpl->mainFrameImpl()->frameView()->fixedLay
outSize().width()); |
| 917 EXPECT_EQ(1.0f, m_webView->pageScaleFactor()); | 931 EXPECT_EQ(1.0f, webViewHelper.webView()->pageScaleFactor()); |
| 918 } | 932 } |
| 919 | 933 |
| 920 TEST_F(WebFrameTest, ScaleFactorShouldNotOscillate) | 934 TEST_F(WebFrameTest, ScaleFactorShouldNotOscillate) |
| 921 { | 935 { |
| 922 registerMockedHttpURLLoad("scale_oscillate.html"); | 936 registerMockedHttpURLLoad("scale_oscillate.html"); |
| 923 | 937 |
| 924 FixedLayoutTestWebViewClient client; | 938 FixedLayoutTestWebViewClient client; |
| 925 client.m_screenInfo.deviceScaleFactor = static_cast<float>(1.325); | 939 client.m_screenInfo.deviceScaleFactor = static_cast<float>(1.325); |
| 926 int viewportWidth = 800; | 940 int viewportWidth = 800; |
| 927 int viewportHeight = 1057; | 941 int viewportHeight = 1057; |
| 928 | 942 |
| 929 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "scale_oscill
ate.html", true, 0, &client); | 943 FrameTestHelpers::WebViewHelper webViewHelper; |
| 930 m_webView->enableFixedLayoutMode(true); | 944 webViewHelper.initializeAndLoad(m_baseURL + "scale_oscillate.html", true, 0,
&client); |
| 931 m_webView->settings()->setViewportEnabled(true); | 945 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 932 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 946 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 933 m_webView->layout(); | 947 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 948 webViewHelper.webView()->layout(); |
| 934 } | 949 } |
| 935 | 950 |
| 936 TEST_F(WebFrameTest, setPageScaleFactorDoesNotLayout) | 951 TEST_F(WebFrameTest, setPageScaleFactorDoesNotLayout) |
| 937 { | 952 { |
| 938 registerMockedHttpURLLoad("fixed_layout.html"); | 953 registerMockedHttpURLLoad("fixed_layout.html"); |
| 939 | 954 |
| 940 FixedLayoutTestWebViewClient client; | 955 FixedLayoutTestWebViewClient client; |
| 941 client.m_screenInfo.deviceScaleFactor = 1; | 956 client.m_screenInfo.deviceScaleFactor = 1; |
| 942 // Small viewport to ensure there are always scrollbars. | 957 // Small viewport to ensure there are always scrollbars. |
| 943 int viewportWidth = 64; | 958 int viewportWidth = 64; |
| 944 int viewportHeight = 48; | 959 int viewportHeight = 48; |
| 945 | 960 |
| 946 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 961 FrameTestHelpers::WebViewHelper webViewHelper; |
| 947 m_webView->enableFixedLayoutMode(true); | 962 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 948 m_webView->settings()->setViewportEnabled(true); | 963 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 949 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 964 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 950 m_webView->layout(); | 965 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 966 webViewHelper.webView()->layout(); |
| 951 | 967 |
| 952 int prevLayoutCount = webViewImpl()->mainFrameImpl()->frameView()->layoutCou
nt(); | 968 int prevLayoutCount = webViewHelper.webViewImpl()->mainFrameImpl()->frameVie
w()->layoutCount(); |
| 953 webViewImpl()->setPageScaleFactor(3, WebPoint()); | 969 webViewHelper.webViewImpl()->setPageScaleFactor(3, WebPoint()); |
| 954 EXPECT_FALSE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); | 970 EXPECT_FALSE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->need
sLayout()); |
| 955 EXPECT_EQ(prevLayoutCount, webViewImpl()->mainFrameImpl()->frameView()->layo
utCount()); | 971 EXPECT_EQ(prevLayoutCount, webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView()->layoutCount()); |
| 956 } | 972 } |
| 957 | 973 |
| 958 TEST_F(WebFrameTest, setPageScaleFactorWithOverlayScrollbarsDoesNotLayout) | 974 TEST_F(WebFrameTest, setPageScaleFactorWithOverlayScrollbarsDoesNotLayout) |
| 959 { | 975 { |
| 960 UseMockScrollbarSettings mockScrollbarSettings; | 976 UseMockScrollbarSettings mockScrollbarSettings; |
| 961 | 977 |
| 962 registerMockedHttpURLLoad("fixed_layout.html"); | 978 registerMockedHttpURLLoad("fixed_layout.html"); |
| 963 | 979 |
| 964 FixedLayoutTestWebViewClient client; | 980 FixedLayoutTestWebViewClient client; |
| 965 client.m_screenInfo.deviceScaleFactor = 1; | 981 client.m_screenInfo.deviceScaleFactor = 1; |
| 966 int viewportWidth = 640; | 982 int viewportWidth = 640; |
| 967 int viewportHeight = 480; | 983 int viewportHeight = 480; |
| 968 | 984 |
| 969 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 985 FrameTestHelpers::WebViewHelper webViewHelper; |
| 970 m_webView->enableFixedLayoutMode(true); | 986 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 971 m_webView->settings()->setViewportEnabled(true); | 987 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 972 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 988 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 973 m_webView->layout(); | 989 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 990 webViewHelper.webView()->layout(); |
| 974 | 991 |
| 975 int prevLayoutCount = webViewImpl()->mainFrameImpl()->frameView()->layoutCou
nt(); | 992 int prevLayoutCount = webViewHelper.webViewImpl()->mainFrameImpl()->frameVie
w()->layoutCount(); |
| 976 webViewImpl()->setPageScaleFactor(30, WebPoint()); | 993 webViewHelper.webViewImpl()->setPageScaleFactor(30, WebPoint()); |
| 977 EXPECT_FALSE(webViewImpl()->mainFrameImpl()->frameView()->needsLayout()); | 994 EXPECT_FALSE(webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->need
sLayout()); |
| 978 EXPECT_EQ(prevLayoutCount, webViewImpl()->mainFrameImpl()->frameView()->layo
utCount()); | 995 EXPECT_EQ(prevLayoutCount, webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView()->layoutCount()); |
| 979 | 996 |
| 980 } | 997 } |
| 981 | 998 |
| 982 TEST_F(WebFrameTest, setPageScaleFactorBeforeFrameHasView) | 999 TEST_F(WebFrameTest, setPageScaleFactorBeforeFrameHasView) |
| 983 { | 1000 { |
| 984 registerMockedHttpURLLoad("fixed_layout.html"); | 1001 registerMockedHttpURLLoad("fixed_layout.html"); |
| 985 | 1002 |
| 986 float pageScaleFactor = 3; | 1003 float pageScaleFactor = 3; |
| 987 m_webView = FrameTestHelpers::createWebViewAndLoad("about:html", true, 0, 0)
; | 1004 FrameTestHelpers::WebViewHelper webViewHelper; |
| 988 m_webView->setPageScaleFactor(pageScaleFactor, WebPoint()); | 1005 webViewHelper.initializeAndLoad("about:html", true, 0, 0); |
| 1006 webViewHelper.webView()->setPageScaleFactor(pageScaleFactor, WebPoint()); |
| 989 | 1007 |
| 990 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "fixed_layou
t.html"); | 1008 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL
+ "fixed_layout.html"); |
| 991 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 1009 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 992 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); | 1010 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView(); |
| 993 EXPECT_EQ(pageScaleFactor, view->visibleContentScaleFactor()); | 1011 EXPECT_EQ(pageScaleFactor, view->visibleContentScaleFactor()); |
| 994 } | 1012 } |
| 995 | 1013 |
| 996 TEST_F(WebFrameTest, pageScaleFactorWrittenToHistoryItem) | 1014 TEST_F(WebFrameTest, pageScaleFactorWrittenToHistoryItem) |
| 997 { | 1015 { |
| 998 registerMockedHttpURLLoad("fixed_layout.html"); | 1016 registerMockedHttpURLLoad("fixed_layout.html"); |
| 999 | 1017 |
| 1000 FixedLayoutTestWebViewClient client; | 1018 FixedLayoutTestWebViewClient client; |
| 1001 client.m_screenInfo.deviceScaleFactor = 1; | 1019 client.m_screenInfo.deviceScaleFactor = 1; |
| 1002 int viewportWidth = 640; | 1020 int viewportWidth = 640; |
| 1003 int viewportHeight = 480; | 1021 int viewportHeight = 480; |
| 1004 | 1022 |
| 1005 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 1023 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1006 m_webView->enableFixedLayoutMode(true); | 1024 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 1007 m_webView->settings()->setViewportEnabled(true); | 1025 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1008 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1026 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1009 m_webView->layout(); | 1027 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1028 webViewHelper.webView()->layout(); |
| 1010 | 1029 |
| 1011 m_webView->setPageScaleFactor(3, WebPoint()); | 1030 webViewHelper.webView()->setPageScaleFactor(3, WebPoint()); |
| 1012 webViewImpl()->page()->mainFrame()->loader()->history()->saveDocumentAndScro
llState(); | 1031 webViewHelper.webViewImpl()->page()->mainFrame()->loader()->history()->saveD
ocumentAndScrollState(); |
| 1013 m_webView->setPageScaleFactor(1, WebPoint()); | 1032 webViewHelper.webView()->setPageScaleFactor(1, WebPoint()); |
| 1014 webViewImpl()->page()->mainFrame()->loader()->history()->restoreScrollPositi
onAndViewState(); | 1033 webViewHelper.webViewImpl()->page()->mainFrame()->loader()->history()->resto
reScrollPositionAndViewState(); |
| 1015 EXPECT_EQ(3, m_webView->pageScaleFactor()); | 1034 EXPECT_EQ(3, webViewHelper.webView()->pageScaleFactor()); |
| 1016 } | 1035 } |
| 1017 | 1036 |
| 1018 TEST_F(WebFrameTest, pageScaleFactorShrinksViewport) | 1037 TEST_F(WebFrameTest, pageScaleFactorShrinksViewport) |
| 1019 { | 1038 { |
| 1020 registerMockedHttpURLLoad("large-div.html"); | 1039 registerMockedHttpURLLoad("large-div.html"); |
| 1021 | 1040 |
| 1022 FixedLayoutTestWebViewClient client; | 1041 FixedLayoutTestWebViewClient client; |
| 1023 client.m_screenInfo.deviceScaleFactor = 1; | 1042 client.m_screenInfo.deviceScaleFactor = 1; |
| 1024 // Small viewport to ensure there are always scrollbars. | 1043 // Small viewport to ensure there are always scrollbars. |
| 1025 int viewportWidth = 64; | 1044 int viewportWidth = 64; |
| 1026 int viewportHeight = 48; | 1045 int viewportHeight = 48; |
| 1027 | 1046 |
| 1028 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "large-div.ht
ml", true, 0, &client); | 1047 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1029 m_webView->enableFixedLayoutMode(true); | 1048 webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &clie
nt); |
| 1030 m_webView->settings()->setViewportEnabled(true); | 1049 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1031 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1050 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1032 m_webView->layout(); | 1051 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1052 webViewHelper.webView()->layout(); |
| 1033 | 1053 |
| 1034 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); | 1054 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView(); |
| 1035 int viewportWidthMinusScrollbar = viewportWidth - (view->verticalScrollbar()
->isOverlayScrollbar() ? 0 : 15); | 1055 int viewportWidthMinusScrollbar = viewportWidth - (view->verticalScrollbar()
->isOverlayScrollbar() ? 0 : 15); |
| 1036 int viewportHeightMinusScrollbar = viewportHeight - (view->horizontalScrollb
ar()->isOverlayScrollbar() ? 0 : 15); | 1056 int viewportHeightMinusScrollbar = viewportHeight - (view->horizontalScrollb
ar()->isOverlayScrollbar() ? 0 : 15); |
| 1037 | 1057 |
| 1038 m_webView->setPageScaleFactor(2, WebPoint()); | 1058 webViewHelper.webView()->setPageScaleFactor(2, WebPoint()); |
| 1039 | 1059 |
| 1040 WebCore::IntSize unscaledSize = view->unscaledVisibleContentSize(WebCore::Sc
rollableArea::IncludeScrollbars); | 1060 WebCore::IntSize unscaledSize = view->unscaledVisibleContentSize(WebCore::Sc
rollableArea::IncludeScrollbars); |
| 1041 EXPECT_EQ(viewportWidth, unscaledSize.width()); | 1061 EXPECT_EQ(viewportWidth, unscaledSize.width()); |
| 1042 EXPECT_EQ(viewportHeight, unscaledSize.height()); | 1062 EXPECT_EQ(viewportHeight, unscaledSize.height()); |
| 1043 | 1063 |
| 1044 WebCore::IntSize unscaledSizeMinusScrollbar = view->unscaledVisibleContentSi
ze(WebCore::ScrollableArea::ExcludeScrollbars); | 1064 WebCore::IntSize unscaledSizeMinusScrollbar = view->unscaledVisibleContentSi
ze(WebCore::ScrollableArea::ExcludeScrollbars); |
| 1045 EXPECT_EQ(viewportWidthMinusScrollbar, unscaledSizeMinusScrollbar.width()); | 1065 EXPECT_EQ(viewportWidthMinusScrollbar, unscaledSizeMinusScrollbar.width()); |
| 1046 EXPECT_EQ(viewportHeightMinusScrollbar, unscaledSizeMinusScrollbar.height())
; | 1066 EXPECT_EQ(viewportHeightMinusScrollbar, unscaledSizeMinusScrollbar.height())
; |
| 1047 | 1067 |
| 1048 WebCore::IntSize scaledSize = view->visibleContentRect().size(); | 1068 WebCore::IntSize scaledSize = view->visibleContentRect().size(); |
| 1049 EXPECT_EQ(ceil(viewportWidthMinusScrollbar / 2.0), scaledSize.width()); | 1069 EXPECT_EQ(ceil(viewportWidthMinusScrollbar / 2.0), scaledSize.width()); |
| 1050 EXPECT_EQ(ceil(viewportHeightMinusScrollbar / 2.0), scaledSize.height()); | 1070 EXPECT_EQ(ceil(viewportHeightMinusScrollbar / 2.0), scaledSize.height()); |
| 1051 } | 1071 } |
| 1052 | 1072 |
| 1053 TEST_F(WebFrameTest, pageScaleFactorDoesNotApplyCssTransform) | 1073 TEST_F(WebFrameTest, pageScaleFactorDoesNotApplyCssTransform) |
| 1054 { | 1074 { |
| 1055 registerMockedHttpURLLoad("fixed_layout.html"); | 1075 registerMockedHttpURLLoad("fixed_layout.html"); |
| 1056 | 1076 |
| 1057 FixedLayoutTestWebViewClient client; | 1077 FixedLayoutTestWebViewClient client; |
| 1058 client.m_screenInfo.deviceScaleFactor = 1; | 1078 client.m_screenInfo.deviceScaleFactor = 1; |
| 1059 int viewportWidth = 640; | 1079 int viewportWidth = 640; |
| 1060 int viewportHeight = 480; | 1080 int viewportHeight = 480; |
| 1061 | 1081 |
| 1062 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 1082 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1063 m_webView->enableFixedLayoutMode(true); | 1083 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 1064 m_webView->settings()->setViewportEnabled(true); | 1084 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1065 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1085 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1066 m_webView->layout(); | 1086 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1087 webViewHelper.webView()->layout(); |
| 1067 | 1088 |
| 1068 m_webView->setPageScaleFactor(2, WebPoint()); | 1089 webViewHelper.webView()->setPageScaleFactor(2, WebPoint()); |
| 1069 | 1090 |
| 1070 EXPECT_EQ(980, webViewImpl()->page()->mainFrame()->contentRenderer()->unscal
edDocumentRect().width()); | 1091 EXPECT_EQ(980, webViewHelper.webViewImpl()->page()->mainFrame()->contentRend
erer()->unscaledDocumentRect().width()); |
| 1071 EXPECT_EQ(980, webViewImpl()->mainFrameImpl()->frameView()->contentsSize().w
idth()); | 1092 EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->co
ntentsSize().width()); |
| 1072 } | 1093 } |
| 1073 | 1094 |
| 1074 TEST_F(WebFrameTest, targetDensityDpiHigh) | 1095 TEST_F(WebFrameTest, targetDensityDpiHigh) |
| 1075 { | 1096 { |
| 1076 UseMockScrollbarSettings mockScrollbarSettings; | 1097 UseMockScrollbarSettings mockScrollbarSettings; |
| 1077 registerMockedHttpURLLoad("viewport-target-densitydpi-high.html"); | 1098 registerMockedHttpURLLoad("viewport-target-densitydpi-high.html"); |
| 1078 | 1099 |
| 1079 FixedLayoutTestWebViewClient client; | 1100 FixedLayoutTestWebViewClient client; |
| 1080 // high-dpi = 240 | 1101 // high-dpi = 240 |
| 1081 float targetDpi = 240.0f; | 1102 float targetDpi = 240.0f; |
| 1082 float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f }; | 1103 float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f }; |
| 1083 int viewportWidth = 640; | 1104 int viewportWidth = 640; |
| 1084 int viewportHeight = 480; | 1105 int viewportHeight = 480; |
| 1085 | 1106 |
| 1086 for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) { | 1107 for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) { |
| 1087 float deviceScaleFactor = deviceScaleFactors[i]; | 1108 float deviceScaleFactor = deviceScaleFactors[i]; |
| 1088 float deviceDpi = deviceScaleFactor * 160.0f; | 1109 float deviceDpi = deviceScaleFactor * 160.0f; |
| 1089 client.m_screenInfo.deviceScaleFactor = deviceScaleFactor; | 1110 client.m_screenInfo.deviceScaleFactor = deviceScaleFactor; |
| 1090 | 1111 |
| 1091 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport
-target-densitydpi-high.html", true, 0, &client); | 1112 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1092 m_webView->enableFixedLayoutMode(true); | 1113 webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-high
.html", true, 0, &client); |
| 1093 m_webView->settings()->setViewportEnabled(true); | 1114 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1094 m_webView->settings()->setSupportDeprecatedTargetDensityDPI(true); | 1115 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1095 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1116 webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDP
I(true); |
| 1117 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1096 | 1118 |
| 1097 // We need to account for the fact that logical pixels are unconditional
ly multiplied by deviceScaleFactor to produce | 1119 // We need to account for the fact that logical pixels are unconditional
ly multiplied by deviceScaleFactor to produce |
| 1098 // physical pixels. | 1120 // physical pixels. |
| 1099 float densityDpiScaleRatio = deviceScaleFactor * targetDpi / deviceDpi; | 1121 float densityDpiScaleRatio = deviceScaleFactor * targetDpi / deviceDpi; |
| 1100 EXPECT_NEAR(viewportWidth * densityDpiScaleRatio, m_webView->fixedLayout
Size().width, 1.0f); | 1122 EXPECT_NEAR(viewportWidth * densityDpiScaleRatio, webViewHelper.webView(
)->fixedLayoutSize().width, 1.0f); |
| 1101 EXPECT_NEAR(viewportHeight * densityDpiScaleRatio, m_webView->fixedLayou
tSize().height, 1.0f); | 1123 EXPECT_NEAR(viewportHeight * densityDpiScaleRatio, webViewHelper.webView
()->fixedLayoutSize().height, 1.0f); |
| 1102 EXPECT_NEAR(1.0f / densityDpiScaleRatio, m_webView->pageScaleFactor(), 0
.01f); | 1124 EXPECT_NEAR(1.0f / densityDpiScaleRatio, webViewHelper.webView()->pageSc
aleFactor(), 0.01f); |
| 1103 | |
| 1104 m_webView->close(); | |
| 1105 m_webView = 0; | |
| 1106 } | 1125 } |
| 1107 } | 1126 } |
| 1108 | 1127 |
| 1109 TEST_F(WebFrameTest, targetDensityDpiDevice) | 1128 TEST_F(WebFrameTest, targetDensityDpiDevice) |
| 1110 { | 1129 { |
| 1111 UseMockScrollbarSettings mockScrollbarSettings; | 1130 UseMockScrollbarSettings mockScrollbarSettings; |
| 1112 registerMockedHttpURLLoad("viewport-target-densitydpi-device.html"); | 1131 registerMockedHttpURLLoad("viewport-target-densitydpi-device.html"); |
| 1113 | 1132 |
| 1114 float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f }; | 1133 float deviceScaleFactors[] = { 1.0f, 4.0f / 3.0f, 2.0f }; |
| 1115 | 1134 |
| 1116 FixedLayoutTestWebViewClient client; | 1135 FixedLayoutTestWebViewClient client; |
| 1117 int viewportWidth = 640; | 1136 int viewportWidth = 640; |
| 1118 int viewportHeight = 480; | 1137 int viewportHeight = 480; |
| 1119 | 1138 |
| 1120 for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) { | 1139 for (size_t i = 0; i < ARRAY_SIZE(deviceScaleFactors); ++i) { |
| 1121 client.m_screenInfo.deviceScaleFactor = deviceScaleFactors[i]; | 1140 client.m_screenInfo.deviceScaleFactor = deviceScaleFactors[i]; |
| 1122 | 1141 |
| 1123 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "viewport
-target-densitydpi-device.html", true, 0, &client); | 1142 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1124 m_webView->enableFixedLayoutMode(true); | 1143 webViewHelper.initializeAndLoad(m_baseURL + "viewport-target-densitydpi-devi
ce.html", true, 0, &client); |
| 1125 m_webView->settings()->setViewportEnabled(true); | 1144 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1126 m_webView->settings()->setSupportDeprecatedTargetDensityDPI(true); | 1145 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1127 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1146 webViewHelper.webView()->settings()->setSupportDeprecatedTargetDensityDP
I(true); |
| 1147 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1128 | 1148 |
| 1129 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, m_web
View->fixedLayoutSize().width, 1.0f); | 1149 EXPECT_NEAR(viewportWidth * client.m_screenInfo.deviceScaleFactor, webVi
ewHelper.webView()->fixedLayoutSize().width, 1.0f); |
| 1130 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, m_we
bView->fixedLayoutSize().height, 1.0f); | 1150 EXPECT_NEAR(viewportHeight * client.m_screenInfo.deviceScaleFactor, webV
iewHelper.webView()->fixedLayoutSize().height, 1.0f); |
| 1131 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, m_webView->pag
eScaleFactor(), 0.01f); | 1151 EXPECT_NEAR(1.0f / client.m_screenInfo.deviceScaleFactor, webViewHelper.
webView()->pageScaleFactor(), 0.01f); |
| 1132 | |
| 1133 m_webView->close(); | |
| 1134 m_webView = 0; | |
| 1135 } | 1152 } |
| 1136 } | 1153 } |
| 1137 | 1154 |
| 1138 class WebFrameResizeTest : public WebFrameTest { | 1155 class WebFrameResizeTest : public WebFrameTest { |
| 1139 protected: | 1156 protected: |
| 1140 | 1157 |
| 1141 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& abs
oluteOffset, const WebCore::LayoutRect& rect) | 1158 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& abs
oluteOffset, const WebCore::LayoutRect& rect) |
| 1142 { | 1159 { |
| 1143 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset)
- rect.location(); | 1160 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset)
- rect.location(); |
| 1144 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height()); | 1161 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height()); |
| 1145 return relativeOffset; | 1162 return relativeOffset; |
| 1146 } | 1163 } |
| 1147 | 1164 |
| 1148 void testResizeYieldsCorrectScrollAndScale(const char* url, | 1165 void testResizeYieldsCorrectScrollAndScale(const char* url, |
| 1149 const float initialPageScaleFacto
r, | 1166 const float initialPageScaleFacto
r, |
| 1150 const WebSize scrollOffset, | 1167 const WebSize scrollOffset, |
| 1151 const WebSize viewportSize, | 1168 const WebSize viewportSize, |
| 1152 const bool shouldScaleRelativeToV
iewportWidth) { | 1169 const bool shouldScaleRelativeToV
iewportWidth) { |
| 1153 registerMockedHttpURLLoad(url); | 1170 registerMockedHttpURLLoad(url); |
| 1154 | 1171 |
| 1155 const float aspectRatio = static_cast<float>(viewportSize.width) / viewp
ortSize.height; | 1172 const float aspectRatio = static_cast<float>(viewportSize.width) / viewp
ortSize.height; |
| 1156 | 1173 |
| 1157 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + url, true
); | 1174 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1158 m_webView->settings()->setViewportEnabled(true); | 1175 webViewHelper.initializeAndLoad(m_baseURL + url, true); |
| 1159 m_webView->enableFixedLayoutMode(true); | 1176 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1177 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1160 | 1178 |
| 1161 // Origin scrollOffsets preserved under resize. | 1179 // Origin scrollOffsets preserved under resize. |
| 1162 { | 1180 { |
| 1163 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh
t)); | 1181 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view
portSize.height)); |
| 1164 webViewImpl()->setPageScaleFactor(initialPageScaleFactor, WebPoint()
); | 1182 webViewHelper.webViewImpl()->setPageScaleFactor(initialPageScaleFact
or, WebPoint()); |
| 1165 ASSERT_EQ(viewportSize, webViewImpl()->size()); | 1183 ASSERT_EQ(viewportSize, webViewHelper.webViewImpl()->size()); |
| 1166 ASSERT_EQ(initialPageScaleFactor, webViewImpl()->pageScaleFactor()); | 1184 ASSERT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageS
caleFactor()); |
| 1167 webViewImpl()->resize(WebSize(viewportSize.height, viewportSize.widt
h)); | 1185 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.height, vie
wportSize.width)); |
| 1168 float expectedPageScaleFactor = initialPageScaleFactor * (shouldScal
eRelativeToViewportWidth ? 1 / aspectRatio : 1); | 1186 float expectedPageScaleFactor = initialPageScaleFactor * (shouldScal
eRelativeToViewportWidth ? 1 / aspectRatio : 1); |
| 1169 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl()->pageScaleFactor(
), 0.05f); | 1187 EXPECT_NEAR(expectedPageScaleFactor, webViewHelper.webViewImpl()->pa
geScaleFactor(), 0.05f); |
| 1170 EXPECT_EQ(WebSize(), webViewImpl()->mainFrame()->scrollOffset()); | 1188 EXPECT_EQ(WebSize(), webViewHelper.webViewImpl()->mainFrame()->scrol
lOffset()); |
| 1171 } | 1189 } |
| 1172 | 1190 |
| 1173 // Resizing just the height should not affect pageScaleFactor or scrollO
ffset. | 1191 // Resizing just the height should not affect pageScaleFactor or scrollO
ffset. |
| 1174 { | 1192 { |
| 1175 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh
t)); | 1193 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view
portSize.height)); |
| 1176 webViewImpl()->setPageScaleFactor(initialPageScaleFactor, WebPoint(s
crollOffset.width, scrollOffset.height)); | 1194 webViewHelper.webViewImpl()->setPageScaleFactor(initialPageScaleFact
or, WebPoint(scrollOffset.width, scrollOffset.height)); |
| 1177 webViewImpl()->layout(); | 1195 webViewHelper.webViewImpl()->layout(); |
| 1178 const WebSize expectedScrollOffset = webViewImpl()->mainFrame()->scr
ollOffset(); | 1196 const WebSize expectedScrollOffset = webViewHelper.webViewImpl()->ma
inFrame()->scrollOffset(); |
| 1179 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh
t * 0.8f)); | 1197 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view
portSize.height * 0.8f)); |
| 1180 EXPECT_EQ(initialPageScaleFactor, webViewImpl()->pageScaleFactor()); | 1198 EXPECT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageS
caleFactor()); |
| 1181 EXPECT_EQ(expectedScrollOffset, webViewImpl()->mainFrame()->scrollOf
fset()); | 1199 EXPECT_EQ(expectedScrollOffset, webViewHelper.webViewImpl()->mainFra
me()->scrollOffset()); |
| 1182 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh
t * 0.8f)); | 1200 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view
portSize.height * 0.8f)); |
| 1183 EXPECT_EQ(initialPageScaleFactor, webViewImpl()->pageScaleFactor()); | 1201 EXPECT_EQ(initialPageScaleFactor, webViewHelper.webViewImpl()->pageS
caleFactor()); |
| 1184 EXPECT_EQ(expectedScrollOffset, webViewImpl()->mainFrame()->scrollOf
fset()); | 1202 EXPECT_EQ(expectedScrollOffset, webViewHelper.webViewImpl()->mainFra
me()->scrollOffset()); |
| 1185 } | 1203 } |
| 1186 | 1204 |
| 1187 // Generic resize preserves scrollOffset relative to anchor node located | 1205 // Generic resize preserves scrollOffset relative to anchor node located |
| 1188 // the top center of the screen. | 1206 // the top center of the screen. |
| 1189 { | 1207 { |
| 1190 webViewImpl()->resize(WebSize(viewportSize.height, viewportSize.widt
h)); | 1208 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.height, vie
wportSize.width)); |
| 1191 float pageScaleFactor = webViewImpl()->pageScaleFactor(); | 1209 float pageScaleFactor = webViewHelper.webViewImpl()->pageScaleFactor
(); |
| 1192 webViewImpl()->resize(WebSize(viewportSize.width, viewportSize.heigh
t)); | 1210 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.width, view
portSize.height)); |
| 1193 float expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelati
veToViewportWidth ? aspectRatio : 1); | 1211 float expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelati
veToViewportWidth ? aspectRatio : 1); |
| 1194 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl()->pageScaleFactor(
), 0.05f); | 1212 EXPECT_NEAR(expectedPageScaleFactor, webViewHelper.webViewImpl()->pa
geScaleFactor(), 0.05f); |
| 1195 webViewImpl()->mainFrame()->setScrollOffset(scrollOffset); | 1213 webViewHelper.webViewImpl()->mainFrame()->setScrollOffset(scrollOffs
et); |
| 1196 | 1214 |
| 1197 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + We
bCore::IntPoint(viewportSize.width / 2, 0); | 1215 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + We
bCore::IntPoint(viewportSize.width / 2, 0); |
| 1198 RefPtr<WebCore::Node> anchorNode = webViewImpl()->mainFrameImpl()->f
rame()->eventHandler()->hitTestResultAtPoint(anchorPoint, HitTestRequest::ReadOn
ly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent).innerNode()
; | 1216 RefPtr<WebCore::Node> anchorNode = webViewHelper.webViewImpl()->main
FrameImpl()->frame()->eventHandler()->hitTestResultAtPoint(anchorPoint, HitTestR
equest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowConten
t).innerNode(); |
| 1199 ASSERT(anchorNode); | 1217 ASSERT(anchorNode); |
| 1200 | 1218 |
| 1201 pageScaleFactor = webViewImpl()->pageScaleFactor(); | 1219 pageScaleFactor = webViewHelper.webViewImpl()->pageScaleFactor(); |
| 1202 const WebCore::FloatSize preResizeRelativeOffset | 1220 const WebCore::FloatSize preResizeRelativeOffset |
| 1203 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox()); | 1221 = computeRelativeOffset(anchorPoint, anchorNode->boundingBox()); |
| 1204 webViewImpl()->resize(WebSize(viewportSize.height, viewportSize.widt
h)); | 1222 webViewHelper.webViewImpl()->resize(WebSize(viewportSize.height, vie
wportSize.width)); |
| 1205 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl()->
mainFrame()->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0); | 1223 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewHelper.w
ebViewImpl()->mainFrame()->scrollOffset()) + WebCore::IntPoint(viewportSize.heig
ht / 2, 0); |
| 1206 const WebCore::FloatSize postResizeRelativeOffset | 1224 const WebCore::FloatSize postResizeRelativeOffset |
| 1207 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox(
)); | 1225 = computeRelativeOffset(newAnchorPoint, anchorNode->boundingBox(
)); |
| 1208 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffse
t.width(), 0.15f); | 1226 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffse
t.width(), 0.15f); |
| 1209 expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToVi
ewportWidth ? 1 / aspectRatio : 1); | 1227 expectedPageScaleFactor = pageScaleFactor * (shouldScaleRelativeToVi
ewportWidth ? 1 / aspectRatio : 1); |
| 1210 EXPECT_NEAR(expectedPageScaleFactor, webViewImpl()->pageScaleFactor(
), 0.05f); | 1228 EXPECT_NEAR(expectedPageScaleFactor, webViewHelper.webViewImpl()->pa
geScaleFactor(), 0.05f); |
| 1211 } | 1229 } |
| 1212 } | 1230 } |
| 1213 }; | 1231 }; |
| 1214 | 1232 |
| 1215 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDevice
Width) | 1233 TEST_F(WebFrameResizeTest, ResizeYieldsCorrectScrollAndScaleForWidthEqualsDevice
Width) |
| 1216 { | 1234 { |
| 1217 // With width=device-width, pageScaleFactor is preserved across resizes as | 1235 // With width=device-width, pageScaleFactor is preserved across resizes as |
| 1218 // long as the content adjusts according to the device-width. | 1236 // long as the content adjusts according to the device-width. |
| 1219 const char* url = "resize_scroll_mobile.html"; | 1237 const char* url = "resize_scroll_mobile.html"; |
| 1220 const float initialPageScaleFactor = 1; | 1238 const float initialPageScaleFactor = 1; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) | 1273 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) |
| 1256 { | 1274 { |
| 1257 UseMockScrollbarSettings mockScrollbarSettings; | 1275 UseMockScrollbarSettings mockScrollbarSettings; |
| 1258 registerMockedHttpURLLoad("large-div.html"); | 1276 registerMockedHttpURLLoad("large-div.html"); |
| 1259 | 1277 |
| 1260 FixedLayoutTestWebViewClient client; | 1278 FixedLayoutTestWebViewClient client; |
| 1261 client.m_screenInfo.deviceScaleFactor = 1; | 1279 client.m_screenInfo.deviceScaleFactor = 1; |
| 1262 int viewportWidth = 50; | 1280 int viewportWidth = 50; |
| 1263 int viewportHeight = 50; | 1281 int viewportHeight = 50; |
| 1264 | 1282 |
| 1265 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "large-div.ht
ml", true, 0, &client); | 1283 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1266 m_webView->enableFixedLayoutMode(true); | 1284 webViewHelper.initializeAndLoad(m_baseURL + "large-div.html", true, 0, &clie
nt); |
| 1267 m_webView->settings()->setViewportEnabled(true); | 1285 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1268 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1286 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1269 m_webView->layout(); | 1287 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1288 webViewHelper.webView()->layout(); |
| 1270 | 1289 |
| 1271 // Set <1 page scale so that the clip rect should be larger than | 1290 // Set <1 page scale so that the clip rect should be larger than |
| 1272 // the viewport size as passed into resize(). | 1291 // the viewport size as passed into resize(). |
| 1273 m_webView->setPageScaleFactor(0.5, WebPoint()); | 1292 webViewHelper.webView()->setPageScaleFactor(0.5, WebPoint()); |
| 1274 | 1293 |
| 1275 SkBitmap bitmap; | 1294 SkBitmap bitmap; |
| 1276 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200); | 1295 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 200); |
| 1277 bitmap.allocPixels(); | 1296 bitmap.allocPixels(); |
| 1278 bitmap.eraseColor(0); | 1297 bitmap.eraseColor(0); |
| 1279 SkCanvas canvas(bitmap); | 1298 SkCanvas canvas(bitmap); |
| 1280 | 1299 |
| 1281 WebCore::GraphicsContext context(&canvas); | 1300 WebCore::GraphicsContext context(&canvas); |
| 1282 context.setTrackOpaqueRegion(true); | 1301 context.setTrackOpaqueRegion(true); |
| 1283 | 1302 |
| 1284 EXPECT_EQ_RECT(WebCore::IntRect(0, 0, 0, 0), context.opaqueRegion().asRect()
); | 1303 EXPECT_EQ_RECT(WebCore::IntRect(0, 0, 0, 0), context.opaqueRegion().asRect()
); |
| 1285 | 1304 |
| 1286 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); | 1305 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView(); |
| 1287 WebCore::IntRect paintRect(0, 0, 200, 200); | 1306 WebCore::IntRect paintRect(0, 0, 200, 200); |
| 1288 view->paint(&context, paintRect); | 1307 view->paint(&context, paintRect); |
| 1289 | 1308 |
| 1290 int viewportWidthMinusScrollbar = 50 - (view->verticalScrollbar()->isOverlay
Scrollbar() ? 0 : 15); | 1309 int viewportWidthMinusScrollbar = 50 - (view->verticalScrollbar()->isOverlay
Scrollbar() ? 0 : 15); |
| 1291 int viewportHeightMinusScrollbar = 50 - (view->horizontalScrollbar()->isOver
layScrollbar() ? 0 : 15); | 1310 int viewportHeightMinusScrollbar = 50 - (view->horizontalScrollbar()->isOver
layScrollbar() ? 0 : 15); |
| 1292 WebCore::IntRect clippedRect(0, 0, viewportWidthMinusScrollbar * 2, viewport
HeightMinusScrollbar * 2); | 1311 WebCore::IntRect clippedRect(0, 0, viewportWidthMinusScrollbar * 2, viewport
HeightMinusScrollbar * 2); |
| 1293 EXPECT_EQ_RECT(clippedRect, context.opaqueRegion().asRect()); | 1312 EXPECT_EQ_RECT(clippedRect, context.opaqueRegion().asRect()); |
| 1294 } | 1313 } |
| 1295 | 1314 |
| 1296 TEST_F(WebFrameTest, pageScaleFactorUpdatesScrollbars) | 1315 TEST_F(WebFrameTest, pageScaleFactorUpdatesScrollbars) |
| 1297 { | 1316 { |
| 1298 UseMockScrollbarSettings mockScrollbarSettings; | 1317 UseMockScrollbarSettings mockScrollbarSettings; |
| 1299 registerMockedHttpURLLoad("fixed_layout.html"); | 1318 registerMockedHttpURLLoad("fixed_layout.html"); |
| 1300 | 1319 |
| 1301 FixedLayoutTestWebViewClient client; | 1320 FixedLayoutTestWebViewClient client; |
| 1302 client.m_screenInfo.deviceScaleFactor = 1; | 1321 client.m_screenInfo.deviceScaleFactor = 1; |
| 1303 int viewportWidth = 640; | 1322 int viewportWidth = 640; |
| 1304 int viewportHeight = 480; | 1323 int viewportHeight = 480; |
| 1305 | 1324 |
| 1306 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout
.html", true, 0, &client); | 1325 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1307 m_webView->enableFixedLayoutMode(true); | 1326 webViewHelper.initializeAndLoad(m_baseURL + "fixed_layout.html", true, 0, &c
lient); |
| 1308 m_webView->settings()->setViewportEnabled(true); | 1327 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1309 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1328 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1310 m_webView->layout(); | 1329 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1330 webViewHelper.webView()->layout(); |
| 1311 | 1331 |
| 1312 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); | 1332 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView(); |
| 1313 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize
().width() - view->visibleContentRect().width()); | 1333 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize
().width() - view->visibleContentRect().width()); |
| 1314 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize()
.height() - view->visibleContentRect().height()); | 1334 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize()
.height() - view->visibleContentRect().height()); |
| 1315 | 1335 |
| 1316 m_webView->setPageScaleFactor(10, WebPoint()); | 1336 webViewHelper.webView()->setPageScaleFactor(10, WebPoint()); |
| 1317 | 1337 |
| 1318 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize
().width() - view->visibleContentRect().width()); | 1338 EXPECT_EQ(view->scrollSize(WebCore::HorizontalScrollbar), view->contentsSize
().width() - view->visibleContentRect().width()); |
| 1319 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize()
.height() - view->visibleContentRect().height()); | 1339 EXPECT_EQ(view->scrollSize(WebCore::VerticalScrollbar), view->contentsSize()
.height() - view->visibleContentRect().height()); |
| 1320 } | 1340 } |
| 1321 | 1341 |
| 1322 TEST_F(WebFrameTest, CanOverrideScaleLimits) | 1342 TEST_F(WebFrameTest, CanOverrideScaleLimits) |
| 1323 { | 1343 { |
| 1324 UseMockScrollbarSettings mockScrollbarSettings; | 1344 UseMockScrollbarSettings mockScrollbarSettings; |
| 1325 | 1345 |
| 1326 registerMockedHttpURLLoad("no_scale_for_you.html"); | 1346 registerMockedHttpURLLoad("no_scale_for_you.html"); |
| 1327 | 1347 |
| 1328 FixedLayoutTestWebViewClient client; | 1348 FixedLayoutTestWebViewClient client; |
| 1329 client.m_screenInfo.deviceScaleFactor = 1; | 1349 client.m_screenInfo.deviceScaleFactor = 1; |
| 1330 int viewportWidth = 640; | 1350 int viewportWidth = 640; |
| 1331 int viewportHeight = 480; | 1351 int viewportHeight = 480; |
| 1332 | 1352 |
| 1333 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_scale_for
_you.html", true, 0, &client); | 1353 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1334 m_webView->enableFixedLayoutMode(true); | 1354 webViewHelper.initializeAndLoad(m_baseURL + "no_scale_for_you.html", true, 0
, &client); |
| 1335 m_webView->settings()->setViewportEnabled(true); | 1355 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1336 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1356 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 1357 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1337 | 1358 |
| 1338 EXPECT_EQ(2.0f, m_webView->minimumPageScaleFactor()); | 1359 EXPECT_EQ(2.0f, webViewHelper.webView()->minimumPageScaleFactor()); |
| 1339 EXPECT_EQ(2.0f, m_webView->maximumPageScaleFactor()); | 1360 EXPECT_EQ(2.0f, webViewHelper.webView()->maximumPageScaleFactor()); |
| 1340 | 1361 |
| 1341 m_webView->setIgnoreViewportTagScaleLimits(true); | 1362 webViewHelper.webView()->setIgnoreViewportTagScaleLimits(true); |
| 1342 m_webView->layout(); | 1363 webViewHelper.webView()->layout(); |
| 1343 | 1364 |
| 1344 EXPECT_EQ(1.0f, m_webView->minimumPageScaleFactor()); | 1365 EXPECT_EQ(1.0f, webViewHelper.webView()->minimumPageScaleFactor()); |
| 1345 EXPECT_EQ(5.0f, m_webView->maximumPageScaleFactor()); | 1366 EXPECT_EQ(5.0f, webViewHelper.webView()->maximumPageScaleFactor()); |
| 1346 | 1367 |
| 1347 m_webView->setIgnoreViewportTagScaleLimits(false); | 1368 webViewHelper.webView()->setIgnoreViewportTagScaleLimits(false); |
| 1348 m_webView->layout(); | 1369 webViewHelper.webView()->layout(); |
| 1349 | 1370 |
| 1350 EXPECT_EQ(2.0f, m_webView->minimumPageScaleFactor()); | 1371 EXPECT_EQ(2.0f, webViewHelper.webView()->minimumPageScaleFactor()); |
| 1351 EXPECT_EQ(2.0f, m_webView->maximumPageScaleFactor()); | 1372 EXPECT_EQ(2.0f, webViewHelper.webView()->maximumPageScaleFactor()); |
| 1352 } | 1373 } |
| 1353 | 1374 |
| 1354 TEST_F(WebFrameTest, updateOverlayScrollbarLayers) | 1375 TEST_F(WebFrameTest, updateOverlayScrollbarLayers) |
| 1355 { | 1376 { |
| 1356 UseMockScrollbarSettings mockScrollbarSettings; | 1377 UseMockScrollbarSettings mockScrollbarSettings; |
| 1357 | 1378 |
| 1358 registerMockedHttpURLLoad("large-div.html"); | 1379 registerMockedHttpURLLoad("large-div.html"); |
| 1359 | 1380 |
| 1360 int viewWidth = 500; | 1381 int viewWidth = 500; |
| 1361 int viewHeight = 500; | 1382 int viewHeight = 500; |
| 1362 | 1383 |
| 1363 createCompositingWebView(); | 1384 OwnPtr<FakeCompositingWebViewClient> fakeCompositingWebViewClient = adoptPtr
(new FakeCompositingWebViewClient()); |
| 1364 m_webView->resize(WebSize(viewWidth, viewHeight)); | 1385 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1365 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "large-div.h
tml"); | 1386 webViewHelper.initialize(true, &fakeCompositingWebViewClient->m_fakeWebFrame
Client, fakeCompositingWebViewClient.get(), &configueCompositingWebView); |
| 1387 |
| 1388 webViewHelper.webView()->resize(WebSize(viewWidth, viewHeight)); |
| 1389 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL
+ "large-div.html"); |
| 1366 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 1390 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 1367 m_webView->layout(); | 1391 webViewHelper.webView()->layout(); |
| 1368 | 1392 |
| 1369 WebCore::FrameView* view = webViewImpl()->mainFrameImpl()->frameView(); | 1393 WebCore::FrameView* view = webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView(); |
| 1370 EXPECT_TRUE(view->renderView()->compositor()->layerForHorizontalScrollbar())
; | 1394 EXPECT_TRUE(view->renderView()->compositor()->layerForHorizontalScrollbar())
; |
| 1371 EXPECT_TRUE(view->renderView()->compositor()->layerForVerticalScrollbar()); | 1395 EXPECT_TRUE(view->renderView()->compositor()->layerForVerticalScrollbar()); |
| 1372 | 1396 |
| 1373 m_webView->resize(WebSize(viewWidth * 10, viewHeight * 10)); | 1397 webViewHelper.webView()->resize(WebSize(viewWidth * 10, viewHeight * 10)); |
| 1374 m_webView->layout(); | 1398 webViewHelper.webView()->layout(); |
| 1375 EXPECT_FALSE(view->renderView()->compositor()->layerForHorizontalScrollbar()
); | 1399 EXPECT_FALSE(view->renderView()->compositor()->layerForHorizontalScrollbar()
); |
| 1376 EXPECT_FALSE(view->renderView()->compositor()->layerForVerticalScrollbar()); | 1400 EXPECT_FALSE(view->renderView()->compositor()->layerForVerticalScrollbar()); |
| 1377 } | 1401 } |
| 1378 | 1402 |
| 1379 void setScaleAndScrollAndLayout(WebKit::WebView* webView, WebPoint scroll, float
scale) | 1403 void setScaleAndScrollAndLayout(WebKit::WebView* webView, WebPoint scroll, float
scale) |
| 1380 { | 1404 { |
| 1381 webView->setPageScaleFactor(scale, WebPoint(scroll.x, scroll.y)); | 1405 webView->setPageScaleFactor(scale, WebPoint(scroll.x, scroll.y)); |
| 1382 webView->layout(); | 1406 webView->layout(); |
| 1383 } | 1407 } |
| 1384 | 1408 |
| 1385 TEST_F(WebFrameTest, DivAutoZoomParamsTest) | 1409 TEST_F(WebFrameTest, DivAutoZoomParamsTest) |
| 1386 { | 1410 { |
| 1387 registerMockedHttpURLLoad("get_scale_for_auto_zoom_into_div_test.html"); | 1411 registerMockedHttpURLLoad("get_scale_for_auto_zoom_into_div_test.html"); |
| 1388 | 1412 |
| 1389 const float deviceScaleFactor = 2.0f; | 1413 const float deviceScaleFactor = 2.0f; |
| 1390 int viewportWidth = 640 / deviceScaleFactor; | 1414 int viewportWidth = 640 / deviceScaleFactor; |
| 1391 int viewportHeight = 1280 / deviceScaleFactor; | 1415 int viewportHeight = 1280 / deviceScaleFactor; |
| 1392 float doubleTapZoomAlreadyLegibleRatio = 1.2f; | 1416 float doubleTapZoomAlreadyLegibleRatio = 1.2f; |
| 1393 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_fo
r_auto_zoom_into_div_test.html"); // | 1417 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1394 m_webView->setDeviceScaleFactor(deviceScaleFactor); | 1418 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_auto_zoom_into_di
v_test.html"); |
| 1395 m_webView->setPageScaleFactorLimits(0.01f, 4); | 1419 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor); |
| 1396 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0)); | 1420 webViewHelper.webView()->setPageScaleFactorLimits(0.01f, 4); |
| 1397 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1421 webViewHelper.webView()->setPageScaleFactor(0.5f, WebPoint(0, 0)); |
| 1398 m_webView->enableFixedLayoutMode(true); | 1422 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1399 m_webView->layout(); | 1423 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1424 webViewHelper.webView()->layout(); |
| 1400 | 1425 |
| 1401 WebRect wideDiv(200, 100, 400, 150); | 1426 WebRect wideDiv(200, 100, 400, 150); |
| 1402 WebRect tallDiv(200, 300, 400, 800); | 1427 WebRect tallDiv(200, 300, 400, 800); |
| 1403 WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, touchPointPadding
, touchPointPadding); | 1428 WebRect doubleTapPointWide(wideDiv.x + 50, wideDiv.y + 50, touchPointPadding
, touchPointPadding); |
| 1404 WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, touchPointPadding
, touchPointPadding); | 1429 WebRect doubleTapPointTall(tallDiv.x + 50, tallDiv.y + 50, touchPointPadding
, touchPointPadding); |
| 1405 WebRect wideBlockBounds; | 1430 WebRect wideBlockBounds; |
| 1406 WebRect tallBlockBounds; | 1431 WebRect tallBlockBounds; |
| 1407 float scale; | 1432 float scale; |
| 1408 WebPoint scroll; | 1433 WebPoint scroll; |
| 1409 | 1434 |
| 1410 float doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFact
or() * doubleTapZoomAlreadyLegibleRatio; | 1435 float doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimu
mPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1411 | 1436 |
| 1412 // Test double-tap zooming into wide div. | 1437 // Test double-tap zooming into wide div. |
| 1413 wideBlockBounds = webViewImpl()->computeBlockBounds(doubleTapPointWide, fals
e); | 1438 wideBlockBounds = webViewHelper.webViewImpl()->computeBlockBounds(doubleTapP
ointWide, false); |
| 1414 webViewImpl()->computeScaleAndScrollForBlockRect(wideBlockBounds, touchPoint
Padding, doubleTapZoomAlreadyLegibleScale, scale, scroll); | 1439 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(wideBlockBoun
ds, touchPointPadding, doubleTapZoomAlreadyLegibleScale, scale, scroll); |
| 1415 // The div should horizontally fill the screen (modulo margins), and | 1440 // The div should horizontally fill the screen (modulo margins), and |
| 1416 // vertically centered (modulo integer rounding). | 1441 // vertically centered (modulo integer rounding). |
| 1417 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1); | 1442 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1); |
| 1418 EXPECT_NEAR(wideDiv.x, scroll.x, 20); | 1443 EXPECT_NEAR(wideDiv.x, scroll.x, 20); |
| 1419 EXPECT_EQ(0, scroll.y); | 1444 EXPECT_EQ(0, scroll.y); |
| 1420 | 1445 |
| 1421 setScaleAndScrollAndLayout(webViewImpl(), scroll, scale); | 1446 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), scroll, scale); |
| 1422 | 1447 |
| 1423 // Test zoom out back to minimum scale. | 1448 // Test zoom out back to minimum scale. |
| 1424 wideBlockBounds = webViewImpl()->computeBlockBounds(doubleTapPointWide, fals
e); | 1449 wideBlockBounds = webViewHelper.webViewImpl()->computeBlockBounds(doubleTapP
ointWide, false); |
| 1425 webViewImpl()->computeScaleAndScrollForBlockRect(wideBlockBounds, touchPoint
Padding, doubleTapZoomAlreadyLegibleScale, scale, scroll); | 1450 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(wideBlockBoun
ds, touchPointPadding, doubleTapZoomAlreadyLegibleScale, scale, scroll); |
| 1426 | 1451 |
| 1427 scale = webViewImpl()->minimumPageScaleFactor(); | 1452 scale = webViewHelper.webViewImpl()->minimumPageScaleFactor(); |
| 1428 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), scale); | 1453 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), scal
e); |
| 1429 | 1454 |
| 1430 // Test double-tap zooming into tall div. | 1455 // Test double-tap zooming into tall div. |
| 1431 tallBlockBounds = webViewImpl()->computeBlockBounds(doubleTapPointTall, fals
e); | 1456 tallBlockBounds = webViewHelper.webViewImpl()->computeBlockBounds(doubleTapP
ointTall, false); |
| 1432 webViewImpl()->computeScaleAndScrollForBlockRect(tallBlockBounds, touchPoint
Padding, doubleTapZoomAlreadyLegibleScale, scale, scroll); | 1457 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(tallBlockBoun
ds, touchPointPadding, doubleTapZoomAlreadyLegibleScale, scale, scroll); |
| 1433 // The div should start at the top left of the viewport. | 1458 // The div should start at the top left of the viewport. |
| 1434 EXPECT_NEAR(viewportWidth / (float) tallDiv.width, scale, 0.1); | 1459 EXPECT_NEAR(viewportWidth / (float) tallDiv.width, scale, 0.1); |
| 1435 EXPECT_NEAR(tallDiv.x, scroll.x, 20); | 1460 EXPECT_NEAR(tallDiv.x, scroll.x, 20); |
| 1436 EXPECT_NEAR(tallDiv.y, scroll.y, 20); | 1461 EXPECT_NEAR(tallDiv.y, scroll.y, 20); |
| 1437 | 1462 |
| 1438 // Test for Non-doubletap scaling | 1463 // Test for Non-doubletap scaling |
| 1439 // Test zooming into div. | 1464 // Test zooming into div. |
| 1440 webViewImpl()->computeScaleAndScrollForBlockRect(webViewImpl()->computeBlock
Bounds(WebRect(250, 250, 10, 10), true), 0, doubleTapZoomAlreadyLegibleScale, sc
ale, scroll); | 1465 webViewHelper.webViewImpl()->computeScaleAndScrollForBlockRect(webViewHelper
.webViewImpl()->computeBlockBounds(WebRect(250, 250, 10, 10), true), 0, doubleTa
pZoomAlreadyLegibleScale, scale, scroll); |
| 1441 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1); | 1466 EXPECT_NEAR(viewportWidth / (float) wideDiv.width, scale, 0.1); |
| 1442 } | 1467 } |
| 1443 | 1468 |
| 1444 void simulatePageScale(WebViewImpl* webViewImpl, float& scale) | 1469 void simulatePageScale(WebViewImpl* webViewImpl, float& scale) |
| 1445 { | 1470 { |
| 1446 WebCore::IntSize scrollDelta = webViewImpl->fakePageScaleAnimationTargetPosi
tionForTesting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition(); | 1471 WebCore::IntSize scrollDelta = webViewImpl->fakePageScaleAnimationTargetPosi
tionForTesting() - webViewImpl->mainFrameImpl()->frameView()->scrollPosition(); |
| 1447 float scaleDelta = webViewImpl->fakePageScaleAnimationPageScaleForTesting()
/ webViewImpl->pageScaleFactor(); | 1472 float scaleDelta = webViewImpl->fakePageScaleAnimationPageScaleForTesting()
/ webViewImpl->pageScaleFactor(); |
| 1448 webViewImpl->applyScrollAndScale(scrollDelta, scaleDelta); | 1473 webViewImpl->applyScrollAndScale(scrollDelta, scaleDelta); |
| 1449 scale = webViewImpl->pageScaleFactor(); | 1474 scale = webViewImpl->pageScaleFactor(); |
| 1450 } | 1475 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1463 } | 1488 } |
| 1464 | 1489 |
| 1465 TEST_F(WebFrameTest, DivAutoZoomWideDivTest) | 1490 TEST_F(WebFrameTest, DivAutoZoomWideDivTest) |
| 1466 { | 1491 { |
| 1467 registerMockedHttpURLLoad("get_wide_div_for_auto_zoom_test.html"); | 1492 registerMockedHttpURLLoad("get_wide_div_for_auto_zoom_test.html"); |
| 1468 | 1493 |
| 1469 const float deviceScaleFactor = 2.0f; | 1494 const float deviceScaleFactor = 2.0f; |
| 1470 int viewportWidth = 640 / deviceScaleFactor; | 1495 int viewportWidth = 640 / deviceScaleFactor; |
| 1471 int viewportHeight = 1280 / deviceScaleFactor; | 1496 int viewportHeight = 1280 / deviceScaleFactor; |
| 1472 float doubleTapZoomAlreadyLegibleRatio = 1.2f; | 1497 float doubleTapZoomAlreadyLegibleRatio = 1.2f; |
| 1473 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_wide_div
_for_auto_zoom_test.html"); | 1498 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1474 m_webView->enableFixedLayoutMode(true); | 1499 webViewHelper.initializeAndLoad(m_baseURL + "get_wide_div_for_auto_zoom_test
.html"); |
| 1475 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1500 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1476 m_webView->setPageScaleFactorLimits(1.0f, 4); | 1501 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1477 m_webView->setDeviceScaleFactor(deviceScaleFactor); | 1502 webViewHelper.webView()->setPageScaleFactorLimits(1.0f, 4); |
| 1478 m_webView->setPageScaleFactor(1.0f, WebPoint(0, 0)); | 1503 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor); |
| 1479 m_webView->layout(); | 1504 webViewHelper.webView()->setPageScaleFactor(1.0f, WebPoint(0, 0)); |
| 1505 webViewHelper.webView()->layout(); |
| 1480 | 1506 |
| 1481 webViewImpl()->enableFakePageScaleAnimationForTesting(true); | 1507 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); |
| 1482 | 1508 |
| 1483 float doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFact
or() * doubleTapZoomAlreadyLegibleRatio; | 1509 float doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimu
mPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1484 | 1510 |
| 1485 WebRect div(0, 100, viewportWidth, 150); | 1511 WebRect div(0, 100, viewportWidth, 150); |
| 1486 WebPoint point(div.x + 50, div.y + 50); | 1512 WebPoint point(div.x + 50, div.y + 50); |
| 1487 float scale; | 1513 float scale; |
| 1488 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1514 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1489 | 1515 |
| 1490 simulateDoubleTap(webViewImpl(), point, scale); | 1516 simulateDoubleTap(webViewHelper.webViewImpl(), point, scale); |
| 1491 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1517 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1492 simulateDoubleTap(webViewImpl(), point, scale); | 1518 simulateDoubleTap(webViewHelper.webViewImpl(), point, scale); |
| 1493 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1519 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1494 } | 1520 } |
| 1495 | 1521 |
| 1496 TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest) | 1522 TEST_F(WebFrameTest, DivAutoZoomMultipleDivsTest) |
| 1497 { | 1523 { |
| 1498 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html"); | 1524 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html"); |
| 1499 | 1525 |
| 1500 const float deviceScaleFactor = 2.0f; | 1526 const float deviceScaleFactor = 2.0f; |
| 1501 int viewportWidth = 640 / deviceScaleFactor; | 1527 int viewportWidth = 640 / deviceScaleFactor; |
| 1502 int viewportHeight = 1280 / deviceScaleFactor; | 1528 int viewportHeight = 1280 / deviceScaleFactor; |
| 1503 float doubleTapZoomAlreadyLegibleRatio = 1.2f; | 1529 float doubleTapZoomAlreadyLegibleRatio = 1.2f; |
| 1504 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_multiple
_divs_for_auto_zoom_test.html"); | 1530 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1505 m_webView->enableFixedLayoutMode(true); | 1531 webViewHelper.initializeAndLoad(m_baseURL + "get_multiple_divs_for_auto_zoom
_test.html"); |
| 1506 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1532 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1507 m_webView->setPageScaleFactorLimits(0.5f, 4); | 1533 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1508 m_webView->setDeviceScaleFactor(deviceScaleFactor); | 1534 webViewHelper.webView()->setPageScaleFactorLimits(0.5f, 4); |
| 1509 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0)); | 1535 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor); |
| 1510 m_webView->layout(); | 1536 webViewHelper.webView()->setPageScaleFactor(0.5f, WebPoint(0, 0)); |
| 1537 webViewHelper.webView()->layout(); |
| 1511 | 1538 |
| 1512 webViewImpl()->enableFakePageScaleAnimationForTesting(true); | 1539 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); |
| 1513 | 1540 |
| 1514 WebRect topDiv(200, 100, 200, 150); | 1541 WebRect topDiv(200, 100, 200, 150); |
| 1515 WebRect bottomDiv(200, 300, 200, 150); | 1542 WebRect bottomDiv(200, 300, 200, 150); |
| 1516 WebPoint topPoint(topDiv.x + 50, topDiv.y + 50); | 1543 WebPoint topPoint(topDiv.x + 50, topDiv.y + 50); |
| 1517 WebPoint bottomPoint(bottomDiv.x + 50, bottomDiv.y + 50); | 1544 WebPoint bottomPoint(bottomDiv.x + 50, bottomDiv.y + 50); |
| 1518 float scale; | 1545 float scale; |
| 1519 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1546 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1520 | 1547 |
| 1521 // Test double tap on two different divs | 1548 // Test double tap on two different divs |
| 1522 // After first zoom, we should go back to minimum page scale with a second d
ouble tap. | 1549 // After first zoom, we should go back to minimum page scale with a second d
ouble tap. |
| 1523 simulateDoubleTap(webViewImpl(), topPoint, scale); | 1550 simulateDoubleTap(webViewHelper.webViewImpl(), topPoint, scale); |
| 1524 EXPECT_FLOAT_EQ(1, scale); | 1551 EXPECT_FLOAT_EQ(1, scale); |
| 1525 simulateDoubleTap(webViewImpl(), bottomPoint, scale); | 1552 simulateDoubleTap(webViewHelper.webViewImpl(), bottomPoint, scale); |
| 1526 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1553 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1527 | 1554 |
| 1528 // If the user pinch zooms after double tap, a second double tap should zoom
back to the div. | 1555 // If the user pinch zooms after double tap, a second double tap should zoom
back to the div. |
| 1529 simulateDoubleTap(webViewImpl(), topPoint, scale); | 1556 simulateDoubleTap(webViewHelper.webViewImpl(), topPoint, scale); |
| 1530 EXPECT_FLOAT_EQ(1, scale); | 1557 EXPECT_FLOAT_EQ(1, scale); |
| 1531 webViewImpl()->applyScrollAndScale(WebSize(), 0.6f); | 1558 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 0.6f); |
| 1532 simulateDoubleTap(webViewImpl(), bottomPoint, scale); | 1559 simulateDoubleTap(webViewHelper.webViewImpl(), bottomPoint, scale); |
| 1533 EXPECT_FLOAT_EQ(1, scale); | 1560 EXPECT_FLOAT_EQ(1, scale); |
| 1534 simulateDoubleTap(webViewImpl(), bottomPoint, scale); | 1561 simulateDoubleTap(webViewHelper.webViewImpl(), bottomPoint, scale); |
| 1535 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1562 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1536 | 1563 |
| 1537 // If we didn't yet get an auto-zoom update and a second double-tap arrives,
should go back to minimum scale. | 1564 // If we didn't yet get an auto-zoom update and a second double-tap arrives,
should go back to minimum scale. |
| 1538 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); | 1565 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); |
| 1539 webViewImpl()->animateDoubleTapZoom(topPoint); | 1566 webViewHelper.webViewImpl()->animateDoubleTapZoom(topPoint); |
| 1540 EXPECT_TRUE(webViewImpl()->fakeDoubleTapAnimationPendingForTesting()); | 1567 EXPECT_TRUE(webViewHelper.webViewImpl()->fakeDoubleTapAnimationPendingForTes
ting()); |
| 1541 simulateDoubleTap(webViewImpl(), bottomPoint, scale); | 1568 simulateDoubleTap(webViewHelper.webViewImpl(), bottomPoint, scale); |
| 1542 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1569 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1543 } | 1570 } |
| 1544 | 1571 |
| 1545 TEST_F(WebFrameTest, DivAutoZoomScaleBoundsTest) | 1572 TEST_F(WebFrameTest, DivAutoZoomScaleBoundsTest) |
| 1546 { | 1573 { |
| 1547 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html"); | 1574 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html"); |
| 1548 | 1575 |
| 1549 int viewportWidth = 320; | 1576 int viewportWidth = 320; |
| 1550 int viewportHeight = 480; | 1577 int viewportHeight = 480; |
| 1551 float doubleTapZoomAlreadyLegibleRatio = 1.2f; | 1578 float doubleTapZoomAlreadyLegibleRatio = 1.2f; |
| 1552 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_bo
unds_check_for_auto_zoom_test.html"); | 1579 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1553 m_webView->enableFixedLayoutMode(true); | 1580 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_bounds_check_for_auto
_zoom_test.html"); |
| 1554 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1581 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1555 m_webView->setDeviceScaleFactor(1.5f); | 1582 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1556 m_webView->layout(); | 1583 webViewHelper.webView()->setDeviceScaleFactor(1.5f); |
| 1584 webViewHelper.webView()->layout(); |
| 1557 | 1585 |
| 1558 webViewImpl()->enableFakePageScaleAnimationForTesting(true); | 1586 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); |
| 1559 | 1587 |
| 1560 WebRect div(200, 100, 200, 150); | 1588 WebRect div(200, 100, 200, 150); |
| 1561 WebPoint doubleTapPoint(div.x + 50, div.y + 50); | 1589 WebPoint doubleTapPoint(div.x + 50, div.y + 50); |
| 1562 float scale; | 1590 float scale; |
| 1563 | 1591 |
| 1564 // Test double tap scale bounds. | 1592 // Test double tap scale bounds. |
| 1565 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 | 1593 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 |
| 1566 m_webView->setPageScaleFactorLimits(0.5f, 4); | 1594 webViewHelper.webView()->setPageScaleFactorLimits(0.5f, 4); |
| 1567 m_webView->layout(); | 1595 webViewHelper.webView()->layout(); |
| 1568 float doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFact
or() * doubleTapZoomAlreadyLegibleRatio; | 1596 float doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimu
mPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1569 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1597 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1570 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1598 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1571 EXPECT_FLOAT_EQ(1, scale); | 1599 EXPECT_FLOAT_EQ(1, scale); |
| 1572 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1600 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1573 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1601 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1574 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1602 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1575 EXPECT_FLOAT_EQ(1, scale); | 1603 EXPECT_FLOAT_EQ(1, scale); |
| 1576 | 1604 |
| 1577 // Zoom in to reset double_tap_zoom_in_effect flag. | 1605 // Zoom in to reset double_tap_zoom_in_effect flag. |
| 1578 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); | 1606 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); |
| 1579 // 1 < minimumPageScale < doubleTapZoomAlreadyLegibleScale | 1607 // 1 < minimumPageScale < doubleTapZoomAlreadyLegibleScale |
| 1580 m_webView->setPageScaleFactorLimits(1.1f, 4); | 1608 webViewHelper.webView()->setPageScaleFactorLimits(1.1f, 4); |
| 1581 m_webView->layout(); | 1609 webViewHelper.webView()->layout(); |
| 1582 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() *
doubleTapZoomAlreadyLegibleRatio; | 1610 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS
caleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1583 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1611 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1584 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1612 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1585 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1613 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1586 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1614 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1587 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1615 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1588 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1616 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1589 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1617 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1590 | 1618 |
| 1591 // Zoom in to reset double_tap_zoom_in_effect flag. | 1619 // Zoom in to reset double_tap_zoom_in_effect flag. |
| 1592 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); | 1620 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); |
| 1593 // minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale | 1621 // minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale |
| 1594 m_webView->setPageScaleFactorLimits(0.95f, 4); | 1622 webViewHelper.webView()->setPageScaleFactorLimits(0.95f, 4); |
| 1595 m_webView->layout(); | 1623 webViewHelper.webView()->layout(); |
| 1596 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() *
doubleTapZoomAlreadyLegibleRatio; | 1624 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS
caleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1597 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1625 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1598 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1626 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1599 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1627 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1600 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1628 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1601 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1629 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1602 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1630 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1603 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1631 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1604 } | 1632 } |
| 1605 | 1633 |
| 1606 TEST_F(WebFrameTest, DivAutoZoomScaleFontScaleFactorTest) | 1634 TEST_F(WebFrameTest, DivAutoZoomScaleFontScaleFactorTest) |
| 1607 { | 1635 { |
| 1608 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html"); | 1636 registerMockedHttpURLLoad("get_scale_bounds_check_for_auto_zoom_test.html"); |
| 1609 | 1637 |
| 1610 int viewportWidth = 320; | 1638 int viewportWidth = 320; |
| 1611 int viewportHeight = 480; | 1639 int viewportHeight = 480; |
| 1612 float doubleTapZoomAlreadyLegibleRatio = 1.2f; | 1640 float doubleTapZoomAlreadyLegibleRatio = 1.2f; |
| 1613 float textAutosizingFontScaleFactor = 1.13f; | 1641 float textAutosizingFontScaleFactor = 1.13f; |
| 1614 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_bo
unds_check_for_auto_zoom_test.html"); | 1642 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1615 m_webView->enableFixedLayoutMode(true); | 1643 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_bounds_check_for_auto
_zoom_test.html"); |
| 1616 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1644 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1617 m_webView->layout(); | 1645 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1646 webViewHelper.webView()->layout(); |
| 1618 | 1647 |
| 1619 webViewImpl()->enableFakePageScaleAnimationForTesting(true); | 1648 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); |
| 1620 webViewImpl()->page()->settings().setTextAutosizingEnabled(true); | 1649 webViewHelper.webViewImpl()->page()->settings().setTextAutosizingEnabled(tru
e); |
| 1621 webViewImpl()->page()->settings().setTextAutosizingFontScaleFactor(textAutos
izingFontScaleFactor); | 1650 webViewHelper.webViewImpl()->page()->settings().setTextAutosizingFontScaleFa
ctor(textAutosizingFontScaleFactor); |
| 1622 | 1651 |
| 1623 WebRect div(200, 100, 200, 150); | 1652 WebRect div(200, 100, 200, 150); |
| 1624 WebPoint doubleTapPoint(div.x + 50, div.y + 50); | 1653 WebPoint doubleTapPoint(div.x + 50, div.y + 50); |
| 1625 float scale; | 1654 float scale; |
| 1626 | 1655 |
| 1627 // Test double tap scale bounds. | 1656 // Test double tap scale bounds. |
| 1628 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 < textAutosizingF
ontScaleFactor | 1657 // minimumPageScale < doubleTapZoomAlreadyLegibleScale < 1 < textAutosizingF
ontScaleFactor |
| 1629 float legibleScale = textAutosizingFontScaleFactor; | 1658 float legibleScale = textAutosizingFontScaleFactor; |
| 1630 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1659 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1631 float doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFact
or() * doubleTapZoomAlreadyLegibleRatio; | 1660 float doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimu
mPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1632 m_webView->setPageScaleFactorLimits(0.5f, 4); | 1661 webViewHelper.webView()->setPageScaleFactorLimits(0.5f, 4); |
| 1633 m_webView->layout(); | 1662 webViewHelper.webView()->layout(); |
| 1634 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1663 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1635 EXPECT_FLOAT_EQ(legibleScale, scale); | 1664 EXPECT_FLOAT_EQ(legibleScale, scale); |
| 1636 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1665 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1637 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1666 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1638 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1667 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1639 EXPECT_FLOAT_EQ(legibleScale, scale); | 1668 EXPECT_FLOAT_EQ(legibleScale, scale); |
| 1640 | 1669 |
| 1641 // Zoom in to reset double_tap_zoom_in_effect flag. | 1670 // Zoom in to reset double_tap_zoom_in_effect flag. |
| 1642 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); | 1671 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); |
| 1643 // 1 < textAutosizingFontScaleFactor < minimumPageScale < doubleTapZoomAlrea
dyLegibleScale | 1672 // 1 < textAutosizingFontScaleFactor < minimumPageScale < doubleTapZoomAlrea
dyLegibleScale |
| 1644 m_webView->setPageScaleFactorLimits(1.0f, 4); | 1673 webViewHelper.webView()->setPageScaleFactorLimits(1.0f, 4); |
| 1645 m_webView->layout(); | 1674 webViewHelper.webView()->layout(); |
| 1646 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() *
doubleTapZoomAlreadyLegibleRatio; | 1675 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS
caleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1647 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1676 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1648 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1677 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1649 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1678 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1650 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1679 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1651 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1680 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1652 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1681 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1653 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1682 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1654 | 1683 |
| 1655 // Zoom in to reset double_tap_zoom_in_effect flag. | 1684 // Zoom in to reset double_tap_zoom_in_effect flag. |
| 1656 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); | 1685 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); |
| 1657 // minimumPageScale < 1 < textAutosizingFontScaleFactor < doubleTapZoomAlrea
dyLegibleScale | 1686 // minimumPageScale < 1 < textAutosizingFontScaleFactor < doubleTapZoomAlrea
dyLegibleScale |
| 1658 m_webView->setPageScaleFactorLimits(0.95f, 4); | 1687 webViewHelper.webView()->setPageScaleFactorLimits(0.95f, 4); |
| 1659 m_webView->layout(); | 1688 webViewHelper.webView()->layout(); |
| 1660 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() *
doubleTapZoomAlreadyLegibleRatio; | 1689 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS
caleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1661 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1690 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1662 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1691 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1663 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1692 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1664 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1693 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1665 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1694 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1666 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1695 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1667 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); | 1696 EXPECT_FLOAT_EQ(doubleTapZoomAlreadyLegibleScale, scale); |
| 1668 | 1697 |
| 1669 // Zoom in to reset double_tap_zoom_in_effect flag. | 1698 // Zoom in to reset double_tap_zoom_in_effect flag. |
| 1670 webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); | 1699 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.1f); |
| 1671 // minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale < textAutosizingF
ontScaleFactor | 1700 // minimumPageScale < 1 < doubleTapZoomAlreadyLegibleScale < textAutosizingF
ontScaleFactor |
| 1672 m_webView->setPageScaleFactorLimits(0.9f, 4); | 1701 webViewHelper.webView()->setPageScaleFactorLimits(0.9f, 4); |
| 1673 m_webView->layout(); | 1702 webViewHelper.webView()->layout(); |
| 1674 doubleTapZoomAlreadyLegibleScale = webViewImpl()->minimumPageScaleFactor() *
doubleTapZoomAlreadyLegibleRatio; | 1703 doubleTapZoomAlreadyLegibleScale = webViewHelper.webViewImpl()->minimumPageS
caleFactor() * doubleTapZoomAlreadyLegibleRatio; |
| 1675 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1704 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1676 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1705 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1677 EXPECT_FLOAT_EQ(legibleScale, scale); | 1706 EXPECT_FLOAT_EQ(legibleScale, scale); |
| 1678 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1707 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1679 EXPECT_FLOAT_EQ(webViewImpl()->minimumPageScaleFactor(), scale); | 1708 EXPECT_FLOAT_EQ(webViewHelper.webViewImpl()->minimumPageScaleFactor(), scale
); |
| 1680 simulateDoubleTap(webViewImpl(), doubleTapPoint, scale); | 1709 simulateDoubleTap(webViewHelper.webViewImpl(), doubleTapPoint, scale); |
| 1681 EXPECT_FLOAT_EQ(legibleScale, scale); | 1710 EXPECT_FLOAT_EQ(legibleScale, scale); |
| 1682 } | 1711 } |
| 1683 | 1712 |
| 1684 TEST_F(WebFrameTest, DivMultipleTargetZoomMultipleDivsTest) | 1713 TEST_F(WebFrameTest, DivMultipleTargetZoomMultipleDivsTest) |
| 1685 { | 1714 { |
| 1686 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html"); | 1715 registerMockedHttpURLLoad("get_multiple_divs_for_auto_zoom_test.html"); |
| 1687 | 1716 |
| 1688 const float deviceScaleFactor = 2.0f; | 1717 const float deviceScaleFactor = 2.0f; |
| 1689 int viewportWidth = 640 / deviceScaleFactor; | 1718 int viewportWidth = 640 / deviceScaleFactor; |
| 1690 int viewportHeight = 1280 / deviceScaleFactor; | 1719 int viewportHeight = 1280 / deviceScaleFactor; |
| 1691 float doubleTapZoomAlreadyLegibleRatio = 1.2f; | 1720 float doubleTapZoomAlreadyLegibleRatio = 1.2f; |
| 1692 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_multiple
_divs_for_auto_zoom_test.html"); | 1721 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1693 m_webView->enableFixedLayoutMode(true); | 1722 webViewHelper.initializeAndLoad(m_baseURL + "get_multiple_divs_for_auto_zoom
_test.html"); |
| 1694 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1723 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1695 m_webView->setPageScaleFactorLimits(0.5f, 4); | 1724 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1696 m_webView->setDeviceScaleFactor(deviceScaleFactor); | 1725 webViewHelper.webView()->setPageScaleFactorLimits(0.5f, 4); |
| 1697 m_webView->setPageScaleFactor(0.5f, WebPoint(0, 0)); | 1726 webViewHelper.webView()->setDeviceScaleFactor(deviceScaleFactor); |
| 1698 m_webView->layout(); | 1727 webViewHelper.webView()->setPageScaleFactor(0.5f, WebPoint(0, 0)); |
| 1728 webViewHelper.webView()->layout(); |
| 1699 | 1729 |
| 1700 webViewImpl()->enableFakePageScaleAnimationForTesting(true); | 1730 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); |
| 1701 | 1731 |
| 1702 WebRect viewportRect(0, 0, viewportWidth, viewportHeight); | 1732 WebRect viewportRect(0, 0, viewportWidth, viewportHeight); |
| 1703 WebRect topDiv(200, 100, 200, 150); | 1733 WebRect topDiv(200, 100, 200, 150); |
| 1704 WebRect bottomDiv(200, 300, 200, 150); | 1734 WebRect bottomDiv(200, 300, 200, 150); |
| 1705 float scale; | 1735 float scale; |
| 1706 setScaleAndScrollAndLayout(webViewImpl(), WebPoint(0, 0), (webViewImpl()->mi
nimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyLegibleRatio) / 2); | 1736 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), WebPoint(0, 0), (web
ViewHelper.webViewImpl()->minimumPageScaleFactor()) * (1 + doubleTapZoomAlreadyL
egibleRatio) / 2); |
| 1707 | 1737 |
| 1708 simulateMultiTargetZoom(webViewImpl(), topDiv, scale); | 1738 simulateMultiTargetZoom(webViewHelper.webViewImpl(), topDiv, scale); |
| 1709 EXPECT_FLOAT_EQ(1, scale); | 1739 EXPECT_FLOAT_EQ(1, scale); |
| 1710 simulateMultiTargetZoom(webViewImpl(), bottomDiv, scale); | 1740 simulateMultiTargetZoom(webViewHelper.webViewImpl(), bottomDiv, scale); |
| 1711 EXPECT_FLOAT_EQ(1, scale); | 1741 EXPECT_FLOAT_EQ(1, scale); |
| 1712 simulateMultiTargetZoom(webViewImpl(), viewportRect, scale); | 1742 simulateMultiTargetZoom(webViewHelper.webViewImpl(), viewportRect, scale); |
| 1713 EXPECT_FLOAT_EQ(1, scale); | 1743 EXPECT_FLOAT_EQ(1, scale); |
| 1714 webViewImpl()->setPageScaleFactor(webViewImpl()->minimumPageScaleFactor(), W
ebPoint(0, 0)); | 1744 webViewHelper.webViewImpl()->setPageScaleFactor(webViewHelper.webViewImpl()-
>minimumPageScaleFactor(), WebPoint(0, 0)); |
| 1715 simulateMultiTargetZoom(webViewImpl(), topDiv, scale); | 1745 simulateMultiTargetZoom(webViewHelper.webViewImpl(), topDiv, scale); |
| 1716 EXPECT_FLOAT_EQ(1, scale); | 1746 EXPECT_FLOAT_EQ(1, scale); |
| 1717 } | 1747 } |
| 1718 | 1748 |
| 1719 TEST_F(WebFrameTest, DivScrollIntoEditableTest) | 1749 TEST_F(WebFrameTest, DivScrollIntoEditableTest) |
| 1720 { | 1750 { |
| 1721 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html"); | 1751 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html"); |
| 1722 | 1752 |
| 1723 int viewportWidth = 450; | 1753 int viewportWidth = 450; |
| 1724 int viewportHeight = 300; | 1754 int viewportHeight = 300; |
| 1725 float leftBoxRatio = 0.3f; | 1755 float leftBoxRatio = 0.3f; |
| 1726 int caretPadding = 10; | 1756 int caretPadding = 10; |
| 1727 float minReadableCaretHeight = 18.0f; | 1757 float minReadableCaretHeight = 18.0f; |
| 1728 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_fo
r_zoom_into_editable_test.html"); | 1758 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1729 m_webView->enableFixedLayoutMode(true); | 1759 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_zoom_into_editabl
e_test.html"); |
| 1730 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1760 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 1731 m_webView->setPageScaleFactorLimits(1, 4); | 1761 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1732 m_webView->layout(); | 1762 webViewHelper.webView()->setPageScaleFactorLimits(1, 4); |
| 1733 m_webView->setDeviceScaleFactor(1.5f); | 1763 webViewHelper.webView()->layout(); |
| 1734 m_webView->settings()->setAutoZoomFocusedNodeToLegibleScale(true); | 1764 webViewHelper.webView()->setDeviceScaleFactor(1.5f); |
| 1765 webViewHelper.webView()->settings()->setAutoZoomFocusedNodeToLegibleScale(tr
ue); |
| 1735 | 1766 |
| 1736 webViewImpl()->enableFakePageScaleAnimationForTesting(true); | 1767 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); |
| 1737 | 1768 |
| 1738 WebRect editBoxWithText(200, 200, 250, 20); | 1769 WebRect editBoxWithText(200, 200, 250, 20); |
| 1739 WebRect editBoxWithNoText(200, 250, 250, 20); | 1770 WebRect editBoxWithNoText(200, 250, 250, 20); |
| 1740 | 1771 |
| 1741 // Test scrolling the focused node | 1772 // Test scrolling the focused node |
| 1742 // The edit box is shorter and narrower than the viewport when legible. | 1773 // The edit box is shorter and narrower than the viewport when legible. |
| 1743 m_webView->advanceFocus(false); | 1774 webViewHelper.webView()->advanceFocus(false); |
| 1744 // Set the caret to the end of the input box. | 1775 // Set the caret to the end of the input box. |
| 1745 m_webView->mainFrame()->document().getElementById("EditBoxWithText").to<WebI
nputElement>().setSelectionRange(1000, 1000); | 1776 webViewHelper.webView()->mainFrame()->document().getElementById("EditBoxWith
Text").to<WebInputElement>().setSelectionRange(1000, 1000); |
| 1746 setScaleAndScrollAndLayout(m_webView, WebPoint(0, 0), 1); | 1777 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); |
| 1747 WebRect rect, caret; | 1778 WebRect rect, caret; |
| 1748 webViewImpl()->selectionBounds(caret, rect); | 1779 webViewHelper.webViewImpl()->selectionBounds(caret, rect); |
| 1749 | 1780 |
| 1750 float scale; | 1781 float scale; |
| 1751 WebCore::IntPoint scroll; | 1782 WebCore::IntPoint scroll; |
| 1752 bool needAnimation; | 1783 bool needAnimation; |
| 1753 webViewImpl()->computeScaleAndScrollForFocusedNode(webViewImpl()->focusedEle
ment(), scale, scroll, needAnimation); | 1784 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
| 1754 EXPECT_TRUE(needAnimation); | 1785 EXPECT_TRUE(needAnimation); |
| 1755 // The edit box should be left aligned with a margin for possible label. | 1786 // The edit box should be left aligned with a margin for possible label. |
| 1756 int hScroll = editBoxWithText.x - leftBoxRatio * viewportWidth / scale; | 1787 int hScroll = editBoxWithText.x - leftBoxRatio * viewportWidth / scale; |
| 1757 EXPECT_NEAR(hScroll, scroll.x(), 1); | 1788 EXPECT_NEAR(hScroll, scroll.x(), 1); |
| 1758 int vScroll = editBoxWithText.y - (viewportHeight / scale - editBoxWithText.
height) / 2; | 1789 int vScroll = editBoxWithText.y - (viewportHeight / scale - editBoxWithText.
height) / 2; |
| 1759 EXPECT_NEAR(vScroll, scroll.y(), 1); | 1790 EXPECT_NEAR(vScroll, scroll.y(), 1); |
| 1760 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); | 1791 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); |
| 1761 | 1792 |
| 1762 // The edit box is wider than the viewport when legible. | 1793 // The edit box is wider than the viewport when legible. |
| 1763 viewportWidth = 200; | 1794 viewportWidth = 200; |
| 1764 viewportHeight = 150; | 1795 viewportHeight = 150; |
| 1765 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 1796 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 1766 setScaleAndScrollAndLayout(m_webView, WebPoint(0, 0), 1); | 1797 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); |
| 1767 webViewImpl()->selectionBounds(caret, rect); | 1798 webViewHelper.webViewImpl()->selectionBounds(caret, rect); |
| 1768 webViewImpl()->computeScaleAndScrollForFocusedNode(webViewImpl()->focusedEle
ment(), scale, scroll, needAnimation); | 1799 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
| 1769 EXPECT_TRUE(needAnimation); | 1800 EXPECT_TRUE(needAnimation); |
| 1770 // The caret should be right aligned since the caret would be offscreen when
the edit box is left aligned. | 1801 // The caret should be right aligned since the caret would be offscreen when
the edit box is left aligned. |
| 1771 hScroll = caret.x + caret.width + caretPadding - viewportWidth / scale; | 1802 hScroll = caret.x + caret.width + caretPadding - viewportWidth / scale; |
| 1772 EXPECT_NEAR(hScroll, scroll.x(), 1); | 1803 EXPECT_NEAR(hScroll, scroll.x(), 1); |
| 1773 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); | 1804 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); |
| 1774 | 1805 |
| 1775 setScaleAndScrollAndLayout(m_webView, WebPoint(0, 0), 1); | 1806 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); |
| 1776 // Move focus to edit box with text. | 1807 // Move focus to edit box with text. |
| 1777 m_webView->advanceFocus(false); | 1808 webViewHelper.webView()->advanceFocus(false); |
| 1778 webViewImpl()->selectionBounds(caret, rect); | 1809 webViewHelper.webViewImpl()->selectionBounds(caret, rect); |
| 1779 webViewImpl()->computeScaleAndScrollForFocusedNode(webViewImpl()->focusedEle
ment(), scale, scroll, needAnimation); | 1810 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
| 1780 EXPECT_TRUE(needAnimation); | 1811 EXPECT_TRUE(needAnimation); |
| 1781 // The edit box should be left aligned. | 1812 // The edit box should be left aligned. |
| 1782 hScroll = editBoxWithNoText.x; | 1813 hScroll = editBoxWithNoText.x; |
| 1783 EXPECT_NEAR(hScroll, scroll.x(), 1); | 1814 EXPECT_NEAR(hScroll, scroll.x(), 1); |
| 1784 vScroll = editBoxWithNoText.y - (viewportHeight / scale - editBoxWithNoText.
height) / 2; | 1815 vScroll = editBoxWithNoText.y - (viewportHeight / scale - editBoxWithNoText.
height) / 2; |
| 1785 EXPECT_NEAR(vScroll, scroll.y(), 1); | 1816 EXPECT_NEAR(vScroll, scroll.y(), 1); |
| 1786 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); | 1817 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); |
| 1787 | 1818 |
| 1788 setScaleAndScrollAndLayout(webViewImpl(), scroll, scale); | 1819 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), scroll, scale); |
| 1789 | 1820 |
| 1790 // Move focus back to the first edit box. | 1821 // Move focus back to the first edit box. |
| 1791 m_webView->advanceFocus(true); | 1822 webViewHelper.webView()->advanceFocus(true); |
| 1792 webViewImpl()->computeScaleAndScrollForFocusedNode(webViewImpl()->focusedEle
ment(), scale, scroll, needAnimation); | 1823 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
| 1793 // The position should have stayed the same since this box was already on sc
reen with the right scale. | 1824 // The position should have stayed the same since this box was already on sc
reen with the right scale. |
| 1794 EXPECT_FALSE(needAnimation); | 1825 EXPECT_FALSE(needAnimation); |
| 1795 } | 1826 } |
| 1796 | 1827 |
| 1797 class TestReloadDoesntRedirectWebFrameClient : public WebFrameClient { | 1828 class TestReloadDoesntRedirectWebFrameClient : public WebFrameClient { |
| 1798 public: | 1829 public: |
| 1799 virtual WebNavigationPolicy decidePolicyForNavigation( | 1830 virtual WebNavigationPolicy decidePolicyForNavigation( |
| 1800 WebFrame*, WebDataSource::ExtraData*, const WebURLRequest&, WebNavigatio
nType, | 1831 WebFrame*, WebDataSource::ExtraData*, const WebURLRequest&, WebNavigatio
nType, |
| 1801 WebNavigationPolicy defaultPolicy, bool isRedirect) OVERRIDE | 1832 WebNavigationPolicy defaultPolicy, bool isRedirect) OVERRIDE |
| 1802 { | 1833 { |
| 1803 EXPECT_FALSE(isRedirect); | 1834 EXPECT_FALSE(isRedirect); |
| 1804 return WebNavigationPolicyCurrentTab; | 1835 return WebNavigationPolicyCurrentTab; |
| 1805 } | 1836 } |
| 1806 }; | 1837 }; |
| 1807 | 1838 |
| 1808 TEST_F(WebFrameTest, ReloadDoesntSetRedirect) | 1839 TEST_F(WebFrameTest, ReloadDoesntSetRedirect) |
| 1809 { | 1840 { |
| 1810 // Test for case in http://crbug.com/73104. Reloading a frame very quickly | 1841 // Test for case in http://crbug.com/73104. Reloading a frame very quickly |
| 1811 // would sometimes call decidePolicyForNavigation with isRedirect=true | 1842 // would sometimes call decidePolicyForNavigation with isRedirect=true |
| 1812 registerMockedHttpURLLoad("form.html"); | 1843 registerMockedHttpURLLoad("form.html"); |
| 1813 | 1844 |
| 1814 TestReloadDoesntRedirectWebFrameClient webFrameClient; | 1845 TestReloadDoesntRedirectWebFrameClient webFrameClient; |
| 1815 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "form.html",
false, &webFrameClient); | 1846 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1847 webViewHelper.initializeAndLoad(m_baseURL + "form.html", false, &webFrameCli
ent); |
| 1816 | 1848 |
| 1817 m_webView->mainFrame()->reload(true); | 1849 webViewHelper.webView()->mainFrame()->reload(true); |
| 1818 // start reload before request is delivered. | 1850 // start reload before request is delivered. |
| 1819 m_webView->mainFrame()->reload(true); | 1851 webViewHelper.webView()->mainFrame()->reload(true); |
| 1820 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 1852 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 1821 | |
| 1822 m_webView->close(); | |
| 1823 m_webView = 0; | |
| 1824 } | 1853 } |
| 1825 | 1854 |
| 1826 TEST_F(WebFrameTest, ReloadWithOverrideURLPreservesState) | 1855 TEST_F(WebFrameTest, ReloadWithOverrideURLPreservesState) |
| 1827 { | 1856 { |
| 1828 const std::string firstURL = "find.html"; | 1857 const std::string firstURL = "find.html"; |
| 1829 const std::string secondURL = "form.html"; | 1858 const std::string secondURL = "form.html"; |
| 1830 const std::string thirdURL = "history.html"; | 1859 const std::string thirdURL = "history.html"; |
| 1831 const float pageScaleFactor = 1.1684f; | 1860 const float pageScaleFactor = 1.1684f; |
| 1832 const int pageWidth = 640; | 1861 const int pageWidth = 640; |
| 1833 const int pageHeight = 480; | 1862 const int pageHeight = 480; |
| 1834 | 1863 |
| 1835 registerMockedHttpURLLoad(firstURL); | 1864 registerMockedHttpURLLoad(firstURL); |
| 1836 registerMockedHttpURLLoad(secondURL); | 1865 registerMockedHttpURLLoad(secondURL); |
| 1837 registerMockedHttpURLLoad(thirdURL); | 1866 registerMockedHttpURLLoad(thirdURL); |
| 1838 | 1867 |
| 1839 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + firstURL, tru
e); | 1868 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1840 webViewImpl()->resize(WebSize(pageWidth, pageHeight)); | 1869 webViewHelper.initializeAndLoad(m_baseURL + firstURL, true); |
| 1841 webViewImpl()->mainFrame()->setScrollOffset(WebSize(pageWidth / 4, pageHeigh
t / 4)); | 1870 webViewHelper.webViewImpl()->resize(WebSize(pageWidth, pageHeight)); |
| 1842 webViewImpl()->setPageScaleFactorPreservingScrollOffset(pageScaleFactor); | 1871 webViewHelper.webViewImpl()->mainFrame()->setScrollOffset(WebSize(pageWidth
/ 4, pageHeight / 4)); |
| 1872 webViewHelper.webViewImpl()->setPageScaleFactorPreservingScrollOffset(pageSc
aleFactor); |
| 1843 | 1873 |
| 1844 WebSize previousOffset = webViewImpl()->mainFrame()->scrollOffset(); | 1874 WebSize previousOffset = webViewHelper.webViewImpl()->mainFrame()->scrollOff
set(); |
| 1845 float previousScale = webViewImpl()->pageScaleFactor(); | 1875 float previousScale = webViewHelper.webViewImpl()->pageScaleFactor(); |
| 1846 | 1876 |
| 1847 // Reload the page using the cache. | 1877 // Reload the page using the cache. |
| 1848 webViewImpl()->mainFrame()->reloadWithOverrideURL(toKURL(m_baseURL + secondU
RL), false); | 1878 webViewHelper.webViewImpl()->mainFrame()->reloadWithOverrideURL(toKURL(m_bas
eURL + secondURL), false); |
| 1849 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 1879 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 1850 ASSERT_EQ(previousOffset, webViewImpl()->mainFrame()->scrollOffset()); | 1880 ASSERT_EQ(previousOffset, webViewHelper.webViewImpl()->mainFrame()->scrollOf
fset()); |
| 1851 ASSERT_EQ(previousScale, webViewImpl()->pageScaleFactor()); | 1881 ASSERT_EQ(previousScale, webViewHelper.webViewImpl()->pageScaleFactor()); |
| 1852 | 1882 |
| 1853 // Reload the page while ignoring the cache. | 1883 // Reload the page while ignoring the cache. |
| 1854 webViewImpl()->mainFrame()->reloadWithOverrideURL(toKURL(m_baseURL + thirdUR
L), true); | 1884 webViewHelper.webViewImpl()->mainFrame()->reloadWithOverrideURL(toKURL(m_bas
eURL + thirdURL), true); |
| 1855 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 1885 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 1856 ASSERT_EQ(previousOffset, webViewImpl()->mainFrame()->scrollOffset()); | 1886 ASSERT_EQ(previousOffset, webViewHelper.webViewImpl()->mainFrame()->scrollOf
fset()); |
| 1857 ASSERT_EQ(previousScale, webViewImpl()->pageScaleFactor()); | 1887 ASSERT_EQ(previousScale, webViewHelper.webViewImpl()->pageScaleFactor()); |
| 1858 } | 1888 } |
| 1859 | 1889 |
| 1860 class TestReloadWhileProvisionalFrameClient : public WebFrameClient { | 1890 class TestReloadWhileProvisionalFrameClient : public WebFrameClient { |
| 1861 }; | 1891 }; |
| 1862 | 1892 |
| 1863 TEST_F(WebFrameTest, ReloadWhileProvisional) | 1893 TEST_F(WebFrameTest, ReloadWhileProvisional) |
| 1864 { | 1894 { |
| 1865 // Test that reloading while the previous load is still pending does not cau
se the initial | 1895 // Test that reloading while the previous load is still pending does not cau
se the initial |
| 1866 // request to get lost. | 1896 // request to get lost. |
| 1867 registerMockedHttpURLLoad("fixed_layout.html"); | 1897 registerMockedHttpURLLoad("fixed_layout.html"); |
| 1868 | 1898 |
| 1869 TestReloadWhileProvisionalFrameClient webFrameClient; | 1899 TestReloadWhileProvisionalFrameClient webFrameClient; |
| 1870 m_webView = FrameTestHelpers::createWebView(false, &webFrameClient); | 1900 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1871 FrameTestHelpers::loadFrame(m_webView->mainFrame(), m_baseURL + "fixed_layou
t.html"); | 1901 webViewHelper.initialize(false, &webFrameClient); |
| 1902 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), m_baseURL
+ "fixed_layout.html"); |
| 1872 // start reload before first request is delivered. | 1903 // start reload before first request is delivered. |
| 1873 m_webView->mainFrame()->reload(true); | 1904 webViewHelper.webView()->mainFrame()->reload(true); |
| 1874 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 1905 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 1875 ASSERT_EQ(WebURL(toKURL(m_baseURL + "fixed_layout.html")), | 1906 ASSERT_EQ(WebURL(toKURL(m_baseURL + "fixed_layout.html")), |
| 1876 m_webView->mainFrame()->dataSource()->request().url()); | 1907 webViewHelper.webView()->mainFrame()->dataSource()->request().url()); |
| 1877 | |
| 1878 m_webView->close(); | |
| 1879 m_webView = 0; | |
| 1880 } | 1908 } |
| 1881 | 1909 |
| 1882 TEST_F(WebFrameTest, IframeRedirect) | 1910 TEST_F(WebFrameTest, IframeRedirect) |
| 1883 { | 1911 { |
| 1884 registerMockedHttpURLLoad("iframe_redirect.html"); | 1912 registerMockedHttpURLLoad("iframe_redirect.html"); |
| 1885 registerMockedHttpURLLoad("visible_iframe.html"); | 1913 registerMockedHttpURLLoad("visible_iframe.html"); |
| 1886 | 1914 |
| 1887 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframe_redir
ect.html", true); | 1915 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1916 webViewHelper.initializeAndLoad(m_baseURL + "iframe_redirect.html", true); |
| 1888 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); /
/ Load the iframe. | 1917 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); /
/ Load the iframe. |
| 1889 | 1918 |
| 1890 WebFrame* iframe = m_webView->findFrameByName(WebString::fromUTF8("ifr")); | 1919 WebFrame* iframe = webViewHelper.webView()->findFrameByName(WebString::fromU
TF8("ifr")); |
| 1891 ASSERT_TRUE(iframe); | 1920 ASSERT_TRUE(iframe); |
| 1892 WebDataSource* iframeDataSource = iframe->dataSource(); | 1921 WebDataSource* iframeDataSource = iframe->dataSource(); |
| 1893 ASSERT_TRUE(iframeDataSource); | 1922 ASSERT_TRUE(iframeDataSource); |
| 1894 WebVector<WebURL> redirects; | 1923 WebVector<WebURL> redirects; |
| 1895 iframeDataSource->redirectChain(redirects); | 1924 iframeDataSource->redirectChain(redirects); |
| 1896 ASSERT_EQ(2U, redirects.size()); | 1925 ASSERT_EQ(2U, redirects.size()); |
| 1897 EXPECT_EQ(toKURL("about:blank"), toKURL(redirects[0].spec().data())); | 1926 EXPECT_EQ(toKURL("about:blank"), toKURL(redirects[0].spec().data())); |
| 1898 EXPECT_EQ(toKURL("http://www.test.com/visible_iframe.html"), toKURL(redirect
s[1].spec().data())); | 1927 EXPECT_EQ(toKURL("http://www.test.com/visible_iframe.html"), toKURL(redirect
s[1].spec().data())); |
| 1899 } | 1928 } |
| 1900 | 1929 |
| 1901 TEST_F(WebFrameTest, ClearFocusedNodeTest) | 1930 TEST_F(WebFrameTest, ClearFocusedNodeTest) |
| 1902 { | 1931 { |
| 1903 registerMockedHttpURLLoad("iframe_clear_focused_node_test.html"); | 1932 registerMockedHttpURLLoad("iframe_clear_focused_node_test.html"); |
| 1904 registerMockedHttpURLLoad("autofocus_input_field_iframe.html"); | 1933 registerMockedHttpURLLoad("autofocus_input_field_iframe.html"); |
| 1905 | 1934 |
| 1906 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframe_clear
_focused_node_test.html", true); | 1935 FrameTestHelpers::WebViewHelper webViewHelper; |
| 1936 webViewHelper.initializeAndLoad(m_baseURL + "iframe_clear_focused_node_test.
html", true); |
| 1907 | 1937 |
| 1908 // Clear the focused node. | 1938 // Clear the focused node. |
| 1909 m_webView->clearFocusedNode(); | 1939 webViewHelper.webView()->clearFocusedNode(); |
| 1910 | 1940 |
| 1911 // Now retrieve the FocusedNode and test it should be null. | 1941 // Now retrieve the FocusedNode and test it should be null. |
| 1912 EXPECT_EQ(0, webViewImpl()->focusedElement()); | 1942 EXPECT_EQ(0, webViewHelper.webViewImpl()->focusedElement()); |
| 1913 } | 1943 } |
| 1914 | 1944 |
| 1915 // Implementation of WebFrameClient that tracks the v8 contexts that are created | 1945 // Implementation of WebFrameClient that tracks the v8 contexts that are created |
| 1916 // and destroyed for verification. | 1946 // and destroyed for verification. |
| 1917 class ContextLifetimeTestWebFrameClient : public WebFrameClient { | 1947 class ContextLifetimeTestWebFrameClient : public WebFrameClient { |
| 1918 public: | 1948 public: |
| 1919 struct Notification { | 1949 struct Notification { |
| 1920 public: | 1950 public: |
| 1921 Notification(WebFrame* frame, v8::Handle<v8::Context> context, int world
Id) | 1951 Notification(WebFrame* frame, v8::Handle<v8::Context> context, int world
Id) |
| 1922 : frame(frame) | 1952 : frame(frame) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 // TODO(aa): Deflake this test. | 2005 // TODO(aa): Deflake this test. |
| 1976 TEST_F(WebFrameTest, FLAKY_ContextNotificationsLoadUnload) | 2006 TEST_F(WebFrameTest, FLAKY_ContextNotificationsLoadUnload) |
| 1977 { | 2007 { |
| 1978 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | 2008 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); |
| 1979 | 2009 |
| 1980 registerMockedHttpURLLoad("context_notifications_test.html"); | 2010 registerMockedHttpURLLoad("context_notifications_test.html"); |
| 1981 registerMockedHttpURLLoad("context_notifications_test_frame.html"); | 2011 registerMockedHttpURLLoad("context_notifications_test_frame.html"); |
| 1982 | 2012 |
| 1983 // Load a frame with an iframe, make sure we get the right create notificati
ons. | 2013 // Load a frame with an iframe, make sure we get the right create notificati
ons. |
| 1984 ContextLifetimeTestWebFrameClient webFrameClient; | 2014 ContextLifetimeTestWebFrameClient webFrameClient; |
| 1985 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_noti
fications_test.html", true, &webFrameClient); | 2015 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2016 webViewHelper.initializeAndLoad(m_baseURL + "context_notifications_test.html
", true, &webFrameClient); |
| 1986 | 2017 |
| 1987 WebFrame* mainFrame = m_webView->mainFrame(); | 2018 WebFrame* mainFrame = webViewHelper.webView()->mainFrame(); |
| 1988 WebFrame* childFrame = mainFrame->firstChild(); | 2019 WebFrame* childFrame = mainFrame->firstChild(); |
| 1989 | 2020 |
| 1990 ASSERT_EQ(2u, webFrameClient.createNotifications.size()); | 2021 ASSERT_EQ(2u, webFrameClient.createNotifications.size()); |
| 1991 EXPECT_EQ(0u, webFrameClient.releaseNotifications.size()); | 2022 EXPECT_EQ(0u, webFrameClient.releaseNotifications.size()); |
| 1992 | 2023 |
| 1993 ContextLifetimeTestWebFrameClient::Notification* firstCreateNotification = w
ebFrameClient.createNotifications[0]; | 2024 ContextLifetimeTestWebFrameClient::Notification* firstCreateNotification = w
ebFrameClient.createNotifications[0]; |
| 1994 ContextLifetimeTestWebFrameClient::Notification* secondCreateNotification =
webFrameClient.createNotifications[1]; | 2025 ContextLifetimeTestWebFrameClient::Notification* secondCreateNotification =
webFrameClient.createNotifications[1]; |
| 1995 | 2026 |
| 1996 EXPECT_EQ(mainFrame, firstCreateNotification->frame); | 2027 EXPECT_EQ(mainFrame, firstCreateNotification->frame); |
| 1997 EXPECT_EQ(mainFrame->mainWorldScriptContext(), firstCreateNotification->cont
ext); | 2028 EXPECT_EQ(mainFrame->mainWorldScriptContext(), firstCreateNotification->cont
ext); |
| 1998 EXPECT_EQ(0, firstCreateNotification->worldId); | 2029 EXPECT_EQ(0, firstCreateNotification->worldId); |
| 1999 | 2030 |
| 2000 EXPECT_EQ(childFrame, secondCreateNotification->frame); | 2031 EXPECT_EQ(childFrame, secondCreateNotification->frame); |
| 2001 EXPECT_EQ(childFrame->mainWorldScriptContext(), secondCreateNotification->co
ntext); | 2032 EXPECT_EQ(childFrame->mainWorldScriptContext(), secondCreateNotification->co
ntext); |
| 2002 EXPECT_EQ(0, secondCreateNotification->worldId); | 2033 EXPECT_EQ(0, secondCreateNotification->worldId); |
| 2003 | 2034 |
| 2004 // Close the view. We should get two release notifications that are exactly
the same as the create ones, in reverse order. | 2035 // Close the view. We should get two release notifications that are exactly
the same as the create ones, in reverse order. |
| 2005 m_webView->close(); | 2036 webViewHelper.reset(); |
| 2006 m_webView = 0; | |
| 2007 | 2037 |
| 2008 ASSERT_EQ(2u, webFrameClient.releaseNotifications.size()); | 2038 ASSERT_EQ(2u, webFrameClient.releaseNotifications.size()); |
| 2009 ContextLifetimeTestWebFrameClient::Notification* firstReleaseNotification =
webFrameClient.releaseNotifications[0]; | 2039 ContextLifetimeTestWebFrameClient::Notification* firstReleaseNotification =
webFrameClient.releaseNotifications[0]; |
| 2010 ContextLifetimeTestWebFrameClient::Notification* secondReleaseNotification =
webFrameClient.releaseNotifications[1]; | 2040 ContextLifetimeTestWebFrameClient::Notification* secondReleaseNotification =
webFrameClient.releaseNotifications[1]; |
| 2011 | 2041 |
| 2012 ASSERT_TRUE(firstCreateNotification->Equals(secondReleaseNotification)); | 2042 ASSERT_TRUE(firstCreateNotification->Equals(secondReleaseNotification)); |
| 2013 ASSERT_TRUE(secondCreateNotification->Equals(firstReleaseNotification)); | 2043 ASSERT_TRUE(secondCreateNotification->Equals(firstReleaseNotification)); |
| 2014 } | 2044 } |
| 2015 | 2045 |
| 2016 TEST_F(WebFrameTest, ContextNotificationsReload) | 2046 TEST_F(WebFrameTest, ContextNotificationsReload) |
| 2017 { | 2047 { |
| 2018 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | 2048 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); |
| 2019 | 2049 |
| 2020 registerMockedHttpURLLoad("context_notifications_test.html"); | 2050 registerMockedHttpURLLoad("context_notifications_test.html"); |
| 2021 registerMockedHttpURLLoad("context_notifications_test_frame.html"); | 2051 registerMockedHttpURLLoad("context_notifications_test_frame.html"); |
| 2022 | 2052 |
| 2023 ContextLifetimeTestWebFrameClient webFrameClient; | 2053 ContextLifetimeTestWebFrameClient webFrameClient; |
| 2024 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_noti
fications_test.html", true, &webFrameClient); | 2054 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2055 webViewHelper.initializeAndLoad(m_baseURL + "context_notifications_test.html
", true, &webFrameClient); |
| 2025 | 2056 |
| 2026 // Refresh, we should get two release notifications and two more create noti
fications. | 2057 // Refresh, we should get two release notifications and two more create noti
fications. |
| 2027 m_webView->mainFrame()->reload(false); | 2058 webViewHelper.webView()->mainFrame()->reload(false); |
| 2028 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 2059 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 2029 ASSERT_EQ(4u, webFrameClient.createNotifications.size()); | 2060 ASSERT_EQ(4u, webFrameClient.createNotifications.size()); |
| 2030 ASSERT_EQ(2u, webFrameClient.releaseNotifications.size()); | 2061 ASSERT_EQ(2u, webFrameClient.releaseNotifications.size()); |
| 2031 | 2062 |
| 2032 // The two release notifications we got should be exactly the same as the fi
rst two create notifications. | 2063 // The two release notifications we got should be exactly the same as the fi
rst two create notifications. |
| 2033 for (size_t i = 0; i < webFrameClient.releaseNotifications.size(); ++i) { | 2064 for (size_t i = 0; i < webFrameClient.releaseNotifications.size(); ++i) { |
| 2034 EXPECT_TRUE(webFrameClient.releaseNotifications[i]->Equals( | 2065 EXPECT_TRUE(webFrameClient.releaseNotifications[i]->Equals( |
| 2035 webFrameClient.createNotifications[webFrameClient.createNotifications.
size() - 3 - i])); | 2066 webFrameClient.createNotifications[webFrameClient.createNotifications.
size() - 3 - i])); |
| 2036 } | 2067 } |
| 2037 | 2068 |
| 2038 // The last two create notifications should be for the current frames and co
ntext. | 2069 // The last two create notifications should be for the current frames and co
ntext. |
| 2039 WebFrame* mainFrame = m_webView->mainFrame(); | 2070 WebFrame* mainFrame = webViewHelper.webView()->mainFrame(); |
| 2040 WebFrame* childFrame = mainFrame->firstChild(); | 2071 WebFrame* childFrame = mainFrame->firstChild(); |
| 2041 ContextLifetimeTestWebFrameClient::Notification* firstRefreshNotification =
webFrameClient.createNotifications[2]; | 2072 ContextLifetimeTestWebFrameClient::Notification* firstRefreshNotification =
webFrameClient.createNotifications[2]; |
| 2042 ContextLifetimeTestWebFrameClient::Notification* secondRefreshNotification =
webFrameClient.createNotifications[3]; | 2073 ContextLifetimeTestWebFrameClient::Notification* secondRefreshNotification =
webFrameClient.createNotifications[3]; |
| 2043 | 2074 |
| 2044 EXPECT_EQ(mainFrame, firstRefreshNotification->frame); | 2075 EXPECT_EQ(mainFrame, firstRefreshNotification->frame); |
| 2045 EXPECT_EQ(mainFrame->mainWorldScriptContext(), firstRefreshNotification->con
text); | 2076 EXPECT_EQ(mainFrame->mainWorldScriptContext(), firstRefreshNotification->con
text); |
| 2046 EXPECT_EQ(0, firstRefreshNotification->worldId); | 2077 EXPECT_EQ(0, firstRefreshNotification->worldId); |
| 2047 | 2078 |
| 2048 EXPECT_EQ(childFrame, secondRefreshNotification->frame); | 2079 EXPECT_EQ(childFrame, secondRefreshNotification->frame); |
| 2049 EXPECT_EQ(childFrame->mainWorldScriptContext(), secondRefreshNotification->c
ontext); | 2080 EXPECT_EQ(childFrame->mainWorldScriptContext(), secondRefreshNotification->c
ontext); |
| 2050 EXPECT_EQ(0, secondRefreshNotification->worldId); | 2081 EXPECT_EQ(0, secondRefreshNotification->worldId); |
| 2051 | |
| 2052 m_webView->close(); | |
| 2053 m_webView = 0; | |
| 2054 } | 2082 } |
| 2055 | 2083 |
| 2056 TEST_F(WebFrameTest, ContextNotificationsIsolatedWorlds) | 2084 TEST_F(WebFrameTest, ContextNotificationsIsolatedWorlds) |
| 2057 { | 2085 { |
| 2058 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 2086 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 2059 v8::HandleScope handleScope(isolate); | 2087 v8::HandleScope handleScope(isolate); |
| 2060 | 2088 |
| 2061 registerMockedHttpURLLoad("context_notifications_test.html"); | 2089 registerMockedHttpURLLoad("context_notifications_test.html"); |
| 2062 registerMockedHttpURLLoad("context_notifications_test_frame.html"); | 2090 registerMockedHttpURLLoad("context_notifications_test_frame.html"); |
| 2063 | 2091 |
| 2064 ContextLifetimeTestWebFrameClient webFrameClient; | 2092 ContextLifetimeTestWebFrameClient webFrameClient; |
| 2065 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_noti
fications_test.html", true, &webFrameClient); | 2093 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2094 webViewHelper.initializeAndLoad(m_baseURL + "context_notifications_test.html
", true, &webFrameClient); |
| 2066 | 2095 |
| 2067 // Add an isolated world. | 2096 // Add an isolated world. |
| 2068 webFrameClient.reset(); | 2097 webFrameClient.reset(); |
| 2069 | 2098 |
| 2070 int isolatedWorldId = 42; | 2099 int isolatedWorldId = 42; |
| 2071 WebScriptSource scriptSource("hi!"); | 2100 WebScriptSource scriptSource("hi!"); |
| 2072 int numSources = 1; | 2101 int numSources = 1; |
| 2073 int extensionGroup = 0; | 2102 int extensionGroup = 0; |
| 2074 m_webView->mainFrame()->executeScriptInIsolatedWorld(isolatedWorldId, &scrip
tSource, numSources, extensionGroup); | 2103 webViewHelper.webView()->mainFrame()->executeScriptInIsolatedWorld(isolatedW
orldId, &scriptSource, numSources, extensionGroup); |
| 2075 | 2104 |
| 2076 // We should now have a new create notification. | 2105 // We should now have a new create notification. |
| 2077 ASSERT_EQ(1u, webFrameClient.createNotifications.size()); | 2106 ASSERT_EQ(1u, webFrameClient.createNotifications.size()); |
| 2078 ContextLifetimeTestWebFrameClient::Notification* notification = webFrameClie
nt.createNotifications[0]; | 2107 ContextLifetimeTestWebFrameClient::Notification* notification = webFrameClie
nt.createNotifications[0]; |
| 2079 ASSERT_EQ(isolatedWorldId, notification->worldId); | 2108 ASSERT_EQ(isolatedWorldId, notification->worldId); |
| 2080 ASSERT_EQ(m_webView->mainFrame(), notification->frame); | 2109 ASSERT_EQ(webViewHelper.webView()->mainFrame(), notification->frame); |
| 2081 | 2110 |
| 2082 // We don't have an API to enumarate isolated worlds for a frame, but we can
at least assert that the context we got is *not* the main world's context. | 2111 // We don't have an API to enumarate isolated worlds for a frame, but we can
at least assert that the context we got is *not* the main world's context. |
| 2083 ASSERT_NE(m_webView->mainFrame()->mainWorldScriptContext(), v8::Local<v8::Co
ntext>::New(isolate, notification->context)); | 2112 ASSERT_NE(webViewHelper.webView()->mainFrame()->mainWorldScriptContext(), v8
::Local<v8::Context>::New(isolate, notification->context)); |
| 2084 | 2113 |
| 2085 m_webView->close(); | 2114 webViewHelper.reset(); |
| 2086 m_webView = 0; | |
| 2087 | 2115 |
| 2088 // We should have gotten three release notifications (one for each of the fr
ames, plus one for the isolated context). | 2116 // We should have gotten three release notifications (one for each of the fr
ames, plus one for the isolated context). |
| 2089 ASSERT_EQ(3u, webFrameClient.releaseNotifications.size()); | 2117 ASSERT_EQ(3u, webFrameClient.releaseNotifications.size()); |
| 2090 | 2118 |
| 2091 // And one of them should be exactly the same as the create notification for
the isolated context. | 2119 // And one of them should be exactly the same as the create notification for
the isolated context. |
| 2092 int matchCount = 0; | 2120 int matchCount = 0; |
| 2093 for (size_t i = 0; i < webFrameClient.releaseNotifications.size(); ++i) { | 2121 for (size_t i = 0; i < webFrameClient.releaseNotifications.size(); ++i) { |
| 2094 if (webFrameClient.releaseNotifications[i]->Equals(webFrameClient.createNo
tifications[0])) | 2122 if (webFrameClient.releaseNotifications[i]->Equals(webFrameClient.createNo
tifications[0])) |
| 2095 ++matchCount; | 2123 ++matchCount; |
| 2096 } | 2124 } |
| 2097 EXPECT_EQ(1, matchCount); | 2125 EXPECT_EQ(1, matchCount); |
| 2098 } | 2126 } |
| 2099 | 2127 |
| 2100 TEST_F(WebFrameTest, FindInPage) | 2128 TEST_F(WebFrameTest, FindInPage) |
| 2101 { | 2129 { |
| 2102 registerMockedHttpURLLoad("find.html"); | 2130 registerMockedHttpURLLoad("find.html"); |
| 2103 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find.html"); | 2131 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2104 WebFrame* frame = m_webView->mainFrame(); | 2132 webViewHelper.initializeAndLoad(m_baseURL + "find.html"); |
| 2133 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 2105 const int findIdentifier = 12345; | 2134 const int findIdentifier = 12345; |
| 2106 WebFindOptions options; | 2135 WebFindOptions options; |
| 2107 | 2136 |
| 2108 // Find in a <div> element. | 2137 // Find in a <div> element. |
| 2109 EXPECT_TRUE(frame->find(findIdentifier, WebString::fromUTF8("bar1"), options
, false, 0)); | 2138 EXPECT_TRUE(frame->find(findIdentifier, WebString::fromUTF8("bar1"), options
, false, 0)); |
| 2110 frame->stopFinding(false); | 2139 frame->stopFinding(false); |
| 2111 WebRange range = frame->selectionRange(); | 2140 WebRange range = frame->selectionRange(); |
| 2112 EXPECT_EQ(5, range.startOffset()); | 2141 EXPECT_EQ(5, range.startOffset()); |
| 2113 EXPECT_EQ(9, range.endOffset()); | 2142 EXPECT_EQ(9, range.endOffset()); |
| 2114 EXPECT_TRUE(frame->document().focusedNode().isNull()); | 2143 EXPECT_TRUE(frame->document().focusedNode().isNull()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 EXPECT_FALSE(frame->find(findIdentifier, WebString::fromUTF8("bar5"), option
s, false, 0)); | 2177 EXPECT_FALSE(frame->find(findIdentifier, WebString::fromUTF8("bar5"), option
s, false, 0)); |
| 2149 // If there are any matches, stopFinding will set the selection on the found
text. | 2178 // If there are any matches, stopFinding will set the selection on the found
text. |
| 2150 // However, we do not expect any matches, so check that the selection is nul
l. | 2179 // However, we do not expect any matches, so check that the selection is nul
l. |
| 2151 frame->stopFinding(false); | 2180 frame->stopFinding(false); |
| 2152 range = frame->selectionRange(); | 2181 range = frame->selectionRange(); |
| 2153 ASSERT_TRUE(range.isNull()); | 2182 ASSERT_TRUE(range.isNull()); |
| 2154 } | 2183 } |
| 2155 | 2184 |
| 2156 TEST_F(WebFrameTest, GetContentAsPlainText) | 2185 TEST_F(WebFrameTest, GetContentAsPlainText) |
| 2157 { | 2186 { |
| 2158 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true); | 2187 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2188 webViewHelper.initializeAndLoad("about:blank", true); |
| 2159 // We set the size because it impacts line wrapping, which changes the | 2189 // We set the size because it impacts line wrapping, which changes the |
| 2160 // resulting text value. | 2190 // resulting text value. |
| 2161 m_webView->resize(WebSize(640, 480)); | 2191 webViewHelper.webView()->resize(WebSize(640, 480)); |
| 2162 WebFrame* frame = m_webView->mainFrame(); | 2192 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 2163 | 2193 |
| 2164 // Generate a simple test case. | 2194 // Generate a simple test case. |
| 2165 const char simpleSource[] = "<div>Foo bar</div><div></div>baz"; | 2195 const char simpleSource[] = "<div>Foo bar</div><div></div>baz"; |
| 2166 WebCore::KURL testURL = toKURL("about:blank"); | 2196 WebCore::KURL testURL = toKURL("about:blank"); |
| 2167 frame->loadHTMLString(simpleSource, testURL); | 2197 frame->loadHTMLString(simpleSource, testURL); |
| 2168 runPendingTasks(); | 2198 runPendingTasks(); |
| 2169 | 2199 |
| 2170 // Make sure it comes out OK. | 2200 // Make sure it comes out OK. |
| 2171 const std::string expected("Foo bar\nbaz"); | 2201 const std::string expected("Foo bar\nbaz"); |
| 2172 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); | 2202 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2192 EXPECT_EQ("Hello world\n\nsub\ntext", std::string(text.utf8().data())); | 2222 EXPECT_EQ("Hello world\n\nsub\ntext", std::string(text.utf8().data())); |
| 2193 | 2223 |
| 2194 // Get the frame text where the subframe separator falls on the boundary of | 2224 // Get the frame text where the subframe separator falls on the boundary of |
| 2195 // what we'll take. There used to be a crash in this case. | 2225 // what we'll take. There used to be a crash in this case. |
| 2196 text = frame->contentAsText(12); | 2226 text = frame->contentAsText(12); |
| 2197 EXPECT_EQ("Hello world", std::string(text.utf8().data())); | 2227 EXPECT_EQ("Hello world", std::string(text.utf8().data())); |
| 2198 } | 2228 } |
| 2199 | 2229 |
| 2200 TEST_F(WebFrameTest, GetFullHtmlOfPage) | 2230 TEST_F(WebFrameTest, GetFullHtmlOfPage) |
| 2201 { | 2231 { |
| 2202 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true); | 2232 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2203 WebFrame* frame = m_webView->mainFrame(); | 2233 webViewHelper.initializeAndLoad("about:blank", true); |
| 2234 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 2204 | 2235 |
| 2205 // Generate a simple test case. | 2236 // Generate a simple test case. |
| 2206 const char simpleSource[] = "<p>Hello</p><p>World</p>"; | 2237 const char simpleSource[] = "<p>Hello</p><p>World</p>"; |
| 2207 WebCore::KURL testURL = toKURL("about:blank"); | 2238 WebCore::KURL testURL = toKURL("about:blank"); |
| 2208 frame->loadHTMLString(simpleSource, testURL); | 2239 frame->loadHTMLString(simpleSource, testURL); |
| 2209 runPendingTasks(); | 2240 runPendingTasks(); |
| 2210 | 2241 |
| 2211 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); | 2242 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); |
| 2212 EXPECT_EQ("Hello\n\nWorld", std::string(text.utf8().data())); | 2243 EXPECT_EQ("Hello\n\nWorld", std::string(text.utf8().data())); |
| 2213 | 2244 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2238 { | 2269 { |
| 2239 frame->executeScript(WebScriptSource("window.history = 'replaced';")); | 2270 frame->executeScript(WebScriptSource("window.history = 'replaced';")); |
| 2240 } | 2271 } |
| 2241 }; | 2272 }; |
| 2242 | 2273 |
| 2243 TEST_F(WebFrameTest, ExecuteScriptDuringDidCreateScriptContext) | 2274 TEST_F(WebFrameTest, ExecuteScriptDuringDidCreateScriptContext) |
| 2244 { | 2275 { |
| 2245 registerMockedHttpURLLoad("hello_world.html"); | 2276 registerMockedHttpURLLoad("hello_world.html"); |
| 2246 | 2277 |
| 2247 TestExecuteScriptDuringDidCreateScriptContext webFrameClient; | 2278 TestExecuteScriptDuringDidCreateScriptContext webFrameClient; |
| 2248 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "hello_world.
html", true, &webFrameClient); | 2279 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2280 webViewHelper.initializeAndLoad(m_baseURL + "hello_world.html", true, &webFr
ameClient); |
| 2249 | 2281 |
| 2250 m_webView->mainFrame()->reload(); | 2282 webViewHelper.webView()->mainFrame()->reload(); |
| 2251 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 2283 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 2252 | |
| 2253 m_webView->close(); | |
| 2254 m_webView = 0; | |
| 2255 } | 2284 } |
| 2256 | 2285 |
| 2257 class TestDidCreateFrameWebFrameClient : public WebFrameClient { | 2286 class TestDidCreateFrameWebFrameClient : public WebFrameClient { |
| 2258 public: | 2287 public: |
| 2259 TestDidCreateFrameWebFrameClient() : m_frameCount(0), m_parent(0) | 2288 TestDidCreateFrameWebFrameClient() : m_frameCount(0), m_parent(0) |
| 2260 { | 2289 { |
| 2261 } | 2290 } |
| 2262 | 2291 |
| 2263 virtual void didCreateFrame(WebFrame* parent, WebFrame* child) | 2292 virtual void didCreateFrame(WebFrame* parent, WebFrame* child) |
| 2264 { | 2293 { |
| 2265 m_frameCount++; | 2294 m_frameCount++; |
| 2266 if (!m_parent) | 2295 if (!m_parent) |
| 2267 m_parent = parent; | 2296 m_parent = parent; |
| 2268 } | 2297 } |
| 2269 | 2298 |
| 2270 int m_frameCount; | 2299 int m_frameCount; |
| 2271 WebFrame* m_parent; | 2300 WebFrame* m_parent; |
| 2272 }; | 2301 }; |
| 2273 | 2302 |
| 2274 TEST_F(WebFrameTest, DidCreateFrame) | 2303 TEST_F(WebFrameTest, DidCreateFrame) |
| 2275 { | 2304 { |
| 2276 registerMockedHttpURLLoad("iframes_test.html"); | 2305 registerMockedHttpURLLoad("iframes_test.html"); |
| 2277 registerMockedHttpURLLoad("visible_iframe.html"); | 2306 registerMockedHttpURLLoad("visible_iframe.html"); |
| 2278 registerMockedHttpURLLoad("invisible_iframe.html"); | 2307 registerMockedHttpURLLoad("invisible_iframe.html"); |
| 2279 registerMockedHttpURLLoad("zero_sized_iframe.html"); | 2308 registerMockedHttpURLLoad("zero_sized_iframe.html"); |
| 2280 | 2309 |
| 2281 TestDidCreateFrameWebFrameClient webFrameClient; | 2310 TestDidCreateFrameWebFrameClient webFrameClient; |
| 2282 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframes_test
.html", false, &webFrameClient); | 2311 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2312 webViewHelper.initializeAndLoad(m_baseURL + "iframes_test.html", false, &web
FrameClient); |
| 2283 | 2313 |
| 2284 EXPECT_EQ(webFrameClient.m_frameCount, 3); | 2314 EXPECT_EQ(webFrameClient.m_frameCount, 3); |
| 2285 EXPECT_EQ(webFrameClient.m_parent, m_webView->mainFrame()); | 2315 EXPECT_EQ(webFrameClient.m_parent, webViewHelper.webView()->mainFrame()); |
| 2286 | |
| 2287 m_webView->close(); | |
| 2288 m_webView = 0; | |
| 2289 } | 2316 } |
| 2290 | 2317 |
| 2291 class FindUpdateWebFrameClient : public WebFrameClient { | 2318 class FindUpdateWebFrameClient : public WebFrameClient { |
| 2292 public: | 2319 public: |
| 2293 FindUpdateWebFrameClient() | 2320 FindUpdateWebFrameClient() |
| 2294 : m_findResultsAreReady(false) | 2321 : m_findResultsAreReady(false) |
| 2295 , m_count(-1) | 2322 , m_count(-1) |
| 2296 { | 2323 { |
| 2297 } | 2324 } |
| 2298 | 2325 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2315 #if OS(MACOSX) | 2342 #if OS(MACOSX) |
| 2316 TEST_F(WebFrameTest, DISABLED_FindInPageMatchRects) | 2343 TEST_F(WebFrameTest, DISABLED_FindInPageMatchRects) |
| 2317 #else | 2344 #else |
| 2318 TEST_F(WebFrameTest, FindInPageMatchRects) | 2345 TEST_F(WebFrameTest, FindInPageMatchRects) |
| 2319 #endif | 2346 #endif |
| 2320 { | 2347 { |
| 2321 registerMockedHttpURLLoad("find_in_page.html"); | 2348 registerMockedHttpURLLoad("find_in_page.html"); |
| 2322 registerMockedHttpURLLoad("find_in_page_frame.html"); | 2349 registerMockedHttpURLLoad("find_in_page_frame.html"); |
| 2323 | 2350 |
| 2324 FindUpdateWebFrameClient client; | 2351 FindUpdateWebFrameClient client; |
| 2325 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_page
.html", true, &client); | 2352 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2326 m_webView->resize(WebSize(640, 480)); | 2353 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie
nt); |
| 2327 m_webView->layout(); | 2354 webViewHelper.webView()->resize(WebSize(640, 480)); |
| 2355 webViewHelper.webView()->layout(); |
| 2328 runPendingTasks(); | 2356 runPendingTasks(); |
| 2329 | 2357 |
| 2330 // Note that the 'result 19' in the <select> element is not expected to prod
uce a match. | 2358 // Note that the 'result 19' in the <select> element is not expected to prod
uce a match. |
| 2331 static const char* kFindString = "result"; | 2359 static const char* kFindString = "result"; |
| 2332 static const int kFindIdentifier = 12345; | 2360 static const int kFindIdentifier = 12345; |
| 2333 static const int kNumResults = 19; | 2361 static const int kNumResults = 19; |
| 2334 | 2362 |
| 2335 WebFindOptions options; | 2363 WebFindOptions options; |
| 2336 WebString searchText = WebString::fromUTF8(kFindString); | 2364 WebString searchText = WebString::fromUTF8(kFindString); |
| 2337 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); | 2365 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame(
)); |
| 2338 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0))
; | 2366 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0))
; |
| 2339 | 2367 |
| 2340 mainFrame->resetMatchCount(); | 2368 mainFrame->resetMatchCount(); |
| 2341 | 2369 |
| 2342 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 2370 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
| 2343 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); | 2371 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); |
| 2344 | 2372 |
| 2345 runPendingTasks(); | 2373 runPendingTasks(); |
| 2346 EXPECT_TRUE(client.findResultsAreReady()); | 2374 EXPECT_TRUE(client.findResultsAreReady()); |
| 2347 | 2375 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2422 EXPECT_TRUE(webMatchRects[12].y < webMatchRects[14].y); | 2450 EXPECT_TRUE(webMatchRects[12].y < webMatchRects[14].y); |
| 2423 | 2451 |
| 2424 // Result 16 should be below result 15. | 2452 // Result 16 should be below result 15. |
| 2425 EXPECT_TRUE(webMatchRects[15].y > webMatchRects[14].y); | 2453 EXPECT_TRUE(webMatchRects[15].y > webMatchRects[14].y); |
| 2426 | 2454 |
| 2427 // Result 18 should be normalized with respect to the position:relative div,
and not it's | 2455 // Result 18 should be normalized with respect to the position:relative div,
and not it's |
| 2428 // immediate containing div. Consequently, result 18 should be above result
17. | 2456 // immediate containing div. Consequently, result 18 should be above result
17. |
| 2429 EXPECT_TRUE(webMatchRects[17].y > webMatchRects[18].y); | 2457 EXPECT_TRUE(webMatchRects[17].y > webMatchRects[18].y); |
| 2430 | 2458 |
| 2431 // Resizing should update the rects version. | 2459 // Resizing should update the rects version. |
| 2432 m_webView->resize(WebSize(800, 600)); | 2460 webViewHelper.webView()->resize(WebSize(800, 600)); |
| 2433 runPendingTasks(); | 2461 runPendingTasks(); |
| 2434 EXPECT_TRUE(mainFrame->findMatchMarkersVersion() != rectsVersion); | 2462 EXPECT_TRUE(mainFrame->findMatchMarkersVersion() != rectsVersion); |
| 2435 | |
| 2436 m_webView->close(); | |
| 2437 m_webView = 0; | |
| 2438 } | 2463 } |
| 2439 | 2464 |
| 2440 TEST_F(WebFrameTest, FindInPageSkipsHiddenFrames) | 2465 TEST_F(WebFrameTest, FindInPageSkipsHiddenFrames) |
| 2441 { | 2466 { |
| 2442 registerMockedHttpURLLoad("find_in_hidden_frame.html"); | 2467 registerMockedHttpURLLoad("find_in_hidden_frame.html"); |
| 2443 | 2468 |
| 2444 FindUpdateWebFrameClient client; | 2469 FindUpdateWebFrameClient client; |
| 2445 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_hidd
en_frame.html", true, &client); | 2470 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2446 m_webView->resize(WebSize(640, 480)); | 2471 webViewHelper.initializeAndLoad(m_baseURL + "find_in_hidden_frame.html", tru
e, &client); |
| 2447 m_webView->layout(); | 2472 webViewHelper.webView()->resize(WebSize(640, 480)); |
| 2473 webViewHelper.webView()->layout(); |
| 2448 runPendingTasks(); | 2474 runPendingTasks(); |
| 2449 | 2475 |
| 2450 static const char* kFindString = "hello"; | 2476 static const char* kFindString = "hello"; |
| 2451 static const int kFindIdentifier = 12345; | 2477 static const int kFindIdentifier = 12345; |
| 2452 static const int kNumResults = 1; | 2478 static const int kNumResults = 1; |
| 2453 | 2479 |
| 2454 WebFindOptions options; | 2480 WebFindOptions options; |
| 2455 WebString searchText = WebString::fromUTF8(kFindString); | 2481 WebString searchText = WebString::fromUTF8(kFindString); |
| 2456 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); | 2482 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame(
)); |
| 2457 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0))
; | 2483 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0))
; |
| 2458 | 2484 |
| 2459 mainFrame->resetMatchCount(); | 2485 mainFrame->resetMatchCount(); |
| 2460 | 2486 |
| 2461 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 2487 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
| 2462 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); | 2488 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); |
| 2463 | 2489 |
| 2464 runPendingTasks(); | 2490 runPendingTasks(); |
| 2465 EXPECT_TRUE(client.findResultsAreReady()); | 2491 EXPECT_TRUE(client.findResultsAreReady()); |
| 2466 EXPECT_EQ(kNumResults, client.count()); | 2492 EXPECT_EQ(kNumResults, client.count()); |
| 2467 | |
| 2468 m_webView->close(); | |
| 2469 m_webView = 0; | |
| 2470 } | 2493 } |
| 2471 | 2494 |
| 2472 TEST_F(WebFrameTest, FindOnDetachedFrame) | 2495 TEST_F(WebFrameTest, FindOnDetachedFrame) |
| 2473 { | 2496 { |
| 2474 registerMockedHttpURLLoad("find_in_page.html"); | 2497 registerMockedHttpURLLoad("find_in_page.html"); |
| 2475 registerMockedHttpURLLoad("find_in_page_frame.html"); | 2498 registerMockedHttpURLLoad("find_in_page_frame.html"); |
| 2476 | 2499 |
| 2477 FindUpdateWebFrameClient client; | 2500 FindUpdateWebFrameClient client; |
| 2478 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_page
.html", true, &client); | 2501 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2479 m_webView->resize(WebSize(640, 480)); | 2502 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie
nt); |
| 2480 m_webView->layout(); | 2503 webViewHelper.webView()->resize(WebSize(640, 480)); |
| 2504 webViewHelper.webView()->layout(); |
| 2481 runPendingTasks(); | 2505 runPendingTasks(); |
| 2482 | 2506 |
| 2483 static const char* kFindString = "result"; | 2507 static const char* kFindString = "result"; |
| 2484 static const int kFindIdentifier = 12345; | 2508 static const int kFindIdentifier = 12345; |
| 2485 | 2509 |
| 2486 WebFindOptions options; | 2510 WebFindOptions options; |
| 2487 WebString searchText = WebString::fromUTF8(kFindString); | 2511 WebString searchText = WebString::fromUTF8(kFindString); |
| 2488 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); | 2512 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame(
)); |
| 2489 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); | 2513 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); |
| 2490 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); | 2514 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); |
| 2491 | 2515 |
| 2492 // Detach the frame before finding. | 2516 // Detach the frame before finding. |
| 2493 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); | 2517 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); |
| 2494 | 2518 |
| 2495 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0))
; | 2519 EXPECT_TRUE(mainFrame->find(kFindIdentifier, searchText, options, false, 0))
; |
| 2496 EXPECT_FALSE(secondFrame->find(kFindIdentifier, searchText, options, false,
0)); | 2520 EXPECT_FALSE(secondFrame->find(kFindIdentifier, searchText, options, false,
0)); |
| 2497 | 2521 |
| 2498 runPendingTasks(); | 2522 runPendingTasks(); |
| 2499 EXPECT_FALSE(client.findResultsAreReady()); | 2523 EXPECT_FALSE(client.findResultsAreReady()); |
| 2500 | 2524 |
| 2501 mainFrame->resetMatchCount(); | 2525 mainFrame->resetMatchCount(); |
| 2502 | 2526 |
| 2503 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 2527 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
| 2504 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); | 2528 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); |
| 2505 | 2529 |
| 2506 runPendingTasks(); | 2530 runPendingTasks(); |
| 2507 EXPECT_TRUE(client.findResultsAreReady()); | 2531 EXPECT_TRUE(client.findResultsAreReady()); |
| 2508 | 2532 |
| 2509 holdSecondFrame.release(); | 2533 holdSecondFrame.release(); |
| 2510 | |
| 2511 m_webView->close(); | |
| 2512 m_webView = 0; | |
| 2513 } | 2534 } |
| 2514 | 2535 |
| 2515 TEST_F(WebFrameTest, FindDetachFrameBeforeScopeStrings) | 2536 TEST_F(WebFrameTest, FindDetachFrameBeforeScopeStrings) |
| 2516 { | 2537 { |
| 2517 registerMockedHttpURLLoad("find_in_page.html"); | 2538 registerMockedHttpURLLoad("find_in_page.html"); |
| 2518 registerMockedHttpURLLoad("find_in_page_frame.html"); | 2539 registerMockedHttpURLLoad("find_in_page_frame.html"); |
| 2519 | 2540 |
| 2520 FindUpdateWebFrameClient client; | 2541 FindUpdateWebFrameClient client; |
| 2521 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_page
.html", true, &client); | 2542 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2522 m_webView->resize(WebSize(640, 480)); | 2543 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie
nt); |
| 2523 m_webView->layout(); | 2544 webViewHelper.webView()->resize(WebSize(640, 480)); |
| 2545 webViewHelper.webView()->layout(); |
| 2524 runPendingTasks(); | 2546 runPendingTasks(); |
| 2525 | 2547 |
| 2526 static const char* kFindString = "result"; | 2548 static const char* kFindString = "result"; |
| 2527 static const int kFindIdentifier = 12345; | 2549 static const int kFindIdentifier = 12345; |
| 2528 | 2550 |
| 2529 WebFindOptions options; | 2551 WebFindOptions options; |
| 2530 WebString searchText = WebString::fromUTF8(kFindString); | 2552 WebString searchText = WebString::fromUTF8(kFindString); |
| 2531 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); | 2553 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame(
)); |
| 2532 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); | 2554 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); |
| 2533 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); | 2555 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); |
| 2534 | 2556 |
| 2535 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 2557 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
| 2536 EXPECT_TRUE(frame->find(kFindIdentifier, searchText, options, false, 0))
; | 2558 EXPECT_TRUE(frame->find(kFindIdentifier, searchText, options, false, 0))
; |
| 2537 | 2559 |
| 2538 runPendingTasks(); | 2560 runPendingTasks(); |
| 2539 EXPECT_FALSE(client.findResultsAreReady()); | 2561 EXPECT_FALSE(client.findResultsAreReady()); |
| 2540 | 2562 |
| 2541 // Detach the frame between finding and scoping. | 2563 // Detach the frame between finding and scoping. |
| 2542 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); | 2564 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); |
| 2543 | 2565 |
| 2544 mainFrame->resetMatchCount(); | 2566 mainFrame->resetMatchCount(); |
| 2545 | 2567 |
| 2546 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 2568 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
| 2547 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); | 2569 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); |
| 2548 | 2570 |
| 2549 runPendingTasks(); | 2571 runPendingTasks(); |
| 2550 EXPECT_TRUE(client.findResultsAreReady()); | 2572 EXPECT_TRUE(client.findResultsAreReady()); |
| 2551 | 2573 |
| 2552 holdSecondFrame.release(); | 2574 holdSecondFrame.release(); |
| 2553 | |
| 2554 m_webView->close(); | |
| 2555 m_webView = 0; | |
| 2556 } | 2575 } |
| 2557 | 2576 |
| 2558 TEST_F(WebFrameTest, FindDetachFrameWhileScopingStrings) | 2577 TEST_F(WebFrameTest, FindDetachFrameWhileScopingStrings) |
| 2559 { | 2578 { |
| 2560 registerMockedHttpURLLoad("find_in_page.html"); | 2579 registerMockedHttpURLLoad("find_in_page.html"); |
| 2561 registerMockedHttpURLLoad("find_in_page_frame.html"); | 2580 registerMockedHttpURLLoad("find_in_page_frame.html"); |
| 2562 | 2581 |
| 2563 FindUpdateWebFrameClient client; | 2582 FindUpdateWebFrameClient client; |
| 2564 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "find_in_page
.html", true, &client); | 2583 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2565 m_webView->resize(WebSize(640, 480)); | 2584 webViewHelper.initializeAndLoad(m_baseURL + "find_in_page.html", true, &clie
nt); |
| 2566 m_webView->layout(); | 2585 webViewHelper.webView()->resize(WebSize(640, 480)); |
| 2586 webViewHelper.webView()->layout(); |
| 2567 runPendingTasks(); | 2587 runPendingTasks(); |
| 2568 | 2588 |
| 2569 static const char* kFindString = "result"; | 2589 static const char* kFindString = "result"; |
| 2570 static const int kFindIdentifier = 12345; | 2590 static const int kFindIdentifier = 12345; |
| 2571 | 2591 |
| 2572 WebFindOptions options; | 2592 WebFindOptions options; |
| 2573 WebString searchText = WebString::fromUTF8(kFindString); | 2593 WebString searchText = WebString::fromUTF8(kFindString); |
| 2574 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); | 2594 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame(
)); |
| 2575 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); | 2595 WebFrameImpl* secondFrame = toWebFrameImpl(mainFrame->traverseNext(false)); |
| 2576 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); | 2596 RefPtr<WebCore::Frame> holdSecondFrame = secondFrame->frame(); |
| 2577 | 2597 |
| 2578 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 2598 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
| 2579 EXPECT_TRUE(frame->find(kFindIdentifier, searchText, options, false, 0))
; | 2599 EXPECT_TRUE(frame->find(kFindIdentifier, searchText, options, false, 0))
; |
| 2580 | 2600 |
| 2581 runPendingTasks(); | 2601 runPendingTasks(); |
| 2582 EXPECT_FALSE(client.findResultsAreReady()); | 2602 EXPECT_FALSE(client.findResultsAreReady()); |
| 2583 | 2603 |
| 2584 mainFrame->resetMatchCount(); | 2604 mainFrame->resetMatchCount(); |
| 2585 | 2605 |
| 2586 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) | 2606 for (WebFrame* frame = mainFrame; frame; frame = frame->traverseNext(false)) |
| 2587 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); | 2607 frame->scopeStringMatches(kFindIdentifier, searchText, options, true); |
| 2588 | 2608 |
| 2589 // The first scopeStringMatches will have reset the state. Detach before it
actually scopes. | 2609 // The first scopeStringMatches will have reset the state. Detach before it
actually scopes. |
| 2590 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); | 2610 EXPECT_TRUE(mainFrame->document().getElementById("frame").remove()); |
| 2591 | 2611 |
| 2592 runPendingTasks(); | 2612 runPendingTasks(); |
| 2593 EXPECT_TRUE(client.findResultsAreReady()); | 2613 EXPECT_TRUE(client.findResultsAreReady()); |
| 2594 | 2614 |
| 2595 holdSecondFrame.release(); | 2615 holdSecondFrame.release(); |
| 2596 | |
| 2597 m_webView->close(); | |
| 2598 m_webView = 0; | |
| 2599 } | |
| 2600 | |
| 2601 static WebView* createWebViewForTextSelection(const std::string& url) | |
| 2602 { | |
| 2603 WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true); | |
| 2604 webView->settings()->setDefaultFontSize(12); | |
| 2605 webView->enableFixedLayoutMode(false); | |
| 2606 webView->resize(WebSize(640, 480)); | |
| 2607 return webView; | |
| 2608 } | 2616 } |
| 2609 | 2617 |
| 2610 static WebPoint topLeft(const WebRect& rect) | 2618 static WebPoint topLeft(const WebRect& rect) |
| 2611 { | 2619 { |
| 2612 return WebPoint(rect.x, rect.y); | 2620 return WebPoint(rect.x, rect.y); |
| 2613 } | 2621 } |
| 2614 | 2622 |
| 2615 static WebPoint bottomRightMinusOne(const WebRect& rect) | 2623 static WebPoint bottomRightMinusOne(const WebRect& rect) |
| 2616 { | 2624 { |
| 2617 // FIXME: If we don't subtract 1 from the x- and y-coordinates of the | 2625 // FIXME: If we don't subtract 1 from the x- and y-coordinates of the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2633 | 2641 |
| 2634 TEST_F(WebFrameTest, SelectRange) | 2642 TEST_F(WebFrameTest, SelectRange) |
| 2635 { | 2643 { |
| 2636 WebFrame* frame; | 2644 WebFrame* frame; |
| 2637 WebRect startWebRect; | 2645 WebRect startWebRect; |
| 2638 WebRect endWebRect; | 2646 WebRect endWebRect; |
| 2639 | 2647 |
| 2640 registerMockedHttpURLLoad("select_range_basic.html"); | 2648 registerMockedHttpURLLoad("select_range_basic.html"); |
| 2641 registerMockedHttpURLLoad("select_range_scroll.html"); | 2649 registerMockedHttpURLLoad("select_range_scroll.html"); |
| 2642 | 2650 |
| 2643 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_basic.ht
ml"); | 2651 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2644 frame = m_webView->mainFrame(); | 2652 initializeTextSelectionWebView(m_baseURL + "select_range_basic.html", &webVi
ewHelper); |
| 2653 frame = webViewHelper.webView()->mainFrame(); |
| 2645 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); | 2654 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); |
| 2646 m_webView->selectionBounds(startWebRect, endWebRect); | 2655 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2647 frame->executeCommand(WebString::fromUTF8("Unselect")); | 2656 frame->executeCommand(WebString::fromUTF8("Unselect")); |
| 2648 EXPECT_EQ("", selectionAsString(frame)); | 2657 EXPECT_EQ("", selectionAsString(frame)); |
| 2649 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); | 2658 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); |
| 2650 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); | 2659 EXPECT_EQ("Some test text for testing.", selectionAsString(frame)); |
| 2651 m_webView->close(); | |
| 2652 m_webView = 0; | |
| 2653 | 2660 |
| 2654 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_scroll.h
tml"); | 2661 initializeTextSelectionWebView(m_baseURL + "select_range_scroll.html", &webV
iewHelper); |
| 2655 frame = m_webView->mainFrame(); | 2662 frame = webViewHelper.webView()->mainFrame(); |
| 2656 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame))
; | 2663 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame))
; |
| 2657 m_webView->selectionBounds(startWebRect, endWebRect); | 2664 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2658 frame->executeCommand(WebString::fromUTF8("Unselect")); | 2665 frame->executeCommand(WebString::fromUTF8("Unselect")); |
| 2659 EXPECT_EQ("", selectionAsString(frame)); | 2666 EXPECT_EQ("", selectionAsString(frame)); |
| 2660 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); | 2667 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); |
| 2661 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame))
; | 2668 EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame))
; |
| 2662 m_webView->close(); | |
| 2663 m_webView = 0; | |
| 2664 } | 2669 } |
| 2665 | 2670 |
| 2666 TEST_F(WebFrameTest, SelectRangeInIframe) | 2671 TEST_F(WebFrameTest, SelectRangeInIframe) |
| 2667 { | 2672 { |
| 2668 WebFrame* frame; | 2673 WebFrame* frame; |
| 2669 WebRect startWebRect; | 2674 WebRect startWebRect; |
| 2670 WebRect endWebRect; | 2675 WebRect endWebRect; |
| 2671 | 2676 |
| 2672 registerMockedHttpURLLoad("select_range_iframe.html"); | 2677 registerMockedHttpURLLoad("select_range_iframe.html"); |
| 2673 registerMockedHttpURLLoad("select_range_basic.html"); | 2678 registerMockedHttpURLLoad("select_range_basic.html"); |
| 2674 | 2679 |
| 2675 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_iframe.h
tml"); | 2680 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2676 frame = m_webView->mainFrame(); | 2681 initializeTextSelectionWebView(m_baseURL + "select_range_iframe.html", &webV
iewHelper); |
| 2682 frame = webViewHelper.webView()->mainFrame(); |
| 2677 WebFrame* subframe = frame->findChildByExpression(WebString::fromUTF8("/html
/body/iframe")); | 2683 WebFrame* subframe = frame->findChildByExpression(WebString::fromUTF8("/html
/body/iframe")); |
| 2678 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); | 2684 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); |
| 2679 m_webView->selectionBounds(startWebRect, endWebRect); | 2685 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2680 subframe->executeCommand(WebString::fromUTF8("Unselect")); | 2686 subframe->executeCommand(WebString::fromUTF8("Unselect")); |
| 2681 EXPECT_EQ("", selectionAsString(subframe)); | 2687 EXPECT_EQ("", selectionAsString(subframe)); |
| 2682 subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)
); | 2688 subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)
); |
| 2683 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); | 2689 EXPECT_EQ("Some test text for testing.", selectionAsString(subframe)); |
| 2684 m_webView->close(); | |
| 2685 m_webView = 0; | |
| 2686 } | 2690 } |
| 2687 | 2691 |
| 2688 TEST_F(WebFrameTest, SelectRangeDivContentEditable) | 2692 TEST_F(WebFrameTest, SelectRangeDivContentEditable) |
| 2689 { | 2693 { |
| 2690 WebFrame* frame; | 2694 WebFrame* frame; |
| 2691 WebRect startWebRect; | 2695 WebRect startWebRect; |
| 2692 WebRect endWebRect; | 2696 WebRect endWebRect; |
| 2693 | 2697 |
| 2694 registerMockedHttpURLLoad("select_range_div_editable.html"); | 2698 registerMockedHttpURLLoad("select_range_div_editable.html"); |
| 2695 | 2699 |
| 2696 // Select the middle of an editable element, then try to extend the selectio
n to the top of the document. | 2700 // Select the middle of an editable element, then try to extend the selectio
n to the top of the document. |
| 2697 // The selection range should be clipped to the bounds of the editable eleme
nt. | 2701 // The selection range should be clipped to the bounds of the editable eleme
nt. |
| 2698 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit
able.html"); | 2702 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2699 frame = m_webView->mainFrame(); | 2703 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html",
&webViewHelper); |
| 2704 frame = webViewHelper.webView()->mainFrame(); |
| 2700 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 2705 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
| 2701 m_webView->selectionBounds(startWebRect, endWebRect); | 2706 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2702 | 2707 |
| 2703 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); | 2708 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); |
| 2704 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr
ing(frame)); | 2709 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr
ing(frame)); |
| 2705 m_webView->close(); | |
| 2706 m_webView = 0; | |
| 2707 | 2710 |
| 2708 // As above, but extending the selection to the bottom of the document. | 2711 // As above, but extending the selection to the bottom of the document. |
| 2709 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit
able.html"); | 2712 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html",
&webViewHelper); |
| 2710 frame = m_webView->mainFrame(); | 2713 frame = webViewHelper.webView()->mainFrame(); |
| 2711 | 2714 |
| 2712 m_webView->selectionBounds(startWebRect, endWebRect); | 2715 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2713 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); | 2716 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); |
| 2714 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 2717 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
| 2715 m_webView->selectionBounds(startWebRect, endWebRect); | 2718 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2716 | 2719 |
| 2717 m_webView->selectionBounds(startWebRect, endWebRect); | 2720 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2718 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); | 2721 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); |
| 2719 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr
ing(frame)); | 2722 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr
ing(frame)); |
| 2720 m_webView->close(); | |
| 2721 m_webView = 0; | |
| 2722 } | 2723 } |
| 2723 | 2724 |
| 2724 // positionForPoint returns the wrong values for contenteditable spans. See | 2725 // positionForPoint returns the wrong values for contenteditable spans. See |
| 2725 // http://crbug.com/238334. | 2726 // http://crbug.com/238334. |
| 2726 TEST_F(WebFrameTest, DISABLED_SelectRangeSpanContentEditable) | 2727 TEST_F(WebFrameTest, DISABLED_SelectRangeSpanContentEditable) |
| 2727 { | 2728 { |
| 2728 WebFrame* frame; | 2729 WebFrame* frame; |
| 2729 WebRect startWebRect; | 2730 WebRect startWebRect; |
| 2730 WebRect endWebRect; | 2731 WebRect endWebRect; |
| 2731 | 2732 |
| 2732 registerMockedHttpURLLoad("select_range_span_editable.html"); | 2733 registerMockedHttpURLLoad("select_range_span_editable.html"); |
| 2733 | 2734 |
| 2734 // Select the middle of an editable element, then try to extend the selectio
n to the top of the document. | 2735 // Select the middle of an editable element, then try to extend the selectio
n to the top of the document. |
| 2735 // The selection range should be clipped to the bounds of the editable eleme
nt. | 2736 // The selection range should be clipped to the bounds of the editable eleme
nt. |
| 2736 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi
table.html"); | 2737 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2737 frame = m_webView->mainFrame(); | 2738 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html"
, &webViewHelper); |
| 2739 frame = webViewHelper.webView()->mainFrame(); |
| 2738 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 2740 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
| 2739 m_webView->selectionBounds(startWebRect, endWebRect); | 2741 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2740 | 2742 |
| 2741 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); | 2743 frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0)); |
| 2742 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr
ing(frame)); | 2744 EXPECT_EQ("16-char header. This text is initially selected.", selectionAsStr
ing(frame)); |
| 2743 m_webView->close(); | |
| 2744 m_webView = 0; | |
| 2745 | 2745 |
| 2746 // As above, but extending the selection to the bottom of the document. | 2746 // As above, but extending the selection to the bottom of the document. |
| 2747 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi
table.html"); | 2747 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html"
, &webViewHelper); |
| 2748 frame = m_webView->mainFrame(); | 2748 frame = webViewHelper.webView()->mainFrame(); |
| 2749 | 2749 |
| 2750 m_webView->selectionBounds(startWebRect, endWebRect); | 2750 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2751 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); | 2751 frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect)); |
| 2752 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 2752 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
| 2753 m_webView->selectionBounds(startWebRect, endWebRect); | 2753 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2754 | 2754 |
| 2755 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); | 2755 EXPECT_EQ("This text is initially selected.", selectionAsString(frame)); |
| 2756 m_webView->selectionBounds(startWebRect, endWebRect); | 2756 webViewHelper.webView()->selectionBounds(startWebRect, endWebRect); |
| 2757 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); | 2757 frame->selectRange(topLeft(startWebRect), WebPoint(640, 480)); |
| 2758 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr
ing(frame)); | 2758 EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsStr
ing(frame)); |
| 2759 m_webView->close(); | |
| 2760 m_webView = 0; | |
| 2761 } | 2759 } |
| 2762 | 2760 |
| 2763 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionStart) | 2761 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionStart) |
| 2764 { | 2762 { |
| 2765 registerMockedHttpURLLoad("text_selection.html"); | 2763 registerMockedHttpURLLoad("text_selection.html"); |
| 2766 m_webView = createWebViewForTextSelection(m_baseURL + "text_selection.html")
; | 2764 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2767 WebFrame* frame = m_webView->mainFrame(); | 2765 initializeTextSelectionWebView(m_baseURL + "text_selection.html", &webViewHe
lper); |
| 2766 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 2768 | 2767 |
| 2769 // Select second span. We can move the start to include the first span. | 2768 // Select second span. We can move the start to include the first span. |
| 2770 frame->executeScript(WebScriptSource("selectElement('header_2');")); | 2769 frame->executeScript(WebScriptSource("selectElement('header_2');")); |
| 2771 EXPECT_EQ("Header 2.", selectionAsString(frame)); | 2770 EXPECT_EQ("Header 2.", selectionAsString(frame)); |
| 2772 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_2")), to
pLeft(elementBounds(frame, "header_1"))); | 2771 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_2")), to
pLeft(elementBounds(frame, "header_1"))); |
| 2773 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); | 2772 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); |
| 2774 | 2773 |
| 2775 // We can move the start and end together. | 2774 // We can move the start and end together. |
| 2776 frame->executeScript(WebScriptSource("selectElement('header_1');")); | 2775 frame->executeScript(WebScriptSource("selectElement('header_1');")); |
| 2777 EXPECT_EQ("Header 1.", selectionAsString(frame)); | 2776 EXPECT_EQ("Header 1.", selectionAsString(frame)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2803 EXPECT_EQ("Editable 2.", selectionAsString(frame)); | 2802 EXPECT_EQ("Editable 2.", selectionAsString(frame)); |
| 2804 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "editable_2")),
topLeft(elementBounds(frame, "header_2"))); | 2803 frame->selectRange(bottomRightMinusOne(elementBounds(frame, "editable_2")),
topLeft(elementBounds(frame, "header_2"))); |
| 2805 // positionForPoint returns the wrong values for contenteditable spans. See | 2804 // positionForPoint returns the wrong values for contenteditable spans. See |
| 2806 // http://crbug.com/238334. | 2805 // http://crbug.com/238334. |
| 2807 // EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame)); | 2806 // EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame)); |
| 2808 } | 2807 } |
| 2809 | 2808 |
| 2810 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd) | 2809 TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd) |
| 2811 { | 2810 { |
| 2812 registerMockedHttpURLLoad("text_selection.html"); | 2811 registerMockedHttpURLLoad("text_selection.html"); |
| 2813 m_webView = createWebViewForTextSelection(m_baseURL + "text_selection.html")
; | 2812 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2814 WebFrame* frame = m_webView->mainFrame(); | 2813 initializeTextSelectionWebView(m_baseURL + "text_selection.html", &webViewHe
lper); |
| 2814 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 2815 | 2815 |
| 2816 // Select first span. We can move the end to include the second span. | 2816 // Select first span. We can move the end to include the second span. |
| 2817 frame->executeScript(WebScriptSource("selectElement('header_1');")); | 2817 frame->executeScript(WebScriptSource("selectElement('header_1');")); |
| 2818 EXPECT_EQ("Header 1.", selectionAsString(frame)); | 2818 EXPECT_EQ("Header 1.", selectionAsString(frame)); |
| 2819 frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMin
usOne(elementBounds(frame, "header_2"))); | 2819 frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMin
usOne(elementBounds(frame, "header_2"))); |
| 2820 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); | 2820 EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame)); |
| 2821 | 2821 |
| 2822 // We can move the start and end together. | 2822 // We can move the start and end together. |
| 2823 frame->executeScript(WebScriptSource("selectElement('header_2');")); | 2823 frame->executeScript(WebScriptSource("selectElement('header_2');")); |
| 2824 EXPECT_EQ("Header 2.", selectionAsString(frame)); | 2824 EXPECT_EQ("Header 2.", selectionAsString(frame)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2857 static int computeOffset(WebCore::RenderObject* renderer, int x, int y) | 2857 static int computeOffset(WebCore::RenderObject* renderer, int x, int y) |
| 2858 { | 2858 { |
| 2859 return WebCore::VisiblePosition(renderer->positionForPoint(WebCore::LayoutPo
int(x, y))).deepEquivalent().computeOffsetInContainerNode(); | 2859 return WebCore::VisiblePosition(renderer->positionForPoint(WebCore::LayoutPo
int(x, y))).deepEquivalent().computeOffsetInContainerNode(); |
| 2860 } | 2860 } |
| 2861 | 2861 |
| 2862 // positionForPoint returns the wrong values for contenteditable spans. See | 2862 // positionForPoint returns the wrong values for contenteditable spans. See |
| 2863 // http://crbug.com/238334. | 2863 // http://crbug.com/238334. |
| 2864 TEST_F(WebFrameTest, DISABLED_PositionForPointTest) | 2864 TEST_F(WebFrameTest, DISABLED_PositionForPointTest) |
| 2865 { | 2865 { |
| 2866 registerMockedHttpURLLoad("select_range_span_editable.html"); | 2866 registerMockedHttpURLLoad("select_range_span_editable.html"); |
| 2867 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_span_edi
table.html"); | 2867 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2868 WebFrameImpl* mainFrame = toWebFrameImpl(m_webView->mainFrame()); | 2868 initializeTextSelectionWebView(m_baseURL + "select_range_span_editable.html"
, &webViewHelper); |
| 2869 WebFrameImpl* mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame(
)); |
| 2869 WebCore::RenderObject* renderer = mainFrame->frame()->selection().rootEditab
leElement()->renderer(); | 2870 WebCore::RenderObject* renderer = mainFrame->frame()->selection().rootEditab
leElement()->renderer(); |
| 2870 EXPECT_EQ(0, computeOffset(renderer, -1, -1)); | 2871 EXPECT_EQ(0, computeOffset(renderer, -1, -1)); |
| 2871 EXPECT_EQ(64, computeOffset(renderer, 1000, 1000)); | 2872 EXPECT_EQ(64, computeOffset(renderer, 1000, 1000)); |
| 2872 | 2873 |
| 2873 registerMockedHttpURLLoad("select_range_div_editable.html"); | 2874 registerMockedHttpURLLoad("select_range_div_editable.html"); |
| 2874 m_webView = createWebViewForTextSelection(m_baseURL + "select_range_div_edit
able.html"); | 2875 initializeTextSelectionWebView(m_baseURL + "select_range_div_editable.html",
&webViewHelper); |
| 2875 mainFrame = toWebFrameImpl(m_webView->mainFrame()); | 2876 mainFrame = toWebFrameImpl(webViewHelper.webView()->mainFrame()); |
| 2876 renderer = mainFrame->frame()->selection().rootEditableElement()->renderer()
; | 2877 renderer = mainFrame->frame()->selection().rootEditableElement()->renderer()
; |
| 2877 EXPECT_EQ(0, computeOffset(renderer, -1, -1)); | 2878 EXPECT_EQ(0, computeOffset(renderer, -1, -1)); |
| 2878 EXPECT_EQ(64, computeOffset(renderer, 1000, 1000)); | 2879 EXPECT_EQ(64, computeOffset(renderer, 1000, 1000)); |
| 2879 } | 2880 } |
| 2880 | 2881 |
| 2881 #if !OS(MACOSX) | 2882 #if !OS(MACOSX) |
| 2882 TEST_F(WebFrameTest, SelectRangeStaysHorizontallyAlignedWhenMoved) | 2883 TEST_F(WebFrameTest, SelectRangeStaysHorizontallyAlignedWhenMoved) |
| 2883 { | 2884 { |
| 2884 WebFrameImpl* frame; | |
| 2885 registerMockedHttpURLLoad("move_caret.html"); | 2885 registerMockedHttpURLLoad("move_caret.html"); |
| 2886 | 2886 |
| 2887 m_webView = createWebViewForTextSelection(m_baseURL + "move_caret.html"); | 2887 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2888 frame = (WebFrameImpl*)m_webView->mainFrame(); | 2888 initializeTextSelectionWebView(m_baseURL + "move_caret.html", &webViewHelper
); |
| 2889 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame()); |
| 2889 | 2890 |
| 2890 WebRect initialStartRect; | 2891 WebRect initialStartRect; |
| 2891 WebRect initialEndRect; | 2892 WebRect initialEndRect; |
| 2892 WebRect startRect; | 2893 WebRect startRect; |
| 2893 WebRect endRect; | 2894 WebRect endRect; |
| 2894 | 2895 |
| 2895 frame->executeScript(WebScriptSource("selectRange();")); | 2896 frame->executeScript(WebScriptSource("selectRange();")); |
| 2896 m_webView->selectionBounds(initialStartRect, initialEndRect); | 2897 webViewHelper.webView()->selectionBounds(initialStartRect, initialEndRect); |
| 2897 WebPoint movedStart(topLeft(initialStartRect)); | 2898 WebPoint movedStart(topLeft(initialStartRect)); |
| 2898 | 2899 |
| 2899 movedStart.y += 40; | 2900 movedStart.y += 40; |
| 2900 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect)); | 2901 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect)); |
| 2901 m_webView->selectionBounds(startRect, endRect); | 2902 webViewHelper.webView()->selectionBounds(startRect, endRect); |
| 2902 EXPECT_EQ(startRect, initialStartRect); | 2903 EXPECT_EQ(startRect, initialStartRect); |
| 2903 EXPECT_EQ(endRect, initialEndRect); | 2904 EXPECT_EQ(endRect, initialEndRect); |
| 2904 | 2905 |
| 2905 movedStart.y -= 80; | 2906 movedStart.y -= 80; |
| 2906 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect)); | 2907 frame->selectRange(movedStart, bottomRightMinusOne(initialEndRect)); |
| 2907 m_webView->selectionBounds(startRect, endRect); | 2908 webViewHelper.webView()->selectionBounds(startRect, endRect); |
| 2908 EXPECT_EQ(startRect, initialStartRect); | 2909 EXPECT_EQ(startRect, initialStartRect); |
| 2909 EXPECT_EQ(endRect, initialEndRect); | 2910 EXPECT_EQ(endRect, initialEndRect); |
| 2910 | 2911 |
| 2911 WebPoint movedEnd(bottomRightMinusOne(initialEndRect)); | 2912 WebPoint movedEnd(bottomRightMinusOne(initialEndRect)); |
| 2912 | 2913 |
| 2913 movedEnd.y += 40; | 2914 movedEnd.y += 40; |
| 2914 frame->selectRange(topLeft(initialStartRect), movedEnd); | 2915 frame->selectRange(topLeft(initialStartRect), movedEnd); |
| 2915 m_webView->selectionBounds(startRect, endRect); | 2916 webViewHelper.webView()->selectionBounds(startRect, endRect); |
| 2916 EXPECT_EQ(startRect, initialStartRect); | 2917 EXPECT_EQ(startRect, initialStartRect); |
| 2917 EXPECT_EQ(endRect, initialEndRect); | 2918 EXPECT_EQ(endRect, initialEndRect); |
| 2918 | 2919 |
| 2919 movedEnd.y -= 80; | 2920 movedEnd.y -= 80; |
| 2920 frame->selectRange(topLeft(initialStartRect), movedEnd); | 2921 frame->selectRange(topLeft(initialStartRect), movedEnd); |
| 2921 m_webView->selectionBounds(startRect, endRect); | 2922 webViewHelper.webView()->selectionBounds(startRect, endRect); |
| 2922 EXPECT_EQ(startRect, initialStartRect); | 2923 EXPECT_EQ(startRect, initialStartRect); |
| 2923 EXPECT_EQ(endRect, initialEndRect); | 2924 EXPECT_EQ(endRect, initialEndRect); |
| 2924 } | 2925 } |
| 2925 | 2926 |
| 2926 TEST_F(WebFrameTest, MoveCaretStaysHorizontallyAlignedWhenMoved) | 2927 TEST_F(WebFrameTest, MoveCaretStaysHorizontallyAlignedWhenMoved) |
| 2927 { | 2928 { |
| 2928 WebFrameImpl* frame; | 2929 WebFrameImpl* frame; |
| 2929 registerMockedHttpURLLoad("move_caret.html"); | 2930 registerMockedHttpURLLoad("move_caret.html"); |
| 2930 | 2931 |
| 2931 m_webView = createWebViewForTextSelection(m_baseURL + "move_caret.html"); | 2932 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2932 frame = (WebFrameImpl*)m_webView->mainFrame(); | 2933 initializeTextSelectionWebView(m_baseURL + "move_caret.html", &webViewHelper
); |
| 2934 frame = (WebFrameImpl*)webViewHelper.webView()->mainFrame(); |
| 2933 | 2935 |
| 2934 WebRect initialStartRect; | 2936 WebRect initialStartRect; |
| 2935 WebRect initialEndRect; | 2937 WebRect initialEndRect; |
| 2936 WebRect startRect; | 2938 WebRect startRect; |
| 2937 WebRect endRect; | 2939 WebRect endRect; |
| 2938 | 2940 |
| 2939 frame->executeScript(WebScriptSource("selectCaret();")); | 2941 frame->executeScript(WebScriptSource("selectCaret();")); |
| 2940 m_webView->selectionBounds(initialStartRect, initialEndRect); | 2942 webViewHelper.webView()->selectionBounds(initialStartRect, initialEndRect); |
| 2941 WebPoint moveTo(topLeft(initialStartRect)); | 2943 WebPoint moveTo(topLeft(initialStartRect)); |
| 2942 | 2944 |
| 2943 moveTo.y += 40; | 2945 moveTo.y += 40; |
| 2944 frame->moveCaretSelectionTowardsWindowPoint(moveTo); | 2946 frame->moveCaretSelectionTowardsWindowPoint(moveTo); |
| 2945 m_webView->selectionBounds(startRect, endRect); | 2947 webViewHelper.webView()->selectionBounds(startRect, endRect); |
| 2946 EXPECT_EQ(startRect, initialStartRect); | 2948 EXPECT_EQ(startRect, initialStartRect); |
| 2947 EXPECT_EQ(endRect, initialEndRect); | 2949 EXPECT_EQ(endRect, initialEndRect); |
| 2948 | 2950 |
| 2949 moveTo.y -= 80; | 2951 moveTo.y -= 80; |
| 2950 frame->moveCaretSelectionTowardsWindowPoint(moveTo); | 2952 frame->moveCaretSelectionTowardsWindowPoint(moveTo); |
| 2951 m_webView->selectionBounds(startRect, endRect); | 2953 webViewHelper.webView()->selectionBounds(startRect, endRect); |
| 2952 EXPECT_EQ(startRect, initialStartRect); | 2954 EXPECT_EQ(startRect, initialStartRect); |
| 2953 EXPECT_EQ(endRect, initialEndRect); | 2955 EXPECT_EQ(endRect, initialEndRect); |
| 2954 } | 2956 } |
| 2955 #endif | 2957 #endif |
| 2956 | 2958 |
| 2957 class DisambiguationPopupTestWebViewClient : public WebViewClient { | 2959 class DisambiguationPopupTestWebViewClient : public WebViewClient { |
| 2958 public: | 2960 public: |
| 2959 virtual bool didTapMultipleTargets(const WebGestureEvent&, const WebVector<W
ebRect>& targetRects) OVERRIDE | 2961 virtual bool didTapMultipleTargets(const WebGestureEvent&, const WebVector<W
ebRect>& targetRects) OVERRIDE |
| 2960 { | 2962 { |
| 2961 EXPECT_GE(targetRects.size(), 2u); | 2963 EXPECT_GE(targetRects.size(), 2u); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2981 | 2983 |
| 2982 TEST_F(WebFrameTest, DisambiguationPopup) | 2984 TEST_F(WebFrameTest, DisambiguationPopup) |
| 2983 { | 2985 { |
| 2984 const std::string htmlFile = "disambiguation_popup.html"; | 2986 const std::string htmlFile = "disambiguation_popup.html"; |
| 2985 registerMockedHttpURLLoad(htmlFile); | 2987 registerMockedHttpURLLoad(htmlFile); |
| 2986 | 2988 |
| 2987 DisambiguationPopupTestWebViewClient client; | 2989 DisambiguationPopupTestWebViewClient client; |
| 2988 | 2990 |
| 2989 // Make sure we initialize to minimum scale, even if the window size | 2991 // Make sure we initialize to minimum scale, even if the window size |
| 2990 // only becomes available after the load begins. | 2992 // only becomes available after the load begins. |
| 2991 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile, tru
e, 0, &client); | 2993 FrameTestHelpers::WebViewHelper webViewHelper; |
| 2992 m_webView->resize(WebSize(1000, 1000)); | 2994 webViewHelper.initializeAndLoad(m_baseURL + htmlFile, true, 0, &client); |
| 2993 m_webView->layout(); | 2995 webViewHelper.webView()->resize(WebSize(1000, 1000)); |
| 2996 webViewHelper.webView()->layout(); |
| 2994 | 2997 |
| 2995 client.resetTriggered(); | 2998 client.resetTriggered(); |
| 2996 m_webView->handleInputEvent(fatTap(0, 0)); | 2999 webViewHelper.webView()->handleInputEvent(fatTap(0, 0)); |
| 2997 EXPECT_FALSE(client.triggered()); | 3000 EXPECT_FALSE(client.triggered()); |
| 2998 | 3001 |
| 2999 client.resetTriggered(); | 3002 client.resetTriggered(); |
| 3000 m_webView->handleInputEvent(fatTap(200, 115)); | 3003 webViewHelper.webView()->handleInputEvent(fatTap(200, 115)); |
| 3001 EXPECT_FALSE(client.triggered()); | 3004 EXPECT_FALSE(client.triggered()); |
| 3002 | 3005 |
| 3003 for (int i = 0; i <= 46; i++) { | 3006 for (int i = 0; i <= 46; i++) { |
| 3004 client.resetTriggered(); | 3007 client.resetTriggered(); |
| 3005 m_webView->handleInputEvent(fatTap(120, 230 + i * 5)); | 3008 webViewHelper.webView()->handleInputEvent(fatTap(120, 230 + i * 5)); |
| 3006 | 3009 |
| 3007 int j = i % 10; | 3010 int j = i % 10; |
| 3008 if (j >= 7 && j <= 9) | 3011 if (j >= 7 && j <= 9) |
| 3009 EXPECT_TRUE(client.triggered()); | 3012 EXPECT_TRUE(client.triggered()); |
| 3010 else | 3013 else |
| 3011 EXPECT_FALSE(client.triggered()); | 3014 EXPECT_FALSE(client.triggered()); |
| 3012 } | 3015 } |
| 3013 | 3016 |
| 3014 for (int i = 0; i <= 46; i++) { | 3017 for (int i = 0; i <= 46; i++) { |
| 3015 client.resetTriggered(); | 3018 client.resetTriggered(); |
| 3016 m_webView->handleInputEvent(fatTap(10 + i * 5, 590)); | 3019 webViewHelper.webView()->handleInputEvent(fatTap(10 + i * 5, 590)); |
| 3017 | 3020 |
| 3018 int j = i % 10; | 3021 int j = i % 10; |
| 3019 if (j >= 7 && j <= 9) | 3022 if (j >= 7 && j <= 9) |
| 3020 EXPECT_TRUE(client.triggered()); | 3023 EXPECT_TRUE(client.triggered()); |
| 3021 else | 3024 else |
| 3022 EXPECT_FALSE(client.triggered()); | 3025 EXPECT_FALSE(client.triggered()); |
| 3023 } | 3026 } |
| 3024 | |
| 3025 m_webView->close(); | |
| 3026 m_webView = 0; | |
| 3027 | |
| 3028 } | 3027 } |
| 3029 | 3028 |
| 3030 TEST_F(WebFrameTest, DisambiguationPopupNoContainer) | 3029 TEST_F(WebFrameTest, DisambiguationPopupNoContainer) |
| 3031 { | 3030 { |
| 3032 registerMockedHttpURLLoad("disambiguation_popup_no_container.html"); | 3031 registerMockedHttpURLLoad("disambiguation_popup_no_container.html"); |
| 3033 | 3032 |
| 3034 DisambiguationPopupTestWebViewClient client; | 3033 DisambiguationPopupTestWebViewClient client; |
| 3035 | 3034 |
| 3036 // Make sure we initialize to minimum scale, even if the window size | 3035 // Make sure we initialize to minimum scale, even if the window size |
| 3037 // only becomes available after the load begins. | 3036 // only becomes available after the load begins. |
| 3038 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "disambiguati
on_popup_no_container.html", true, 0, &client); | 3037 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3039 m_webView->resize(WebSize(1000, 1000)); | 3038 webViewHelper.initializeAndLoad(m_baseURL + "disambiguation_popup_no_contain
er.html", true, 0, &client); |
| 3040 m_webView->layout(); | 3039 webViewHelper.webView()->resize(WebSize(1000, 1000)); |
| 3040 webViewHelper.webView()->layout(); |
| 3041 | 3041 |
| 3042 client.resetTriggered(); | 3042 client.resetTriggered(); |
| 3043 m_webView->handleInputEvent(fatTap(50, 50)); | 3043 webViewHelper.webView()->handleInputEvent(fatTap(50, 50)); |
| 3044 EXPECT_FALSE(client.triggered()); | 3044 EXPECT_FALSE(client.triggered()); |
| 3045 | |
| 3046 m_webView->close(); | |
| 3047 m_webView = 0; | |
| 3048 } | 3045 } |
| 3049 | 3046 |
| 3050 TEST_F(WebFrameTest, DisambiguationPopupMobileSite) | 3047 TEST_F(WebFrameTest, DisambiguationPopupMobileSite) |
| 3051 { | 3048 { |
| 3052 const std::string htmlFile = "disambiguation_popup_mobile_site.html"; | 3049 const std::string htmlFile = "disambiguation_popup_mobile_site.html"; |
| 3053 registerMockedHttpURLLoad(htmlFile); | 3050 registerMockedHttpURLLoad(htmlFile); |
| 3054 | 3051 |
| 3055 DisambiguationPopupTestWebViewClient client; | 3052 DisambiguationPopupTestWebViewClient client; |
| 3056 | 3053 |
| 3057 // Make sure we initialize to minimum scale, even if the window size | 3054 // Make sure we initialize to minimum scale, even if the window size |
| 3058 // only becomes available after the load begins. | 3055 // only becomes available after the load begins. |
| 3059 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile, tru
e, 0, &client); | 3056 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3060 m_webView->enableFixedLayoutMode(true); | 3057 webViewHelper.initializeAndLoad(m_baseURL + htmlFile, true, 0, &client); |
| 3061 m_webView->settings()->setViewportEnabled(true); | 3058 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 3062 m_webView->resize(WebSize(1000, 1000)); | 3059 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 3063 m_webView->layout(); | 3060 webViewHelper.webView()->resize(WebSize(1000, 1000)); |
| 3061 webViewHelper.webView()->layout(); |
| 3064 | 3062 |
| 3065 client.resetTriggered(); | 3063 client.resetTriggered(); |
| 3066 m_webView->handleInputEvent(fatTap(0, 0)); | 3064 webViewHelper.webView()->handleInputEvent(fatTap(0, 0)); |
| 3067 EXPECT_FALSE(client.triggered()); | 3065 EXPECT_FALSE(client.triggered()); |
| 3068 | 3066 |
| 3069 client.resetTriggered(); | 3067 client.resetTriggered(); |
| 3070 m_webView->handleInputEvent(fatTap(200, 115)); | 3068 webViewHelper.webView()->handleInputEvent(fatTap(200, 115)); |
| 3071 EXPECT_FALSE(client.triggered()); | 3069 EXPECT_FALSE(client.triggered()); |
| 3072 | 3070 |
| 3073 for (int i = 0; i <= 46; i++) { | 3071 for (int i = 0; i <= 46; i++) { |
| 3074 client.resetTriggered(); | 3072 client.resetTriggered(); |
| 3075 m_webView->handleInputEvent(fatTap(120, 230 + i * 5)); | 3073 webViewHelper.webView()->handleInputEvent(fatTap(120, 230 + i * 5)); |
| 3076 EXPECT_FALSE(client.triggered()); | 3074 EXPECT_FALSE(client.triggered()); |
| 3077 } | 3075 } |
| 3078 | 3076 |
| 3079 for (int i = 0; i <= 46; i++) { | 3077 for (int i = 0; i <= 46; i++) { |
| 3080 client.resetTriggered(); | 3078 client.resetTriggered(); |
| 3081 m_webView->handleInputEvent(fatTap(10 + i * 5, 590)); | 3079 webViewHelper.webView()->handleInputEvent(fatTap(10 + i * 5, 590)); |
| 3082 EXPECT_FALSE(client.triggered()); | 3080 EXPECT_FALSE(client.triggered()); |
| 3083 } | 3081 } |
| 3084 | |
| 3085 m_webView->close(); | |
| 3086 m_webView = 0; | |
| 3087 } | 3082 } |
| 3088 | 3083 |
| 3089 TEST_F(WebFrameTest, DisambiguationPopupViewportSite) | 3084 TEST_F(WebFrameTest, DisambiguationPopupViewportSite) |
| 3090 { | 3085 { |
| 3091 const std::string htmlFile = "disambiguation_popup_viewport_site.html"; | 3086 const std::string htmlFile = "disambiguation_popup_viewport_site.html"; |
| 3092 registerMockedHttpURLLoad(htmlFile); | 3087 registerMockedHttpURLLoad(htmlFile); |
| 3093 | 3088 |
| 3094 DisambiguationPopupTestWebViewClient client; | 3089 DisambiguationPopupTestWebViewClient client; |
| 3095 | 3090 |
| 3096 // Make sure we initialize to minimum scale, even if the window size | 3091 // Make sure we initialize to minimum scale, even if the window size |
| 3097 // only becomes available after the load begins. | 3092 // only becomes available after the load begins. |
| 3098 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile, tru
e, 0, &client); | 3093 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3099 m_webView->enableFixedLayoutMode(true); | 3094 webViewHelper.initializeAndLoad(m_baseURL + htmlFile, true, 0, &client); |
| 3100 m_webView->settings()->setViewportEnabled(true); | 3095 webViewHelper.webView()->enableFixedLayoutMode(true); |
| 3101 m_webView->resize(WebSize(1000, 1000)); | 3096 webViewHelper.webView()->settings()->setViewportEnabled(true); |
| 3102 m_webView->layout(); | 3097 webViewHelper.webView()->resize(WebSize(1000, 1000)); |
| 3098 webViewHelper.webView()->layout(); |
| 3103 | 3099 |
| 3104 client.resetTriggered(); | 3100 client.resetTriggered(); |
| 3105 m_webView->handleInputEvent(fatTap(0, 0)); | 3101 webViewHelper.webView()->handleInputEvent(fatTap(0, 0)); |
| 3106 EXPECT_FALSE(client.triggered()); | 3102 EXPECT_FALSE(client.triggered()); |
| 3107 | 3103 |
| 3108 client.resetTriggered(); | 3104 client.resetTriggered(); |
| 3109 m_webView->handleInputEvent(fatTap(200, 115)); | 3105 webViewHelper.webView()->handleInputEvent(fatTap(200, 115)); |
| 3110 EXPECT_FALSE(client.triggered()); | 3106 EXPECT_FALSE(client.triggered()); |
| 3111 | 3107 |
| 3112 for (int i = 0; i <= 46; i++) { | 3108 for (int i = 0; i <= 46; i++) { |
| 3113 client.resetTriggered(); | 3109 client.resetTriggered(); |
| 3114 m_webView->handleInputEvent(fatTap(120, 230 + i * 5)); | 3110 webViewHelper.webView()->handleInputEvent(fatTap(120, 230 + i * 5)); |
| 3115 EXPECT_FALSE(client.triggered()); | 3111 EXPECT_FALSE(client.triggered()); |
| 3116 } | 3112 } |
| 3117 | 3113 |
| 3118 for (int i = 0; i <= 46; i++) { | 3114 for (int i = 0; i <= 46; i++) { |
| 3119 client.resetTriggered(); | 3115 client.resetTriggered(); |
| 3120 m_webView->handleInputEvent(fatTap(10 + i * 5, 590)); | 3116 webViewHelper.webView()->handleInputEvent(fatTap(10 + i * 5, 590)); |
| 3121 EXPECT_FALSE(client.triggered()); | 3117 EXPECT_FALSE(client.triggered()); |
| 3122 } | 3118 } |
| 3123 | |
| 3124 m_webView->close(); | |
| 3125 m_webView = 0; | |
| 3126 } | 3119 } |
| 3127 | 3120 |
| 3128 TEST_F(WebFrameTest, DisambiguationPopupBlacklist) | 3121 TEST_F(WebFrameTest, DisambiguationPopupBlacklist) |
| 3129 { | 3122 { |
| 3130 const unsigned viewportWidth = 500; | 3123 const unsigned viewportWidth = 500; |
| 3131 const unsigned viewportHeight = 1000; | 3124 const unsigned viewportHeight = 1000; |
| 3132 const unsigned divHeight = 100; | 3125 const unsigned divHeight = 100; |
| 3133 const std::string htmlFile = "disambiguation_popup_blacklist.html"; | 3126 const std::string htmlFile = "disambiguation_popup_blacklist.html"; |
| 3134 registerMockedHttpURLLoad(htmlFile); | 3127 registerMockedHttpURLLoad(htmlFile); |
| 3135 | 3128 |
| 3136 DisambiguationPopupTestWebViewClient client; | 3129 DisambiguationPopupTestWebViewClient client; |
| 3137 | 3130 |
| 3138 // Make sure we initialize to minimum scale, even if the window size | 3131 // Make sure we initialize to minimum scale, even if the window size |
| 3139 // only becomes available after the load begins. | 3132 // only becomes available after the load begins. |
| 3140 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFile, tru
e, 0, &client); | 3133 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3141 m_webView->resize(WebSize(viewportWidth, viewportHeight)); | 3134 webViewHelper.initializeAndLoad(m_baseURL + htmlFile, true, 0, &client); |
| 3142 m_webView->layout(); | 3135 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
| 3136 webViewHelper.webView()->layout(); |
| 3143 | 3137 |
| 3144 // Click somewhere where the popup shouldn't appear. | 3138 // Click somewhere where the popup shouldn't appear. |
| 3145 client.resetTriggered(); | 3139 client.resetTriggered(); |
| 3146 m_webView->handleInputEvent(fatTap(viewportWidth / 2, 0)); | 3140 webViewHelper.webView()->handleInputEvent(fatTap(viewportWidth / 2, 0)); |
| 3147 EXPECT_FALSE(client.triggered()); | 3141 EXPECT_FALSE(client.triggered()); |
| 3148 | 3142 |
| 3149 // Click directly in between two container divs with click handlers, with ch
ildren that don't handle clicks. | 3143 // Click directly in between two container divs with click handlers, with ch
ildren that don't handle clicks. |
| 3150 client.resetTriggered(); | 3144 client.resetTriggered(); |
| 3151 m_webView->handleInputEvent(fatTap(viewportWidth / 2, divHeight)); | 3145 webViewHelper.webView()->handleInputEvent(fatTap(viewportWidth / 2, divHeigh
t)); |
| 3152 EXPECT_TRUE(client.triggered()); | 3146 EXPECT_TRUE(client.triggered()); |
| 3153 | 3147 |
| 3154 // The third div container should be blacklisted if you click on the link it
contains. | 3148 // The third div container should be blacklisted if you click on the link it
contains. |
| 3155 client.resetTriggered(); | 3149 client.resetTriggered(); |
| 3156 m_webView->handleInputEvent(fatTap(viewportWidth / 2, divHeight * 3.25)); | 3150 webViewHelper.webView()->handleInputEvent(fatTap(viewportWidth / 2, divHeigh
t * 3.25)); |
| 3157 EXPECT_FALSE(client.triggered()); | 3151 EXPECT_FALSE(client.triggered()); |
| 3158 | |
| 3159 m_webView->close(); | |
| 3160 m_webView = 0; | |
| 3161 } | 3152 } |
| 3162 | 3153 |
| 3163 TEST_F(WebFrameTest, DisambiguationPopupPageScale) | 3154 TEST_F(WebFrameTest, DisambiguationPopupPageScale) |
| 3164 { | 3155 { |
| 3165 registerMockedHttpURLLoad("disambiguation_popup_page_scale.html"); | 3156 registerMockedHttpURLLoad("disambiguation_popup_page_scale.html"); |
| 3166 | 3157 |
| 3167 DisambiguationPopupTestWebViewClient client; | 3158 DisambiguationPopupTestWebViewClient client; |
| 3168 | 3159 |
| 3169 // Make sure we initialize to minimum scale, even if the window size | 3160 // Make sure we initialize to minimum scale, even if the window size |
| 3170 // only becomes available after the load begins. | 3161 // only becomes available after the load begins. |
| 3171 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "disambiguati
on_popup_page_scale.html", true, 0, &client); | 3162 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3172 m_webView->resize(WebSize(1000, 1000)); | 3163 webViewHelper.initializeAndLoad(m_baseURL + "disambiguation_popup_page_scale
.html", true, 0, &client); |
| 3173 m_webView->layout(); | 3164 webViewHelper.webView()->resize(WebSize(1000, 1000)); |
| 3165 webViewHelper.webView()->layout(); |
| 3174 | 3166 |
| 3175 client.resetTriggered(); | 3167 client.resetTriggered(); |
| 3176 m_webView->handleInputEvent(fatTap(80, 80)); | 3168 webViewHelper.webView()->handleInputEvent(fatTap(80, 80)); |
| 3177 EXPECT_TRUE(client.triggered()); | 3169 EXPECT_TRUE(client.triggered()); |
| 3178 | 3170 |
| 3179 client.resetTriggered(); | 3171 client.resetTriggered(); |
| 3180 m_webView->handleInputEvent(fatTap(230, 190)); | 3172 webViewHelper.webView()->handleInputEvent(fatTap(230, 190)); |
| 3181 EXPECT_TRUE(client.triggered()); | 3173 EXPECT_TRUE(client.triggered()); |
| 3182 | 3174 |
| 3183 m_webView->setPageScaleFactor(3.0f, WebPoint(0, 0)); | 3175 webViewHelper.webView()->setPageScaleFactor(3.0f, WebPoint(0, 0)); |
| 3184 m_webView->layout(); | 3176 webViewHelper.webView()->layout(); |
| 3185 | 3177 |
| 3186 client.resetTriggered(); | 3178 client.resetTriggered(); |
| 3187 m_webView->handleInputEvent(fatTap(240, 240)); | 3179 webViewHelper.webView()->handleInputEvent(fatTap(240, 240)); |
| 3188 EXPECT_TRUE(client.triggered()); | 3180 EXPECT_TRUE(client.triggered()); |
| 3189 | 3181 |
| 3190 client.resetTriggered(); | 3182 client.resetTriggered(); |
| 3191 m_webView->handleInputEvent(fatTap(690, 570)); | 3183 webViewHelper.webView()->handleInputEvent(fatTap(690, 570)); |
| 3192 EXPECT_FALSE(client.triggered()); | 3184 EXPECT_FALSE(client.triggered()); |
| 3193 | |
| 3194 m_webView->close(); | |
| 3195 m_webView = 0; | |
| 3196 } | 3185 } |
| 3197 | 3186 |
| 3198 class TestSubstituteDataWebFrameClient : public WebFrameClient { | 3187 class TestSubstituteDataWebFrameClient : public WebFrameClient { |
| 3199 public: | 3188 public: |
| 3200 TestSubstituteDataWebFrameClient() | 3189 TestSubstituteDataWebFrameClient() |
| 3201 : m_commitCalled(false) | 3190 : m_commitCalled(false) |
| 3202 { | 3191 { |
| 3203 } | 3192 } |
| 3204 | 3193 |
| 3205 virtual void didFailProvisionalLoad(WebFrame* frame, const WebURLError& erro
r) | 3194 virtual void didFailProvisionalLoad(WebFrame* frame, const WebURLError& erro
r) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3217 bool commitCalled() const { return m_commitCalled; } | 3206 bool commitCalled() const { return m_commitCalled; } |
| 3218 | 3207 |
| 3219 private: | 3208 private: |
| 3220 bool m_commitCalled; | 3209 bool m_commitCalled; |
| 3221 }; | 3210 }; |
| 3222 | 3211 |
| 3223 TEST_F(WebFrameTest, ReplaceNavigationAfterHistoryNavigation) | 3212 TEST_F(WebFrameTest, ReplaceNavigationAfterHistoryNavigation) |
| 3224 { | 3213 { |
| 3225 TestSubstituteDataWebFrameClient webFrameClient; | 3214 TestSubstituteDataWebFrameClient webFrameClient; |
| 3226 | 3215 |
| 3227 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true, &web
FrameClient); | 3216 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3217 webViewHelper.initializeAndLoad("about:blank", true, &webFrameClient); |
| 3228 runPendingTasks(); | 3218 runPendingTasks(); |
| 3229 WebFrame* frame = m_webView->mainFrame(); | 3219 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 3230 | 3220 |
| 3231 // Load a url as a history navigation that will return an error. TestSubstit
uteDataWebFrameClient | 3221 // Load a url as a history navigation that will return an error. TestSubstit
uteDataWebFrameClient |
| 3232 // will start a SubstituteData load in response to the load failure, which s
hould get fully committed. | 3222 // will start a SubstituteData load in response to the load failure, which s
hould get fully committed. |
| 3233 // Due to https://bugs.webkit.org/show_bug.cgi?id=91685, FrameLoader::didRec
eiveData() wasn't getting | 3223 // Due to https://bugs.webkit.org/show_bug.cgi?id=91685, FrameLoader::didRec
eiveData() wasn't getting |
| 3234 // called in this case, which resulted in the SubstituteData document not ge
tting displayed. | 3224 // called in this case, which resulted in the SubstituteData document not ge
tting displayed. |
| 3235 WebURLError error; | 3225 WebURLError error; |
| 3236 error.reason = 1337; | 3226 error.reason = 1337; |
| 3237 error.domain = "WebFrameTest"; | 3227 error.domain = "WebFrameTest"; |
| 3238 std::string errorURL = "http://0.0.0.0"; | 3228 std::string errorURL = "http://0.0.0.0"; |
| 3239 WebURLResponse response; | 3229 WebURLResponse response; |
| 3240 response.initialize(); | 3230 response.initialize(); |
| 3241 response.setURL(URLTestHelpers::toKURL(errorURL)); | 3231 response.setURL(URLTestHelpers::toKURL(errorURL)); |
| 3242 response.setMIMEType("text/html"); | 3232 response.setMIMEType("text/html"); |
| 3243 response.setHTTPStatusCode(500); | 3233 response.setHTTPStatusCode(500); |
| 3244 WebHistoryItem errorHistoryItem; | 3234 WebHistoryItem errorHistoryItem; |
| 3245 errorHistoryItem.initialize(); | 3235 errorHistoryItem.initialize(); |
| 3246 errorHistoryItem.setURLString(WebString::fromUTF8(errorURL.c_str(), errorURL
.length())); | 3236 errorHistoryItem.setURLString(WebString::fromUTF8(errorURL.c_str(), errorURL
.length())); |
| 3247 errorHistoryItem.setOriginalURLString(WebString::fromUTF8(errorURL.c_str(),
errorURL.length())); | 3237 errorHistoryItem.setOriginalURLString(WebString::fromUTF8(errorURL.c_str(),
errorURL.length())); |
| 3248 Platform::current()->unitTestSupport()->registerMockedErrorURL(URLTestHelper
s::toKURL(errorURL), response, error); | 3238 Platform::current()->unitTestSupport()->registerMockedErrorURL(URLTestHelper
s::toKURL(errorURL), response, error); |
| 3249 frame->loadHistoryItem(errorHistoryItem); | 3239 frame->loadHistoryItem(errorHistoryItem); |
| 3250 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 3240 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 3251 | 3241 |
| 3252 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); | 3242 WebString text = frame->contentAsText(std::numeric_limits<size_t>::max()); |
| 3253 EXPECT_EQ("This should appear", std::string(text.utf8().data())); | 3243 EXPECT_EQ("This should appear", std::string(text.utf8().data())); |
| 3254 EXPECT_TRUE(webFrameClient.commitCalled()); | 3244 EXPECT_TRUE(webFrameClient.commitCalled()); |
| 3255 | |
| 3256 m_webView->close(); | |
| 3257 m_webView = 0; | |
| 3258 } | 3245 } |
| 3259 | 3246 |
| 3260 class TestWillInsertBodyWebFrameClient : public WebFrameClient { | 3247 class TestWillInsertBodyWebFrameClient : public WebFrameClient { |
| 3261 public: | 3248 public: |
| 3262 TestWillInsertBodyWebFrameClient() : m_numBodies(0), m_didLoad(false) | 3249 TestWillInsertBodyWebFrameClient() : m_numBodies(0), m_didLoad(false) |
| 3263 { | 3250 { |
| 3264 } | 3251 } |
| 3265 | 3252 |
| 3266 virtual void didCommitProvisionalLoad(WebFrame*, bool) OVERRIDE | 3253 virtual void didCommitProvisionalLoad(WebFrame*, bool) OVERRIDE |
| 3267 { | 3254 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3281 | 3268 |
| 3282 int m_numBodies; | 3269 int m_numBodies; |
| 3283 bool m_didLoad; | 3270 bool m_didLoad; |
| 3284 }; | 3271 }; |
| 3285 | 3272 |
| 3286 TEST_F(WebFrameTest, HTMLDocument) | 3273 TEST_F(WebFrameTest, HTMLDocument) |
| 3287 { | 3274 { |
| 3288 registerMockedHttpURLLoad("clipped-body.html"); | 3275 registerMockedHttpURLLoad("clipped-body.html"); |
| 3289 | 3276 |
| 3290 TestWillInsertBodyWebFrameClient webFrameClient; | 3277 TestWillInsertBodyWebFrameClient webFrameClient; |
| 3291 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "clipped-body
.html", false, &webFrameClient); | 3278 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3279 webViewHelper.initializeAndLoad(m_baseURL + "clipped-body.html", false, &web
FrameClient); |
| 3292 | 3280 |
| 3293 EXPECT_TRUE(webFrameClient.m_didLoad); | 3281 EXPECT_TRUE(webFrameClient.m_didLoad); |
| 3294 EXPECT_EQ(1, webFrameClient.m_numBodies); | 3282 EXPECT_EQ(1, webFrameClient.m_numBodies); |
| 3295 | |
| 3296 m_webView->close(); | |
| 3297 m_webView = 0; | |
| 3298 } | 3283 } |
| 3299 | 3284 |
| 3300 TEST_F(WebFrameTest, EmptyDocument) | 3285 TEST_F(WebFrameTest, EmptyDocument) |
| 3301 { | 3286 { |
| 3302 registerMockedHttpURLLoad("pageserializer/green_rectangle.svg"); | 3287 registerMockedHttpURLLoad("pageserializer/green_rectangle.svg"); |
| 3303 | 3288 |
| 3304 TestWillInsertBodyWebFrameClient webFrameClient; | 3289 TestWillInsertBodyWebFrameClient webFrameClient; |
| 3305 m_webView = FrameTestHelpers::createWebView(false, &webFrameClient); | 3290 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3291 webViewHelper.initialize(false, &webFrameClient); |
| 3306 | 3292 |
| 3307 EXPECT_FALSE(webFrameClient.m_didLoad); | 3293 EXPECT_FALSE(webFrameClient.m_didLoad); |
| 3308 EXPECT_EQ(1, webFrameClient.m_numBodies); // The empty document that a new f
rame starts with triggers this. | 3294 EXPECT_EQ(1, webFrameClient.m_numBodies); // The empty document that a new f
rame starts with triggers this. |
| 3309 m_webView->close(); | |
| 3310 m_webView = 0; | |
| 3311 } | 3295 } |
| 3312 | 3296 |
| 3313 TEST_F(WebFrameTest, MoveCaretSelectionTowardsWindowPointWithNoSelection) | 3297 TEST_F(WebFrameTest, MoveCaretSelectionTowardsWindowPointWithNoSelection) |
| 3314 { | 3298 { |
| 3315 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true); | 3299 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3316 WebFrame* frame = m_webView->mainFrame(); | 3300 webViewHelper.initializeAndLoad("about:blank", true); |
| 3301 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 3317 | 3302 |
| 3318 // This test passes if this doesn't crash. | 3303 // This test passes if this doesn't crash. |
| 3319 frame->moveCaretSelectionTowardsWindowPoint(WebPoint(0, 0)); | 3304 frame->moveCaretSelectionTowardsWindowPoint(WebPoint(0, 0)); |
| 3320 } | 3305 } |
| 3321 | 3306 |
| 3322 class SpellCheckClient : public WebSpellCheckClient { | 3307 class SpellCheckClient : public WebSpellCheckClient { |
| 3323 public: | 3308 public: |
| 3324 explicit SpellCheckClient(uint32_t hash = 0) : m_numberOfTimesChecked(0), m_
hash(hash) { } | 3309 explicit SpellCheckClient(uint32_t hash = 0) : m_numberOfTimesChecked(0), m_
hash(hash) { } |
| 3325 virtual ~SpellCheckClient() { } | 3310 virtual ~SpellCheckClient() { } |
| 3326 virtual void requestCheckingOfText(const WebKit::WebString&, const WebKit::W
ebVector<uint32_t>&, const WebKit::WebVector<unsigned>&, WebKit::WebTextChecking
Completion* completion) OVERRIDE | 3311 virtual void requestCheckingOfText(const WebKit::WebString&, const WebKit::W
ebVector<uint32_t>&, const WebKit::WebVector<unsigned>&, WebKit::WebTextChecking
Completion* completion) OVERRIDE |
| 3327 { | 3312 { |
| 3328 ++m_numberOfTimesChecked; | 3313 ++m_numberOfTimesChecked; |
| 3329 Vector<WebTextCheckingResult> results; | 3314 Vector<WebTextCheckingResult> results; |
| 3330 const int misspellingStartOffset = 1; | 3315 const int misspellingStartOffset = 1; |
| 3331 const int misspellingLength = 8; | 3316 const int misspellingLength = 8; |
| 3332 results.append(WebTextCheckingResult(WebTextCheckingTypeSpelling, misspe
llingStartOffset, misspellingLength, WebString(), m_hash)); | 3317 results.append(WebTextCheckingResult(WebTextCheckingTypeSpelling, misspe
llingStartOffset, misspellingLength, WebString(), m_hash)); |
| 3333 completion->didFinishCheckingText(results); | 3318 completion->didFinishCheckingText(results); |
| 3334 } | 3319 } |
| 3335 int numberOfTimesChecked() const { return m_numberOfTimesChecked; } | 3320 int numberOfTimesChecked() const { return m_numberOfTimesChecked; } |
| 3336 private: | 3321 private: |
| 3337 int m_numberOfTimesChecked; | 3322 int m_numberOfTimesChecked; |
| 3338 uint32_t m_hash; | 3323 uint32_t m_hash; |
| 3339 }; | 3324 }; |
| 3340 | 3325 |
| 3341 TEST_F(WebFrameTest, ReplaceMisspelledRange) | 3326 TEST_F(WebFrameTest, ReplaceMisspelledRange) |
| 3342 { | 3327 { |
| 3343 registerMockedHttpURLLoad("spell.html"); | 3328 registerMockedHttpURLLoad("spell.html"); |
| 3344 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html")
; | 3329 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3330 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
| 3345 SpellCheckClient spellcheck; | 3331 SpellCheckClient spellcheck; |
| 3346 m_webView->setSpellCheckClient(&spellcheck); | 3332 webViewHelper.webView()->setSpellCheckClient(&spellcheck); |
| 3347 | 3333 |
| 3348 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); | 3334 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame()); |
| 3349 Document* document = frame->frame()->document(); | 3335 Document* document = frame->frame()->document(); |
| 3350 Element* element = document->getElementById("data"); | 3336 Element* element = document->getElementById("data"); |
| 3351 | 3337 |
| 3352 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); | 3338 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru
e); |
| 3353 m_webView->settings()->setUnifiedTextCheckerEnabled(true); | 3339 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); |
| 3354 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); | 3340 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing
BehaviorWin); |
| 3355 | 3341 |
| 3356 element->focus(); | 3342 element->focus(); |
| 3357 document->execCommand("InsertText", false, "_wellcome_."); | 3343 document->execCommand("InsertText", false, "_wellcome_."); |
| 3358 | 3344 |
| 3359 const int allTextBeginOffset = 0; | 3345 const int allTextBeginOffset = 0; |
| 3360 const int allTextLength = 11; | 3346 const int allTextLength = 11; |
| 3361 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al
lTextLength)); | 3347 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al
lTextLength)); |
| 3362 RefPtr<Range> selectionRange = frame->frame()->selection().toNormalizedRange
(); | 3348 RefPtr<Range> selectionRange = frame->frame()->selection().toNormalizedRange
(); |
| 3363 | 3349 |
| 3364 EXPECT_EQ(1, spellcheck.numberOfTimesChecked()); | 3350 EXPECT_EQ(1, spellcheck.numberOfTimesChecked()); |
| 3365 EXPECT_EQ(1U, document->markers()->markersInRange(selectionRange.get(), Docu
mentMarker::Spelling).size()); | 3351 EXPECT_EQ(1U, document->markers()->markersInRange(selectionRange.get(), Docu
mentMarker::Spelling).size()); |
| 3366 | 3352 |
| 3367 frame->replaceMisspelledRange("welcome"); | 3353 frame->replaceMisspelledRange("welcome"); |
| 3368 EXPECT_EQ("_welcome_.", std::string(frame->contentAsText(std::numeric_limits
<size_t>::max()).utf8().data())); | 3354 EXPECT_EQ("_welcome_.", std::string(frame->contentAsText(std::numeric_limits
<size_t>::max()).utf8().data())); |
| 3369 | |
| 3370 m_webView->close(); | |
| 3371 m_webView = 0; | |
| 3372 } | 3355 } |
| 3373 | 3356 |
| 3374 TEST_F(WebFrameTest, RemoveSpellingMarkers) | 3357 TEST_F(WebFrameTest, RemoveSpellingMarkers) |
| 3375 { | 3358 { |
| 3376 registerMockedHttpURLLoad("spell.html"); | 3359 registerMockedHttpURLLoad("spell.html"); |
| 3377 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html")
; | 3360 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3361 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
| 3378 SpellCheckClient spellcheck; | 3362 SpellCheckClient spellcheck; |
| 3379 m_webView->setSpellCheckClient(&spellcheck); | 3363 webViewHelper.webView()->setSpellCheckClient(&spellcheck); |
| 3380 | 3364 |
| 3381 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); | 3365 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame()); |
| 3382 Document* document = frame->frame()->document(); | 3366 Document* document = frame->frame()->document(); |
| 3383 Element* element = document->getElementById("data"); | 3367 Element* element = document->getElementById("data"); |
| 3384 | 3368 |
| 3385 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); | 3369 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru
e); |
| 3386 m_webView->settings()->setUnifiedTextCheckerEnabled(true); | 3370 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); |
| 3387 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); | 3371 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing
BehaviorWin); |
| 3388 | 3372 |
| 3389 element->focus(); | 3373 element->focus(); |
| 3390 document->execCommand("InsertText", false, "_wellcome_."); | 3374 document->execCommand("InsertText", false, "_wellcome_."); |
| 3391 | 3375 |
| 3392 frame->removeSpellingMarkers(); | 3376 frame->removeSpellingMarkers(); |
| 3393 | 3377 |
| 3394 const int allTextBeginOffset = 0; | 3378 const int allTextBeginOffset = 0; |
| 3395 const int allTextLength = 11; | 3379 const int allTextLength = 11; |
| 3396 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al
lTextLength)); | 3380 frame->selectRange(WebRange::fromDocumentRange(frame, allTextBeginOffset, al
lTextLength)); |
| 3397 RefPtr<Range> selectionRange = frame->frame()->selection().toNormalizedRange
(); | 3381 RefPtr<Range> selectionRange = frame->frame()->selection().toNormalizedRange
(); |
| 3398 | 3382 |
| 3399 EXPECT_EQ(0U, document->markers()->markersInRange(selectionRange.get(), Docu
mentMarker::Spelling).size()); | 3383 EXPECT_EQ(0U, document->markers()->markersInRange(selectionRange.get(), Docu
mentMarker::Spelling).size()); |
| 3400 | |
| 3401 m_webView->close(); | |
| 3402 m_webView = 0; | |
| 3403 } | 3384 } |
| 3404 | 3385 |
| 3405 TEST_F(WebFrameTest, MarkerHashIdentifiers) { | 3386 TEST_F(WebFrameTest, MarkerHashIdentifiers) { |
| 3406 registerMockedHttpURLLoad("spell.html"); | 3387 registerMockedHttpURLLoad("spell.html"); |
| 3407 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html")
; | 3388 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3389 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
| 3408 | 3390 |
| 3409 static const uint32_t kHash = 42; | 3391 static const uint32_t kHash = 42; |
| 3410 SpellCheckClient spellcheck(kHash); | 3392 SpellCheckClient spellcheck(kHash); |
| 3411 m_webView->setSpellCheckClient(&spellcheck); | 3393 webViewHelper.webView()->setSpellCheckClient(&spellcheck); |
| 3412 | 3394 |
| 3413 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); | 3395 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame()); |
| 3414 Document* document = frame->frame()->document(); | 3396 Document* document = frame->frame()->document(); |
| 3415 Element* element = document->getElementById("data"); | 3397 Element* element = document->getElementById("data"); |
| 3416 | 3398 |
| 3417 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); | 3399 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru
e); |
| 3418 m_webView->settings()->setUnifiedTextCheckerEnabled(true); | 3400 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); |
| 3419 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); | 3401 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing
BehaviorWin); |
| 3420 | 3402 |
| 3421 element->focus(); | 3403 element->focus(); |
| 3422 document->execCommand("InsertText", false, "wellcome."); | 3404 document->execCommand("InsertText", false, "wellcome."); |
| 3423 | 3405 |
| 3424 WebVector<uint32_t> documentMarkers; | 3406 WebVector<uint32_t> documentMarkers; |
| 3425 m_webView->spellingMarkers(&documentMarkers); | 3407 webViewHelper.webView()->spellingMarkers(&documentMarkers); |
| 3426 EXPECT_EQ(1U, documentMarkers.size()); | 3408 EXPECT_EQ(1U, documentMarkers.size()); |
| 3427 EXPECT_EQ(kHash, documentMarkers[0]); | 3409 EXPECT_EQ(kHash, documentMarkers[0]); |
| 3428 | |
| 3429 m_webView->close(); | |
| 3430 m_webView = 0; | |
| 3431 } | 3410 } |
| 3432 | 3411 |
| 3433 class StubbornSpellCheckClient : public WebSpellCheckClient { | 3412 class StubbornSpellCheckClient : public WebSpellCheckClient { |
| 3434 public: | 3413 public: |
| 3435 StubbornSpellCheckClient() : m_completion(0) { } | 3414 StubbornSpellCheckClient() : m_completion(0) { } |
| 3436 virtual ~StubbornSpellCheckClient() { } | 3415 virtual ~StubbornSpellCheckClient() { } |
| 3437 | 3416 |
| 3438 virtual void requestCheckingOfText( | 3417 virtual void requestCheckingOfText( |
| 3439 const WebKit::WebString&, | 3418 const WebKit::WebString&, |
| 3440 const WebKit::WebVector<uint32_t>&, | 3419 const WebKit::WebVector<uint32_t>&, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3456 m_completion = 0; | 3435 m_completion = 0; |
| 3457 } | 3436 } |
| 3458 | 3437 |
| 3459 private: | 3438 private: |
| 3460 WebKit::WebTextCheckingCompletion* m_completion; | 3439 WebKit::WebTextCheckingCompletion* m_completion; |
| 3461 }; | 3440 }; |
| 3462 | 3441 |
| 3463 TEST_F(WebFrameTest, SlowSpellcheckMarkerPosition) | 3442 TEST_F(WebFrameTest, SlowSpellcheckMarkerPosition) |
| 3464 { | 3443 { |
| 3465 registerMockedHttpURLLoad("spell.html"); | 3444 registerMockedHttpURLLoad("spell.html"); |
| 3466 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html")
; | 3445 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3446 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
| 3467 | 3447 |
| 3468 StubbornSpellCheckClient spellcheck; | 3448 StubbornSpellCheckClient spellcheck; |
| 3469 m_webView->setSpellCheckClient(&spellcheck); | 3449 webViewHelper.webView()->setSpellCheckClient(&spellcheck); |
| 3470 | 3450 |
| 3471 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); | 3451 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame()); |
| 3472 WebInputElement webInputElement = frame->document().getElementById("data").t
o<WebInputElement>(); | 3452 WebInputElement webInputElement = frame->document().getElementById("data").t
o<WebInputElement>(); |
| 3473 Document* document = frame->frame()->document(); | 3453 Document* document = frame->frame()->document(); |
| 3474 Element* element = document->getElementById("data"); | 3454 Element* element = document->getElementById("data"); |
| 3475 | 3455 |
| 3476 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); | 3456 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru
e); |
| 3477 m_webView->settings()->setUnifiedTextCheckerEnabled(true); | 3457 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); |
| 3478 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); | 3458 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing
BehaviorWin); |
| 3479 | 3459 |
| 3480 element->focus(); | 3460 element->focus(); |
| 3481 document->execCommand("InsertText", false, "wellcome "); | 3461 document->execCommand("InsertText", false, "wellcome "); |
| 3482 webInputElement.setSelectionRange(0, 0); | 3462 webInputElement.setSelectionRange(0, 0); |
| 3483 document->execCommand("InsertText", false, "he"); | 3463 document->execCommand("InsertText", false, "he"); |
| 3484 | 3464 |
| 3485 spellcheck.kick(); | 3465 spellcheck.kick(); |
| 3486 | 3466 |
| 3487 WebVector<uint32_t> documentMarkers; | 3467 WebVector<uint32_t> documentMarkers; |
| 3488 m_webView->spellingMarkers(&documentMarkers); | 3468 webViewHelper.webView()->spellingMarkers(&documentMarkers); |
| 3489 EXPECT_EQ(0U, documentMarkers.size()); | 3469 EXPECT_EQ(0U, documentMarkers.size()); |
| 3490 | |
| 3491 m_webView->close(); | |
| 3492 m_webView = 0; | |
| 3493 } | 3470 } |
| 3494 | 3471 |
| 3495 // This test verifies that cancelling spelling request does not cause a | 3472 // This test verifies that cancelling spelling request does not cause a |
| 3496 // write-after-free when there's no spellcheck client set. | 3473 // write-after-free when there's no spellcheck client set. |
| 3497 TEST_F(WebFrameTest, CancelSpellingRequestCrash) | 3474 TEST_F(WebFrameTest, CancelSpellingRequestCrash) |
| 3498 { | 3475 { |
| 3499 registerMockedHttpURLLoad("spell.html"); | 3476 registerMockedHttpURLLoad("spell.html"); |
| 3500 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "spell.html")
; | 3477 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3501 m_webView->setSpellCheckClient(0); | 3478 webViewHelper.initializeAndLoad(m_baseURL + "spell.html"); |
| 3479 webViewHelper.webView()->setSpellCheckClient(0); |
| 3502 | 3480 |
| 3503 WebFrameImpl* frame = toWebFrameImpl(m_webView->mainFrame()); | 3481 WebFrameImpl* frame = toWebFrameImpl(webViewHelper.webView()->mainFrame()); |
| 3504 Document* document = frame->frame()->document(); | 3482 Document* document = frame->frame()->document(); |
| 3505 Element* element = document->getElementById("data"); | 3483 Element* element = document->getElementById("data"); |
| 3506 | 3484 |
| 3507 m_webView->settings()->setAsynchronousSpellCheckingEnabled(true); | 3485 webViewHelper.webView()->settings()->setAsynchronousSpellCheckingEnabled(tru
e); |
| 3508 m_webView->settings()->setUnifiedTextCheckerEnabled(true); | 3486 webViewHelper.webView()->settings()->setUnifiedTextCheckerEnabled(true); |
| 3509 m_webView->settings()->setEditingBehavior(WebSettings::EditingBehaviorWin); | 3487 webViewHelper.webView()->settings()->setEditingBehavior(WebSettings::Editing
BehaviorWin); |
| 3510 | 3488 |
| 3511 element->focus(); | 3489 element->focus(); |
| 3512 frame->frame()->editor().replaceSelectionWithText("A", false, false); | 3490 frame->frame()->editor().replaceSelectionWithText("A", false, false); |
| 3513 frame->frame()->editor().spellCheckRequester().cancelCheck(); | 3491 frame->frame()->editor().spellCheckRequester().cancelCheck(); |
| 3514 | |
| 3515 m_webView->close(); | |
| 3516 m_webView = 0; | |
| 3517 } | 3492 } |
| 3518 | 3493 |
| 3519 class TestAccessInitialDocumentWebFrameClient : public WebFrameClient { | 3494 class TestAccessInitialDocumentWebFrameClient : public WebFrameClient { |
| 3520 public: | 3495 public: |
| 3521 TestAccessInitialDocumentWebFrameClient() : m_didAccessInitialDocument(false
) | 3496 TestAccessInitialDocumentWebFrameClient() : m_didAccessInitialDocument(false
) |
| 3522 { | 3497 { |
| 3523 } | 3498 } |
| 3524 | 3499 |
| 3525 virtual void didAccessInitialDocument(WebFrame* frame) | 3500 virtual void didAccessInitialDocument(WebFrame* frame) |
| 3526 { | 3501 { |
| 3527 EXPECT_TRUE(!m_didAccessInitialDocument); | 3502 EXPECT_TRUE(!m_didAccessInitialDocument); |
| 3528 m_didAccessInitialDocument = true; | 3503 m_didAccessInitialDocument = true; |
| 3529 } | 3504 } |
| 3530 | 3505 |
| 3531 bool m_didAccessInitialDocument; | 3506 bool m_didAccessInitialDocument; |
| 3532 }; | 3507 }; |
| 3533 | 3508 |
| 3534 TEST_F(WebFrameTest, DidAccessInitialDocumentBody) | 3509 TEST_F(WebFrameTest, DidAccessInitialDocumentBody) |
| 3535 { | 3510 { |
| 3536 TestAccessInitialDocumentWebFrameClient webFrameClient; | 3511 TestAccessInitialDocumentWebFrameClient webFrameClient; |
| 3537 m_webView = FrameTestHelpers::createWebView(true, &webFrameClient); | 3512 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3513 webViewHelper.initialize(true, &webFrameClient); |
| 3538 runPendingTasks(); | 3514 runPendingTasks(); |
| 3539 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); | 3515 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); |
| 3540 | 3516 |
| 3541 // Create another window that will try to access it. | 3517 // Create another window that will try to access it. |
| 3542 WebView* newView = FrameTestHelpers::createWebView(true); | 3518 FrameTestHelpers::WebViewHelper newWebViewHelper; |
| 3543 newView->mainFrame()->setOpener(m_webView->mainFrame()); | 3519 WebView* newView = newWebViewHelper.initialize(true); |
| 3520 newView->mainFrame()->setOpener(webViewHelper.webView()->mainFrame()); |
| 3544 runPendingTasks(); | 3521 runPendingTasks(); |
| 3545 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); | 3522 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); |
| 3546 | 3523 |
| 3547 // Access the initial document by modifying the body. | 3524 // Access the initial document by modifying the body. |
| 3548 newView->mainFrame()->executeScript( | 3525 newView->mainFrame()->executeScript( |
| 3549 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';"))
; | 3526 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';"))
; |
| 3550 runPendingTasks(); | 3527 runPendingTasks(); |
| 3551 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); | 3528 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); |
| 3552 | 3529 |
| 3553 // Access the initial document again, to ensure we don't notify twice. | 3530 // Access the initial document again, to ensure we don't notify twice. |
| 3554 newView->mainFrame()->executeScript( | 3531 newView->mainFrame()->executeScript( |
| 3555 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';"))
; | 3532 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';"))
; |
| 3556 runPendingTasks(); | 3533 runPendingTasks(); |
| 3557 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); | 3534 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); |
| 3558 | |
| 3559 newView->close(); | |
| 3560 m_webView->close(); | |
| 3561 m_webView = 0; | |
| 3562 } | 3535 } |
| 3563 | 3536 |
| 3564 TEST_F(WebFrameTest, DidAccessInitialDocumentNavigator) | 3537 TEST_F(WebFrameTest, DidAccessInitialDocumentNavigator) |
| 3565 { | 3538 { |
| 3566 TestAccessInitialDocumentWebFrameClient webFrameClient; | 3539 TestAccessInitialDocumentWebFrameClient webFrameClient; |
| 3567 m_webView = FrameTestHelpers::createWebView(true, &webFrameClient); | 3540 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3541 webViewHelper.initialize(true, &webFrameClient); |
| 3568 runPendingTasks(); | 3542 runPendingTasks(); |
| 3569 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); | 3543 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); |
| 3570 | 3544 |
| 3571 // Create another window that will try to access it. | 3545 // Create another window that will try to access it. |
| 3572 WebView* newView = FrameTestHelpers::createWebView(true); | 3546 FrameTestHelpers::WebViewHelper newWebViewHelper; |
| 3573 newView->mainFrame()->setOpener(m_webView->mainFrame()); | 3547 WebView* newView = newWebViewHelper.initialize(true); |
| 3548 newView->mainFrame()->setOpener(webViewHelper.webView()->mainFrame()); |
| 3574 runPendingTasks(); | 3549 runPendingTasks(); |
| 3575 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); | 3550 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); |
| 3576 | 3551 |
| 3577 // Access the initial document to get to the navigator object. | 3552 // Access the initial document to get to the navigator object. |
| 3578 newView->mainFrame()->executeScript( | 3553 newView->mainFrame()->executeScript( |
| 3579 WebScriptSource("console.log(window.opener.navigator);")); | 3554 WebScriptSource("console.log(window.opener.navigator);")); |
| 3580 runPendingTasks(); | 3555 runPendingTasks(); |
| 3581 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); | 3556 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); |
| 3582 | |
| 3583 newView->close(); | |
| 3584 m_webView->close(); | |
| 3585 m_webView = 0; | |
| 3586 } | 3557 } |
| 3587 | 3558 |
| 3588 TEST_F(WebFrameTest, DidAccessInitialDocumentViaJavascriptUrl) | 3559 TEST_F(WebFrameTest, DidAccessInitialDocumentViaJavascriptUrl) |
| 3589 { | 3560 { |
| 3590 TestAccessInitialDocumentWebFrameClient webFrameClient; | 3561 TestAccessInitialDocumentWebFrameClient webFrameClient; |
| 3591 m_webView = FrameTestHelpers::createWebView(true, &webFrameClient); | 3562 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3563 webViewHelper.initialize(true, &webFrameClient); |
| 3592 runPendingTasks(); | 3564 runPendingTasks(); |
| 3593 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); | 3565 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); |
| 3594 | 3566 |
| 3595 // Access the initial document from a javascript: URL. | 3567 // Access the initial document from a javascript: URL. |
| 3596 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.bod
y.appendChild(document.createTextNode('Modified'))"); | 3568 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.body.appendChild(document.createTextNode('Modified'))"); |
| 3597 runPendingTasks(); | 3569 runPendingTasks(); |
| 3598 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); | 3570 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); |
| 3599 | |
| 3600 m_webView->close(); | |
| 3601 m_webView = 0; | |
| 3602 } | 3571 } |
| 3603 | 3572 |
| 3604 TEST_F(WebFrameTest, DidAccessInitialDocumentBodyBeforeModalDialog) | 3573 TEST_F(WebFrameTest, DidAccessInitialDocumentBodyBeforeModalDialog) |
| 3605 { | 3574 { |
| 3606 TestAccessInitialDocumentWebFrameClient webFrameClient; | 3575 TestAccessInitialDocumentWebFrameClient webFrameClient; |
| 3607 m_webView = FrameTestHelpers::createWebView(true, &webFrameClient); | 3576 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3577 webViewHelper.initialize(true, &webFrameClient); |
| 3608 runPendingTasks(); | 3578 runPendingTasks(); |
| 3609 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); | 3579 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); |
| 3610 | 3580 |
| 3611 // Create another window that will try to access it. | 3581 // Create another window that will try to access it. |
| 3612 WebView* newView = FrameTestHelpers::createWebView(true); | 3582 FrameTestHelpers::WebViewHelper newWebViewHelper; |
| 3613 newView->mainFrame()->setOpener(m_webView->mainFrame()); | 3583 WebView* newView = newWebViewHelper.initialize(true); |
| 3584 newView->mainFrame()->setOpener(webViewHelper.webView()->mainFrame()); |
| 3614 runPendingTasks(); | 3585 runPendingTasks(); |
| 3615 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); | 3586 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); |
| 3616 | 3587 |
| 3617 // Access the initial document by modifying the body. We normally set a | 3588 // Access the initial document by modifying the body. We normally set a |
| 3618 // timer to notify the client. | 3589 // timer to notify the client. |
| 3619 newView->mainFrame()->executeScript( | 3590 newView->mainFrame()->executeScript( |
| 3620 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';"))
; | 3591 WebScriptSource("window.opener.document.body.innerHTML += 'Modified';"))
; |
| 3621 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); | 3592 EXPECT_FALSE(webFrameClient.m_didAccessInitialDocument); |
| 3622 | 3593 |
| 3623 // Make sure that a modal dialog forces us to notify right away. | 3594 // Make sure that a modal dialog forces us to notify right away. |
| 3624 newView->mainFrame()->executeScript( | 3595 newView->mainFrame()->executeScript( |
| 3625 WebScriptSource("window.opener.confirm('Modal');")); | 3596 WebScriptSource("window.opener.confirm('Modal');")); |
| 3626 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); | 3597 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); |
| 3627 | 3598 |
| 3628 // Ensure that we don't notify again later. | 3599 // Ensure that we don't notify again later. |
| 3629 runPendingTasks(); | 3600 runPendingTasks(); |
| 3630 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); | 3601 EXPECT_TRUE(webFrameClient.m_didAccessInitialDocument); |
| 3631 | |
| 3632 newView->close(); | |
| 3633 m_webView->close(); | |
| 3634 m_webView = 0; | |
| 3635 } | 3602 } |
| 3636 | 3603 |
| 3637 class TestMainFrameUserOrProgrammaticScrollFrameClient : public WebFrameClient { | 3604 class TestMainFrameUserOrProgrammaticScrollFrameClient : public WebFrameClient { |
| 3638 public: | 3605 public: |
| 3639 TestMainFrameUserOrProgrammaticScrollFrameClient() { reset(); } | 3606 TestMainFrameUserOrProgrammaticScrollFrameClient() { reset(); } |
| 3640 void reset() | 3607 void reset() |
| 3641 { | 3608 { |
| 3642 m_didScrollMainFrame = false; | 3609 m_didScrollMainFrame = false; |
| 3643 m_wasProgrammaticScroll = false; | 3610 m_wasProgrammaticScroll = false; |
| 3644 } | 3611 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3665 bool m_wasProgrammaticScroll; | 3632 bool m_wasProgrammaticScroll; |
| 3666 }; | 3633 }; |
| 3667 | 3634 |
| 3668 TEST_F(WebFrameTest, CompositorScrollIsUserScrollLongPage) | 3635 TEST_F(WebFrameTest, CompositorScrollIsUserScrollLongPage) |
| 3669 { | 3636 { |
| 3670 registerMockedHttpURLLoad("long_scroll.html"); | 3637 registerMockedHttpURLLoad("long_scroll.html"); |
| 3671 TestMainFrameUserOrProgrammaticScrollFrameClient client; | 3638 TestMainFrameUserOrProgrammaticScrollFrameClient client; |
| 3672 | 3639 |
| 3673 // Make sure we initialize to minimum scale, even if the window size | 3640 // Make sure we initialize to minimum scale, even if the window size |
| 3674 // only becomes available after the load begins. | 3641 // only becomes available after the load begins. |
| 3675 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "long_scroll.
html", true, &client); | 3642 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3676 m_webView->resize(WebSize(1000, 1000)); | 3643 webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.html", true, &clien
t); |
| 3677 m_webView->layout(); | 3644 webViewHelper.webView()->resize(WebSize(1000, 1000)); |
| 3645 webViewHelper.webView()->layout(); |
| 3678 | 3646 |
| 3679 EXPECT_FALSE(client.wasUserScroll()); | 3647 EXPECT_FALSE(client.wasUserScroll()); |
| 3680 EXPECT_FALSE(client.wasProgrammaticScroll()); | 3648 EXPECT_FALSE(client.wasProgrammaticScroll()); |
| 3681 | 3649 |
| 3682 // Do a compositor scroll, verify that this is counted as a user scroll. | 3650 // Do a compositor scroll, verify that this is counted as a user scroll. |
| 3683 webViewImpl()->applyScrollAndScale(WebSize(0, 1), 1.1f); | 3651 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(0, 1), 1.1f); |
| 3684 EXPECT_TRUE(client.wasUserScroll()); | 3652 EXPECT_TRUE(client.wasUserScroll()); |
| 3685 client.reset(); | 3653 client.reset(); |
| 3686 | 3654 |
| 3687 EXPECT_FALSE(client.wasUserScroll()); | 3655 EXPECT_FALSE(client.wasUserScroll()); |
| 3688 EXPECT_FALSE(client.wasProgrammaticScroll()); | 3656 EXPECT_FALSE(client.wasProgrammaticScroll()); |
| 3689 | 3657 |
| 3690 // The page scale 1.0f and scroll. | 3658 // The page scale 1.0f and scroll. |
| 3691 webViewImpl()->applyScrollAndScale(WebSize(0, 1), 1.0f); | 3659 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(0, 1), 1.0f); |
| 3692 EXPECT_TRUE(client.wasUserScroll()); | 3660 EXPECT_TRUE(client.wasUserScroll()); |
| 3693 client.reset(); | 3661 client.reset(); |
| 3694 | 3662 |
| 3695 // No scroll event if there is no scroll delta. | 3663 // No scroll event if there is no scroll delta. |
| 3696 webViewImpl()->applyScrollAndScale(WebSize(), 1.0f); | 3664 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(), 1.0f); |
| 3697 EXPECT_FALSE(client.wasUserScroll()); | 3665 EXPECT_FALSE(client.wasUserScroll()); |
| 3698 EXPECT_FALSE(client.wasProgrammaticScroll()); | 3666 EXPECT_FALSE(client.wasProgrammaticScroll()); |
| 3699 client.reset(); | 3667 client.reset(); |
| 3700 | 3668 |
| 3701 // Non zero page scale and scroll. | 3669 // Non zero page scale and scroll. |
| 3702 webViewImpl()->applyScrollAndScale(WebSize(9, 13), 0.6f); | 3670 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(9, 13), 0.6f); |
| 3703 EXPECT_TRUE(client.wasUserScroll()); | 3671 EXPECT_TRUE(client.wasUserScroll()); |
| 3704 client.reset(); | 3672 client.reset(); |
| 3705 | 3673 |
| 3706 // Programmatic scroll. | 3674 // Programmatic scroll. |
| 3707 WebFrameImpl* frameImpl = webViewImpl()->mainFrameImpl(); | 3675 WebFrameImpl* frameImpl = webViewHelper.webViewImpl()->mainFrameImpl(); |
| 3708 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);")); | 3676 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);")); |
| 3709 EXPECT_FALSE(client.wasUserScroll()); | 3677 EXPECT_FALSE(client.wasUserScroll()); |
| 3710 EXPECT_TRUE(client.wasProgrammaticScroll()); | 3678 EXPECT_TRUE(client.wasProgrammaticScroll()); |
| 3711 client.reset(); | 3679 client.reset(); |
| 3712 | 3680 |
| 3713 // Programmatic scroll to same offset. No scroll event should be generated. | 3681 // Programmatic scroll to same offset. No scroll event should be generated. |
| 3714 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);")); | 3682 frameImpl->executeScript(WebScriptSource("window.scrollTo(0, 20);")); |
| 3715 EXPECT_FALSE(client.wasProgrammaticScroll()); | 3683 EXPECT_FALSE(client.wasProgrammaticScroll()); |
| 3716 EXPECT_FALSE(client.wasUserScroll()); | 3684 EXPECT_FALSE(client.wasUserScroll()); |
| 3717 client.reset(); | 3685 client.reset(); |
| 3718 | |
| 3719 m_webView->close(); | |
| 3720 m_webView = 0; | |
| 3721 } | 3686 } |
| 3722 | 3687 |
| 3723 TEST_F(WebFrameTest, CompositorScrollIsUserScrollShortPage) | 3688 TEST_F(WebFrameTest, CompositorScrollIsUserScrollShortPage) |
| 3724 { | 3689 { |
| 3725 registerMockedHttpURLLoad("short_scroll.html"); | 3690 registerMockedHttpURLLoad("short_scroll.html"); |
| 3726 | 3691 |
| 3727 TestMainFrameUserOrProgrammaticScrollFrameClient client; | 3692 TestMainFrameUserOrProgrammaticScrollFrameClient client; |
| 3728 | 3693 |
| 3729 // Short page tests. | 3694 // Short page tests. |
| 3730 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "short_scroll
.html", true, &client); | 3695 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3696 webViewHelper.initializeAndLoad(m_baseURL + "short_scroll.html", true, &clie
nt); |
| 3731 | 3697 |
| 3732 m_webView->resize(WebSize(1000, 1000)); | 3698 webViewHelper.webView()->resize(WebSize(1000, 1000)); |
| 3733 m_webView->layout(); | 3699 webViewHelper.webView()->layout(); |
| 3734 | 3700 |
| 3735 EXPECT_FALSE(client.wasUserScroll()); | 3701 EXPECT_FALSE(client.wasUserScroll()); |
| 3736 EXPECT_FALSE(client.wasProgrammaticScroll()); | 3702 EXPECT_FALSE(client.wasProgrammaticScroll()); |
| 3737 | 3703 |
| 3738 // Non zero page scale and scroll. | 3704 // Non zero page scale and scroll. |
| 3739 webViewImpl()->applyScrollAndScale(WebSize(9, 13), 2.0f); | 3705 webViewHelper.webViewImpl()->applyScrollAndScale(WebSize(9, 13), 2.0f); |
| 3740 EXPECT_FALSE(client.wasProgrammaticScroll()); | 3706 EXPECT_FALSE(client.wasProgrammaticScroll()); |
| 3741 EXPECT_TRUE(client.wasUserScroll()); | 3707 EXPECT_TRUE(client.wasUserScroll()); |
| 3742 client.reset(); | 3708 client.reset(); |
| 3743 | |
| 3744 m_webView->close(); | |
| 3745 m_webView = 0; | |
| 3746 } | 3709 } |
| 3747 | 3710 |
| 3748 TEST_F(WebFrameTest, FirstPartyForCookiesForRedirect) | 3711 TEST_F(WebFrameTest, FirstPartyForCookiesForRedirect) |
| 3749 { | 3712 { |
| 3750 WTF::String filePath = Platform::current()->unitTestSupport()->webKitRootDir
(); | 3713 WTF::String filePath = Platform::current()->unitTestSupport()->webKitRootDir
(); |
| 3751 filePath.append("/Source/web/tests/data/first_party.html"); | 3714 filePath.append("/Source/web/tests/data/first_party.html"); |
| 3752 | 3715 |
| 3753 WebURL testURL(toKURL("http://www.test.com/first_party_redirect.html")); | 3716 WebURL testURL(toKURL("http://www.test.com/first_party_redirect.html")); |
| 3754 char redirect[] = "http://www.test.com/first_party.html"; | 3717 char redirect[] = "http://www.test.com/first_party.html"; |
| 3755 WebURL redirectURL(toKURL(redirect)); | 3718 WebURL redirectURL(toKURL(redirect)); |
| 3756 WebURLResponse redirectResponse; | 3719 WebURLResponse redirectResponse; |
| 3757 redirectResponse.initialize(); | 3720 redirectResponse.initialize(); |
| 3758 redirectResponse.setMIMEType("text/html"); | 3721 redirectResponse.setMIMEType("text/html"); |
| 3759 redirectResponse.setHTTPStatusCode(302); | 3722 redirectResponse.setHTTPStatusCode(302); |
| 3760 redirectResponse.setHTTPHeaderField("Location", redirect); | 3723 redirectResponse.setHTTPHeaderField("Location", redirect); |
| 3761 Platform::current()->unitTestSupport()->registerMockedURL(testURL, redirectR
esponse, filePath); | 3724 Platform::current()->unitTestSupport()->registerMockedURL(testURL, redirectR
esponse, filePath); |
| 3762 | 3725 |
| 3763 WebURLResponse finalResponse; | 3726 WebURLResponse finalResponse; |
| 3764 finalResponse.initialize(); | 3727 finalResponse.initialize(); |
| 3765 finalResponse.setMIMEType("text/html"); | 3728 finalResponse.setMIMEType("text/html"); |
| 3766 Platform::current()->unitTestSupport()->registerMockedURL(redirectURL, final
Response, filePath); | 3729 Platform::current()->unitTestSupport()->registerMockedURL(redirectURL, final
Response, filePath); |
| 3767 | 3730 |
| 3768 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "first_party_
redirect.html", true); | 3731 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3769 EXPECT_TRUE(m_webView->mainFrame()->document().firstPartyForCookies() == red
irectURL); | 3732 webViewHelper.initializeAndLoad(m_baseURL + "first_party_redirect.html", tru
e); |
| 3770 | 3733 EXPECT_TRUE(webViewHelper.webView()->mainFrame()->document().firstPartyForCo
okies() == redirectURL); |
| 3771 m_webView->close(); | |
| 3772 m_webView = 0; | |
| 3773 } | 3734 } |
| 3774 | 3735 |
| 3775 class TestNavigationPolicyWebFrameClient : public WebFrameClient { | 3736 class TestNavigationPolicyWebFrameClient : public WebFrameClient { |
| 3776 public: | 3737 public: |
| 3777 | 3738 |
| 3778 virtual void didNavigateWithinPage(WebFrame*, bool) | 3739 virtual void didNavigateWithinPage(WebFrame*, bool) |
| 3779 { | 3740 { |
| 3780 EXPECT_TRUE(false); | 3741 EXPECT_TRUE(false); |
| 3781 } | 3742 } |
| 3782 }; | 3743 }; |
| 3783 | 3744 |
| 3784 TEST_F(WebFrameTest, SimulateFragmentAnchorMiddleClick) | 3745 TEST_F(WebFrameTest, SimulateFragmentAnchorMiddleClick) |
| 3785 { | 3746 { |
| 3786 registerMockedHttpURLLoad("fragment_middle_click.html"); | 3747 registerMockedHttpURLLoad("fragment_middle_click.html"); |
| 3787 TestNavigationPolicyWebFrameClient client; | 3748 TestNavigationPolicyWebFrameClient client; |
| 3788 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fragment_mid
dle_click.html", true, &client); | 3749 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3750 webViewHelper.initializeAndLoad(m_baseURL + "fragment_middle_click.html", tr
ue, &client); |
| 3789 | 3751 |
| 3790 WebCore::Document* document = webViewImpl()->page()->mainFrame()->document()
; | 3752 WebCore::Document* document = webViewHelper.webViewImpl()->page()->mainFrame
()->document(); |
| 3791 WebCore::KURL destination = document->url(); | 3753 WebCore::KURL destination = document->url(); |
| 3792 destination.setFragmentIdentifier("test"); | 3754 destination.setFragmentIdentifier("test"); |
| 3793 | 3755 |
| 3794 RefPtr<WebCore::Event> event = WebCore::MouseEvent::create(WebCore::eventNam
es().clickEvent, false, false, | 3756 RefPtr<WebCore::Event> event = WebCore::MouseEvent::create(WebCore::eventNam
es().clickEvent, false, false, |
| 3795 document->defaultView(), 0, 0, 0, 0, 0, 0, 0, false, false, false, false
, 1, 0, 0); | 3757 document->defaultView(), 0, 0, 0, 0, 0, 0, 0, false, false, false, false
, 1, 0, 0); |
| 3796 WebCore::FrameLoadRequest frameRequest(document->securityOrigin(), WebCore::
ResourceRequest(destination)); | 3758 WebCore::FrameLoadRequest frameRequest(document->securityOrigin(), WebCore::
ResourceRequest(destination)); |
| 3797 frameRequest.setTriggeringEvent(event); | 3759 frameRequest.setTriggeringEvent(event); |
| 3798 webViewImpl()->page()->mainFrame()->loader()->load(frameRequest); | 3760 webViewHelper.webViewImpl()->page()->mainFrame()->loader()->load(frameReques
t); |
| 3799 | |
| 3800 m_webView->close(); | |
| 3801 m_webView = 0; | |
| 3802 } | 3761 } |
| 3803 | 3762 |
| 3804 TEST_F(WebFrameTest, BackToReload) | 3763 TEST_F(WebFrameTest, BackToReload) |
| 3805 { | 3764 { |
| 3806 registerMockedHttpURLLoad("fragment_middle_click.html"); | 3765 registerMockedHttpURLLoad("fragment_middle_click.html"); |
| 3807 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fragment_mid
dle_click.html", true); | 3766 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3808 WebFrame* frame = m_webView->mainFrame(); | 3767 webViewHelper.initializeAndLoad(m_baseURL + "fragment_middle_click.html", tr
ue); |
| 3768 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 3809 WebHistoryItem firstItem = frame->currentHistoryItem(); | 3769 WebHistoryItem firstItem = frame->currentHistoryItem(); |
| 3810 EXPECT_FALSE(firstItem.isNull()); | 3770 EXPECT_FALSE(firstItem.isNull()); |
| 3811 | 3771 |
| 3812 registerMockedHttpURLLoad("white-1x1.png"); | 3772 registerMockedHttpURLLoad("white-1x1.png"); |
| 3813 FrameTestHelpers::loadFrame(frame, m_baseURL + "white-1x1.png"); | 3773 FrameTestHelpers::loadFrame(frame, m_baseURL + "white-1x1.png"); |
| 3814 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 3774 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 3815 EXPECT_FALSE(frame->previousHistoryItem().isNull()); | 3775 EXPECT_FALSE(frame->previousHistoryItem().isNull()); |
| 3816 EXPECT_EQ(firstItem.urlString(), frame->previousHistoryItem().urlString()); | 3776 EXPECT_EQ(firstItem.urlString(), frame->previousHistoryItem().urlString()); |
| 3817 | 3777 |
| 3818 frame->loadHistoryItem(frame->previousHistoryItem()); | 3778 frame->loadHistoryItem(frame->previousHistoryItem()); |
| 3819 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 3779 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 3820 EXPECT_EQ(firstItem.urlString(), frame->currentHistoryItem().urlString()); | 3780 EXPECT_EQ(firstItem.urlString(), frame->currentHistoryItem().urlString()); |
| 3821 | 3781 |
| 3822 frame->reload(); | 3782 frame->reload(); |
| 3823 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 3783 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 3824 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque
st().cachePolicy()); | 3784 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque
st().cachePolicy()); |
| 3825 | |
| 3826 m_webView->close(); | |
| 3827 m_webView = 0; | |
| 3828 } | 3785 } |
| 3829 | 3786 |
| 3830 TEST_F(WebFrameTest, ReloadPost) | 3787 TEST_F(WebFrameTest, ReloadPost) |
| 3831 { | 3788 { |
| 3832 registerMockedHttpURLLoad("reload_post.html"); | 3789 registerMockedHttpURLLoad("reload_post.html"); |
| 3833 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "reload_post.
html", true); | 3790 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3834 WebFrame* frame = m_webView->mainFrame(); | 3791 webViewHelper.initializeAndLoad(m_baseURL + "reload_post.html", true); |
| 3792 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 3835 | 3793 |
| 3836 FrameTestHelpers::loadFrame(m_webView->mainFrame(), "javascript:document.for
ms[0].submit()"); | 3794 FrameTestHelpers::loadFrame(webViewHelper.webView()->mainFrame(), "javascrip
t:document.forms[0].submit()"); |
| 3837 runPendingTasks(); | 3795 runPendingTasks(); |
| 3838 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 3796 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 3839 EXPECT_FALSE(frame->previousHistoryItem().isNull()); | 3797 EXPECT_FALSE(frame->previousHistoryItem().isNull()); |
| 3840 EXPECT_EQ(WebString::fromUTF8("POST"), frame->dataSource()->request().httpMe
thod()); | 3798 EXPECT_EQ(WebString::fromUTF8("POST"), frame->dataSource()->request().httpMe
thod()); |
| 3841 | 3799 |
| 3842 frame->reload(); | 3800 frame->reload(); |
| 3843 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 3801 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 3844 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque
st().cachePolicy()); | 3802 EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->reque
st().cachePolicy()); |
| 3845 EXPECT_EQ(WebNavigationTypeFormResubmitted, frame->dataSource()->navigationT
ype()); | 3803 EXPECT_EQ(WebNavigationTypeFormResubmitted, frame->dataSource()->navigationT
ype()); |
| 3846 | |
| 3847 m_webView->close(); | |
| 3848 m_webView = 0; | |
| 3849 } | 3804 } |
| 3850 | 3805 |
| 3851 class TestSameDocumentWebFrameClient : public WebFrameClient { | 3806 class TestSameDocumentWebFrameClient : public WebFrameClient { |
| 3852 public: | 3807 public: |
| 3853 TestSameDocumentWebFrameClient() | 3808 TestSameDocumentWebFrameClient() |
| 3854 : m_frameLoadTypeSameSeen(false) | 3809 : m_frameLoadTypeSameSeen(false) |
| 3855 { | 3810 { |
| 3856 } | 3811 } |
| 3857 | 3812 |
| 3858 virtual void willSendRequest(WebFrame* frame, unsigned, WebURLRequest&, cons
t WebURLResponse&) | 3813 virtual void willSendRequest(WebFrame* frame, unsigned, WebURLRequest&, cons
t WebURLResponse&) |
| 3859 { | 3814 { |
| 3860 if (toWebFrameImpl(frame)->frame()->loader()->loadType() == WebCore::Fra
meLoadTypeSame) | 3815 if (toWebFrameImpl(frame)->frame()->loader()->loadType() == WebCore::Fra
meLoadTypeSame) |
| 3861 m_frameLoadTypeSameSeen = true; | 3816 m_frameLoadTypeSameSeen = true; |
| 3862 } | 3817 } |
| 3863 | 3818 |
| 3864 bool frameLoadTypeSameSeen() const { return m_frameLoadTypeSameSeen; } | 3819 bool frameLoadTypeSameSeen() const { return m_frameLoadTypeSameSeen; } |
| 3865 | 3820 |
| 3866 private: | 3821 private: |
| 3867 bool m_frameLoadTypeSameSeen; | 3822 bool m_frameLoadTypeSameSeen; |
| 3868 }; | 3823 }; |
| 3869 | 3824 |
| 3870 TEST_F(WebFrameTest, NavigateToSame) | 3825 TEST_F(WebFrameTest, NavigateToSame) |
| 3871 { | 3826 { |
| 3872 registerMockedHttpURLLoad("navigate_to_same.html"); | 3827 registerMockedHttpURLLoad("navigate_to_same.html"); |
| 3873 TestSameDocumentWebFrameClient client; | 3828 TestSameDocumentWebFrameClient client; |
| 3874 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "navigate_to_
same.html", true, &client); | 3829 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3830 webViewHelper.initializeAndLoad(m_baseURL + "navigate_to_same.html", true, &
client); |
| 3875 EXPECT_FALSE(client.frameLoadTypeSameSeen()); | 3831 EXPECT_FALSE(client.frameLoadTypeSameSeen()); |
| 3876 | 3832 |
| 3877 WebCore::FrameLoadRequest frameRequest(0, WebCore::ResourceRequest(webViewIm
pl()->page()->mainFrame()->document()->url())); | 3833 WebCore::FrameLoadRequest frameRequest(0, WebCore::ResourceRequest(webViewHe
lper.webViewImpl()->page()->mainFrame()->document()->url())); |
| 3878 webViewImpl()->page()->mainFrame()->loader()->load(frameRequest); | 3834 webViewHelper.webViewImpl()->page()->mainFrame()->loader()->load(frameReques
t); |
| 3879 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 3835 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 3880 | 3836 |
| 3881 EXPECT_TRUE(client.frameLoadTypeSameSeen()); | 3837 EXPECT_TRUE(client.frameLoadTypeSameSeen()); |
| 3882 m_webView->close(); | |
| 3883 m_webView = 0; | |
| 3884 } | 3838 } |
| 3885 | 3839 |
| 3886 TEST_F(WebFrameTest, WebNodeImageContents) | 3840 TEST_F(WebFrameTest, WebNodeImageContents) |
| 3887 { | 3841 { |
| 3888 m_webView = FrameTestHelpers::createWebViewAndLoad("about:blank", true); | 3842 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3889 WebFrame* frame = m_webView->mainFrame(); | 3843 webViewHelper.initializeAndLoad("about:blank", true); |
| 3844 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 3890 | 3845 |
| 3891 static const char bluePNG[] = "<img src=\"data:image/png;base64,iVBORw0KGgoA
AAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYV2NkYPj/n4EIwDiqEF8oUT94AFIQE/cCn90I
AAAAAElFTkSuQmCC\">"; | 3846 static const char bluePNG[] = "<img src=\"data:image/png;base64,iVBORw0KGgoA
AAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYV2NkYPj/n4EIwDiqEF8oUT94AFIQE/cCn90I
AAAAAElFTkSuQmCC\">"; |
| 3892 | 3847 |
| 3893 // Load up the image and test that we can extract the contents. | 3848 // Load up the image and test that we can extract the contents. |
| 3894 WebCore::KURL testURL = toKURL("about:blank"); | 3849 WebCore::KURL testURL = toKURL("about:blank"); |
| 3895 frame->loadHTMLString(bluePNG, testURL); | 3850 frame->loadHTMLString(bluePNG, testURL); |
| 3896 runPendingTasks(); | 3851 runPendingTasks(); |
| 3897 | 3852 |
| 3898 WebNode node = frame->document().body().firstChild(); | 3853 WebNode node = frame->document().body().firstChild(); |
| 3899 EXPECT_TRUE(node.isElementNode()); | 3854 EXPECT_TRUE(node.isElementNode()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3932 | 3887 |
| 3933 private: | 3888 private: |
| 3934 int m_startLoadingCount; | 3889 int m_startLoadingCount; |
| 3935 int m_stopLoadingCount; | 3890 int m_stopLoadingCount; |
| 3936 }; | 3891 }; |
| 3937 | 3892 |
| 3938 TEST_F(WebFrameTest, PushStateStartsAndStops) | 3893 TEST_F(WebFrameTest, PushStateStartsAndStops) |
| 3939 { | 3894 { |
| 3940 registerMockedHttpURLLoad("push_state.html"); | 3895 registerMockedHttpURLLoad("push_state.html"); |
| 3941 TestStartStopCallbackWebViewClient client; | 3896 TestStartStopCallbackWebViewClient client; |
| 3942 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "push_state.h
tml", true, 0, &client); | 3897 FrameTestHelpers::WebViewHelper webViewHelper; |
| 3898 webViewHelper.initializeAndLoad(m_baseURL + "push_state.html", true, 0, &cli
ent); |
| 3943 runPendingTasks(); | 3899 runPendingTasks(); |
| 3944 | 3900 |
| 3945 EXPECT_EQ(client.startLoadingCount(), 2); | 3901 EXPECT_EQ(client.startLoadingCount(), 2); |
| 3946 EXPECT_EQ(client.stopLoadingCount(), 2); | 3902 EXPECT_EQ(client.stopLoadingCount(), 2); |
| 3947 m_webView->close(); | |
| 3948 m_webView = 0; | |
| 3949 } | 3903 } |
| 3950 | 3904 |
| 3951 } // namespace | 3905 } // namespace |
| OLD | NEW |