OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 protected: | 219 protected: |
220 void testAutoResize(const WebSize& minAutoResize, const WebSize& maxAutoResi
ze, | 220 void testAutoResize(const WebSize& minAutoResize, const WebSize& maxAutoResi
ze, |
221 const std::string& pageWidth, const std::string& pageHei
ght, | 221 const std::string& pageWidth, const std::string& pageHei
ght, |
222 int expectedWidth, int expectedHeight, | 222 int expectedWidth, int expectedHeight, |
223 HorizontalScrollbarState expectedHorizontalState, Vertic
alScrollbarState expectedVerticalState); | 223 HorizontalScrollbarState expectedHorizontalState, Vertic
alScrollbarState expectedVerticalState); |
224 | 224 |
225 void testTextInputType(WebTextInputType expectedType, const std::string& htm
lFile); | 225 void testTextInputType(WebTextInputType expectedType, const std::string& htm
lFile); |
226 void testInputMode(const WebString& expectedInputMode, const std::string& ht
mlFile); | 226 void testInputMode(const WebString& expectedInputMode, const std::string& ht
mlFile); |
227 | 227 |
228 std::string m_baseURL; | 228 std::string m_baseURL; |
| 229 FrameTestHelpers::WebViewHelper m_webViewHelper; |
229 }; | 230 }; |
230 | 231 |
231 TEST_F(WebViewTest, SetBaseBackgroundColor) | 232 TEST_F(WebViewTest, SetBaseBackgroundColor) |
232 { | 233 { |
233 const WebColor kWhite = 0xFFFFFFFF; | 234 const WebColor kWhite = 0xFFFFFFFF; |
234 const WebColor kBlue = 0xFF0000FF; | 235 const WebColor kBlue = 0xFF0000FF; |
235 const WebColor kDarkCyan = 0xFF227788; | 236 const WebColor kDarkCyan = 0xFF227788; |
236 const WebColor kTranslucentPutty = 0x80BFB196; | 237 const WebColor kTranslucentPutty = 0x80BFB196; |
237 | 238 |
238 WebView* webView = FrameTestHelpers::createWebView(); | 239 WebView* webView = m_webViewHelper.initialize(); |
239 EXPECT_EQ(kWhite, webView->backgroundColor()); | 240 EXPECT_EQ(kWhite, webView->backgroundColor()); |
240 | 241 |
241 webView->setBaseBackgroundColor(kBlue); | 242 webView->setBaseBackgroundColor(kBlue); |
242 EXPECT_EQ(kBlue, webView->backgroundColor()); | 243 EXPECT_EQ(kBlue, webView->backgroundColor()); |
243 | 244 |
244 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); | 245 WebURL baseURL = URLTestHelpers::toKURL("http://example.com/"); |
245 webView->mainFrame()->loadHTMLString( | 246 webView->mainFrame()->loadHTMLString( |
246 "<html><head><style>body {background-color:#227788}</style></head></html
>", baseURL); | 247 "<html><head><style>body {background-color:#227788}</style></head></html
>", baseURL); |
247 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 248 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
248 EXPECT_EQ(kDarkCyan, webView->backgroundColor()); | 249 EXPECT_EQ(kDarkCyan, webView->backgroundColor()); |
249 | 250 |
250 webView->mainFrame()->loadHTMLString( | 251 webView->mainFrame()->loadHTMLString( |
251 "<html><head><style>body {background-color:rgba(255,0,0,0.5)}</style></h
ead></html>", baseURL); | 252 "<html><head><style>body {background-color:rgba(255,0,0,0.5)}</style></h
ead></html>", baseURL); |
252 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | 253 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
253 // Expected: red (50% alpha) blended atop base of kBlue. | 254 // Expected: red (50% alpha) blended atop base of kBlue. |
254 EXPECT_EQ(0xFF7F0080, webView->backgroundColor()); | 255 EXPECT_EQ(0xFF7F0080, webView->backgroundColor()); |
255 | 256 |
256 webView->setBaseBackgroundColor(kTranslucentPutty); | 257 webView->setBaseBackgroundColor(kTranslucentPutty); |
257 // Expected: red (50% alpha) blended atop kTranslucentPutty. Note the alpha. | 258 // Expected: red (50% alpha) blended atop kTranslucentPutty. Note the alpha. |
258 EXPECT_EQ(0xBFE93B32, webView->backgroundColor()); | 259 EXPECT_EQ(0xBFE93B32, webView->backgroundColor()); |
259 | |
260 webView->close(); | |
261 } | 260 } |
262 | 261 |
263 TEST_F(WebViewTest, FocusIsInactive) | 262 TEST_F(WebViewTest, FocusIsInactive) |
264 { | 263 { |
265 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "visible_iframe.html"); | 264 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "visible_iframe.html"); |
266 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "visib
le_iframe.html"); | 265 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "visible_if
rame.html"); |
267 | 266 |
268 webView->setFocus(true); | 267 webView->setFocus(true); |
269 webView->setIsActive(true); | 268 webView->setIsActive(true); |
270 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); | 269 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); |
271 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); | 270 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); |
272 | 271 |
273 WebCore::HTMLDocument* document = WebCore::toHTMLDocument(frame->frame()->do
cument()); | 272 WebCore::HTMLDocument* document = WebCore::toHTMLDocument(frame->frame()->do
cument()); |
274 EXPECT_TRUE(document->hasFocus()); | 273 EXPECT_TRUE(document->hasFocus()); |
275 webView->setFocus(false); | 274 webView->setFocus(false); |
276 webView->setIsActive(false); | 275 webView->setIsActive(false); |
277 EXPECT_FALSE(document->hasFocus()); | 276 EXPECT_FALSE(document->hasFocus()); |
278 webView->setFocus(true); | 277 webView->setFocus(true); |
279 webView->setIsActive(true); | 278 webView->setIsActive(true); |
280 EXPECT_TRUE(document->hasFocus()); | 279 EXPECT_TRUE(document->hasFocus()); |
281 webView->setFocus(true); | 280 webView->setFocus(true); |
282 webView->setIsActive(false); | 281 webView->setIsActive(false); |
283 EXPECT_FALSE(document->hasFocus()); | 282 EXPECT_FALSE(document->hasFocus()); |
284 webView->setFocus(false); | 283 webView->setFocus(false); |
285 webView->setIsActive(true); | 284 webView->setIsActive(true); |
286 EXPECT_FALSE(document->hasFocus()); | 285 EXPECT_FALSE(document->hasFocus()); |
287 | |
288 webView->close(); | |
289 } | 286 } |
290 | 287 |
291 TEST_F(WebViewTest, ActiveState) | 288 TEST_F(WebViewTest, ActiveState) |
292 { | 289 { |
293 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "visible_iframe.html"); | 290 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "visible_iframe.html"); |
294 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "visib
le_iframe.html"); | 291 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "visible_if
rame.html"); |
295 | 292 |
296 ASSERT_TRUE(webView); | 293 ASSERT_TRUE(webView); |
297 | 294 |
298 webView->setIsActive(true); | 295 webView->setIsActive(true); |
299 EXPECT_TRUE(webView->isActive()); | 296 EXPECT_TRUE(webView->isActive()); |
300 | 297 |
301 webView->setIsActive(false); | 298 webView->setIsActive(false); |
302 EXPECT_FALSE(webView->isActive()); | 299 EXPECT_FALSE(webView->isActive()); |
303 | 300 |
304 webView->setIsActive(true); | 301 webView->setIsActive(true); |
305 EXPECT_TRUE(webView->isActive()); | 302 EXPECT_TRUE(webView->isActive()); |
306 | |
307 webView->close(); | |
308 } | 303 } |
309 | 304 |
310 TEST_F(WebViewTest, HitTestResultAtWithPageScale) | 305 TEST_F(WebViewTest, HitTestResultAtWithPageScale) |
311 { | 306 { |
312 std::string url = m_baseURL + "specify_size.html?" + "50px" + ":" + "50px"; | 307 std::string url = m_baseURL + "specify_size.html?" + "50px" + ":" + "50px"; |
313 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); | 308 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); |
314 WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true, 0); | 309 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); |
315 webView->resize(WebSize(100, 100)); | 310 webView->resize(WebSize(100, 100)); |
316 WebPoint hitPoint(75, 75); | 311 WebPoint hitPoint(75, 75); |
317 | 312 |
318 // Image is at top left quandrant, so should not hit it. | 313 // Image is at top left quandrant, so should not hit it. |
319 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint); | 314 WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint); |
320 ASSERT_EQ(WebNode::ElementNode, negativeResult.node().nodeType()); | 315 ASSERT_EQ(WebNode::ElementNode, negativeResult.node().nodeType()); |
321 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasTagName("img")); | 316 EXPECT_FALSE(negativeResult.node().to<WebElement>().hasTagName("img")); |
322 negativeResult.reset(); | 317 negativeResult.reset(); |
323 | 318 |
324 // Scale page up 2x so image should occupy the whole viewport. | 319 // Scale page up 2x so image should occupy the whole viewport. |
325 webView->setPageScaleFactor(2.0f, WebPoint(0, 0)); | 320 webView->setPageScaleFactor(2.0f, WebPoint(0, 0)); |
326 WebHitTestResult positiveResult = webView->hitTestResultAt(hitPoint); | 321 WebHitTestResult positiveResult = webView->hitTestResultAt(hitPoint); |
327 ASSERT_EQ(WebNode::ElementNode, positiveResult.node().nodeType()); | 322 ASSERT_EQ(WebNode::ElementNode, positiveResult.node().nodeType()); |
328 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasTagName("img")); | 323 EXPECT_TRUE(positiveResult.node().to<WebElement>().hasTagName("img")); |
329 positiveResult.reset(); | 324 positiveResult.reset(); |
330 | |
331 webView->close(); | |
332 } | 325 } |
333 | 326 |
334 void WebViewTest::testAutoResize(const WebSize& minAutoResize, const WebSize& ma
xAutoResize, | 327 void WebViewTest::testAutoResize(const WebSize& minAutoResize, const WebSize& ma
xAutoResize, |
335 const std::string& pageWidth, const std::string
& pageHeight, | 328 const std::string& pageWidth, const std::string
& pageHeight, |
336 int expectedWidth, int expectedHeight, | 329 int expectedWidth, int expectedHeight, |
337 HorizontalScrollbarState expectedHorizontalStat
e, VerticalScrollbarState expectedVerticalState) | 330 HorizontalScrollbarState expectedHorizontalStat
e, VerticalScrollbarState expectedVerticalState) |
338 { | 331 { |
339 AutoResizeWebViewClient client; | 332 AutoResizeWebViewClient client; |
340 std::string url = m_baseURL + "specify_size.html?" + pageWidth + ":" + pageH
eight; | 333 std::string url = m_baseURL + "specify_size.html?" + pageWidth + ":" + pageH
eight; |
341 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); | 334 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); |
342 WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true, 0, &cli
ent); | 335 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client); |
343 client.testData().setWebView(webView); | 336 client.testData().setWebView(webView); |
344 | 337 |
345 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); | 338 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); |
346 WebCore::FrameView* frameView = frame->frame()->view(); | 339 WebCore::FrameView* frameView = frame->frame()->view(); |
347 frameView->layout(); | 340 frameView->layout(); |
348 EXPECT_FALSE(frameView->layoutPending()); | 341 EXPECT_FALSE(frameView->layoutPending()); |
349 EXPECT_FALSE(frameView->needsLayout()); | 342 EXPECT_FALSE(frameView->needsLayout()); |
350 | 343 |
351 webView->enableAutoResizeMode(minAutoResize, maxAutoResize); | 344 webView->enableAutoResizeMode(minAutoResize, maxAutoResize); |
352 EXPECT_TRUE(frameView->layoutPending()); | 345 EXPECT_TRUE(frameView->layoutPending()); |
353 EXPECT_TRUE(frameView->needsLayout()); | 346 EXPECT_TRUE(frameView->needsLayout()); |
354 frameView->layout(); | 347 frameView->layout(); |
355 | 348 |
356 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); | 349 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); |
357 | 350 |
358 EXPECT_EQ(expectedWidth, client.testData().width()); | 351 EXPECT_EQ(expectedWidth, client.testData().width()); |
359 EXPECT_EQ(expectedHeight, client.testData().height()); | 352 EXPECT_EQ(expectedHeight, client.testData().height()); |
360 EXPECT_EQ(expectedHorizontalState, client.testData().horizontalScrollbarStat
e()); | 353 EXPECT_EQ(expectedHorizontalState, client.testData().horizontalScrollbarStat
e()); |
361 EXPECT_EQ(expectedVerticalState, client.testData().verticalScrollbarState())
; | 354 EXPECT_EQ(expectedVerticalState, client.testData().verticalScrollbarState())
; |
362 | 355 |
363 webView->close(); | 356 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
364 } | 357 } |
365 | 358 |
366 TEST_F(WebViewTest, DISABLED_AutoResizeMinimumSize) | 359 TEST_F(WebViewTest, DISABLED_AutoResizeMinimumSize) |
367 { | 360 { |
368 WebSize minAutoResize(91, 56); | 361 WebSize minAutoResize(91, 56); |
369 WebSize maxAutoResize(403, 302); | 362 WebSize maxAutoResize(403, 302); |
370 std::string pageWidth = "91px"; | 363 std::string pageWidth = "91px"; |
371 std::string pageHeight = "56px"; | 364 std::string pageHeight = "56px"; |
372 int expectedWidth = 91; | 365 int expectedWidth = 91; |
373 int expectedHeight = 56; | 366 int expectedHeight = 56; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 std::string pageHeight = "300px"; | 426 std::string pageHeight = "300px"; |
434 int expectedWidth = 200; | 427 int expectedWidth = 200; |
435 int expectedHeight = 300; | 428 int expectedHeight = 300; |
436 testAutoResize(minAutoResize, maxAutoResize, pageWidth, pageHeight, | 429 testAutoResize(minAutoResize, maxAutoResize, pageWidth, pageHeight, |
437 expectedWidth, expectedHeight, NoHorizontalScrollbar, NoVerti
calScrollbar); | 430 expectedWidth, expectedHeight, NoHorizontalScrollbar, NoVerti
calScrollbar); |
438 } | 431 } |
439 | 432 |
440 void WebViewTest::testTextInputType(WebTextInputType expectedType, const std::st
ring& htmlFile) | 433 void WebViewTest::testTextInputType(WebTextInputType expectedType, const std::st
ring& htmlFile) |
441 { | 434 { |
442 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8(htmlFile.c_str())); | 435 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8(htmlFile.c_str())); |
443 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFi
le); | 436 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + htmlFile); |
444 webView->setInitialFocus(false); | 437 webView->setInitialFocus(false); |
445 EXPECT_EQ(expectedType, webView->textInputInfo().type); | 438 EXPECT_EQ(expectedType, webView->textInputInfo().type); |
446 webView->close(); | |
447 } | 439 } |
448 | 440 |
449 TEST_F(WebViewTest, TextInputType) | 441 TEST_F(WebViewTest, TextInputType) |
450 { | 442 { |
451 testTextInputType(WebTextInputTypeText, "input_field_default.html"); | 443 testTextInputType(WebTextInputTypeText, "input_field_default.html"); |
452 testTextInputType(WebTextInputTypePassword, "input_field_password.html"); | 444 testTextInputType(WebTextInputTypePassword, "input_field_password.html"); |
453 testTextInputType(WebTextInputTypeEmail, "input_field_email.html"); | 445 testTextInputType(WebTextInputTypeEmail, "input_field_email.html"); |
454 testTextInputType(WebTextInputTypeSearch, "input_field_search.html"); | 446 testTextInputType(WebTextInputTypeSearch, "input_field_search.html"); |
455 testTextInputType(WebTextInputTypeNumber, "input_field_number.html"); | 447 testTextInputType(WebTextInputTypeNumber, "input_field_number.html"); |
456 testTextInputType(WebTextInputTypeTelephone, "input_field_tel.html"); | 448 testTextInputType(WebTextInputTypeTelephone, "input_field_tel.html"); |
457 testTextInputType(WebTextInputTypeURL, "input_field_url.html"); | 449 testTextInputType(WebTextInputTypeURL, "input_field_url.html"); |
458 } | 450 } |
459 | 451 |
460 void WebViewTest::testInputMode(const WebString& expectedInputMode, const std::s
tring& htmlFile) | 452 void WebViewTest::testInputMode(const WebString& expectedInputMode, const std::s
tring& htmlFile) |
461 { | 453 { |
462 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8(htmlFile.c_str())); | 454 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8(htmlFile.c_str())); |
463 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + htmlFi
le); | 455 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + htmlFile); |
464 webView->setInitialFocus(false); | 456 webView->setInitialFocus(false); |
465 EXPECT_EQ(expectedInputMode, webView->textInputInfo().inputMode); | 457 EXPECT_EQ(expectedInputMode, webView->textInputInfo().inputMode); |
466 webView->close(); | |
467 } | 458 } |
468 | 459 |
469 TEST_F(WebViewTest, InputMode) | 460 TEST_F(WebViewTest, InputMode) |
470 { | 461 { |
471 testInputMode(WebString(), "input_mode_default.html"); | 462 testInputMode(WebString(), "input_mode_default.html"); |
472 testInputMode(WebString("unknown"), "input_mode_default_unknown.html"); | 463 testInputMode(WebString("unknown"), "input_mode_default_unknown.html"); |
473 testInputMode(WebString("verbatim"), "input_mode_default_verbatim.html"); | 464 testInputMode(WebString("verbatim"), "input_mode_default_verbatim.html"); |
474 testInputMode(WebString("verbatim"), "input_mode_type_text_verbatim.html"); | 465 testInputMode(WebString("verbatim"), "input_mode_type_text_verbatim.html"); |
475 testInputMode(WebString("verbatim"), "input_mode_type_search_verbatim.html")
; | 466 testInputMode(WebString("verbatim"), "input_mode_type_search_verbatim.html")
; |
476 testInputMode(WebString(), "input_mode_type_url_verbatim.html"); | 467 testInputMode(WebString(), "input_mode_type_url_verbatim.html"); |
477 testInputMode(WebString("verbatim"), "input_mode_textarea_verbatim.html"); | 468 testInputMode(WebString("verbatim"), "input_mode_textarea_verbatim.html"); |
478 } | 469 } |
479 | 470 |
480 TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo) | 471 TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo) |
481 { | 472 { |
482 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 473 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
483 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html"); | 474 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
484 webView->setInitialFocus(false); | 475 webView->setInitialFocus(false); |
485 webView->setEditableSelectionOffsets(5, 13); | 476 webView->setEditableSelectionOffsets(5, 13); |
486 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); | 477 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); |
487 EXPECT_EQ("56789abc", frame->selectionAsText()); | 478 EXPECT_EQ("56789abc", frame->selectionAsText()); |
488 WebTextInputInfo info = webView->textInputInfo(); | 479 WebTextInputInfo info = webView->textInputInfo(); |
489 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); | 480 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); |
490 EXPECT_EQ(5, info.selectionStart); | 481 EXPECT_EQ(5, info.selectionStart); |
491 EXPECT_EQ(13, info.selectionEnd); | 482 EXPECT_EQ(13, info.selectionEnd); |
492 EXPECT_EQ(-1, info.compositionStart); | 483 EXPECT_EQ(-1, info.compositionStart); |
493 EXPECT_EQ(-1, info.compositionEnd); | 484 EXPECT_EQ(-1, info.compositionEnd); |
494 webView->close(); | |
495 | 485 |
496 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_editable_populated.html")); | 486 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_editable_populated.html")); |
497 webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "content_editab
le_populated.html"); | 487 webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_editable_po
pulated.html"); |
498 webView->setInitialFocus(false); | 488 webView->setInitialFocus(false); |
499 webView->setEditableSelectionOffsets(8, 19); | 489 webView->setEditableSelectionOffsets(8, 19); |
500 frame = toWebFrameImpl(webView->mainFrame()); | 490 frame = toWebFrameImpl(webView->mainFrame()); |
501 EXPECT_EQ("89abcdefghi", frame->selectionAsText()); | 491 EXPECT_EQ("89abcdefghi", frame->selectionAsText()); |
502 info = webView->textInputInfo(); | 492 info = webView->textInputInfo(); |
503 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); | 493 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", info.value); |
504 EXPECT_EQ(8, info.selectionStart); | 494 EXPECT_EQ(8, info.selectionStart); |
505 EXPECT_EQ(19, info.selectionEnd); | 495 EXPECT_EQ(19, info.selectionEnd); |
506 EXPECT_EQ(-1, info.compositionStart); | 496 EXPECT_EQ(-1, info.compositionStart); |
507 EXPECT_EQ(-1, info.compositionEnd); | 497 EXPECT_EQ(-1, info.compositionEnd); |
508 webView->close(); | |
509 } | 498 } |
510 | 499 |
511 TEST_F(WebViewTest, ConfirmCompositionCursorPositionChange) | 500 TEST_F(WebViewTest, ConfirmCompositionCursorPositionChange) |
512 { | 501 { |
513 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 502 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
514 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html"); | 503 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
515 webView->setInitialFocus(false); | 504 webView->setInitialFocus(false); |
516 | 505 |
517 // Set up a composition that needs to be committed. | 506 // Set up a composition that needs to be committed. |
518 std::string compositionText("hello"); | 507 std::string compositionText("hello"); |
519 | 508 |
520 WebVector<WebCompositionUnderline> emptyUnderlines; | 509 WebVector<WebCompositionUnderline> emptyUnderlines; |
521 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU
nderlines, 3, 3); | 510 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU
nderlines, 3, 3); |
522 | 511 |
523 WebTextInputInfo info = webView->textInputInfo(); | 512 WebTextInputInfo info = webView->textInputInfo(); |
524 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 513 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
(...skipping 16 matching lines...) Expand all Loading... |
541 EXPECT_EQ(6, info.selectionEnd); | 530 EXPECT_EQ(6, info.selectionEnd); |
542 EXPECT_EQ(3, info.compositionStart); | 531 EXPECT_EQ(3, info.compositionStart); |
543 EXPECT_EQ(8, info.compositionEnd); | 532 EXPECT_EQ(8, info.compositionEnd); |
544 | 533 |
545 webView->confirmComposition(WebWidget::DoNotKeepSelection); | 534 webView->confirmComposition(WebWidget::DoNotKeepSelection); |
546 info = webView->textInputInfo(); | 535 info = webView->textInputInfo(); |
547 EXPECT_EQ(8, info.selectionStart); | 536 EXPECT_EQ(8, info.selectionStart); |
548 EXPECT_EQ(8, info.selectionEnd); | 537 EXPECT_EQ(8, info.selectionEnd); |
549 EXPECT_EQ(-1, info.compositionStart); | 538 EXPECT_EQ(-1, info.compositionStart); |
550 EXPECT_EQ(-1, info.compositionEnd); | 539 EXPECT_EQ(-1, info.compositionEnd); |
551 | |
552 webView->close(); | |
553 } | 540 } |
554 | 541 |
555 TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition) | 542 TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition) |
556 { | 543 { |
557 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("text_area_populated.html")); | 544 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("text_area_populated.html")); |
558 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "text_
area_populated.html"); | 545 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_
populated.html"); |
559 webView->setInitialFocus(false); | 546 webView->setInitialFocus(false); |
560 | 547 |
561 WebVector<WebCompositionUnderline> emptyUnderlines; | 548 WebVector<WebCompositionUnderline> emptyUnderlines; |
562 | 549 |
563 webView->setEditableSelectionOffsets(4, 4); | 550 webView->setEditableSelectionOffsets(4, 4); |
564 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); | 551 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); |
565 | 552 |
566 WebTextInputInfo info = webView->textInputInfo(); | 553 WebTextInputInfo info = webView->textInputInfo(); |
567 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); | 554 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); |
568 EXPECT_EQ(4, info.selectionStart); | 555 EXPECT_EQ(4, info.selectionStart); |
569 EXPECT_EQ(4, info.selectionEnd); | 556 EXPECT_EQ(4, info.selectionEnd); |
570 EXPECT_EQ(8, info.compositionStart); | 557 EXPECT_EQ(8, info.compositionStart); |
571 EXPECT_EQ(12, info.compositionEnd); | 558 EXPECT_EQ(12, info.compositionEnd); |
572 | 559 |
573 webView->confirmComposition(WebWidget::KeepSelection); | 560 webView->confirmComposition(WebWidget::KeepSelection); |
574 info = webView->textInputInfo(); | 561 info = webView->textInputInfo(); |
575 EXPECT_EQ(4, info.selectionStart); | 562 EXPECT_EQ(4, info.selectionStart); |
576 EXPECT_EQ(4, info.selectionEnd); | 563 EXPECT_EQ(4, info.selectionEnd); |
577 EXPECT_EQ(-1, info.compositionStart); | 564 EXPECT_EQ(-1, info.compositionStart); |
578 EXPECT_EQ(-1, info.compositionEnd); | 565 EXPECT_EQ(-1, info.compositionEnd); |
579 | 566 |
580 std::string compositionText("\n"); | 567 std::string compositionText("\n"); |
581 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); | 568 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); |
582 info = webView->textInputInfo(); | 569 info = webView->textInputInfo(); |
583 EXPECT_EQ(5, info.selectionStart); | 570 EXPECT_EQ(5, info.selectionStart); |
584 EXPECT_EQ(5, info.selectionEnd); | 571 EXPECT_EQ(5, info.selectionEnd); |
585 EXPECT_EQ(-1, info.compositionStart); | 572 EXPECT_EQ(-1, info.compositionStart); |
586 EXPECT_EQ(-1, info.compositionEnd); | 573 EXPECT_EQ(-1, info.compositionEnd); |
587 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.u
tf8().data())); | 574 EXPECT_EQ("0123\n456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.u
tf8().data())); |
588 | |
589 webView->close(); | |
590 } | 575 } |
591 | 576 |
592 TEST_F(WebViewTest, FormChange) | 577 TEST_F(WebViewTest, FormChange) |
593 { | 578 { |
594 FormChangeWebViewClient client; | 579 FormChangeWebViewClient client; |
595 client.reset(); | 580 client.reset(); |
596 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_set_value_while_focused.html")); | 581 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_set_value_while_focused.html")); |
597 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_set_value_while_focused.html", true, 0, &client); | 582 m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_set_value_while_f
ocused.html", true, 0, &client); |
598 EXPECT_TRUE(client.called()); | 583 EXPECT_TRUE(client.called()); |
599 EXPECT_TRUE(client.focused()); | 584 EXPECT_TRUE(client.focused()); |
600 client.reset(); | 585 client.reset(); |
601 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_set_value_while_not_focused.html")); | 586 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_set_value_while_not_focused.html")); |
602 webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_se
t_value_while_not_focused.html", true, 0, &client); | 587 m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_set_value_while_n
ot_focused.html", true, 0, &client); |
603 EXPECT_TRUE(client.called()); | 588 EXPECT_TRUE(client.called()); |
604 EXPECT_FALSE(client.focused()); | 589 EXPECT_FALSE(client.focused()); |
605 webView->close(); | |
606 } | 590 } |
607 | 591 |
608 TEST_F(WebViewTest, ExtendSelectionAndDelete) | 592 TEST_F(WebViewTest, ExtendSelectionAndDelete) |
609 { | 593 { |
610 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 594 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
611 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html"); | 595 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
612 webView->setInitialFocus(false); | 596 webView->setInitialFocus(false); |
613 webView->setEditableSelectionOffsets(10, 10); | 597 webView->setEditableSelectionOffsets(10, 10); |
614 webView->extendSelectionAndDelete(5, 8); | 598 webView->extendSelectionAndDelete(5, 8); |
615 WebTextInputInfo info = webView->textInputInfo(); | 599 WebTextInputInfo info = webView->textInputInfo(); |
616 EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); | 600 EXPECT_EQ("01234ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); |
617 EXPECT_EQ(5, info.selectionStart); | 601 EXPECT_EQ(5, info.selectionStart); |
618 EXPECT_EQ(5, info.selectionEnd); | 602 EXPECT_EQ(5, info.selectionEnd); |
619 webView->extendSelectionAndDelete(10, 0); | 603 webView->extendSelectionAndDelete(10, 0); |
620 info = webView->textInputInfo(); | 604 info = webView->textInputInfo(); |
621 EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); | 605 EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); |
622 webView->close(); | |
623 } | 606 } |
624 | 607 |
625 TEST_F(WebViewTest, SetCompositionFromExistingText) | 608 TEST_F(WebViewTest, SetCompositionFromExistingText) |
626 { | 609 { |
627 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 610 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
628 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html"); | 611 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
629 webView->setInitialFocus(false); | 612 webView->setInitialFocus(false); |
630 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 613 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
631 underlines[0] = WebKit::WebCompositionUnderline(0, 4, 0, false); | 614 underlines[0] = WebKit::WebCompositionUnderline(0, 4, 0, false); |
632 webView->setEditableSelectionOffsets(4, 10); | 615 webView->setEditableSelectionOffsets(4, 10); |
633 webView->setCompositionFromExistingText(8, 12, underlines); | 616 webView->setCompositionFromExistingText(8, 12, underlines); |
634 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); | 617 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); |
635 EXPECT_EQ(8u, underlineResults[0].startOffset); | 618 EXPECT_EQ(8u, underlineResults[0].startOffset); |
636 EXPECT_EQ(12u, underlineResults[0].endOffset); | 619 EXPECT_EQ(12u, underlineResults[0].endOffset); |
637 WebTextInputInfo info = webView->textInputInfo(); | 620 WebTextInputInfo info = webView->textInputInfo(); |
638 EXPECT_EQ(4, info.selectionStart); | 621 EXPECT_EQ(4, info.selectionStart); |
639 EXPECT_EQ(10, info.selectionEnd); | 622 EXPECT_EQ(10, info.selectionEnd); |
640 EXPECT_EQ(8, info.compositionStart); | 623 EXPECT_EQ(8, info.compositionStart); |
641 EXPECT_EQ(12, info.compositionEnd); | 624 EXPECT_EQ(12, info.compositionEnd); |
642 WebVector<WebCompositionUnderline> emptyUnderlines; | 625 WebVector<WebCompositionUnderline> emptyUnderlines; |
643 webView->setCompositionFromExistingText(0, 0, emptyUnderlines); | 626 webView->setCompositionFromExistingText(0, 0, emptyUnderlines); |
644 info = webView->textInputInfo(); | 627 info = webView->textInputInfo(); |
645 EXPECT_EQ(4, info.selectionStart); | 628 EXPECT_EQ(4, info.selectionStart); |
646 EXPECT_EQ(10, info.selectionEnd); | 629 EXPECT_EQ(10, info.selectionEnd); |
647 EXPECT_EQ(-1, info.compositionStart); | 630 EXPECT_EQ(-1, info.compositionStart); |
648 EXPECT_EQ(-1, info.compositionEnd); | 631 EXPECT_EQ(-1, info.compositionEnd); |
649 webView->close(); | |
650 } | 632 } |
651 | 633 |
652 TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea) | 634 TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea) |
653 { | 635 { |
654 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("text_area_populated.html")); | 636 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("text_area_populated.html")); |
655 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "text_
area_populated.html"); | 637 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_
populated.html"); |
656 webView->setInitialFocus(false); | 638 webView->setInitialFocus(false); |
657 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 639 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
658 underlines[0] = WebKit::WebCompositionUnderline(0, 4, 0, false); | 640 underlines[0] = WebKit::WebCompositionUnderline(0, 4, 0, false); |
659 webView->setEditableSelectionOffsets(27, 27); | 641 webView->setEditableSelectionOffsets(27, 27); |
660 std::string newLineText("\n"); | 642 std::string newLineText("\n"); |
661 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); | 643 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); |
662 WebTextInputInfo info = webView->textInputInfo(); | 644 WebTextInputInfo info = webView->textInputInfo(); |
663 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); | 645 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); |
664 | 646 |
665 webView->setEditableSelectionOffsets(31, 31); | 647 webView->setEditableSelectionOffsets(31, 31); |
666 webView->setCompositionFromExistingText(30, 34, underlines); | 648 webView->setCompositionFromExistingText(30, 34, underlines); |
667 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); | 649 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); |
668 EXPECT_EQ(2u, underlineResults[0].startOffset); | 650 EXPECT_EQ(2u, underlineResults[0].startOffset); |
669 EXPECT_EQ(6u, underlineResults[0].endOffset); | 651 EXPECT_EQ(6u, underlineResults[0].endOffset); |
670 info = webView->textInputInfo(); | 652 info = webView->textInputInfo(); |
671 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); | 653 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); |
672 EXPECT_EQ(31, info.selectionStart); | 654 EXPECT_EQ(31, info.selectionStart); |
673 EXPECT_EQ(31, info.selectionEnd); | 655 EXPECT_EQ(31, info.selectionEnd); |
674 EXPECT_EQ(30, info.compositionStart); | 656 EXPECT_EQ(30, info.compositionStart); |
675 EXPECT_EQ(34, info.compositionEnd); | 657 EXPECT_EQ(34, info.compositionEnd); |
676 | 658 |
677 std::string compositionText("yolo"); | 659 std::string compositionText("yolo"); |
678 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); | 660 webView->confirmComposition(WebString::fromUTF8(compositionText.c_str())); |
679 info = webView->textInputInfo(); | 661 info = webView->textInputInfo(); |
680 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u
tf8().data())); | 662 EXPECT_EQ("0123456789abcdefghijklmnopq\nrsyoloxyz", std::string(info.value.u
tf8().data())); |
681 EXPECT_EQ(34, info.selectionStart); | 663 EXPECT_EQ(34, info.selectionStart); |
682 EXPECT_EQ(34, info.selectionEnd); | 664 EXPECT_EQ(34, info.selectionEnd); |
683 EXPECT_EQ(-1, info.compositionStart); | 665 EXPECT_EQ(-1, info.compositionStart); |
684 EXPECT_EQ(-1, info.compositionEnd); | 666 EXPECT_EQ(-1, info.compositionEnd); |
685 webView->close(); | |
686 } | 667 } |
687 | 668 |
688 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) | 669 TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition) |
689 { | 670 { |
690 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 671 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
691 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html"); | 672 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
692 webView->setInitialFocus(false); | 673 webView->setInitialFocus(false); |
693 | 674 |
694 std::string compositionTextFirst("hello "); | 675 std::string compositionTextFirst("hello "); |
695 std::string compositionTextSecond("world"); | 676 std::string compositionTextSecond("world"); |
696 WebVector<WebCompositionUnderline> emptyUnderlines; | 677 WebVector<WebCompositionUnderline> emptyUnderlines; |
697 | 678 |
698 webView->confirmComposition(WebString::fromUTF8(compositionTextFirst.c_str()
)); | 679 webView->confirmComposition(WebString::fromUTF8(compositionTextFirst.c_str()
)); |
699 webView->setComposition(WebString::fromUTF8(compositionTextSecond.c_str()),
emptyUnderlines, 5, 5); | 680 webView->setComposition(WebString::fromUTF8(compositionTextSecond.c_str()),
emptyUnderlines, 5, 5); |
700 | 681 |
701 WebTextInputInfo info = webView->textInputInfo(); | 682 WebTextInputInfo info = webView->textInputInfo(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 EXPECT_EQ(6, info.compositionStart); | 718 EXPECT_EQ(6, info.compositionStart); |
738 EXPECT_EQ(11, info.compositionEnd); | 719 EXPECT_EQ(11, info.compositionEnd); |
739 | 720 |
740 webView->setEditableSelectionOffsets(2, 2); | 721 webView->setEditableSelectionOffsets(2, 2); |
741 info = webView->textInputInfo(); | 722 info = webView->textInputInfo(); |
742 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); | 723 EXPECT_EQ("hello world", std::string(info.value.utf8().data())); |
743 EXPECT_EQ(2, info.selectionStart); | 724 EXPECT_EQ(2, info.selectionStart); |
744 EXPECT_EQ(2, info.selectionEnd); | 725 EXPECT_EQ(2, info.selectionEnd); |
745 EXPECT_EQ(-1, info.compositionStart); | 726 EXPECT_EQ(-1, info.compositionStart); |
746 EXPECT_EQ(-1, info.compositionEnd); | 727 EXPECT_EQ(-1, info.compositionEnd); |
747 webView->close(); | |
748 } | 728 } |
749 | 729 |
750 TEST_F(WebViewTest, IsSelectionAnchorFirst) | 730 TEST_F(WebViewTest, IsSelectionAnchorFirst) |
751 { | 731 { |
752 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 732 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
753 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html"); | 733 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
754 WebFrame* frame = webView->mainFrame(); | 734 WebFrame* frame = webView->mainFrame(); |
755 | 735 |
756 webView->setInitialFocus(false); | 736 webView->setInitialFocus(false); |
757 webView->setEditableSelectionOffsets(4, 10); | 737 webView->setEditableSelectionOffsets(4, 10); |
758 EXPECT_TRUE(webView->isSelectionAnchorFirst()); | 738 EXPECT_TRUE(webView->isSelectionAnchorFirst()); |
759 WebRect anchor; | 739 WebRect anchor; |
760 WebRect focus; | 740 WebRect focus; |
761 webView->selectionBounds(anchor, focus); | 741 webView->selectionBounds(anchor, focus); |
762 frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y))
; | 742 frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y))
; |
763 EXPECT_FALSE(webView->isSelectionAnchorFirst()); | 743 EXPECT_FALSE(webView->isSelectionAnchorFirst()); |
764 webView->close(); | |
765 } | 744 } |
766 | 745 |
767 TEST_F(WebViewTest, HistoryResetScrollAndScaleState) | 746 TEST_F(WebViewTest, HistoryResetScrollAndScaleState) |
768 { | 747 { |
769 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("hello_world.html")); | 748 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("hello_world.html")); |
770 WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebViewAndL
oad(m_baseURL + "hello_world.html")); | 749 WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initializeAndLoad(m
_baseURL + "hello_world.html")); |
771 webViewImpl->resize(WebSize(640, 480)); | 750 webViewImpl->resize(WebSize(640, 480)); |
772 webViewImpl->layout(); | 751 webViewImpl->layout(); |
773 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 752 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
774 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 753 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
775 | 754 |
776 // Make the page scale and scroll with the given paremeters. | 755 // Make the page scale and scroll with the given paremeters. |
777 webViewImpl->setPageScaleFactor(2.0f, WebPoint(116, 84)); | 756 webViewImpl->setPageScaleFactor(2.0f, WebPoint(116, 84)); |
778 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 757 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
779 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); | 758 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); |
780 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); | 759 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); |
(...skipping 18 matching lines...) Expand all Loading... |
799 // The HistoryController treats a page scale factor of 0.0f as special and a
voids | 778 // The HistoryController treats a page scale factor of 0.0f as special and a
voids |
800 // restoring it to the WebView. | 779 // restoring it to the WebView. |
801 webViewImpl->resetScrollAndScaleState(); | 780 webViewImpl->resetScrollAndScaleState(); |
802 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); | 781 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); |
803 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 782 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
804 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 783 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
805 webViewImpl->page()->mainFrame()->loader()->history()->restoreScrollPosition
AndViewState(); | 784 webViewImpl->page()->mainFrame()->loader()->history()->restoreScrollPosition
AndViewState(); |
806 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); | 785 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); |
807 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 786 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
808 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 787 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
809 webViewImpl->close(); | |
810 } | 788 } |
811 | 789 |
812 class EnterFullscreenWebViewClient : public WebViewClient { | 790 class EnterFullscreenWebViewClient : public WebViewClient { |
813 public: | 791 public: |
814 // WebViewClient methods | 792 // WebViewClient methods |
815 virtual bool enterFullScreen() { return true; } | 793 virtual bool enterFullScreen() { return true; } |
816 virtual void exitFullScreen() { } | 794 virtual void exitFullScreen() { } |
817 }; | 795 }; |
818 | 796 |
819 | 797 |
820 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) | 798 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) |
821 { | 799 { |
822 EnterFullscreenWebViewClient client; | 800 EnterFullscreenWebViewClient client; |
823 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("hello_world.html")); | 801 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("hello_world.html")); |
824 WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebViewAndL
oad(m_baseURL + "hello_world.html", true, 0, &client)); | 802 WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initializeAndLoad(m
_baseURL + "hello_world.html", true, 0, &client)); |
825 webViewImpl->settings()->setFullScreenEnabled(true); | 803 webViewImpl->settings()->setFullScreenEnabled(true); |
826 webViewImpl->resize(WebSize(640, 480)); | 804 webViewImpl->resize(WebSize(640, 480)); |
827 webViewImpl->layout(); | 805 webViewImpl->layout(); |
828 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 806 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
829 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 807 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
830 | 808 |
831 // Make the page scale and scroll with the given paremeters. | 809 // Make the page scale and scroll with the given paremeters. |
832 webViewImpl->setPageScaleFactor(2.0f, WebPoint(116, 84)); | 810 webViewImpl->setPageScaleFactor(2.0f, WebPoint(116, 84)); |
833 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 811 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
834 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); | 812 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); |
(...skipping 12 matching lines...) Expand all Loading... |
847 RefPtr<WebCore::Element> otherElement = static_cast<PassRefPtr<WebCore::Elem
ent> >(webViewImpl->mainFrame()->document().head()); | 825 RefPtr<WebCore::Element> otherElement = static_cast<PassRefPtr<WebCore::Elem
ent> >(webViewImpl->mainFrame()->document().head()); |
848 webViewImpl->enterFullScreenForElement(otherElement.get()); | 826 webViewImpl->enterFullScreenForElement(otherElement.get()); |
849 | 827 |
850 // Confirm that exiting fullscreen restores the parameters. | 828 // Confirm that exiting fullscreen restores the parameters. |
851 webViewImpl->willExitFullScreen(); | 829 webViewImpl->willExitFullScreen(); |
852 webViewImpl->didExitFullScreen(); | 830 webViewImpl->didExitFullScreen(); |
853 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 831 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
854 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); | 832 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); |
855 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); | 833 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); |
856 | 834 |
857 webViewImpl->close(); | 835 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
858 } | 836 } |
859 | 837 |
860 class ContentDetectorClient : public WebViewClient { | 838 class ContentDetectorClient : public WebViewClient { |
861 public: | 839 public: |
862 ContentDetectorClient() { reset(); } | 840 ContentDetectorClient() { reset(); } |
863 | 841 |
864 virtual WebContentDetectionResult detectContentAround(const WebHitTestResult
& hitTest) OVERRIDE | 842 virtual WebContentDetectionResult detectContentAround(const WebHitTestResult
& hitTest) OVERRIDE |
865 { | 843 { |
866 m_contentDetectionRequested = true; | 844 m_contentDetectionRequested = true; |
867 return m_contentDetectionResult; | 845 return m_contentDetectionResult; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 webView->handleInputEvent(event); | 893 webView->handleInputEvent(event); |
916 runPendingTasks(); | 894 runPendingTasks(); |
917 return true; | 895 return true; |
918 } | 896 } |
919 | 897 |
920 TEST_F(WebViewTest, DetectContentAroundPosition) | 898 TEST_F(WebViewTest, DetectContentAroundPosition) |
921 { | 899 { |
922 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_listeners.html")); | 900 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_listeners.html")); |
923 | 901 |
924 ContentDetectorClient client; | 902 ContentDetectorClient client; |
925 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "conte
nt_listeners.html", true, 0, &client); | 903 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_li
steners.html", true, 0, &client); |
926 webView->resize(WebSize(500, 300)); | 904 webView->resize(WebSize(500, 300)); |
927 webView->layout(); | 905 webView->layout(); |
928 runPendingTasks(); | 906 runPendingTasks(); |
929 | 907 |
930 WebString clickListener = WebString::fromUTF8("clickListener"); | 908 WebString clickListener = WebString::fromUTF8("clickListener"); |
931 WebString touchstartListener = WebString::fromUTF8("touchstartListener"); | 909 WebString touchstartListener = WebString::fromUTF8("touchstartListener"); |
932 WebString mousedownListener = WebString::fromUTF8("mousedownListener"); | 910 WebString mousedownListener = WebString::fromUTF8("mousedownListener"); |
933 WebString noListener = WebString::fromUTF8("noListener"); | 911 WebString noListener = WebString::fromUTF8("noListener"); |
934 WebString link = WebString::fromUTF8("link"); | 912 WebString link = WebString::fromUTF8("link"); |
935 | 913 |
(...skipping 21 matching lines...) Expand all Loading... |
957 client.setContentDetectionResult(WebContentDetectionResult(WebRange(), WebSt
ring(), intentURL)); | 935 client.setContentDetectionResult(WebContentDetectionResult(WebRange(), WebSt
ring(), intentURL)); |
958 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, noListener)); | 936 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, noListener)); |
959 EXPECT_TRUE(client.scheduledIntentURL() == intentURL); | 937 EXPECT_TRUE(client.scheduledIntentURL() == intentURL); |
960 | 938 |
961 // Tapping elsewhere should cancel the scheduled intent. | 939 // Tapping elsewhere should cancel the scheduled intent. |
962 WebGestureEvent event; | 940 WebGestureEvent event; |
963 event.type = WebInputEvent::GestureTap; | 941 event.type = WebInputEvent::GestureTap; |
964 webView->handleInputEvent(event); | 942 webView->handleInputEvent(event); |
965 runPendingTasks(); | 943 runPendingTasks(); |
966 EXPECT_TRUE(client.pendingIntentsCancelled()); | 944 EXPECT_TRUE(client.pendingIntentsCancelled()); |
967 webView->close(); | |
968 } | 945 } |
969 | 946 |
970 TEST_F(WebViewTest, ClientTapHandling) | 947 TEST_F(WebViewTest, ClientTapHandling) |
971 { | 948 { |
972 TapHandlingWebViewClient client; | 949 TapHandlingWebViewClient client; |
973 client.reset(); | 950 client.reset(); |
974 WebView* webView = FrameTestHelpers::createWebViewAndLoad("about:blank", tru
e, 0, &client); | 951 WebView* webView = m_webViewHelper.initializeAndLoad("about:blank", true, 0,
&client); |
975 WebGestureEvent event; | 952 WebGestureEvent event; |
976 event.type = WebInputEvent::GestureTap; | 953 event.type = WebInputEvent::GestureTap; |
977 event.x = 3; | 954 event.x = 3; |
978 event.y = 8; | 955 event.y = 8; |
979 webView->handleInputEvent(event); | 956 webView->handleInputEvent(event); |
980 runPendingTasks(); | 957 runPendingTasks(); |
981 EXPECT_EQ(3, client.tapX()); | 958 EXPECT_EQ(3, client.tapX()); |
982 EXPECT_EQ(8, client.tapY()); | 959 EXPECT_EQ(8, client.tapY()); |
983 client.reset(); | 960 client.reset(); |
984 event.type = WebInputEvent::GestureLongPress; | 961 event.type = WebInputEvent::GestureLongPress; |
985 event.x = 25; | 962 event.x = 25; |
986 event.y = 7; | 963 event.y = 7; |
987 webView->handleInputEvent(event); | 964 webView->handleInputEvent(event); |
988 runPendingTasks(); | 965 runPendingTasks(); |
989 EXPECT_EQ(25, client.longpressX()); | 966 EXPECT_EQ(25, client.longpressX()); |
990 EXPECT_EQ(7, client.longpressY()); | 967 EXPECT_EQ(7, client.longpressY()); |
991 webView->close(); | 968 |
| 969 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
992 } | 970 } |
993 | 971 |
994 #if OS(ANDROID) | 972 #if OS(ANDROID) |
995 TEST_F(WebViewTest, LongPressSelection) | 973 TEST_F(WebViewTest, LongPressSelection) |
996 { | 974 { |
997 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("longpress_selection.html")); | 975 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("longpress_selection.html")); |
998 | 976 |
999 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "longp
ress_selection.html", true); | 977 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_
selection.html", true); |
1000 webView->resize(WebSize(500, 300)); | 978 webView->resize(WebSize(500, 300)); |
1001 webView->layout(); | 979 webView->layout(); |
1002 runPendingTasks(); | 980 runPendingTasks(); |
1003 | 981 |
1004 WebString target = WebString::fromUTF8("target"); | 982 WebString target = WebString::fromUTF8("target"); |
1005 WebString onselectstartfalse = WebString::fromUTF8("onselectstartfalse"); | 983 WebString onselectstartfalse = WebString::fromUTF8("onselectstartfalse"); |
1006 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); | 984 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); |
1007 | 985 |
1008 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, onselec
tstartfalse)); | 986 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, onselec
tstartfalse)); |
1009 EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data())); | 987 EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data())); |
1010 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target)
); | 988 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target)
); |
1011 EXPECT_EQ("testword", std::string(frame->selectionAsText().utf8().data())); | 989 EXPECT_EQ("testword", std::string(frame->selectionAsText().utf8().data())); |
1012 webView->close(); | |
1013 } | 990 } |
1014 #endif | 991 #endif |
1015 | 992 |
1016 TEST_F(WebViewTest, SelectionOnDisabledInput) | 993 TEST_F(WebViewTest, SelectionOnDisabledInput) |
1017 { | 994 { |
1018 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("selection_disabled.html")); | 995 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("selection_disabled.html")); |
1019 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "selec
tion_disabled.html", true); | 996 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "selection_
disabled.html", true); |
1020 webView->resize(WebSize(640, 480)); | 997 webView->resize(WebSize(640, 480)); |
1021 webView->layout(); | 998 webView->layout(); |
1022 runPendingTasks(); | 999 runPendingTasks(); |
1023 | 1000 |
1024 std::string testWord = "This text should be selected."; | 1001 std::string testWord = "This text should be selected."; |
1025 | 1002 |
1026 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); | 1003 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); |
1027 EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data())); | 1004 EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data())); |
1028 | 1005 |
1029 size_t location; | 1006 size_t location; |
1030 size_t length; | 1007 size_t length; |
1031 EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length
)); | 1008 EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length
)); |
1032 EXPECT_EQ(location, 0UL); | 1009 EXPECT_EQ(location, 0UL); |
1033 EXPECT_EQ(length, testWord.length()); | 1010 EXPECT_EQ(length, testWord.length()); |
1034 | |
1035 webView->close(); | |
1036 } | 1011 } |
1037 | 1012 |
1038 TEST_F(WebViewTest, SelectionOnReadOnlyInput) | 1013 TEST_F(WebViewTest, SelectionOnReadOnlyInput) |
1039 { | 1014 { |
1040 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("selection_readonly.html")); | 1015 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("selection_readonly.html")); |
1041 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "selec
tion_readonly.html", true); | 1016 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "selection_
readonly.html", true); |
1042 webView->resize(WebSize(640, 480)); | 1017 webView->resize(WebSize(640, 480)); |
1043 webView->layout(); | 1018 webView->layout(); |
1044 runPendingTasks(); | 1019 runPendingTasks(); |
1045 | 1020 |
1046 std::string testWord = "This text should be selected."; | 1021 std::string testWord = "This text should be selected."; |
1047 | 1022 |
1048 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); | 1023 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); |
1049 EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data())); | 1024 EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data())); |
1050 | 1025 |
1051 size_t location; | 1026 size_t location; |
1052 size_t length; | 1027 size_t length; |
1053 EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length
)); | 1028 EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length
)); |
1054 EXPECT_EQ(location, 0UL); | 1029 EXPECT_EQ(location, 0UL); |
1055 EXPECT_EQ(length, testWord.length()); | 1030 EXPECT_EQ(length, testWord.length()); |
1056 | |
1057 webView->close(); | |
1058 } | 1031 } |
1059 | 1032 |
1060 class MockAutofillClient : public WebAutofillClient { | 1033 class MockAutofillClient : public WebAutofillClient { |
1061 public: | 1034 public: |
1062 MockAutofillClient() | 1035 MockAutofillClient() |
1063 : m_ignoreTextChanges(false) | 1036 : m_ignoreTextChanges(false) |
1064 , m_textChangesWhileIgnored(0) | 1037 , m_textChangesWhileIgnored(0) |
1065 , m_textChangesWhileNotIgnored(0) { } | 1038 , m_textChangesWhileNotIgnored(0) { } |
1066 | 1039 |
1067 virtual ~MockAutofillClient() { } | 1040 virtual ~MockAutofillClient() { } |
(...skipping 20 matching lines...) Expand all Loading... |
1088 bool m_ignoreTextChanges; | 1061 bool m_ignoreTextChanges; |
1089 int m_textChangesWhileIgnored; | 1062 int m_textChangesWhileIgnored; |
1090 int m_textChangesWhileNotIgnored; | 1063 int m_textChangesWhileNotIgnored; |
1091 }; | 1064 }; |
1092 | 1065 |
1093 | 1066 |
1094 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) | 1067 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) |
1095 { | 1068 { |
1096 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1069 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
1097 MockAutofillClient client; | 1070 MockAutofillClient client; |
1098 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html"); | 1071 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
1099 webView->setAutofillClient(&client); | 1072 webView->setAutofillClient(&client); |
1100 webView->setInitialFocus(false); | 1073 webView->setInitialFocus(false); |
1101 | 1074 |
1102 // Set up a composition that needs to be committed. | 1075 // Set up a composition that needs to be committed. |
1103 WebVector<WebCompositionUnderline> emptyUnderlines; | 1076 WebVector<WebCompositionUnderline> emptyUnderlines; |
1104 webView->setEditableSelectionOffsets(4, 10); | 1077 webView->setEditableSelectionOffsets(4, 10); |
1105 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); | 1078 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); |
1106 WebTextInputInfo info = webView->textInputInfo(); | 1079 WebTextInputInfo info = webView->textInputInfo(); |
1107 EXPECT_EQ(4, info.selectionStart); | 1080 EXPECT_EQ(4, info.selectionStart); |
1108 EXPECT_EQ(10, info.selectionEnd); | 1081 EXPECT_EQ(10, info.selectionEnd); |
1109 EXPECT_EQ(8, info.compositionStart); | 1082 EXPECT_EQ(8, info.compositionStart); |
1110 EXPECT_EQ(12, info.compositionEnd); | 1083 EXPECT_EQ(12, info.compositionEnd); |
1111 | 1084 |
1112 // Clear the focus and track that the subsequent composition commit does not
trigger a | 1085 // Clear the focus and track that the subsequent composition commit does not
trigger a |
1113 // text changed notification for autofill. | 1086 // text changed notification for autofill. |
1114 client.clearChangeCounts(); | 1087 client.clearChangeCounts(); |
1115 webView->setFocus(false); | 1088 webView->setFocus(false); |
1116 EXPECT_EQ(1, client.textChangesWhileIgnored()); | 1089 EXPECT_EQ(1, client.textChangesWhileIgnored()); |
1117 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 1090 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
1118 | 1091 |
1119 webView->setAutofillClient(0); | 1092 webView->setAutofillClient(0); |
1120 webView->close(); | |
1121 } | 1093 } |
1122 | 1094 |
1123 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) | 1095 TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange) |
1124 { | 1096 { |
1125 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1097 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
1126 MockAutofillClient client; | 1098 MockAutofillClient client; |
1127 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html"); | 1099 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
1128 webView->setAutofillClient(&client); | 1100 webView->setAutofillClient(&client); |
1129 webView->setInitialFocus(false); | 1101 webView->setInitialFocus(false); |
1130 | 1102 |
1131 // Set up a composition that needs to be committed. | 1103 // Set up a composition that needs to be committed. |
1132 std::string compositionText("testingtext"); | 1104 std::string compositionText("testingtext"); |
1133 | 1105 |
1134 WebVector<WebCompositionUnderline> emptyUnderlines; | 1106 WebVector<WebCompositionUnderline> emptyUnderlines; |
1135 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU
nderlines, 0, compositionText.length()); | 1107 webView->setComposition(WebString::fromUTF8(compositionText.c_str()), emptyU
nderlines, 0, compositionText.length()); |
1136 | 1108 |
1137 WebTextInputInfo info = webView->textInputInfo(); | 1109 WebTextInputInfo info = webView->textInputInfo(); |
1138 EXPECT_EQ(0, info.selectionStart); | 1110 EXPECT_EQ(0, info.selectionStart); |
1139 EXPECT_EQ((int) compositionText.length(), info.selectionEnd); | 1111 EXPECT_EQ((int) compositionText.length(), info.selectionEnd); |
1140 EXPECT_EQ(0, info.compositionStart); | 1112 EXPECT_EQ(0, info.compositionStart); |
1141 EXPECT_EQ((int) compositionText.length(), info.compositionEnd); | 1113 EXPECT_EQ((int) compositionText.length(), info.compositionEnd); |
1142 | 1114 |
1143 client.clearChangeCounts(); | 1115 client.clearChangeCounts(); |
1144 webView->confirmComposition(); | 1116 webView->confirmComposition(); |
1145 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 1117 EXPECT_EQ(0, client.textChangesWhileIgnored()); |
1146 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); | 1118 EXPECT_EQ(1, client.textChangesWhileNotIgnored()); |
1147 | 1119 |
1148 webView->setAutofillClient(0); | 1120 webView->setAutofillClient(0); |
1149 webView->close(); | |
1150 } | 1121 } |
1151 | 1122 |
1152 TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) | 1123 TEST_F(WebViewTest, SetCompositionFromExistingTextTriggersAutofillTextChange) |
1153 { | 1124 { |
1154 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 1125 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
1155 MockAutofillClient client; | 1126 MockAutofillClient client; |
1156 WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input
_field_populated.html", true); | 1127 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html", true); |
1157 webView->setAutofillClient(&client); | 1128 webView->setAutofillClient(&client); |
1158 webView->setInitialFocus(false); | 1129 webView->setInitialFocus(false); |
1159 | 1130 |
1160 WebVector<WebCompositionUnderline> emptyUnderlines; | 1131 WebVector<WebCompositionUnderline> emptyUnderlines; |
1161 | 1132 |
1162 client.clearChangeCounts(); | 1133 client.clearChangeCounts(); |
1163 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); | 1134 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); |
1164 | 1135 |
1165 WebTextInputInfo info = webView->textInputInfo(); | 1136 WebTextInputInfo info = webView->textInputInfo(); |
1166 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); | 1137 EXPECT_EQ("0123456789abcdefghijklmnopqrstuvwxyz", std::string(info.value.utf
8().data())); |
1167 EXPECT_EQ(8, info.compositionStart); | 1138 EXPECT_EQ(8, info.compositionStart); |
1168 EXPECT_EQ(12, info.compositionEnd); | 1139 EXPECT_EQ(12, info.compositionEnd); |
1169 | 1140 |
1170 EXPECT_EQ(0, client.textChangesWhileIgnored()); | 1141 EXPECT_EQ(0, client.textChangesWhileIgnored()); |
1171 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); | 1142 EXPECT_EQ(0, client.textChangesWhileNotIgnored()); |
1172 | 1143 |
1173 WebDocument document = webView->mainFrame()->document(); | 1144 WebDocument document = webView->mainFrame()->document(); |
1174 EXPECT_EQ(WebString::fromUTF8("none"), document.getElementById("inputEvent"
).firstChild().nodeValue()); | 1145 EXPECT_EQ(WebString::fromUTF8("none"), document.getElementById("inputEvent"
).firstChild().nodeValue()); |
1175 | 1146 |
1176 webView->setAutofillClient(0); | 1147 webView->setAutofillClient(0); |
1177 webView->close(); | |
1178 } | 1148 } |
1179 | 1149 |
1180 TEST_F(WebViewTest, ShadowRoot) | 1150 TEST_F(WebViewTest, ShadowRoot) |
1181 { | 1151 { |
1182 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("shadow_dom_test.html")); | 1152 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("shadow_dom_test.html")); |
1183 WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebViewAndL
oad(m_baseURL + "shadow_dom_test.html", true)); | 1153 WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initializeAndLoad(m
_baseURL + "shadow_dom_test.html", true)); |
1184 | 1154 |
1185 WebDocument document = webViewImpl->mainFrame()->document(); | 1155 WebDocument document = webViewImpl->mainFrame()->document(); |
1186 { | 1156 { |
1187 WebElement elementWithShadowRoot = document.getElementById("shadowroot")
; | 1157 WebElement elementWithShadowRoot = document.getElementById("shadowroot")
; |
1188 EXPECT_FALSE(elementWithShadowRoot.isNull()); | 1158 EXPECT_FALSE(elementWithShadowRoot.isNull()); |
1189 WebNode shadowRoot = elementWithShadowRoot.shadowRoot(); | 1159 WebNode shadowRoot = elementWithShadowRoot.shadowRoot(); |
1190 EXPECT_FALSE(shadowRoot.isNull()); | 1160 EXPECT_FALSE(shadowRoot.isNull()); |
1191 } | 1161 } |
1192 { | 1162 { |
1193 WebElement elementWithoutShadowRoot = document.getElementById("noshadowr
oot"); | 1163 WebElement elementWithoutShadowRoot = document.getElementById("noshadowr
oot"); |
1194 EXPECT_FALSE(elementWithoutShadowRoot.isNull()); | 1164 EXPECT_FALSE(elementWithoutShadowRoot.isNull()); |
1195 WebNode shadowRoot = elementWithoutShadowRoot.shadowRoot(); | 1165 WebNode shadowRoot = elementWithoutShadowRoot.shadowRoot(); |
1196 EXPECT_TRUE(shadowRoot.isNull()); | 1166 EXPECT_TRUE(shadowRoot.isNull()); |
1197 } | 1167 } |
1198 webViewImpl->close(); | |
1199 } | 1168 } |
1200 | 1169 |
1201 TEST_F(WebViewTest, HelperPlugin) | 1170 TEST_F(WebViewTest, HelperPlugin) |
1202 { | 1171 { |
1203 HelperPluginCreatingWebViewClient client; | 1172 HelperPluginCreatingWebViewClient client; |
1204 WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebView(tru
e, 0, &client)); | 1173 WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initialize(true, 0,
&client)); |
1205 | 1174 |
1206 WebFrameImpl* frame = toWebFrameImpl(webViewImpl->mainFrame()); | 1175 WebFrameImpl* frame = toWebFrameImpl(webViewImpl->mainFrame()); |
1207 client.setWebFrameClient(frame->client()); | 1176 client.setWebFrameClient(frame->client()); |
1208 | 1177 |
1209 WebHelperPluginImpl* helperPlugin = webViewImpl->createHelperPlugin("dummy-p
lugin-type", frame->document()); | 1178 WebHelperPluginImpl* helperPlugin = webViewImpl->createHelperPlugin("dummy-p
lugin-type", frame->document()); |
1210 EXPECT_TRUE(helperPlugin); | 1179 EXPECT_TRUE(helperPlugin); |
1211 EXPECT_EQ(0, helperPlugin->getPlugin()); // Invalid plugin type means no plu
gin. | 1180 EXPECT_EQ(0, helperPlugin->getPlugin()); // Invalid plugin type means no plu
gin. |
1212 | 1181 |
1213 webViewImpl->closeHelperPluginSoon(helperPlugin); | 1182 webViewImpl->closeHelperPluginSoon(helperPlugin); |
1214 | 1183 |
1215 webViewImpl->close(); | 1184 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
1216 } | 1185 } |
1217 | 1186 |
1218 | 1187 |
1219 class ViewCreatingWebViewClient : public WebViewClient { | 1188 class ViewCreatingWebViewClient : public WebViewClient { |
1220 public: | 1189 public: |
1221 ViewCreatingWebViewClient() | 1190 ViewCreatingWebViewClient() |
1222 : m_createdWebView(0) | 1191 : m_didFocusCalled(false) |
1223 , m_didFocusCalled(false) | |
1224 { | 1192 { |
1225 } | 1193 } |
1226 | 1194 |
1227 // WebViewClient methods | 1195 // WebViewClient methods |
1228 virtual WebView* createView(WebFrame*, const WebURLRequest&, const WebWindow
Features&, const WebString& name, WebNavigationPolicy) OVERRIDE | 1196 virtual WebView* createView(WebFrame*, const WebURLRequest&, const WebWindow
Features&, const WebString& name, WebNavigationPolicy) OVERRIDE |
1229 { | 1197 { |
1230 m_createdWebView = FrameTestHelpers::createWebView(true, 0, 0); | 1198 return m_webViewHelper.initialize(true, 0, 0); |
1231 return m_createdWebView; | |
1232 } | 1199 } |
1233 | 1200 |
1234 // WebWidgetClient methods | 1201 // WebWidgetClient methods |
1235 virtual void didFocus() OVERRIDE | 1202 virtual void didFocus() OVERRIDE |
1236 { | 1203 { |
1237 m_didFocusCalled = true; | 1204 m_didFocusCalled = true; |
1238 } | 1205 } |
1239 | 1206 |
1240 void close() | |
1241 { | |
1242 if (m_createdWebView) | |
1243 m_createdWebView->close(); | |
1244 } | |
1245 bool didFocusCalled() const { return m_didFocusCalled; } | 1207 bool didFocusCalled() const { return m_didFocusCalled; } |
1246 WebView* createdWebView() const { return m_createdWebView; } | 1208 WebView* createdWebView() const { return m_webViewHelper.webView(); } |
1247 | 1209 |
1248 private: | 1210 private: |
1249 WebView* m_createdWebView; | 1211 FrameTestHelpers::WebViewHelper m_webViewHelper; |
1250 bool m_didFocusCalled; | 1212 bool m_didFocusCalled; |
1251 }; | 1213 }; |
1252 | 1214 |
1253 TEST_F(WebViewTest, FocusExistingFrameOnNavigate) | 1215 TEST_F(WebViewTest, FocusExistingFrameOnNavigate) |
1254 { | 1216 { |
1255 ViewCreatingWebViewClient client; | 1217 ViewCreatingWebViewClient client; |
1256 WebViewImpl* webViewImpl = toWebViewImpl(FrameTestHelpers::createWebView(tru
e, 0, &client)); | 1218 FrameTestHelpers::WebViewHelper m_webViewHelper; |
| 1219 WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initialize(true, 0,
&client)); |
1257 webViewImpl->page()->settings().setJavaScriptCanOpenWindowsAutomatically(tru
e); | 1220 webViewImpl->page()->settings().setJavaScriptCanOpenWindowsAutomatically(tru
e); |
1258 WebFrameImpl* frame = toWebFrameImpl(webViewImpl->mainFrame()); | 1221 WebFrameImpl* frame = toWebFrameImpl(webViewImpl->mainFrame()); |
1259 frame->setName("_start"); | 1222 frame->setName("_start"); |
1260 | 1223 |
1261 // Make a request that will open a new window | 1224 // Make a request that will open a new window |
1262 WebURLRequest webURLRequest; | 1225 WebURLRequest webURLRequest; |
1263 webURLRequest.initialize(); | 1226 webURLRequest.initialize(); |
1264 WebCore::FrameLoadRequest request(0, webURLRequest.toResourceRequest(), WTF:
:String("_blank")); | 1227 WebCore::FrameLoadRequest request(0, webURLRequest.toResourceRequest(), WTF:
:String("_blank")); |
1265 webViewImpl->page()->mainFrame()->loader()->load(request); | 1228 webViewImpl->page()->mainFrame()->loader()->load(request); |
1266 ASSERT_TRUE(client.createdWebView()); | 1229 ASSERT_TRUE(client.createdWebView()); |
1267 EXPECT_FALSE(client.didFocusCalled()); | 1230 EXPECT_FALSE(client.didFocusCalled()); |
1268 | 1231 |
1269 // Make a request from the new window that will navigate the original window
. The original window should be focused. | 1232 // Make a request from the new window that will navigate the original window
. The original window should be focused. |
1270 WebURLRequest webURLRequestWithTargetStart; | 1233 WebURLRequest webURLRequestWithTargetStart; |
1271 webURLRequestWithTargetStart.initialize(); | 1234 webURLRequestWithTargetStart.initialize(); |
1272 WebCore::FrameLoadRequest requestWithTargetStart(0, webURLRequestWithTargetS
tart.toResourceRequest(), WTF::String("_start")); | 1235 WebCore::FrameLoadRequest requestWithTargetStart(0, webURLRequestWithTargetS
tart.toResourceRequest(), WTF::String("_start")); |
1273 toWebViewImpl(client.createdWebView())->page()->mainFrame()->loader()->load(
requestWithTargetStart); | 1236 toWebViewImpl(client.createdWebView())->page()->mainFrame()->loader()->load(
requestWithTargetStart); |
1274 EXPECT_TRUE(client.didFocusCalled()); | 1237 EXPECT_TRUE(client.didFocusCalled()); |
1275 | 1238 |
1276 client.close(); | 1239 m_webViewHelper.reset(); // Remove dependency on locally scoped client. |
1277 webViewImpl->close(); | |
1278 } | 1240 } |
1279 | 1241 |
1280 } | 1242 } |
OLD | NEW |