| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 TEST_F(WebViewTest, CopyImageAt) | 222 TEST_F(WebViewTest, CopyImageAt) |
| 223 { | 223 { |
| 224 std::string url = m_baseURL + "canvas-copy-image.html"; | 224 std::string url = m_baseURL + "canvas-copy-image.html"; |
| 225 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html")
; | 225 URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html")
; |
| 226 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); | 226 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0); |
| 227 webView->resize(WebSize(400, 400)); | 227 webView->resize(WebSize(400, 400)); |
| 228 webView->copyImageAt(WebPoint(50, 50)); | 228 webView->copyImageAt(WebPoint(50, 50)); |
| 229 | 229 |
| 230 blink::WebData data = blink::Platform::current()->clipboard()->readImage(bli
nk::WebClipboard::Buffer()); | 230 WebData data = Platform::current()->clipboard()->readImage(WebClipboard::Buf
fer()); |
| 231 blink::WebImage image = blink::WebImage::fromData(data, WebSize()); | 231 WebImage image = WebImage::fromData(data, WebSize()); |
| 232 | 232 |
| 233 SkAutoLockPixels autoLock(image.getSkBitmap()); | 233 SkAutoLockPixels autoLock(image.getSkBitmap()); |
| 234 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0)
); | 234 EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0)
); |
| 235 }; | 235 }; |
| 236 | 236 |
| 237 TEST_F(WebViewTest, SetBaseBackgroundColor) | 237 TEST_F(WebViewTest, SetBaseBackgroundColor) |
| 238 { | 238 { |
| 239 const WebColor kWhite = 0xFFFFFFFF; | 239 const WebColor kWhite = 0xFFFFFFFF; |
| 240 const WebColor kBlue = 0xFF0000FF; | 240 const WebColor kBlue = 0xFF0000FF; |
| 241 const WebColor kDarkCyan = 0xFF227788; | 241 const WebColor kDarkCyan = 0xFF227788; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 258 | 258 |
| 259 webView->setBaseBackgroundColor(kTranslucentPutty); | 259 webView->setBaseBackgroundColor(kTranslucentPutty); |
| 260 // Expected: red (50% alpha) blended atop kTranslucentPutty. Note the alpha. | 260 // Expected: red (50% alpha) blended atop kTranslucentPutty. Note the alpha. |
| 261 EXPECT_EQ(0xBFE93B32, webView->backgroundColor()); | 261 EXPECT_EQ(0xBFE93B32, webView->backgroundColor()); |
| 262 | 262 |
| 263 webView->setBaseBackgroundColor(kTransparent); | 263 webView->setBaseBackgroundColor(kTransparent); |
| 264 FrameTestHelpers::loadHTMLString(webView->mainFrame(), "<html><head><style>b
ody {background-color:transparent}</style></head></html>", baseURL); | 264 FrameTestHelpers::loadHTMLString(webView->mainFrame(), "<html><head><style>b
ody {background-color:transparent}</style></head></html>", baseURL); |
| 265 // Expected: transparent on top of kTransparent will still be transparent. | 265 // Expected: transparent on top of kTransparent will still be transparent. |
| 266 EXPECT_EQ(kTransparent, webView->backgroundColor()); | 266 EXPECT_EQ(kTransparent, webView->backgroundColor()); |
| 267 | 267 |
| 268 blink::LocalFrame* frame = webView->mainFrameImpl()->frame(); | 268 LocalFrame* frame = webView->mainFrameImpl()->frame(); |
| 269 | 269 |
| 270 // Creating a new frame view with the background color having 0 alpha. | 270 // Creating a new frame view with the background color having 0 alpha. |
| 271 frame->createView(blink::IntSize(1024, 768), blink::Color::transparent, true
); | 271 frame->createView(IntSize(1024, 768), Color::transparent, true); |
| 272 EXPECT_EQ(kTransparent, frame->view()->baseBackgroundColor()); | 272 EXPECT_EQ(kTransparent, frame->view()->baseBackgroundColor()); |
| 273 | 273 |
| 274 blink::Color kTransparentRed(100, 0, 0, 0); | 274 Color kTransparentRed(100, 0, 0, 0); |
| 275 frame->createView(blink::IntSize(1024, 768), kTransparentRed, true); | 275 frame->createView(IntSize(1024, 768), kTransparentRed, true); |
| 276 EXPECT_EQ(kTransparentRed, frame->view()->baseBackgroundColor()); | 276 EXPECT_EQ(kTransparentRed, frame->view()->baseBackgroundColor()); |
| 277 } | 277 } |
| 278 | 278 |
| 279 TEST_F(WebViewTest, SetBaseBackgroundColorBeforeMainFrame) | 279 TEST_F(WebViewTest, SetBaseBackgroundColorBeforeMainFrame) |
| 280 { | 280 { |
| 281 const WebColor kBlue = 0xFF0000FF; | 281 const WebColor kBlue = 0xFF0000FF; |
| 282 FrameTestHelpers::TestWebViewClient webViewClient; | 282 FrameTestHelpers::TestWebViewClient webViewClient; |
| 283 WebView* webView = WebViewImpl::create(&webViewClient); | 283 WebView* webView = WebViewImpl::create(&webViewClient); |
| 284 EXPECT_NE(kBlue, webView->backgroundColor()); | 284 EXPECT_NE(kBlue, webView->backgroundColor()); |
| 285 // webView does not have a frame yet, but we should still be able to set the
background color. | 285 // webView does not have a frame yet, but we should still be able to set the
background color. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 303 webView->settings()->setShouldClearDocumentBackground(false); | 303 webView->settings()->setShouldClearDocumentBackground(false); |
| 304 webView->resize(WebSize(kWidth, kHeight)); | 304 webView->resize(WebSize(kWidth, kHeight)); |
| 305 webView->layout(); | 305 webView->layout(); |
| 306 | 306 |
| 307 // Set canvas background to red with alpha. | 307 // Set canvas background to red with alpha. |
| 308 SkBitmap bitmap; | 308 SkBitmap bitmap; |
| 309 ASSERT_TRUE(bitmap.allocN32Pixels(kWidth, kHeight)); | 309 ASSERT_TRUE(bitmap.allocN32Pixels(kWidth, kHeight)); |
| 310 SkCanvas canvas(bitmap); | 310 SkCanvas canvas(bitmap); |
| 311 canvas.clear(kAlphaRed); | 311 canvas.clear(kAlphaRed); |
| 312 | 312 |
| 313 blink::GraphicsContext context(&canvas); | 313 GraphicsContext context(&canvas); |
| 314 | 314 |
| 315 // Paint the root of the main frame in the way that CompositedLayerMapping w
ould. | 315 // Paint the root of the main frame in the way that CompositedLayerMapping w
ould. |
| 316 blink::FrameView* view = m_webViewHelper.webViewImpl()->mainFrameImpl()->fra
meView(); | 316 FrameView* view = m_webViewHelper.webViewImpl()->mainFrameImpl()->frameView(
); |
| 317 blink::RenderLayer* rootLayer = view->renderView()->layer(); | 317 RenderLayer* rootLayer = view->renderView()->layer(); |
| 318 blink::IntRect paintRect(0, 0, kWidth, kHeight); | 318 IntRect paintRect(0, 0, kWidth, kHeight); |
| 319 blink::LayerPaintingInfo paintingInfo(rootLayer, paintRect, blink::PaintBeha
viorNormal, blink::LayoutSize()); | 319 LayerPaintingInfo paintingInfo(rootLayer, paintRect, PaintBehaviorNormal, La
youtSize()); |
| 320 rootLayer->paintLayerContents(&context, paintingInfo, blink::PaintLayerPaint
ingCompositingAllPhases); | 320 rootLayer->paintLayerContents(&context, paintingInfo, PaintLayerPaintingComp
ositingAllPhases); |
| 321 | 321 |
| 322 // The result should be a blend of red and green. | 322 // The result should be a blend of red and green. |
| 323 SkColor color = bitmap.getColor(kWidth / 2, kHeight / 2); | 323 SkColor color = bitmap.getColor(kWidth / 2, kHeight / 2); |
| 324 EXPECT_TRUE(blink::redChannel(color)); | 324 EXPECT_TRUE(redChannel(color)); |
| 325 EXPECT_TRUE(blink::greenChannel(color)); | 325 EXPECT_TRUE(greenChannel(color)); |
| 326 } | 326 } |
| 327 | 327 |
| 328 TEST_F(WebViewTest, FocusIsInactive) | 328 TEST_F(WebViewTest, FocusIsInactive) |
| 329 { | 329 { |
| 330 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "visible_iframe.html"); | 330 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "visible_iframe.html"); |
| 331 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "visible_if
rame.html"); | 331 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "visible_if
rame.html"); |
| 332 | 332 |
| 333 webView->setFocus(true); | 333 webView->setFocus(true); |
| 334 webView->setIsActive(true); | 334 webView->setIsActive(true); |
| 335 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 335 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 336 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); | 336 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); |
| 337 | 337 |
| 338 blink::HTMLDocument* document = blink::toHTMLDocument(frame->frame()->docume
nt()); | 338 HTMLDocument* document = toHTMLDocument(frame->frame()->document()); |
| 339 EXPECT_TRUE(document->hasFocus()); | 339 EXPECT_TRUE(document->hasFocus()); |
| 340 webView->setFocus(false); | 340 webView->setFocus(false); |
| 341 webView->setIsActive(false); | 341 webView->setIsActive(false); |
| 342 EXPECT_FALSE(document->hasFocus()); | 342 EXPECT_FALSE(document->hasFocus()); |
| 343 webView->setFocus(true); | 343 webView->setFocus(true); |
| 344 webView->setIsActive(true); | 344 webView->setIsActive(true); |
| 345 EXPECT_TRUE(document->hasFocus()); | 345 EXPECT_TRUE(document->hasFocus()); |
| 346 webView->setFocus(true); | 346 webView->setFocus(true); |
| 347 webView->setIsActive(false); | 347 webView->setIsActive(false); |
| 348 EXPECT_FALSE(document->hasFocus()); | 348 EXPECT_FALSE(document->hasFocus()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 int expectedWidth, int expectedHeight, | 395 int expectedWidth, int expectedHeight, |
| 396 HorizontalScrollbarState expectedHorizontalStat
e, VerticalScrollbarState expectedVerticalState) | 396 HorizontalScrollbarState expectedHorizontalStat
e, VerticalScrollbarState expectedVerticalState) |
| 397 { | 397 { |
| 398 AutoResizeWebViewClient client; | 398 AutoResizeWebViewClient client; |
| 399 std::string url = m_baseURL + "specify_size.html?" + pageWidth + ":" + pageH
eight; | 399 std::string url = m_baseURL + "specify_size.html?" + pageWidth + ":" + pageH
eight; |
| 400 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); | 400 URLTestHelpers::registerMockedURLLoad(toKURL(url), "specify_size.html"); |
| 401 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client); | 401 WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client); |
| 402 client.testData().setWebView(webView); | 402 client.testData().setWebView(webView); |
| 403 | 403 |
| 404 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 404 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 405 blink::FrameView* frameView = frame->frame()->view(); | 405 FrameView* frameView = frame->frame()->view(); |
| 406 frameView->layout(); | 406 frameView->layout(); |
| 407 EXPECT_FALSE(frameView->layoutPending()); | 407 EXPECT_FALSE(frameView->layoutPending()); |
| 408 EXPECT_FALSE(frameView->needsLayout()); | 408 EXPECT_FALSE(frameView->needsLayout()); |
| 409 | 409 |
| 410 webView->enableAutoResizeMode(minAutoResize, maxAutoResize); | 410 webView->enableAutoResizeMode(minAutoResize, maxAutoResize); |
| 411 EXPECT_TRUE(frameView->layoutPending()); | 411 EXPECT_TRUE(frameView->layoutPending()); |
| 412 EXPECT_TRUE(frameView->needsLayout()); | 412 EXPECT_TRUE(frameView->needsLayout()); |
| 413 frameView->layout(); | 413 frameView->layout(); |
| 414 | 414 |
| 415 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); | 415 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 info = webView->textInputInfo(); | 668 info = webView->textInputInfo(); |
| 669 EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); | 669 EXPECT_EQ("ijklmnopqrstuvwxyz", std::string(info.value.utf8().data())); |
| 670 } | 670 } |
| 671 | 671 |
| 672 TEST_F(WebViewTest, SetCompositionFromExistingText) | 672 TEST_F(WebViewTest, SetCompositionFromExistingText) |
| 673 { | 673 { |
| 674 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); | 674 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("input_field_populated.html")); |
| 675 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); | 675 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel
d_populated.html"); |
| 676 webView->setInitialFocus(false); | 676 webView->setInitialFocus(false); |
| 677 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 677 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
| 678 underlines[0] = blink::WebCompositionUnderline(0, 4, 0, false, 0); | 678 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
| 679 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 679 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 680 frame->setEditableSelectionOffsets(4, 10); | 680 frame->setEditableSelectionOffsets(4, 10); |
| 681 frame->setCompositionFromExistingText(8, 12, underlines); | 681 frame->setCompositionFromExistingText(8, 12, underlines); |
| 682 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); | 682 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); |
| 683 EXPECT_EQ(8u, underlineResults[0].startOffset); | 683 EXPECT_EQ(8u, underlineResults[0].startOffset); |
| 684 EXPECT_EQ(12u, underlineResults[0].endOffset); | 684 EXPECT_EQ(12u, underlineResults[0].endOffset); |
| 685 WebTextInputInfo info = webView->textInputInfo(); | 685 WebTextInputInfo info = webView->textInputInfo(); |
| 686 EXPECT_EQ(4, info.selectionStart); | 686 EXPECT_EQ(4, info.selectionStart); |
| 687 EXPECT_EQ(10, info.selectionEnd); | 687 EXPECT_EQ(10, info.selectionEnd); |
| 688 EXPECT_EQ(8, info.compositionStart); | 688 EXPECT_EQ(8, info.compositionStart); |
| 689 EXPECT_EQ(12, info.compositionEnd); | 689 EXPECT_EQ(12, info.compositionEnd); |
| 690 WebVector<WebCompositionUnderline> emptyUnderlines; | 690 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 691 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); | 691 frame->setCompositionFromExistingText(0, 0, emptyUnderlines); |
| 692 info = webView->textInputInfo(); | 692 info = webView->textInputInfo(); |
| 693 EXPECT_EQ(4, info.selectionStart); | 693 EXPECT_EQ(4, info.selectionStart); |
| 694 EXPECT_EQ(10, info.selectionEnd); | 694 EXPECT_EQ(10, info.selectionEnd); |
| 695 EXPECT_EQ(-1, info.compositionStart); | 695 EXPECT_EQ(-1, info.compositionStart); |
| 696 EXPECT_EQ(-1, info.compositionEnd); | 696 EXPECT_EQ(-1, info.compositionEnd); |
| 697 } | 697 } |
| 698 | 698 |
| 699 TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea) | 699 TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea) |
| 700 { | 700 { |
| 701 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("text_area_populated.html")); | 701 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("text_area_populated.html")); |
| 702 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_
populated.html"); | 702 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_
populated.html"); |
| 703 webView->setInitialFocus(false); | 703 webView->setInitialFocus(false); |
| 704 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); | 704 WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1)); |
| 705 underlines[0] = blink::WebCompositionUnderline(0, 4, 0, false, 0); | 705 underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0); |
| 706 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 706 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 707 frame->setEditableSelectionOffsets(27, 27); | 707 frame->setEditableSelectionOffsets(27, 27); |
| 708 std::string newLineText("\n"); | 708 std::string newLineText("\n"); |
| 709 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); | 709 webView->confirmComposition(WebString::fromUTF8(newLineText.c_str())); |
| 710 WebTextInputInfo info = webView->textInputInfo(); | 710 WebTextInputInfo info = webView->textInputInfo(); |
| 711 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); | 711 EXPECT_EQ("0123456789abcdefghijklmnopq\nrstuvwxyz", std::string(info.value.u
tf8().data())); |
| 712 | 712 |
| 713 frame->setEditableSelectionOffsets(31, 31); | 713 frame->setEditableSelectionOffsets(31, 31); |
| 714 frame->setCompositionFromExistingText(30, 34, underlines); | 714 frame->setCompositionFromExistingText(30, 34, underlines); |
| 715 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); | 715 WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)
->compositionUnderlines(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 webViewImpl->layout(); | 819 webViewImpl->layout(); |
| 820 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 820 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
| 821 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 821 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 822 | 822 |
| 823 // Make the page scale and scroll with the given paremeters. | 823 // Make the page scale and scroll with the given paremeters. |
| 824 webViewImpl->setPageScaleFactor(2.0f); | 824 webViewImpl->setPageScaleFactor(2.0f); |
| 825 webViewImpl->setMainFrameScrollOffset(WebPoint(116, 84)); | 825 webViewImpl->setMainFrameScrollOffset(WebPoint(116, 84)); |
| 826 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 826 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 827 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); | 827 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); |
| 828 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); | 828 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); |
| 829 blink::LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFr
ame()); | 829 LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFrame()); |
| 830 mainFrameLocal->loader().saveScrollState(); | 830 mainFrameLocal->loader().saveScrollState(); |
| 831 EXPECT_EQ(2.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); | 831 EXPECT_EQ(2.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); |
| 832 EXPECT_EQ(116, mainFrameLocal->loader().currentItem()->scrollPoint().x()); | 832 EXPECT_EQ(116, mainFrameLocal->loader().currentItem()->scrollPoint().x()); |
| 833 EXPECT_EQ(84, mainFrameLocal->loader().currentItem()->scrollPoint().y()); | 833 EXPECT_EQ(84, mainFrameLocal->loader().currentItem()->scrollPoint().y()); |
| 834 | 834 |
| 835 // Confirm that resetting the page state resets the saved scroll position. | 835 // Confirm that resetting the page state resets the saved scroll position. |
| 836 // The HistoryController treats a page scale factor of 0.0f as special and a
voids | 836 // The HistoryController treats a page scale factor of 0.0f as special and a
voids |
| 837 // restoring it to the WebView. | 837 // restoring it to the WebView. |
| 838 webViewImpl->resetScrollAndScaleState(); | 838 webViewImpl->resetScrollAndScaleState(); |
| 839 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); | 839 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); |
| 840 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 840 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
| 841 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 841 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 842 EXPECT_EQ(0.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); | 842 EXPECT_EQ(0.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor()); |
| 843 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().x()); | 843 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().x()); |
| 844 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().y()); | 844 EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().y()); |
| 845 } | 845 } |
| 846 | 846 |
| 847 TEST_F(WebViewTest, BackForwardRestoreScroll) | 847 TEST_F(WebViewTest, BackForwardRestoreScroll) |
| 848 { | 848 { |
| 849 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("back_forward_restore_scroll.html")); | 849 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("back_forward_restore_scroll.html")); |
| 850 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "ba
ck_forward_restore_scroll.html"); | 850 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "ba
ck_forward_restore_scroll.html"); |
| 851 webViewImpl->resize(WebSize(640, 480)); | 851 webViewImpl->resize(WebSize(640, 480)); |
| 852 webViewImpl->layout(); | 852 webViewImpl->layout(); |
| 853 | 853 |
| 854 // Emulate a user scroll | 854 // Emulate a user scroll |
| 855 webViewImpl->setMainFrameScrollOffset(WebPoint(0, 900)); | 855 webViewImpl->setMainFrameScrollOffset(WebPoint(0, 900)); |
| 856 blink::LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFr
ame()); | 856 LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFrame()); |
| 857 RefPtr<blink::HistoryItem> item1 = mainFrameLocal->loader().currentItem(); | 857 RefPtr<HistoryItem> item1 = mainFrameLocal->loader().currentItem(); |
| 858 | 858 |
| 859 // Click an anchor | 859 // Click an anchor |
| 860 mainFrameLocal->loader().load(blink::FrameLoadRequest(mainFrameLocal->docume
nt(), blink::ResourceRequest(mainFrameLocal->document()->completeURL("#a")))); | 860 mainFrameLocal->loader().load(FrameLoadRequest(mainFrameLocal->document(), R
esourceRequest(mainFrameLocal->document()->completeURL("#a")))); |
| 861 RefPtr<blink::HistoryItem> item2 = mainFrameLocal->loader().currentItem(); | 861 RefPtr<HistoryItem> item2 = mainFrameLocal->loader().currentItem(); |
| 862 | 862 |
| 863 // Go back, then forward, then back again. | 863 // Go back, then forward, then back again. |
| 864 mainFrameLocal->loader().loadHistoryItem(item1.get(), blink::HistorySameDocu
mentLoad); | 864 mainFrameLocal->loader().loadHistoryItem(item1.get(), HistorySameDocumentLoa
d); |
| 865 mainFrameLocal->loader().loadHistoryItem(item2.get(), blink::HistorySameDocu
mentLoad); | 865 mainFrameLocal->loader().loadHistoryItem(item2.get(), HistorySameDocumentLoa
d); |
| 866 mainFrameLocal->loader().loadHistoryItem(item1.get(), blink::HistorySameDocu
mentLoad); | 866 mainFrameLocal->loader().loadHistoryItem(item1.get(), HistorySameDocumentLoa
d); |
| 867 | 867 |
| 868 // Click a different anchor | 868 // Click a different anchor |
| 869 mainFrameLocal->loader().load(blink::FrameLoadRequest(mainFrameLocal->docume
nt(), blink::ResourceRequest(mainFrameLocal->document()->completeURL("#b")))); | 869 mainFrameLocal->loader().load(FrameLoadRequest(mainFrameLocal->document(), R
esourceRequest(mainFrameLocal->document()->completeURL("#b")))); |
| 870 RefPtr<blink::HistoryItem> item3 = mainFrameLocal->loader().currentItem(); | 870 RefPtr<HistoryItem> item3 = mainFrameLocal->loader().currentItem(); |
| 871 | 871 |
| 872 // Go back, then forward. The scroll position should be properly set on the
forward navigation. | 872 // Go back, then forward. The scroll position should be properly set on the
forward navigation. |
| 873 mainFrameLocal->loader().loadHistoryItem(item1.get(), blink::HistorySameDocu
mentLoad); | 873 mainFrameLocal->loader().loadHistoryItem(item1.get(), HistorySameDocumentLoa
d); |
| 874 mainFrameLocal->loader().loadHistoryItem(item3.get(), blink::HistorySameDocu
mentLoad); | 874 mainFrameLocal->loader().loadHistoryItem(item3.get(), HistorySameDocumentLoa
d); |
| 875 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 875 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
| 876 EXPECT_GT(webViewImpl->mainFrame()->scrollOffset().height, 2000); | 876 EXPECT_GT(webViewImpl->mainFrame()->scrollOffset().height, 2000); |
| 877 } | 877 } |
| 878 | 878 |
| 879 class EnterFullscreenWebViewClient : public FrameTestHelpers::TestWebViewClient
{ | 879 class EnterFullscreenWebViewClient : public FrameTestHelpers::TestWebViewClient
{ |
| 880 public: | 880 public: |
| 881 // WebViewClient methods | 881 // WebViewClient methods |
| 882 virtual bool enterFullScreen() { return true; } | 882 virtual bool enterFullScreen() { return true; } |
| 883 virtual void exitFullScreen() { } | 883 virtual void exitFullScreen() { } |
| 884 }; | 884 }; |
| 885 | 885 |
| 886 | 886 |
| 887 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) | 887 TEST_F(WebViewTest, EnterFullscreenResetScrollAndScaleState) |
| 888 { | 888 { |
| 889 EnterFullscreenWebViewClient client; | 889 EnterFullscreenWebViewClient client; |
| 890 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("hello_world.html")); | 890 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("hello_world.html")); |
| 891 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "he
llo_world.html", true, 0, &client); | 891 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "he
llo_world.html", true, 0, &client); |
| 892 webViewImpl->resize(WebSize(640, 480)); | 892 webViewImpl->resize(WebSize(640, 480)); |
| 893 webViewImpl->layout(); | 893 webViewImpl->layout(); |
| 894 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); | 894 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width); |
| 895 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); | 895 EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height); |
| 896 | 896 |
| 897 // Make the page scale and scroll with the given paremeters. | 897 // Make the page scale and scroll with the given paremeters. |
| 898 webViewImpl->setPageScaleFactor(2.0f); | 898 webViewImpl->setPageScaleFactor(2.0f); |
| 899 webViewImpl->setMainFrameScrollOffset(WebPoint(116, 84)); | 899 webViewImpl->setMainFrameScrollOffset(WebPoint(116, 84)); |
| 900 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 900 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 901 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); | 901 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); |
| 902 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); | 902 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); |
| 903 | 903 |
| 904 RefPtrWillBeRawPtr<blink::Element> element = static_cast<PassRefPtrWillBeRaw
Ptr<blink::Element> >(webViewImpl->mainFrame()->document().body()); | 904 RefPtrWillBeRawPtr<Element> element = static_cast<PassRefPtrWillBeRawPtr<Ele
ment> >(webViewImpl->mainFrame()->document().body()); |
| 905 webViewImpl->enterFullScreenForElement(element.get()); | 905 webViewImpl->enterFullScreenForElement(element.get()); |
| 906 webViewImpl->didEnterFullScreen(); | 906 webViewImpl->didEnterFullScreen(); |
| 907 | 907 |
| 908 // Page scale factor must be 1.0 during fullscreen for elements to be sized | 908 // Page scale factor must be 1.0 during fullscreen for elements to be sized |
| 909 // properly. | 909 // properly. |
| 910 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); | 910 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); |
| 911 | 911 |
| 912 // Make sure fullscreen nesting doesn't disrupt scroll/scale saving. | 912 // Make sure fullscreen nesting doesn't disrupt scroll/scale saving. |
| 913 RefPtrWillBeRawPtr<blink::Element> otherElement = static_cast<PassRefPtrWill
BeRawPtr<blink::Element> >(webViewImpl->mainFrame()->document().head()); | 913 RefPtrWillBeRawPtr<Element> otherElement = static_cast<PassRefPtrWillBeRawPt
r<Element> >(webViewImpl->mainFrame()->document().head()); |
| 914 webViewImpl->enterFullScreenForElement(otherElement.get()); | 914 webViewImpl->enterFullScreenForElement(otherElement.get()); |
| 915 | 915 |
| 916 // Confirm that exiting fullscreen restores the parameters. | 916 // Confirm that exiting fullscreen restores the parameters. |
| 917 webViewImpl->didExitFullScreen(); | 917 webViewImpl->didExitFullScreen(); |
| 918 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 918 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 919 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); | 919 EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width); |
| 920 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); | 920 EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height); |
| 921 | 921 |
| 922 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | 922 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
| 923 } | 923 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 941 bool m_printCalled; | 941 bool m_printCalled; |
| 942 }; | 942 }; |
| 943 | 943 |
| 944 | 944 |
| 945 TEST_F(WebViewTest, PrintWithXHRInFlight) | 945 TEST_F(WebViewTest, PrintWithXHRInFlight) |
| 946 { | 946 { |
| 947 PrintWebViewClient client; | 947 PrintWebViewClient client; |
| 948 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("print_with_xhr_inflight.html")); | 948 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("print_with_xhr_inflight.html")); |
| 949 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "pr
int_with_xhr_inflight.html", true, 0, &client); | 949 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "pr
int_with_xhr_inflight.html", true, 0, &client); |
| 950 | 950 |
| 951 ASSERT_EQ(blink::FrameStateComplete, toLocalFrame(webViewImpl->page()->mainF
rame())->loader().state()); | 951 ASSERT_EQ(FrameStateComplete, toLocalFrame(webViewImpl->page()->mainFrame())
->loader().state()); |
| 952 EXPECT_TRUE(client.printCalled()); | 952 EXPECT_TRUE(client.printCalled()); |
| 953 m_webViewHelper.reset(); | 953 m_webViewHelper.reset(); |
| 954 } | 954 } |
| 955 | 955 |
| 956 class DropTask : public WebThread::Task { | 956 class DropTask : public WebThread::Task { |
| 957 public: | 957 public: |
| 958 explicit DropTask(WebView* webView) : m_webView(webView) | 958 explicit DropTask(WebView* webView) : m_webView(webView) |
| 959 { | 959 { |
| 960 } | 960 } |
| 961 | 961 |
| 962 virtual void run() OVERRIDE | 962 virtual void run() OVERRIDE |
| 963 { | 963 { |
| 964 const WebPoint clientPoint(0, 0); | 964 const WebPoint clientPoint(0, 0); |
| 965 const WebPoint screenPoint(0, 0); | 965 const WebPoint screenPoint(0, 0); |
| 966 m_webView->dragTargetDrop(clientPoint, screenPoint, 0); | 966 m_webView->dragTargetDrop(clientPoint, screenPoint, 0); |
| 967 } | 967 } |
| 968 | 968 |
| 969 private: | 969 private: |
| 970 WebView* const m_webView; | 970 WebView* const m_webView; |
| 971 }; | 971 }; |
| 972 static void DragAndDropURL(WebViewImpl* webView, const std::string& url) | 972 static void DragAndDropURL(WebViewImpl* webView, const std::string& url) |
| 973 { | 973 { |
| 974 blink::WebDragData dragData; | 974 WebDragData dragData; |
| 975 dragData.initialize(); | 975 dragData.initialize(); |
| 976 | 976 |
| 977 WebDragData::Item item; | 977 WebDragData::Item item; |
| 978 item.storageType = WebDragData::Item::StorageTypeString; | 978 item.storageType = WebDragData::Item::StorageTypeString; |
| 979 item.stringType = "text/uri-list"; | 979 item.stringType = "text/uri-list"; |
| 980 item.stringData = WebString::fromUTF8(url); | 980 item.stringData = WebString::fromUTF8(url); |
| 981 dragData.addItem(item); | 981 dragData.addItem(item); |
| 982 | 982 |
| 983 const WebPoint clientPoint(0, 0); | 983 const WebPoint clientPoint(0, 0); |
| 984 const WebPoint screenPoint(0, 0); | 984 const WebPoint screenPoint(0, 0); |
| 985 webView->dragTargetDragEnter(dragData, clientPoint, screenPoint, blink::WebD
ragOperationCopy, 0); | 985 webView->dragTargetDragEnter(dragData, clientPoint, screenPoint, WebDragOper
ationCopy, 0); |
| 986 Platform::current()->currentThread()->postTask(new DropTask(webView)); | 986 Platform::current()->currentThread()->postTask(new DropTask(webView)); |
| 987 FrameTestHelpers::pumpPendingRequestsDoNotUse(webView->mainFrame()); | 987 FrameTestHelpers::pumpPendingRequestsDoNotUse(webView->mainFrame()); |
| 988 } | 988 } |
| 989 | 989 |
| 990 TEST_F(WebViewTest, DragDropURL) | 990 TEST_F(WebViewTest, DragDropURL) |
| 991 { | 991 { |
| 992 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "foo.html"); | 992 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "foo.html"); |
| 993 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "bar.html"); | 993 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "bar.html"); |
| 994 | 994 |
| 995 const std::string fooUrl = m_baseURL + "foo.html"; | 995 const std::string fooUrl = m_baseURL + "foo.html"; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 private: | 1051 private: |
| 1052 bool m_contentDetectionRequested; | 1052 bool m_contentDetectionRequested; |
| 1053 bool m_pendingIntentsCancelled; | 1053 bool m_pendingIntentsCancelled; |
| 1054 WebURL m_scheduledIntentURL; | 1054 WebURL m_scheduledIntentURL; |
| 1055 WebContentDetectionResult m_contentDetectionResult; | 1055 WebContentDetectionResult m_contentDetectionResult; |
| 1056 }; | 1056 }; |
| 1057 | 1057 |
| 1058 static bool tapElementById(WebView* webView, WebInputEvent::Type type, const Web
String& id) | 1058 static bool tapElementById(WebView* webView, WebInputEvent::Type type, const Web
String& id) |
| 1059 { | 1059 { |
| 1060 ASSERT(webView); | 1060 ASSERT(webView); |
| 1061 RefPtrWillBeRawPtr<blink::Element> element = static_cast<PassRefPtrWillBeRaw
Ptr<blink::Element> >(webView->mainFrame()->document().getElementById(id)); | 1061 RefPtrWillBeRawPtr<Element> element = static_cast<PassRefPtrWillBeRawPtr<Ele
ment> >(webView->mainFrame()->document().getElementById(id)); |
| 1062 if (!element) | 1062 if (!element) |
| 1063 return false; | 1063 return false; |
| 1064 | 1064 |
| 1065 element->scrollIntoViewIfNeeded(); | 1065 element->scrollIntoViewIfNeeded(); |
| 1066 blink::IntPoint center = element->screenRect().center(); | 1066 IntPoint center = element->screenRect().center(); |
| 1067 | 1067 |
| 1068 WebGestureEvent event; | 1068 WebGestureEvent event; |
| 1069 event.type = type; | 1069 event.type = type; |
| 1070 event.x = center.x(); | 1070 event.x = center.x(); |
| 1071 event.y = center.y(); | 1071 event.y = center.y(); |
| 1072 | 1072 |
| 1073 webView->handleInputEvent(event); | 1073 webView->handleInputEvent(event); |
| 1074 runPendingTasks(); | 1074 runPendingTasks(); |
| 1075 return true; | 1075 return true; |
| 1076 } | 1076 } |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 ViewCreatingWebViewClient client; | 1438 ViewCreatingWebViewClient client; |
| 1439 FrameTestHelpers::WebViewHelper m_webViewHelper; | 1439 FrameTestHelpers::WebViewHelper m_webViewHelper; |
| 1440 WebViewImpl* webViewImpl = m_webViewHelper.initialize(true, 0, &client); | 1440 WebViewImpl* webViewImpl = m_webViewHelper.initialize(true, 0, &client); |
| 1441 webViewImpl->page()->settings().setJavaScriptCanOpenWindowsAutomatically(tru
e); | 1441 webViewImpl->page()->settings().setJavaScriptCanOpenWindowsAutomatically(tru
e); |
| 1442 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame()); | 1442 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame()); |
| 1443 frame->setName("_start"); | 1443 frame->setName("_start"); |
| 1444 | 1444 |
| 1445 // Make a request that will open a new window | 1445 // Make a request that will open a new window |
| 1446 WebURLRequest webURLRequest; | 1446 WebURLRequest webURLRequest; |
| 1447 webURLRequest.initialize(); | 1447 webURLRequest.initialize(); |
| 1448 blink::FrameLoadRequest request(0, webURLRequest.toResourceRequest(), "_blan
k"); | 1448 FrameLoadRequest request(0, webURLRequest.toResourceRequest(), "_blank"); |
| 1449 toLocalFrame(webViewImpl->page()->mainFrame())->loader().load(request); | 1449 toLocalFrame(webViewImpl->page()->mainFrame())->loader().load(request); |
| 1450 ASSERT_TRUE(client.createdWebView()); | 1450 ASSERT_TRUE(client.createdWebView()); |
| 1451 EXPECT_FALSE(client.didFocusCalled()); | 1451 EXPECT_FALSE(client.didFocusCalled()); |
| 1452 | 1452 |
| 1453 // Make a request from the new window that will navigate the original window
. The original window should be focused. | 1453 // Make a request from the new window that will navigate the original window
. The original window should be focused. |
| 1454 WebURLRequest webURLRequestWithTargetStart; | 1454 WebURLRequest webURLRequestWithTargetStart; |
| 1455 webURLRequestWithTargetStart.initialize(); | 1455 webURLRequestWithTargetStart.initialize(); |
| 1456 blink::FrameLoadRequest requestWithTargetStart(0, webURLRequestWithTargetSta
rt.toResourceRequest(), "_start"); | 1456 FrameLoadRequest requestWithTargetStart(0, webURLRequestWithTargetStart.toRe
sourceRequest(), "_start"); |
| 1457 toLocalFrame(toWebViewImpl(client.createdWebView())->page()->mainFrame())->l
oader().load(requestWithTargetStart); | 1457 toLocalFrame(toWebViewImpl(client.createdWebView())->page()->mainFrame())->l
oader().load(requestWithTargetStart); |
| 1458 EXPECT_TRUE(client.didFocusCalled()); | 1458 EXPECT_TRUE(client.didFocusCalled()); |
| 1459 | 1459 |
| 1460 m_webViewHelper.reset(); // Remove dependency on locally scoped client. | 1460 m_webViewHelper.reset(); // Remove dependency on locally scoped client. |
| 1461 } | 1461 } |
| 1462 | 1462 |
| 1463 TEST_F(WebViewTest, DispatchesFocusOutFocusInOnViewToggleFocus) | 1463 TEST_F(WebViewTest, DispatchesFocusOutFocusInOnViewToggleFocus) |
| 1464 { | 1464 { |
| 1465 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "focusout_focusin_events.html"); | 1465 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), "focusout_focusin_events.html"); |
| 1466 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "focusout_f
ocusin_events.html", true, 0); | 1466 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "focusout_f
ocusin_events.html", true, 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1480 | 1480 |
| 1481 webView->setFocus(true); | 1481 webView->setFocus(true); |
| 1482 webView->setFocus(false); | 1482 webView->setFocus(false); |
| 1483 webView->setFocus(true); | 1483 webView->setFocus(true); |
| 1484 | 1484 |
| 1485 WebElement element = webView->mainFrame()->document().getElementById("messag
e"); | 1485 WebElement element = webView->mainFrame()->document().getElementById("messag
e"); |
| 1486 EXPECT_STREQ("DOMFocusOutDOMFocusIn", element.innerText().utf8().data()); | 1486 EXPECT_STREQ("DOMFocusOutDOMFocusIn", element.innerText().utf8().data()); |
| 1487 } | 1487 } |
| 1488 | 1488 |
| 1489 #if !ENABLE(INPUT_MULTIPLE_FIELDS_UI) | 1489 #if !ENABLE(INPUT_MULTIPLE_FIELDS_UI) |
| 1490 static void openDateTimeChooser(WebView* webView, blink::HTMLInputElement* input
Element) | 1490 static void openDateTimeChooser(WebView* webView, HTMLInputElement* inputElement
) |
| 1491 { | 1491 { |
| 1492 inputElement->focus(); | 1492 inputElement->focus(); |
| 1493 | 1493 |
| 1494 WebKeyboardEvent keyEvent; | 1494 WebKeyboardEvent keyEvent; |
| 1495 keyEvent.windowsKeyCode = blink::VKEY_SPACE; | 1495 keyEvent.windowsKeyCode = VKEY_SPACE; |
| 1496 keyEvent.type = WebInputEvent::RawKeyDown; | 1496 keyEvent.type = WebInputEvent::RawKeyDown; |
| 1497 keyEvent.setKeyIdentifierFromWindowsKeyCode(); | 1497 keyEvent.setKeyIdentifierFromWindowsKeyCode(); |
| 1498 webView->handleInputEvent(keyEvent); | 1498 webView->handleInputEvent(keyEvent); |
| 1499 | 1499 |
| 1500 keyEvent.type = WebInputEvent::KeyUp; | 1500 keyEvent.type = WebInputEvent::KeyUp; |
| 1501 webView->handleInputEvent(keyEvent); | 1501 webView->handleInputEvent(keyEvent); |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 TEST_F(WebViewTest, ChooseValueFromDateTimeChooser) | 1504 TEST_F(WebViewTest, ChooseValueFromDateTimeChooser) |
| 1505 { | 1505 { |
| 1506 DateTimeChooserWebViewClient client; | 1506 DateTimeChooserWebViewClient client; |
| 1507 std::string url = m_baseURL + "date_time_chooser.html"; | 1507 std::string url = m_baseURL + "date_time_chooser.html"; |
| 1508 URLTestHelpers::registerMockedURLLoad(toKURL(url), "date_time_chooser.html")
; | 1508 URLTestHelpers::registerMockedURLLoad(toKURL(url), "date_time_chooser.html")
; |
| 1509 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); | 1509 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); |
| 1510 | 1510 |
| 1511 blink::Document* document = webViewImpl->mainFrameImpl()->frame()->document(
); | 1511 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
| 1512 | 1512 |
| 1513 blink::HTMLInputElement* inputElement; | 1513 HTMLInputElement* inputElement; |
| 1514 | 1514 |
| 1515 inputElement = toHTMLInputElement(document->getElementById("date")); | 1515 inputElement = toHTMLInputElement(document->getElementById("date")); |
| 1516 openDateTimeChooser(webViewImpl, inputElement); | 1516 openDateTimeChooser(webViewImpl, inputElement); |
| 1517 client.chooserCompletion()->didChooseValue(0); | 1517 client.chooserCompletion()->didChooseValue(0); |
| 1518 client.clearChooserCompletion(); | 1518 client.clearChooserCompletion(); |
| 1519 EXPECT_STREQ("1970-01-01", inputElement->value().utf8().data()); | 1519 EXPECT_STREQ("1970-01-01", inputElement->value().utf8().data()); |
| 1520 | 1520 |
| 1521 openDateTimeChooser(webViewImpl, inputElement); | 1521 openDateTimeChooser(webViewImpl, inputElement); |
| 1522 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie
t_NaN()); | 1522 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie
t_NaN()); |
| 1523 client.clearChooserCompletion(); | 1523 client.clearChooserCompletion(); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called | 1722 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called |
| 1723 // accordingly for various calls to EventHandlerRegistry::did{Add|Remove| | 1723 // accordingly for various calls to EventHandlerRegistry::did{Add|Remove| |
| 1724 // RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made | 1724 // RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made |
| 1725 // correctly is the job of LayoutTests/fast/events/event-handler-count.html. | 1725 // correctly is the job of LayoutTests/fast/events/event-handler-count.html. |
| 1726 TEST_F(WebViewTest, HasTouchEventHandlers) | 1726 TEST_F(WebViewTest, HasTouchEventHandlers) |
| 1727 { | 1727 { |
| 1728 TouchEventHandlerWebViewClient client; | 1728 TouchEventHandlerWebViewClient client; |
| 1729 std::string url = m_baseURL + "has_touch_event_handlers.html"; | 1729 std::string url = m_baseURL + "has_touch_event_handlers.html"; |
| 1730 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); | 1730 URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers
.html"); |
| 1731 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); | 1731 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); |
| 1732 const blink::EventHandlerRegistry::EventHandlerClass touchEvent = blink::Eve
ntHandlerRegistry::TouchEvent; | 1732 const EventHandlerRegistry::EventHandlerClass touchEvent = EventHandlerRegis
try::TouchEvent; |
| 1733 | 1733 |
| 1734 // The page is initialized with at least one no-handlers call. | 1734 // The page is initialized with at least one no-handlers call. |
| 1735 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first | 1735 // In practice we get two such calls because WebViewHelper::initializeAndLoa
d first |
| 1736 // initializes and empty frame, and then loads a document into it, so there
are two | 1736 // initializes and empty frame, and then loads a document into it, so there
are two |
| 1737 // FrameLoader::commitProvisionalLoad calls. | 1737 // FrameLoader::commitProvisionalLoad calls. |
| 1738 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); | 1738 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); |
| 1739 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1739 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1740 | 1740 |
| 1741 // Adding the first document handler results in a has-handlers call. | 1741 // Adding the first document handler results in a has-handlers call. |
| 1742 blink::Document* document = webViewImpl->mainFrameImpl()->frame()->document(
); | 1742 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
| 1743 blink::EventHandlerRegistry* registry = &document->frameHost()->eventHandler
Registry(); | 1743 EventHandlerRegistry* registry = &document->frameHost()->eventHandlerRegistr
y(); |
| 1744 registry->didAddEventHandler(*document, touchEvent); | 1744 registry->didAddEventHandler(*document, touchEvent); |
| 1745 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1745 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1746 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1746 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1747 | 1747 |
| 1748 // Adding another handler has no effect. | 1748 // Adding another handler has no effect. |
| 1749 registry->didAddEventHandler(*document, touchEvent); | 1749 registry->didAddEventHandler(*document, touchEvent); |
| 1750 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1750 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1751 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1751 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1752 | 1752 |
| 1753 // Removing the duplicate handler has no effect. | 1753 // Removing the duplicate handler has no effect. |
| 1754 registry->didRemoveEventHandler(*document, touchEvent); | 1754 registry->didRemoveEventHandler(*document, touchEvent); |
| 1755 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1755 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1756 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1756 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1757 | 1757 |
| 1758 // Removing the final handler results in a no-handlers call. | 1758 // Removing the final handler results in a no-handlers call. |
| 1759 registry->didRemoveEventHandler(*document, touchEvent); | 1759 registry->didRemoveEventHandler(*document, touchEvent); |
| 1760 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1760 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1761 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1761 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1762 | 1762 |
| 1763 // Adding a handler on a div results in a has-handlers call. | 1763 // Adding a handler on a div results in a has-handlers call. |
| 1764 blink::Element* parentDiv = document->getElementById("parentdiv"); | 1764 Element* parentDiv = document->getElementById("parentdiv"); |
| 1765 ASSERT(parentDiv); | 1765 ASSERT(parentDiv); |
| 1766 registry->didAddEventHandler(*parentDiv, touchEvent); | 1766 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1767 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1767 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1768 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1768 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1769 | 1769 |
| 1770 // Adding a duplicate handler on the div, clearing all document handlers | 1770 // Adding a duplicate handler on the div, clearing all document handlers |
| 1771 // (of which there are none) and removing the extra handler on the div | 1771 // (of which there are none) and removing the extra handler on the div |
| 1772 // all have no effect. | 1772 // all have no effect. |
| 1773 registry->didAddEventHandler(*parentDiv, touchEvent); | 1773 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1774 registry->didRemoveAllEventHandlers(*document); | 1774 registry->didRemoveAllEventHandlers(*document); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1787 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1787 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1788 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1788 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1789 registry->didAddEventHandler(*parentDiv, touchEvent); | 1789 registry->didAddEventHandler(*parentDiv, touchEvent); |
| 1790 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1790 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1791 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1791 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1792 registry->didRemoveAllEventHandlers(*parentDiv); | 1792 registry->didRemoveAllEventHandlers(*parentDiv); |
| 1793 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1793 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1794 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1794 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1795 | 1795 |
| 1796 // Adding a handler inside of a child iframe results in a has-handlers call. | 1796 // Adding a handler inside of a child iframe results in a has-handlers call. |
| 1797 blink::Element* childFrame = document->getElementById("childframe"); | 1797 Element* childFrame = document->getElementById("childframe"); |
| 1798 ASSERT(childFrame); | 1798 ASSERT(childFrame); |
| 1799 blink::Document* childDocument = toHTMLIFrameElement(childFrame)->contentDoc
ument(); | 1799 Document* childDocument = toHTMLIFrameElement(childFrame)->contentDocument()
; |
| 1800 blink::Element* childDiv = childDocument->getElementById("childdiv"); | 1800 Element* childDiv = childDocument->getElementById("childdiv"); |
| 1801 ASSERT(childDiv); | 1801 ASSERT(childDiv); |
| 1802 registry->didAddEventHandler(*childDiv, touchEvent); | 1802 registry->didAddEventHandler(*childDiv, touchEvent); |
| 1803 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1803 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
| 1804 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1804 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
| 1805 | 1805 |
| 1806 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc | 1806 // Adding and clearing handlers in the parent doc or elsewhere in the child
doc |
| 1807 // has no impact. | 1807 // has no impact. |
| 1808 registry->didAddEventHandler(*document, touchEvent); | 1808 registry->didAddEventHandler(*document, touchEvent); |
| 1809 registry->didAddEventHandler(*childFrame, touchEvent); | 1809 registry->didAddEventHandler(*childFrame, touchEvent); |
| 1810 registry->didAddEventHandler(*childDocument, touchEvent); | 1810 registry->didAddEventHandler(*childDocument, touchEvent); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 // This test checks that deleting nodes which have only non-JS-registered touch | 1845 // This test checks that deleting nodes which have only non-JS-registered touch |
| 1846 // handlers also removes them from the event handler registry. Note that this | 1846 // handlers also removes them from the event handler registry. Note that this |
| 1847 // is different from detaching and re-attaching the same node, which is covered | 1847 // is different from detaching and re-attaching the same node, which is covered |
| 1848 // by layout tests under fast/events/. | 1848 // by layout tests under fast/events/. |
| 1849 TEST_F(WebViewTest, DeleteElementWithRegisteredHandler) | 1849 TEST_F(WebViewTest, DeleteElementWithRegisteredHandler) |
| 1850 { | 1850 { |
| 1851 std::string url = m_baseURL + "simple_div.html"; | 1851 std::string url = m_baseURL + "simple_div.html"; |
| 1852 URLTestHelpers::registerMockedURLLoad(toKURL(url), "simple_div.html"); | 1852 URLTestHelpers::registerMockedURLLoad(toKURL(url), "simple_div.html"); |
| 1853 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true); | 1853 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true); |
| 1854 | 1854 |
| 1855 RefPtrWillBePersistent<blink::Document> document = webViewImpl->mainFrameImp
l()->frame()->document(); | 1855 RefPtrWillBePersistent<Document> document = webViewImpl->mainFrameImpl()->fr
ame()->document(); |
| 1856 blink::Element* div = document->getElementById("div"); | 1856 Element* div = document->getElementById("div"); |
| 1857 blink::EventHandlerRegistry& registry = document->frameHost()->eventHandlerR
egistry(); | 1857 EventHandlerRegistry& registry = document->frameHost()->eventHandlerRegistry
(); |
| 1858 | 1858 |
| 1859 registry.didAddEventHandler(*div, blink::EventHandlerRegistry::ScrollEvent); | 1859 registry.didAddEventHandler(*div, EventHandlerRegistry::ScrollEvent); |
| 1860 EXPECT_TRUE(registry.hasEventHandlers(blink::EventHandlerRegistry::ScrollEve
nt)); | 1860 EXPECT_TRUE(registry.hasEventHandlers(EventHandlerRegistry::ScrollEvent)); |
| 1861 | 1861 |
| 1862 blink::TrackExceptionState exceptionState; | 1862 TrackExceptionState exceptionState; |
| 1863 div->remove(exceptionState); | 1863 div->remove(exceptionState); |
| 1864 #if ENABLE(OILPAN) | 1864 #if ENABLE(OILPAN) |
| 1865 // For oilpan we have to force a GC to ensure the event handlers have been r
emoved when | 1865 // For oilpan we have to force a GC to ensure the event handlers have been r
emoved when |
| 1866 // checking below. We do a precise GC (collectAllGarbage does not scan the s
tack) | 1866 // checking below. We do a precise GC (collectAllGarbage does not scan the s
tack) |
| 1867 // to ensure the div element dies. This is also why the Document is in a Per
sistent | 1867 // to ensure the div element dies. This is also why the Document is in a Per
sistent |
| 1868 // since we want that to stay around. | 1868 // since we want that to stay around. |
| 1869 Heap::collectAllGarbage(); | 1869 Heap::collectAllGarbage(); |
| 1870 #endif | 1870 #endif |
| 1871 EXPECT_FALSE(registry.hasEventHandlers(blink::EventHandlerRegistry::ScrollEv
ent)); | 1871 EXPECT_FALSE(registry.hasEventHandlers(EventHandlerRegistry::ScrollEvent)); |
| 1872 } | 1872 } |
| 1873 | 1873 |
| 1874 static WebRect ExpectedRootBounds(blink::Document* document, float scaleFactor) | 1874 static WebRect ExpectedRootBounds(Document* document, float scaleFactor) |
| 1875 { | 1875 { |
| 1876 blink::Element* element = document->getElementById("root"); | 1876 Element* element = document->getElementById("root"); |
| 1877 if (!element) | 1877 if (!element) |
| 1878 element = document->getElementById("target"); | 1878 element = document->getElementById("target"); |
| 1879 if (element->hasTagName(blink::HTMLNames::iframeTag)) | 1879 if (element->hasTagName(HTMLNames::iframeTag)) |
| 1880 return ExpectedRootBounds(toHTMLIFrameElement(element)->contentDocument(
), scaleFactor); | 1880 return ExpectedRootBounds(toHTMLIFrameElement(element)->contentDocument(
), scaleFactor); |
| 1881 | 1881 |
| 1882 blink::IntRect boundingBox; | 1882 IntRect boundingBox; |
| 1883 if (element->hasTagName(blink::HTMLNames::htmlTag)) | 1883 if (element->hasTagName(HTMLNames::htmlTag)) |
| 1884 boundingBox = blink::IntRect(blink::IntPoint(0, 0), document->frame()->v
iew()->contentsSize()); | 1884 boundingBox = IntRect(IntPoint(0, 0), document->frame()->view()->content
sSize()); |
| 1885 else | 1885 else |
| 1886 boundingBox = element->pixelSnappedBoundingBox(); | 1886 boundingBox = element->pixelSnappedBoundingBox(); |
| 1887 boundingBox = document->frame()->view()->contentsToWindow(boundingBox); | 1887 boundingBox = document->frame()->view()->contentsToWindow(boundingBox); |
| 1888 boundingBox.scale(scaleFactor); | 1888 boundingBox.scale(scaleFactor); |
| 1889 return boundingBox; | 1889 return boundingBox; |
| 1890 } | 1890 } |
| 1891 | 1891 |
| 1892 void WebViewTest::testSelectionRootBounds(const char* htmlFile, float pageScaleF
actor) | 1892 void WebViewTest::testSelectionRootBounds(const char* htmlFile, float pageScaleF
actor) |
| 1893 { | 1893 { |
| 1894 std::string url = m_baseURL + htmlFile; | 1894 std::string url = m_baseURL + htmlFile; |
| 1895 | 1895 |
| 1896 WebView* webView = m_webViewHelper.initializeAndLoad(url, true); | 1896 WebView* webView = m_webViewHelper.initializeAndLoad(url, true); |
| 1897 webView->resize(WebSize(640, 480)); | 1897 webView->resize(WebSize(640, 480)); |
| 1898 webView->setPageScaleFactor(pageScaleFactor); | 1898 webView->setPageScaleFactor(pageScaleFactor); |
| 1899 webView->layout(); | 1899 webView->layout(); |
| 1900 runPendingTasks(); | 1900 runPendingTasks(); |
| 1901 | 1901 |
| 1902 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 1902 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 1903 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); | 1903 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); |
| 1904 blink::HTMLDocument* document = blink::toHTMLDocument(frame->frame()->docume
nt()); | 1904 HTMLDocument* document = toHTMLDocument(frame->frame()->document()); |
| 1905 | 1905 |
| 1906 WebRect expectedRootBounds = ExpectedRootBounds(document, webView->pageScale
Factor()); | 1906 WebRect expectedRootBounds = ExpectedRootBounds(document, webView->pageScale
Factor()); |
| 1907 WebRect actualRootBounds; | 1907 WebRect actualRootBounds; |
| 1908 webView->getSelectionRootBounds(actualRootBounds); | 1908 webView->getSelectionRootBounds(actualRootBounds); |
| 1909 ASSERT_EQ(expectedRootBounds, actualRootBounds); | 1909 ASSERT_EQ(expectedRootBounds, actualRootBounds); |
| 1910 | 1910 |
| 1911 WebRect anchor, focus; | 1911 WebRect anchor, focus; |
| 1912 webView->selectionBounds(anchor, focus); | 1912 webView->selectionBounds(anchor, focus); |
| 1913 blink::IntRect expectedIntRect = expectedRootBounds; | 1913 IntRect expectedIntRect = expectedRootBounds; |
| 1914 ASSERT_TRUE(expectedIntRect.contains(anchor)); | 1914 ASSERT_TRUE(expectedIntRect.contains(anchor)); |
| 1915 // The "overflow" tests have the focus boundary outside of the element box. | 1915 // The "overflow" tests have the focus boundary outside of the element box. |
| 1916 ASSERT_EQ(url.find("overflow") == std::string::npos, expectedIntRect.contain
s(focus)); | 1916 ASSERT_EQ(url.find("overflow") == std::string::npos, expectedIntRect.contain
s(focus)); |
| 1917 } | 1917 } |
| 1918 | 1918 |
| 1919 TEST_F(WebViewTest, GetSelectionRootBounds) | 1919 TEST_F(WebViewTest, GetSelectionRootBounds) |
| 1920 { | 1920 { |
| 1921 // Register all the pages we will be using. | 1921 // Register all the pages we will be using. |
| 1922 registerMockedHttpURLLoad("select_range_basic.html"); | 1922 registerMockedHttpURLLoad("select_range_basic.html"); |
| 1923 registerMockedHttpURLLoad("select_range_div_editable.html"); | 1923 registerMockedHttpURLLoad("select_range_div_editable.html"); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2012 // called iff value of a focused element is modified via script. | 2012 // called iff value of a focused element is modified via script. |
| 2013 TEST_F(WebViewTest, NonUserInputTextUpdate) | 2013 TEST_F(WebViewTest, NonUserInputTextUpdate) |
| 2014 { | 2014 { |
| 2015 NonUserInputTextUpdateWebViewClient client; | 2015 NonUserInputTextUpdateWebViewClient client; |
| 2016 std::string url = m_baseURL + "non_user_input_text_update.html"; | 2016 std::string url = m_baseURL + "non_user_input_text_update.html"; |
| 2017 URLTestHelpers::registerMockedURLLoad(toKURL(url), "non_user_input_text_upda
te.html"); | 2017 URLTestHelpers::registerMockedURLLoad(toKURL(url), "non_user_input_text_upda
te.html"); |
| 2018 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); | 2018 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &
client); |
| 2019 webViewImpl->setInitialFocus(false); | 2019 webViewImpl->setInitialFocus(false); |
| 2020 | 2020 |
| 2021 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame()); | 2021 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame()); |
| 2022 blink::HTMLDocument* document = blink::toHTMLDocument(frame->frame()->docume
nt()); | 2022 HTMLDocument* document = toHTMLDocument(frame->frame()->document()); |
| 2023 | 2023 |
| 2024 // (A) <input> | 2024 // (A) <input> |
| 2025 // (A.1) Focused and value is changed by script. | 2025 // (A.1) Focused and value is changed by script. |
| 2026 client.reset(); | 2026 client.reset(); |
| 2027 EXPECT_FALSE(client.textIsUpdated()); | 2027 EXPECT_FALSE(client.textIsUpdated()); |
| 2028 | 2028 |
| 2029 blink::HTMLInputElement* inputElement = toHTMLInputElement(document->getElem
entById("input")); | 2029 HTMLInputElement* inputElement = toHTMLInputElement(document->getElementById
("input")); |
| 2030 document->setFocusedElement(inputElement); | 2030 document->setFocusedElement(inputElement); |
| 2031 webViewImpl->setFocus(true); | 2031 webViewImpl->setFocus(true); |
| 2032 EXPECT_EQ(document->focusedElement(), static_cast<blink::Element*>(inputElem
ent)); | 2032 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(inputElement)); |
| 2033 | 2033 |
| 2034 // Emulate value change from script. | 2034 // Emulate value change from script. |
| 2035 inputElement->setValue("testA"); | 2035 inputElement->setValue("testA"); |
| 2036 EXPECT_TRUE(client.textIsUpdated()); | 2036 EXPECT_TRUE(client.textIsUpdated()); |
| 2037 WebTextInputInfo info = webViewImpl->textInputInfo(); | 2037 WebTextInputInfo info = webViewImpl->textInputInfo(); |
| 2038 EXPECT_EQ("testA", std::string(info.value.utf8().data())); | 2038 EXPECT_EQ("testA", std::string(info.value.utf8().data())); |
| 2039 | 2039 |
| 2040 // (A.2) Focused and user input modifies value. | 2040 // (A.2) Focused and user input modifies value. |
| 2041 client.reset(); | 2041 client.reset(); |
| 2042 EXPECT_FALSE(client.textIsUpdated()); | 2042 EXPECT_FALSE(client.textIsUpdated()); |
| 2043 | 2043 |
| 2044 WebVector<WebCompositionUnderline> emptyUnderlines; | 2044 WebVector<WebCompositionUnderline> emptyUnderlines; |
| 2045 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1)
; | 2045 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1)
; |
| 2046 webViewImpl->confirmComposition(WebWidget::KeepSelection); | 2046 webViewImpl->confirmComposition(WebWidget::KeepSelection); |
| 2047 EXPECT_FALSE(client.textIsUpdated()); | 2047 EXPECT_FALSE(client.textIsUpdated()); |
| 2048 info = webViewImpl->textInputInfo(); | 2048 info = webViewImpl->textInputInfo(); |
| 2049 EXPECT_EQ("testA2", std::string(info.value.utf8().data())); | 2049 EXPECT_EQ("testA2", std::string(info.value.utf8().data())); |
| 2050 | 2050 |
| 2051 // (A.3) Unfocused and value is changed by script. | 2051 // (A.3) Unfocused and value is changed by script. |
| 2052 client.reset(); | 2052 client.reset(); |
| 2053 EXPECT_FALSE(client.textIsUpdated()); | 2053 EXPECT_FALSE(client.textIsUpdated()); |
| 2054 document->setFocusedElement(nullptr); | 2054 document->setFocusedElement(nullptr); |
| 2055 webViewImpl->setFocus(false); | 2055 webViewImpl->setFocus(false); |
| 2056 EXPECT_NE(document->focusedElement(), static_cast<blink::Element*>(inputElem
ent)); | 2056 EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement)); |
| 2057 inputElement->setValue("testA3"); | 2057 inputElement->setValue("testA3"); |
| 2058 EXPECT_FALSE(client.textIsUpdated()); | 2058 EXPECT_FALSE(client.textIsUpdated()); |
| 2059 | 2059 |
| 2060 // (B) <textarea> | 2060 // (B) <textarea> |
| 2061 // (B.1) Focused and value is changed by script. | 2061 // (B.1) Focused and value is changed by script. |
| 2062 client.reset(); | 2062 client.reset(); |
| 2063 EXPECT_FALSE(client.textIsUpdated()); | 2063 EXPECT_FALSE(client.textIsUpdated()); |
| 2064 blink::HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(document
->getElementById("textarea")); | 2064 HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(document->getEl
ementById("textarea")); |
| 2065 document->setFocusedElement(textAreaElement); | 2065 document->setFocusedElement(textAreaElement); |
| 2066 webViewImpl->setFocus(true); | 2066 webViewImpl->setFocus(true); |
| 2067 EXPECT_EQ(document->focusedElement(), static_cast<blink::Element*>(textAreaE
lement)); | 2067 EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement)
); |
| 2068 textAreaElement->setValue("testB"); | 2068 textAreaElement->setValue("testB"); |
| 2069 EXPECT_TRUE(client.textIsUpdated()); | 2069 EXPECT_TRUE(client.textIsUpdated()); |
| 2070 info = webViewImpl->textInputInfo(); | 2070 info = webViewImpl->textInputInfo(); |
| 2071 EXPECT_EQ("testB", std::string(info.value.utf8().data())); | 2071 EXPECT_EQ("testB", std::string(info.value.utf8().data())); |
| 2072 | 2072 |
| 2073 // (B.2) Focused and user input modifies value. | 2073 // (B.2) Focused and user input modifies value. |
| 2074 client.reset(); | 2074 client.reset(); |
| 2075 EXPECT_FALSE(client.textIsUpdated()); | 2075 EXPECT_FALSE(client.textIsUpdated()); |
| 2076 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1)
; | 2076 webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1)
; |
| 2077 webViewImpl->confirmComposition(WebWidget::KeepSelection); | 2077 webViewImpl->confirmComposition(WebWidget::KeepSelection); |
| 2078 info = webViewImpl->textInputInfo(); | 2078 info = webViewImpl->textInputInfo(); |
| 2079 EXPECT_EQ("testB2", std::string(info.value.utf8().data())); | 2079 EXPECT_EQ("testB2", std::string(info.value.utf8().data())); |
| 2080 | 2080 |
| 2081 // (B.3) Unfocused and value is changed by script. | 2081 // (B.3) Unfocused and value is changed by script. |
| 2082 client.reset(); | 2082 client.reset(); |
| 2083 EXPECT_FALSE(client.textIsUpdated()); | 2083 EXPECT_FALSE(client.textIsUpdated()); |
| 2084 document->setFocusedElement(nullptr); | 2084 document->setFocusedElement(nullptr); |
| 2085 webViewImpl->setFocus(false); | 2085 webViewImpl->setFocus(false); |
| 2086 EXPECT_NE(document->focusedElement(), static_cast<blink::Element*>(textAreaE
lement)); | 2086 EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement)
); |
| 2087 inputElement->setValue("testB3"); | 2087 inputElement->setValue("testB3"); |
| 2088 EXPECT_FALSE(client.textIsUpdated()); | 2088 EXPECT_FALSE(client.textIsUpdated()); |
| 2089 | 2089 |
| 2090 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. | 2090 // Free the webView before freeing the NonUserInputTextUpdateWebViewClient. |
| 2091 m_webViewHelper.reset(); | 2091 m_webViewHelper.reset(); |
| 2092 } | 2092 } |
| 2093 | 2093 |
| 2094 // Check that the WebAutofillClient is correctly notified about first user | 2094 // Check that the WebAutofillClient is correctly notified about first user |
| 2095 // gestures after load, following various input events. | 2095 // gestures after load, following various input events. |
| 2096 TEST_F(WebViewTest, FirstUserGestureObservedKeyEvent) | 2096 TEST_F(WebViewTest, FirstUserGestureObservedKeyEvent) |
| 2097 { | 2097 { |
| 2098 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("form.html")); | 2098 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("form.html")); |
| 2099 MockAutofillClient client; | 2099 MockAutofillClient client; |
| 2100 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html"
, true); | 2100 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html"
, true); |
| 2101 webView->setAutofillClient(&client); | 2101 webView->setAutofillClient(&client); |
| 2102 webView->setInitialFocus(false); | 2102 webView->setInitialFocus(false); |
| 2103 | 2103 |
| 2104 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); | 2104 EXPECT_EQ(0, client.getUserGestureNotificationsCount()); |
| 2105 | 2105 |
| 2106 WebKeyboardEvent keyEvent; | 2106 WebKeyboardEvent keyEvent; |
| 2107 keyEvent.windowsKeyCode = blink::VKEY_SPACE; | 2107 keyEvent.windowsKeyCode = VKEY_SPACE; |
| 2108 keyEvent.type = WebInputEvent::RawKeyDown; | 2108 keyEvent.type = WebInputEvent::RawKeyDown; |
| 2109 keyEvent.setKeyIdentifierFromWindowsKeyCode(); | 2109 keyEvent.setKeyIdentifierFromWindowsKeyCode(); |
| 2110 webView->handleInputEvent(keyEvent); | 2110 webView->handleInputEvent(keyEvent); |
| 2111 keyEvent.type = WebInputEvent::KeyUp; | 2111 keyEvent.type = WebInputEvent::KeyUp; |
| 2112 webView->handleInputEvent(keyEvent); | 2112 webView->handleInputEvent(keyEvent); |
| 2113 | 2113 |
| 2114 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); | 2114 EXPECT_EQ(1, client.getUserGestureNotificationsCount()); |
| 2115 webView->setAutofillClient(0); | 2115 webView->setAutofillClient(0); |
| 2116 } | 2116 } |
| 2117 | 2117 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 | 2171 |
| 2172 TEST_F(WebViewTest, AutoResizeSubtreeLayout) | 2172 TEST_F(WebViewTest, AutoResizeSubtreeLayout) |
| 2173 { | 2173 { |
| 2174 std::string url = m_baseURL + "subtree-layout.html"; | 2174 std::string url = m_baseURL + "subtree-layout.html"; |
| 2175 URLTestHelpers::registerMockedURLLoad(toKURL(url), "subtree-layout.html"); | 2175 URLTestHelpers::registerMockedURLLoad(toKURL(url), "subtree-layout.html"); |
| 2176 WebView* webView = m_webViewHelper.initialize(true); | 2176 WebView* webView = m_webViewHelper.initialize(true); |
| 2177 | 2177 |
| 2178 webView->enableAutoResizeMode(WebSize(200, 200), WebSize(200, 200)); | 2178 webView->enableAutoResizeMode(WebSize(200, 200), WebSize(200, 200)); |
| 2179 loadFrame(webView->mainFrame(), url); | 2179 loadFrame(webView->mainFrame(), url); |
| 2180 | 2180 |
| 2181 blink::FrameView* frameView = m_webViewHelper.webViewImpl()->mainFrameImpl()
->frameView(); | 2181 FrameView* frameView = m_webViewHelper.webViewImpl()->mainFrameImpl()->frame
View(); |
| 2182 | 2182 |
| 2183 // Auto-resizing used to ASSERT(needsLayout()) in RenderBlockFlow::layout. T
his EXPECT is | 2183 // Auto-resizing used to ASSERT(needsLayout()) in RenderBlockFlow::layout. T
his EXPECT is |
| 2184 // merely a dummy. The real test is that we don't trigger asserts in debug b
uilds. | 2184 // merely a dummy. The real test is that we don't trigger asserts in debug b
uilds. |
| 2185 EXPECT_FALSE(frameView->needsLayout()); | 2185 EXPECT_FALSE(frameView->needsLayout()); |
| 2186 }; | 2186 }; |
| 2187 | 2187 |
| 2188 } // namespace | 2188 } // namespace |
| OLD | NEW |