*/
#include "config.h"
-#include "WebView.h"
+#include "public/web/WebView.h"
-#include <gtest/gtest.h>
-#include "FrameTestHelpers.h"
-#include "URLTestHelpers.h"
-#include "WebAutofillClient.h"
-#include "WebContentDetectionResult.h"
-#include "WebDateTimeChooserCompletion.h"
-#include "WebDocument.h"
-#include "WebElement.h"
-#include "WebFrame.h"
-#include "WebFrameClient.h"
-#include "WebFrameImpl.h"
-#include "WebHitTestResult.h"
-#include "WebInputEvent.h"
-#include "WebSettings.h"
-#include "WebSettingsImpl.h"
-#include "WebViewClient.h"
-#include "WebViewImpl.h"
-#include "WebWidget.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
+#include "core/editing/FrameSelection.h"
+#include "core/frame/EventHandlerRegistry.h"
+#include "core/frame/FrameView.h"
+#include "core/frame/LocalFrame.h"
+#include "core/frame/Settings.h"
#include "core/html/HTMLDocument.h"
#include "core/html/HTMLIFrameElement.h"
#include "core/html/HTMLInputElement.h"
+#include "core/html/HTMLTextAreaElement.h"
#include "core/loader/FrameLoadRequest.h"
-#include "core/frame/FrameView.h"
#include "core/page/Chrome.h"
-#include "core/frame/Settings.h"
+#include "core/page/Page.h"
+#include "core/paint/LayerPainter.h"
+#include "core/rendering/RenderLayer.h"
+#include "core/rendering/RenderView.h"
+#include "core/testing/URLTestHelpers.h"
#include "platform/KeyboardCodes.h"
+#include "platform/geometry/IntSize.h"
#include "platform/graphics/Color.h"
#include "public/platform/Platform.h"
+#include "public/platform/WebClipboard.h"
#include "public/platform/WebDragData.h"
#include "public/platform/WebSize.h"
#include "public/platform/WebThread.h"
#include "public/platform/WebUnitTestSupport.h"
+#include "public/web/WebAutofillClient.h"
+#include "public/web/WebContentDetectionResult.h"
+#include "public/web/WebDateTimeChooserCompletion.h"
+#include "public/web/WebDocument.h"
#include "public/web/WebDragOperation.h"
+#include "public/web/WebElement.h"
+#include "public/web/WebFrame.h"
+#include "public/web/WebFrameClient.h"
+#include "public/web/WebHitTestResult.h"
+#include "public/web/WebInputEvent.h"
+#include "public/web/WebScriptSource.h"
+#include "public/web/WebSettings.h"
+#include "public/web/WebViewClient.h"
+#include "public/web/WebWidget.h"
#include "public/web/WebWidgetClient.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkBitmapDevice.h"
#include "third_party/skia/include/core/SkCanvas.h"
+#include "web/WebLocalFrameImpl.h"
+#include "web/WebSettingsImpl.h"
+#include "web/WebViewImpl.h"
+#include "web/tests/FrameTestHelpers.h"
+#include <gtest/gtest.h>
using namespace blink;
+using blink::FrameTestHelpers::loadFrame;
using blink::FrameTestHelpers::runPendingTasks;
using blink::URLTestHelpers::toKURL;
WebViewImpl* m_webView;
};
-class AutoResizeWebViewClient : public WebViewClient {
+class AutoResizeWebViewClient : public FrameTestHelpers::TestWebViewClient {
public:
// WebViewClient methods
virtual void didAutoResize(const WebSize& newSize) { m_testData.setSize(newSize); }
TestData m_testData;
};
-class TapHandlingWebViewClient : public WebViewClient {
+class SaveImageFromDataURLWebViewClient : public FrameTestHelpers::TestWebViewClient {
+public:
+ // WebViewClient methods
+ virtual void saveImageFromDataURL(const WebString& dataURL) { m_dataURL = dataURL; }
+
+ // Local methods
+ const WebString& result() const { return m_dataURL; }
+ void reset() { m_dataURL = WebString(); }
+
+private:
+ WebString m_dataURL;
+};
+
+class TapHandlingWebViewClient : public FrameTestHelpers::TestWebViewClient {
public:
// WebViewClient methods
virtual void didHandleGestureEvent(const WebGestureEvent& event, bool eventCancelled)
int m_longpressY;
};
-class FakeCompositingWebViewClient : public WebViewClient {
-public:
- virtual ~FakeCompositingWebViewClient()
- {
- }
-
- virtual void initializeLayerTreeView() OVERRIDE
- {
- m_layerTreeView = adoptPtr(Platform::current()->unitTestSupport()->createLayerTreeViewForTesting(WebUnitTestSupport::TestViewTypeUnitTest));
- ASSERT(m_layerTreeView);
- }
-
- virtual WebLayerTreeView* layerTreeView() OVERRIDE
- {
- return m_layerTreeView.get();
- }
-
-private:
- OwnPtr<WebLayerTreeView> m_layerTreeView;
-};
-
-class DateTimeChooserWebViewClient : public WebViewClient {
+class DateTimeChooserWebViewClient : public FrameTestHelpers::TestWebViewClient {
public:
WebDateTimeChooserCompletion* chooserCompletion()
{
}
// WebViewClient methods
- virtual bool openDateTimeChooser(const WebDateTimeChooserParams&, WebDateTimeChooserCompletion* chooser_completion) OVERRIDE
+ virtual bool openDateTimeChooser(const WebDateTimeChooserParams&, WebDateTimeChooserCompletion* chooser_completion) override
{
m_chooserCompletion = chooser_completion;
return true;
FrameTestHelpers::WebViewHelper m_webViewHelper;
};
+TEST_F(WebViewTest, SaveImageAt)
+{
+ SaveImageFromDataURLWebViewClient client;
+
+ std::string url = m_baseURL + "image-with-data-url.html";
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "image-with-data-url.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
+ webView->resize(WebSize(400, 400));
+
+ client.reset();
+ webView->saveImageAt(WebPoint(1, 1));
+ EXPECT_EQ(WebString::fromUTF8("data:image/gif;base64"
+ ",R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="), client.result());
+
+ client.reset();
+ webView->saveImageAt(WebPoint(1, 2));
+ EXPECT_EQ(WebString(), client.result());
+
+ m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
+};
+
+TEST_F(WebViewTest, CopyImageAt)
+{
+ std::string url = m_baseURL + "canvas-copy-image.html";
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "canvas-copy-image.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0);
+ webView->resize(WebSize(400, 400));
+ webView->copyImageAt(WebPoint(50, 50));
+
+ WebData data = Platform::current()->clipboard()->readImage(WebClipboard::Buffer());
+ WebImage image = WebImage::fromData(data, WebSize());
+
+ SkAutoLockPixels autoLock(image.getSkBitmap());
+ EXPECT_EQ(SkColorSetARGB(255, 255, 0, 0), image.getSkBitmap().getColor(0, 0));
+};
+
TEST_F(WebViewTest, SetBaseBackgroundColor)
{
const WebColor kWhite = 0xFFFFFFFF;
const WebColor kBlue = 0xFF0000FF;
const WebColor kDarkCyan = 0xFF227788;
const WebColor kTranslucentPutty = 0x80BFB196;
+ const WebColor kTransparent = 0x00000000;
- WebView* webView = m_webViewHelper.initialize();
+ WebViewImpl* webView = m_webViewHelper.initialize();
EXPECT_EQ(kWhite, webView->backgroundColor());
webView->setBaseBackgroundColor(kBlue);
EXPECT_EQ(kBlue, webView->backgroundColor());
WebURL baseURL = URLTestHelpers::toKURL("http://example.com/");
- webView->mainFrame()->loadHTMLString(
- "<html><head><style>body {background-color:#227788}</style></head></html>", baseURL);
- Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ FrameTestHelpers::loadHTMLString(webView->mainFrame(), "<html><head><style>body {background-color:#227788}</style></head></html>", baseURL);
EXPECT_EQ(kDarkCyan, webView->backgroundColor());
- webView->mainFrame()->loadHTMLString(
- "<html><head><style>body {background-color:rgba(255,0,0,0.5)}</style></head></html>", baseURL);
- Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ FrameTestHelpers::loadHTMLString(webView->mainFrame(), "<html><head><style>body {background-color:rgba(255,0,0,0.5)}</style></head></html>", baseURL);
// Expected: red (50% alpha) blended atop base of kBlue.
EXPECT_EQ(0xFF7F0080, webView->backgroundColor());
webView->setBaseBackgroundColor(kTranslucentPutty);
// Expected: red (50% alpha) blended atop kTranslucentPutty. Note the alpha.
EXPECT_EQ(0xBFE93B32, webView->backgroundColor());
+
+ webView->setBaseBackgroundColor(kTransparent);
+ FrameTestHelpers::loadHTMLString(webView->mainFrame(), "<html><head><style>body {background-color:transparent}</style></head></html>", baseURL);
+ // Expected: transparent on top of kTransparent will still be transparent.
+ EXPECT_EQ(kTransparent, webView->backgroundColor());
+
+ LocalFrame* frame = webView->mainFrameImpl()->frame();
+
+ // Creating a new frame view with the background color having 0 alpha.
+ frame->createView(IntSize(1024, 768), Color::transparent, true);
+ EXPECT_EQ(kTransparent, frame->view()->baseBackgroundColor());
+
+ Color kTransparentRed(100, 0, 0, 0);
+ frame->createView(IntSize(1024, 768), kTransparentRed, true);
+ EXPECT_EQ(kTransparentRed, frame->view()->baseBackgroundColor());
}
TEST_F(WebViewTest, SetBaseBackgroundColorBeforeMainFrame)
{
const WebColor kBlue = 0xFF0000FF;
- WebView* webView = WebViewImpl::create(0);
+ FrameTestHelpers::TestWebViewClient webViewClient;
+ WebView* webView = WebViewImpl::create(&webViewClient);
EXPECT_NE(kBlue, webView->backgroundColor());
// webView does not have a frame yet, but we should still be able to set the background color.
webView->setBaseBackgroundColor(kBlue);
EXPECT_EQ(kBlue, webView->backgroundColor());
+ WebLocalFrameImpl* frame = WebLocalFrameImpl::create(0);
+ webView->setMainFrame(frame);
+ webView->close();
+ frame->close();
}
TEST_F(WebViewTest, SetBaseBackgroundColorAndBlendWithExistingContent)
const int kWidth = 100;
const int kHeight = 100;
- // Set WebView background to green with alpha.
WebView* webView = m_webViewHelper.initialize();
+
+ // Set WebView background to green with alpha.
webView->setBaseBackgroundColor(kAlphaGreen);
webView->settings()->setShouldClearDocumentBackground(false);
webView->resize(WebSize(kWidth, kHeight));
// Set canvas background to red with alpha.
SkBitmap bitmap;
- ASSERT_TRUE(bitmap.allocN32Pixels(kWidth, kHeight));
+ bitmap.allocN32Pixels(kWidth, kHeight);
SkCanvas canvas(bitmap);
canvas.clear(kAlphaRed);
- webView->paint(&canvas, WebRect(0, 0, kWidth, kHeight));
+
+ GraphicsContext context(&canvas);
+
+ // Paint the root of the main frame in the way that CompositedLayerMapping would.
+ FrameView* view = m_webViewHelper.webViewImpl()->mainFrameImpl()->frameView();
+ RenderLayer* rootLayer = view->renderView()->layer();
+ IntRect paintRect(0, 0, kWidth, kHeight);
+ LayerPaintingInfo paintingInfo(rootLayer, paintRect, PaintBehaviorNormal, LayoutSize());
+ LayerPainter(*rootLayer).paintLayerContents(&context, paintingInfo, PaintLayerPaintingCompositingAllPhases);
// The result should be a blend of red and green.
SkColor color = bitmap.getColor(kWidth / 2, kHeight / 2);
- EXPECT_TRUE(WebCore::redChannel(color));
- EXPECT_TRUE(WebCore::greenChannel(color));
+ EXPECT_TRUE(redChannel(color));
+ EXPECT_TRUE(greenChannel(color));
}
TEST_F(WebViewTest, FocusIsInactive)
webView->setFocus(true);
webView->setIsActive(true);
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
EXPECT_TRUE(frame->frame()->document()->isHTMLDocument());
- WebCore::HTMLDocument* document = WebCore::toHTMLDocument(frame->frame()->document());
+ HTMLDocument* document = toHTMLDocument(frame->frame()->document());
EXPECT_TRUE(document->hasFocus());
webView->setFocus(false);
webView->setIsActive(false);
// Image is at top left quandrant, so should not hit it.
WebHitTestResult negativeResult = webView->hitTestResultAt(hitPoint);
ASSERT_EQ(WebNode::ElementNode, negativeResult.node().nodeType());
- EXPECT_FALSE(negativeResult.node().to<WebElement>().hasTagName("img"));
+ EXPECT_FALSE(negativeResult.node().to<WebElement>().hasHTMLTagName("img"));
negativeResult.reset();
// Scale page up 2x so image should occupy the whole viewport.
- webView->setPageScaleFactor(2.0f, WebPoint(0, 0));
+ webView->setPageScaleFactor(2.0f);
WebHitTestResult positiveResult = webView->hitTestResultAt(hitPoint);
ASSERT_EQ(WebNode::ElementNode, positiveResult.node().nodeType());
- EXPECT_TRUE(positiveResult.node().to<WebElement>().hasTagName("img"));
+ EXPECT_TRUE(positiveResult.node().to<WebElement>().hasHTMLTagName("img"));
positiveResult.reset();
}
WebView* webView = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
client.testData().setWebView(webView);
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
- WebCore::FrameView* frameView = frame->frame()->view();
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
+ FrameView* frameView = frame->frame()->view();
frameView->layout();
EXPECT_FALSE(frameView->layoutPending());
EXPECT_FALSE(frameView->needsLayout());
m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
}
-TEST_F(WebViewTest, DISABLED_AutoResizeMinimumSize)
+TEST_F(WebViewTest, AutoResizeMinimumSize)
{
WebSize minAutoResize(91, 56);
WebSize maxAutoResize(403, 302);
// Next three tests disabled for https://bugs.webkit.org/show_bug.cgi?id=92318 .
// It seems we can run three AutoResize tests, then the next one breaks.
-TEST_F(WebViewTest, DISABLED_AutoResizeInBetweenSizes)
+TEST_F(WebViewTest, AutoResizeInBetweenSizes)
{
WebSize minAutoResize(90, 95);
WebSize maxAutoResize(200, 300);
expectedWidth, expectedHeight, NoHorizontalScrollbar, NoVerticalScrollbar);
}
-TEST_F(WebViewTest, DISABLED_AutoResizeOverflowSizes)
+TEST_F(WebViewTest, AutoResizeOverflowSizes)
{
WebSize minAutoResize(90, 95);
WebSize maxAutoResize(200, 300);
expectedWidth, expectedHeight, VisibleHorizontalScrollbar, VisibleVerticalScrollbar);
}
-TEST_F(WebViewTest, DISABLED_AutoResizeMaxSize)
+TEST_F(WebViewTest, AutoResizeMaxSize)
{
WebSize minAutoResize(90, 95);
WebSize maxAutoResize(200, 300);
testInputMode(WebString("verbatim"), "input_mode_textarea_verbatim.html");
}
+TEST_F(WebViewTest, TextInputInfoWithReplacedElements)
+{
+ std::string url = m_baseURL + "div_with_image.html";
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "div_with_image.html");
+ WebView* webView = m_webViewHelper.initializeAndLoad(url);
+ webView->setInitialFocus(false);
+ WebTextInputInfo info = webView->textInputInfo();
+
+ EXPECT_EQ("foo\xef\xbf\xbc", info.value.utf8());
+}
+
TEST_F(WebViewTest, SetEditableSelectionOffsetsAndTextInputInfo)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setInitialFocus(false);
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
frame->setEditableSelectionOffsets(5, 13);
EXPECT_EQ("56789abc", frame->selectionAsText());
WebTextInputInfo info = webView->textInputInfo();
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("content_editable_populated.html"));
webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_editable_populated.html");
webView->setInitialFocus(false);
- frame = toWebFrameImpl(webView->mainFrame());
+ frame = toWebLocalFrameImpl(webView->mainFrame());
frame->setEditableSelectionOffsets(8, 19);
EXPECT_EQ("89abcdefghi", frame->selectionAsText());
info = webView->textInputInfo();
WebVector<WebCompositionUnderline> emptyUnderlines;
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
frame->setEditableSelectionOffsets(4, 4);
frame->setCompositionFromExistingText(8, 12, emptyUnderlines);
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
webView->setInitialFocus(false);
frame->setEditableSelectionOffsets(10, 10);
frame->extendSelectionAndDelete(5, 8);
WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
webView->setInitialFocus(false);
WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
- underlines[0] = blink::WebCompositionUnderline(0, 4, 0, false);
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
frame->setEditableSelectionOffsets(4, 10);
frame->setCompositionFromExistingText(8, 12, underlines);
WebVector<WebCompositionUnderline> underlineResults = toWebViewImpl(webView)->compositionUnderlines();
WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_populated.html");
webView->setInitialFocus(false);
WebVector<WebCompositionUnderline> underlines(static_cast<size_t>(1));
- underlines[0] = blink::WebCompositionUnderline(0, 4, 0, false);
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ underlines[0] = WebCompositionUnderline(0, 4, 0, false, 0);
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
frame->setEditableSelectionOffsets(27, 27);
std::string newLineText("\n");
webView->confirmComposition(WebString::fromUTF8(newLineText.c_str()));
EXPECT_EQ(6, info.compositionStart);
EXPECT_EQ(11, info.compositionEnd);
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
frame->setEditableSelectionOffsets(6, 6);
info = webView->textInputInfo();
EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_field_populated.html");
WebFrame* frame = webView->mainFrame();
+ webView->setPageScaleFactorLimits(1, 1);
webView->setInitialFocus(false);
frame->setEditableSelectionOffsets(4, 10);
EXPECT_TRUE(webView->isSelectionAnchorFirst());
EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
// Make the page scale and scroll with the given paremeters.
- webViewImpl->setPageScaleFactor(2.0f, WebPoint(116, 84));
+ webViewImpl->setPageScaleFactor(2.0f);
+ webViewImpl->setMainFrameScrollOffset(WebPoint(116, 84));
EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor());
EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width);
EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height);
- webViewImpl->page()->mainFrame()->loader().saveScrollState();
- EXPECT_EQ(2.0f, webViewImpl->page()->mainFrame()->loader().currentItem()->pageScaleFactor());
- EXPECT_EQ(116, webViewImpl->page()->mainFrame()->loader().currentItem()->scrollPoint().x());
- EXPECT_EQ(84, webViewImpl->page()->mainFrame()->loader().currentItem()->scrollPoint().y());
+ LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFrame());
+ mainFrameLocal->loader().saveScrollState();
+ EXPECT_EQ(2.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor());
+ EXPECT_EQ(116, mainFrameLocal->loader().currentItem()->scrollPoint().x());
+ EXPECT_EQ(84, mainFrameLocal->loader().currentItem()->scrollPoint().y());
// Confirm that resetting the page state resets the saved scroll position.
// The HistoryController treats a page scale factor of 0.0f as special and avoids
EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor());
EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
- EXPECT_EQ(0.0f, webViewImpl->page()->mainFrame()->loader().currentItem()->pageScaleFactor());
- EXPECT_EQ(0, webViewImpl->page()->mainFrame()->loader().currentItem()->scrollPoint().x());
- EXPECT_EQ(0, webViewImpl->page()->mainFrame()->loader().currentItem()->scrollPoint().y());
+ EXPECT_EQ(0.0f, mainFrameLocal->loader().currentItem()->pageScaleFactor());
+ EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().x());
+ EXPECT_EQ(0, mainFrameLocal->loader().currentItem()->scrollPoint().y());
}
-class EnterFullscreenWebViewClient : public WebViewClient {
+TEST_F(WebViewTest, BackForwardRestoreScroll)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("back_forward_restore_scroll.html"));
+ WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "back_forward_restore_scroll.html");
+ webViewImpl->resize(WebSize(640, 480));
+ webViewImpl->layout();
+
+ // Emulate a user scroll
+ webViewImpl->setMainFrameScrollOffset(WebPoint(0, 900));
+ LocalFrame* mainFrameLocal = toLocalFrame(webViewImpl->page()->mainFrame());
+ RefPtrWillBePersistent<HistoryItem> item1 = mainFrameLocal->loader().currentItem();
+
+ // Click an anchor
+ mainFrameLocal->loader().load(FrameLoadRequest(mainFrameLocal->document(), ResourceRequest(mainFrameLocal->document()->completeURL("#a"))));
+ RefPtrWillBePersistent<HistoryItem> item2 = mainFrameLocal->loader().currentItem();
+
+ // Go back, then forward, then back again.
+ mainFrameLocal->loader().loadHistoryItem(item1.get(), FrameLoadTypeBackForward, HistorySameDocumentLoad);
+ mainFrameLocal->loader().loadHistoryItem(item2.get(), FrameLoadTypeBackForward, HistorySameDocumentLoad);
+ mainFrameLocal->loader().loadHistoryItem(item1.get(), FrameLoadTypeBackForward, HistorySameDocumentLoad);
+
+ // Click a different anchor
+ mainFrameLocal->loader().load(FrameLoadRequest(mainFrameLocal->document(), ResourceRequest(mainFrameLocal->document()->completeURL("#b"))));
+ RefPtrWillBePersistent<HistoryItem> item3 = mainFrameLocal->loader().currentItem();
+
+ // Go back, then forward. The scroll position should be properly set on the forward navigation.
+ mainFrameLocal->loader().loadHistoryItem(item1.get(), FrameLoadTypeBackForward, HistorySameDocumentLoad);
+ mainFrameLocal->loader().loadHistoryItem(item3.get(), FrameLoadTypeBackForward, HistorySameDocumentLoad);
+ EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
+ EXPECT_GT(webViewImpl->mainFrame()->scrollOffset().height, 2000);
+}
+
+class EnterFullscreenWebViewClient : public FrameTestHelpers::TestWebViewClient {
public:
// WebViewClient methods
virtual bool enterFullScreen() { return true; }
EnterFullscreenWebViewClient client;
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("hello_world.html"));
WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "hello_world.html", true, 0, &client);
- webViewImpl->settings()->setFullScreenEnabled(true);
webViewImpl->resize(WebSize(640, 480));
webViewImpl->layout();
EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
// Make the page scale and scroll with the given paremeters.
- webViewImpl->setPageScaleFactor(2.0f, WebPoint(116, 84));
+ webViewImpl->setPageScaleFactor(2.0f);
+ webViewImpl->setMainFrameScrollOffset(WebPoint(116, 84));
EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor());
EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width);
EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height);
- RefPtr<WebCore::Element> element = static_cast<PassRefPtr<WebCore::Element> >(webViewImpl->mainFrame()->document().body());
+ RefPtrWillBeRawPtr<Element> element = static_cast<PassRefPtrWillBeRawPtr<Element> >(webViewImpl->mainFrame()->document().body());
webViewImpl->enterFullScreenForElement(element.get());
- webViewImpl->willEnterFullScreen();
webViewImpl->didEnterFullScreen();
// Page scale factor must be 1.0 during fullscreen for elements to be sized
EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor());
// Make sure fullscreen nesting doesn't disrupt scroll/scale saving.
- RefPtr<WebCore::Element> otherElement = static_cast<PassRefPtr<WebCore::Element> >(webViewImpl->mainFrame()->document().head());
+ RefPtrWillBeRawPtr<Element> otherElement = static_cast<PassRefPtrWillBeRawPtr<Element> >(webViewImpl->mainFrame()->document().head());
webViewImpl->enterFullScreenForElement(otherElement.get());
// Confirm that exiting fullscreen restores the parameters.
- webViewImpl->willExitFullScreen();
webViewImpl->didExitFullScreen();
EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor());
EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width);
m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
}
+class PrintWebViewClient : public FrameTestHelpers::TestWebViewClient {
+public:
+ PrintWebViewClient()
+ : m_printCalled(false)
+ {
+ }
+
+ // WebViewClient methods
+ virtual void printPage(WebLocalFrame*) override
+ {
+ m_printCalled = true;
+ }
+
+ bool printCalled() const { return m_printCalled; }
+
+private:
+ bool m_printCalled;
+};
+
+
+TEST_F(WebViewTest, PrintWithXHRInFlight)
+{
+ PrintWebViewClient client;
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("print_with_xhr_inflight.html"));
+ WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "print_with_xhr_inflight.html", true, 0, &client);
+
+ ASSERT_EQ(FrameStateComplete, toLocalFrame(webViewImpl->page()->mainFrame())->loader().state());
+ EXPECT_TRUE(client.printCalled());
+ m_webViewHelper.reset();
+}
+
+class DropTask : public WebThread::Task {
+public:
+ explicit DropTask(WebView* webView) : m_webView(webView)
+ {
+ }
+
+ virtual void run() override
+ {
+ const WebPoint clientPoint(0, 0);
+ const WebPoint screenPoint(0, 0);
+ m_webView->dragTargetDrop(clientPoint, screenPoint, 0);
+ }
+
+private:
+ WebView* const m_webView;
+};
static void DragAndDropURL(WebViewImpl* webView, const std::string& url)
{
- blink::WebDragData dragData;
+ WebDragData dragData;
dragData.initialize();
WebDragData::Item item;
const WebPoint clientPoint(0, 0);
const WebPoint screenPoint(0, 0);
- webView->dragTargetDragEnter(dragData, clientPoint, screenPoint, blink::WebDragOperationCopy, 0);
- webView->dragTargetDrop(clientPoint, screenPoint, 0);
- FrameTestHelpers::runPendingTasks();
- Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ webView->dragTargetDragEnter(dragData, clientPoint, screenPoint, WebDragOperationCopy, 0);
+ Platform::current()->currentThread()->postTask(new DropTask(webView));
+ FrameTestHelpers::pumpPendingRequestsDoNotUse(webView->mainFrame());
}
TEST_F(WebViewTest, DragDropURL)
EXPECT_EQ(fooUrl, webView->mainFrame()->document().url().string().utf8());
}
-class ContentDetectorClient : public WebViewClient {
+class ContentDetectorClient : public FrameTestHelpers::TestWebViewClient {
public:
ContentDetectorClient() { reset(); }
- virtual WebContentDetectionResult detectContentAround(const WebHitTestResult& hitTest) OVERRIDE
+ virtual WebContentDetectionResult detectContentAround(const WebHitTestResult& hitTest) override
{
m_contentDetectionRequested = true;
return m_contentDetectionResult;
}
- virtual void scheduleContentIntent(const WebURL& url) OVERRIDE
+ virtual void scheduleContentIntent(const WebURL& url) override
{
m_scheduledIntentURL = url;
}
- virtual void cancelScheduledContentIntents() OVERRIDE
+ virtual void cancelScheduledContentIntents() override
{
m_pendingIntentsCancelled = true;
}
static bool tapElementById(WebView* webView, WebInputEvent::Type type, const WebString& id)
{
ASSERT(webView);
- RefPtr<WebCore::Element> element = static_cast<PassRefPtr<WebCore::Element> >(webView->mainFrame()->document().getElementById(id));
+ RefPtrWillBeRawPtr<Element> element = static_cast<PassRefPtrWillBeRawPtr<Element> >(webView->mainFrame()->document().getElementById(id));
if (!element)
return false;
element->scrollIntoViewIfNeeded();
- WebCore::IntPoint center = element->screenRect().center();
+ IntPoint center = element->screenRect().center();
WebGestureEvent event;
event.type = type;
WebString target = WebString::fromUTF8("target");
WebString onselectstartfalse = WebString::fromUTF8("onselectstartfalse");
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, onselectstartfalse));
EXPECT_EQ("", std::string(frame->selectionAsText().utf8().data()));
EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target));
EXPECT_EQ("testword", std::string(frame->selectionAsText().utf8().data()));
}
-#endif
-TEST_F(WebViewTest, SelectionOnDisabledInput)
+TEST_F(WebViewTest, BlinkCaretOnTypingAfterLongPress)
{
- URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("selection_disabled.html"));
- WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "selection_disabled.html", true);
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("blink_caret_on_typing_after_long_press.html"));
+
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "blink_caret_on_typing_after_long_press.html", true);
webView->resize(WebSize(640, 480));
webView->layout();
runPendingTasks();
- std::string testWord = "This text should be selected.";
+ WebString target = WebString::fromUTF8("target");
+ WebLocalFrameImpl* mainFrame = toWebLocalFrameImpl(webView->mainFrame());
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
- EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data()));
+ EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target));
+ EXPECT_TRUE(mainFrame->frame()->selection().isCaretBlinkingSuspended());
- size_t location;
- size_t length;
- EXPECT_TRUE(toWebViewImpl(webView)->caretOrSelectionRange(&location, &length));
- EXPECT_EQ(location, 0UL);
- EXPECT_EQ(length, testWord.length());
+ WebKeyboardEvent keyEvent;
+ keyEvent.type = WebInputEvent::RawKeyDown;
+ webView->handleInputEvent(keyEvent);
+ keyEvent.type = WebInputEvent::KeyUp;
+ webView->handleInputEvent(keyEvent);
+ EXPECT_FALSE(mainFrame->frame()->selection().isCaretBlinkingSuspended());
}
+#endif
TEST_F(WebViewTest, SelectionOnReadOnlyInput)
{
std::string testWord = "This text should be selected.";
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
EXPECT_EQ(testWord, std::string(frame->selectionAsText().utf8().data()));
size_t location;
static void configueCompositingWebView(WebSettings* settings)
{
- settings->setForceCompositingMode(true);
settings->setAcceleratedCompositingEnabled(true);
- settings->setAcceleratedCompositingForFixedPositionEnabled(true);
- settings->setAcceleratedCompositingForOverflowScrollEnabled(true);
- settings->setAcceleratedCompositingForScrollableFramesEnabled(true);
- settings->setCompositedScrollingForFramesEnabled(true);
+ settings->setPreferCompositingToLCDTextEnabled(true);
}
TEST_F(WebViewTest, ShowPressOnTransformedLink)
{
- OwnPtr<FakeCompositingWebViewClient> fakeCompositingWebViewClient = adoptPtr(new FakeCompositingWebViewClient());
+ OwnPtr<FrameTestHelpers::TestWebViewClient> fakeCompositingWebViewClient = adoptPtr(new FrameTestHelpers::TestWebViewClient());
FrameTestHelpers::WebViewHelper webViewHelper;
WebViewImpl* webViewImpl = webViewHelper.initialize(true, 0, fakeCompositingWebViewClient.get(), &configueCompositingWebView);
webViewImpl->resize(WebSize(pageWidth, pageHeight));
WebURL baseURL = URLTestHelpers::toKURL("http://example.com/");
- webViewImpl->mainFrame()->loadHTMLString(
- "<a href='http://www.test.com' style='position: absolute; left: 20px; top: 20px; width: 200px; -webkit-transform:translateZ(0);'>A link to highlight</a>", baseURL);
- Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+ FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), "<a href='http://www.test.com' style='position: absolute; left: 20px; top: 20px; width: 200px; transform:translateZ(0);'>A link to highlight</a>", baseURL);
WebGestureEvent event;
event.type = WebInputEvent::GestureShowPress;
MockAutofillClient()
: m_ignoreTextChanges(false)
, m_textChangesWhileIgnored(0)
- , m_textChangesWhileNotIgnored(0) { }
+ , m_textChangesWhileNotIgnored(0)
+ , m_userGestureNotificationsCount(0) { }
virtual ~MockAutofillClient() { }
- virtual void setIgnoreTextChanges(bool ignore) OVERRIDE { m_ignoreTextChanges = ignore; }
- virtual void textFieldDidChange(const WebFormControlElement&) OVERRIDE
+ virtual void setIgnoreTextChanges(bool ignore) override { m_ignoreTextChanges = ignore; }
+ virtual void textFieldDidChange(const WebFormControlElement&) override
{
if (m_ignoreTextChanges)
++m_textChangesWhileIgnored;
else
++m_textChangesWhileNotIgnored;
}
+ virtual void firstUserGestureObserved() override { ++m_userGestureNotificationsCount; }
void clearChangeCounts()
{
int textChangesWhileIgnored() { return m_textChangesWhileIgnored; }
int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; }
+ int getUserGestureNotificationsCount() { return m_userGestureNotificationsCount; }
private:
bool m_ignoreTextChanges;
int m_textChangesWhileIgnored;
int m_textChangesWhileNotIgnored;
+ int m_userGestureNotificationsCount;
};
// Set up a composition that needs to be committed.
WebVector<WebCompositionUnderline> emptyUnderlines;
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
frame->setEditableSelectionOffsets(4, 10);
frame->setCompositionFromExistingText(8, 12, emptyUnderlines);
WebTextInputInfo info = webView->textInputInfo();
WebVector<WebCompositionUnderline> emptyUnderlines;
client.clearChangeCounts();
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
frame->setCompositionFromExistingText(8, 12, emptyUnderlines);
WebTextInputInfo info = webView->textInputInfo();
}
}
-class ViewCreatingWebViewClient : public WebViewClient {
+class ViewCreatingWebViewClient : public FrameTestHelpers::TestWebViewClient {
public:
ViewCreatingWebViewClient()
: m_didFocusCalled(false)
}
// WebViewClient methods
- virtual WebView* createView(WebFrame*, const WebURLRequest&, const WebWindowFeatures&, const WebString& name, WebNavigationPolicy, bool) OVERRIDE
+ virtual WebView* createView(WebLocalFrame*, const WebURLRequest&, const WebWindowFeatures&, const WebString& name, WebNavigationPolicy, bool) override
{
return m_webViewHelper.initialize(true, 0, 0);
}
// WebWidgetClient methods
- virtual void didFocus() OVERRIDE
+ virtual void didFocus() override
{
m_didFocusCalled = true;
}
FrameTestHelpers::WebViewHelper m_webViewHelper;
WebViewImpl* webViewImpl = m_webViewHelper.initialize(true, 0, &client);
webViewImpl->page()->settings().setJavaScriptCanOpenWindowsAutomatically(true);
- WebFrameImpl* frame = toWebFrameImpl(webViewImpl->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
frame->setName("_start");
// Make a request that will open a new window
WebURLRequest webURLRequest;
webURLRequest.initialize();
- WebCore::FrameLoadRequest request(0, webURLRequest.toResourceRequest(), "_blank");
- webViewImpl->page()->mainFrame()->loader().load(request);
+ FrameLoadRequest request(0, webURLRequest.toResourceRequest(), "_blank");
+ toLocalFrame(webViewImpl->page()->mainFrame())->loader().load(request);
ASSERT_TRUE(client.createdWebView());
EXPECT_FALSE(client.didFocusCalled());
// Make a request from the new window that will navigate the original window. The original window should be focused.
WebURLRequest webURLRequestWithTargetStart;
webURLRequestWithTargetStart.initialize();
- WebCore::FrameLoadRequest requestWithTargetStart(0, webURLRequestWithTargetStart.toResourceRequest(), "_start");
- toWebViewImpl(client.createdWebView())->page()->mainFrame()->loader().load(requestWithTargetStart);
+ FrameLoadRequest requestWithTargetStart(0, webURLRequestWithTargetStart.toResourceRequest(), "_start");
+ toLocalFrame(toWebViewImpl(client.createdWebView())->page()->mainFrame())->loader().load(requestWithTargetStart);
EXPECT_TRUE(client.didFocusCalled());
m_webViewHelper.reset(); // Remove dependency on locally scoped client.
}
#if !ENABLE(INPUT_MULTIPLE_FIELDS_UI)
-static void openDateTimeChooser(WebView* webView, WebCore::HTMLInputElement* inputElement)
+static void openDateTimeChooser(WebView* webView, HTMLInputElement* inputElement)
{
inputElement->focus();
WebKeyboardEvent keyEvent;
- keyEvent.windowsKeyCode = WebCore::VKEY_SPACE;
+ keyEvent.windowsKeyCode = VKEY_SPACE;
keyEvent.type = WebInputEvent::RawKeyDown;
keyEvent.setKeyIdentifierFromWindowsKeyCode();
webView->handleInputEvent(keyEvent);
URLTestHelpers::registerMockedURLLoad(toKURL(url), "date_time_chooser.html");
WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
- WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->document();
+ Document* document = webViewImpl->mainFrameImpl()->frame()->document();
- WebCore::HTMLInputElement* inputElement;
+ HTMLInputElement* inputElement;
inputElement = toHTMLInputElement(document->getElementById("date"));
openDateTimeChooser(webViewImpl, inputElement);
client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quiet_NaN());
client.clearChooserCompletion();
EXPECT_STREQ("", inputElement->value().utf8().data());
+
+ // Clear the WebViewClient from the webViewHelper to avoid use-after-free in the
+ // WebViewHelper destructor.
+ m_webViewHelper.reset();
}
#endif
TEST_F(WebViewTest, SmartClipData)
{
+ static const char* kExpectedClipText = "\nPrice 10,000,000won";
+ static const char* kExpectedClipHtml =
+ "<div id=\"div4\" style=\"padding: 10px; margin: 10px; border: 2px "
+ "solid rgb(135, 206, 235); float: left; width: 190px; height: 30px; "
+ "color: rgb(0, 0, 0); font-family: myahem; font-size: 8px; font-style: "
+ "normal; font-variant: normal; font-weight: normal; letter-spacing: "
+ "normal; line-height: normal; orphans: auto; text-align: start; "
+ "text-indent: 0px; text-transform: none; white-space: normal; widows: "
+ "auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;\">Air "
+ "conditioner</div><div id=\"div5\" style=\"padding: 10px; margin: "
+ "10px; border: 2px solid rgb(135, 206, 235); float: left; width: "
+ "190px; height: 30px; color: rgb(0, 0, 0); font-family: myahem; "
+ "font-size: 8px; font-style: normal; font-variant: normal; "
+ "font-weight: normal; letter-spacing: normal; line-height: normal; "
+ "orphans: auto; text-align: start; text-indent: 0px; text-transform: "
+ "none; white-space: normal; widows: auto; word-spacing: 0px; "
+ "-webkit-text-stroke-width: 0px;\">Price 10,000,000won</div>";
+ WebString clipText;
+ WebString clipHtml;
+ WebRect clipRect;
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf"));
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("smartclip.html"));
WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip.html");
+ webView->setPageScaleFactorLimits(1, 1);
webView->resize(WebSize(500, 500));
webView->layout();
- WebRect cropRect(300, 125, 100, 50);
+ WebRect cropRect(300, 125, 152, 50);
+ webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect);
+ EXPECT_STREQ(kExpectedClipText, clipText.utf8().c_str());
+ EXPECT_STREQ(kExpectedClipHtml, clipHtml.utf8().c_str());
+}
- // FIXME: We should test the structure of the data we get back.
- EXPECT_FALSE(webView->getSmartClipData(cropRect).isEmpty());
+TEST_F(WebViewTest, SmartClipReturnsEmptyStringsWhenUserSelectIsNone)
+{
+ WebString clipText;
+ WebString clipHtml;
+ WebRect clipRect;
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("Ahem.ttf"));
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("smartclip_user_select_none.html"));
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "smartclip_user_select_none.html");
+ webView->setPageScaleFactorLimits(1, 1);
+ webView->resize(WebSize(500, 500));
+ webView->layout();
+ WebRect cropRect(0, 0, 100, 100);
+ webView->extractSmartClipData(cropRect, clipText, clipHtml, clipRect);
+ EXPECT_STREQ("", clipText.utf8().c_str());
+ EXPECT_STREQ("", clipHtml.utf8().c_str());
}
class CreateChildCounterFrameClient : public FrameTestHelpers::TestWebFrameClient {
public:
CreateChildCounterFrameClient() : m_count(0) { }
- virtual WebFrame* createChildFrame(WebFrame* parent, const WebString& frameName) OVERRIDE;
+ virtual WebFrame* createChildFrame(WebLocalFrame* parent, const WebString& frameName) override;
int count() const { return m_count; }
int m_count;
};
-WebFrame* CreateChildCounterFrameClient::createChildFrame(WebFrame* parent, const WebString& frameName)
+WebFrame* CreateChildCounterFrameClient::createChildFrame(WebLocalFrame* parent, const WebString& frameName)
{
++m_count;
return TestWebFrameClient::createChildFrame(parent, frameName);
CreateChildCounterFrameClient frameClient;
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("add_frame_in_unload.html"));
m_webViewHelper.initializeAndLoad(m_baseURL + "add_frame_in_unload.html", true, &frameClient);
- m_webViewHelper.webViewImpl()->dispatchUnloadEvent();
+ m_webViewHelper.webViewImpl()->mainFrame()->dispatchUnloadEvent();
EXPECT_EQ(0, frameClient.count());
m_webViewHelper.reset();
}
m_webViewHelper.reset();
}
-class TouchEventHandlerWebViewClient : public WebViewClient {
+class TouchEventHandlerWebViewClient : public FrameTestHelpers::TestWebViewClient {
public:
// WebWidgetClient methods
- virtual void hasTouchEventHandlers(bool state) OVERRIDE
+ virtual void hasTouchEventHandlers(bool state) override
{
m_hasTouchEventHandlerCount[state]++;
}
int m_hasTouchEventHandlerCount[2];
};
-// This test verifies that WebWidgetClient::hasTouchEventHandlers is called accordingly for various
-// calls to Document::did{Add|Remove|Clear}TouchEventHandler. Verifying that those calls are made
-// correctly is the job of LayoutTests/fast/events/touch/touch-handler-count.html.
+// This test verifies that WebWidgetClient::hasTouchEventHandlers is called
+// accordingly for various calls to EventHandlerRegistry::did{Add|Remove|
+// RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made
+// correctly is the job of LayoutTests/fast/events/event-handler-count.html.
TEST_F(WebViewTest, HasTouchEventHandlers)
{
TouchEventHandlerWebViewClient client;
std::string url = m_baseURL + "has_touch_event_handlers.html";
URLTestHelpers::registerMockedURLLoad(toKURL(url), "has_touch_event_handlers.html");
WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
+ const EventHandlerRegistry::EventHandlerClass touchEvent = EventHandlerRegistry::TouchEvent;
// The page is initialized with at least one no-handlers call.
// In practice we get two such calls because WebViewHelper::initializeAndLoad first
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding the first document handler results in a has-handlers call.
- WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->document();
- document->didAddTouchEventHandler(document);
+ Document* document = webViewImpl->mainFrameImpl()->frame()->document();
+ EventHandlerRegistry* registry = &document->frameHost()->eventHandlerRegistry();
+ registry->didAddEventHandler(*document, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding another handler has no effect.
- document->didAddTouchEventHandler(document);
+ registry->didAddEventHandler(*document, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Removing the duplicate handler has no effect.
- document->didRemoveTouchEventHandler(document);
+ registry->didRemoveEventHandler(*document, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Removing the final handler results in a no-handlers call.
- document->didRemoveTouchEventHandler(document);
+ registry->didRemoveEventHandler(*document, touchEvent);
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding a handler on a div results in a has-handlers call.
- WebCore::Element* parentDiv = document->getElementById("parentdiv");
+ Element* parentDiv = document->getElementById("parentdiv");
ASSERT(parentDiv);
- document->didAddTouchEventHandler(parentDiv);
+ registry->didAddEventHandler(*parentDiv, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding a duplicate handler on the div, clearing all document handlers
// (of which there are none) and removing the extra handler on the div
// all have no effect.
- document->didAddTouchEventHandler(parentDiv);
- document->didClearTouchEventHandlers(document);
- document->didRemoveTouchEventHandler(parentDiv);
+ registry->didAddEventHandler(*parentDiv, touchEvent);
+ registry->didRemoveAllEventHandlers(*document);
+ registry->didRemoveEventHandler(*parentDiv, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Removing the final handler on the div results in a no-handlers call.
- document->didRemoveTouchEventHandler(parentDiv);
+ registry->didRemoveEventHandler(*parentDiv, touchEvent);
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding two handlers then clearing them in a single call results in a
// has-handlers then no-handlers call.
- document->didAddTouchEventHandler(parentDiv);
+ registry->didAddEventHandler(*parentDiv, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
- document->didAddTouchEventHandler(parentDiv);
+ registry->didAddEventHandler(*parentDiv, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
- document->didClearTouchEventHandlers(parentDiv);
+ registry->didRemoveAllEventHandlers(*parentDiv);
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding a handler inside of a child iframe results in a has-handlers call.
- WebCore::Element* childFrame = document->getElementById("childframe");
+ Element* childFrame = document->getElementById("childframe");
ASSERT(childFrame);
- WebCore::Document* childDocument = toHTMLIFrameElement(childFrame)->contentDocument();
- WebCore::Element* childDiv = childDocument->getElementById("childdiv");
+ Document* childDocument = toHTMLIFrameElement(childFrame)->contentDocument();
+ Element* childDiv = childDocument->getElementById("childdiv");
ASSERT(childDiv);
- childDocument->didAddTouchEventHandler(childDiv);
+ registry->didAddEventHandler(*childDiv, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding and clearing handlers in the parent doc or elsewhere in the child doc
// has no impact.
- document->didAddTouchEventHandler(document);
- document->didAddTouchEventHandler(childFrame);
- childDocument->didAddTouchEventHandler(childDocument);
- document->didClearTouchEventHandlers(document);
- document->didClearTouchEventHandlers(childFrame);
- childDocument->didClearTouchEventHandlers(childDocument);
+ registry->didAddEventHandler(*document, touchEvent);
+ registry->didAddEventHandler(*childFrame, touchEvent);
+ registry->didAddEventHandler(*childDocument, touchEvent);
+ registry->didRemoveAllEventHandlers(*document);
+ registry->didRemoveAllEventHandlers(*childFrame);
+ registry->didRemoveAllEventHandlers(*childDocument);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Removing the final handler inside the child frame results in a no-handlers call.
- childDocument->didRemoveTouchEventHandler(childDiv);
+ registry->didRemoveAllEventHandlers(*childDiv);
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding a handler inside the child frame results in a has-handlers call.
- childDocument->didAddTouchEventHandler(childDocument);
+ registry->didAddEventHandler(*childDocument, touchEvent);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true));
// Adding a handler in the parent document and removing the one in the frame
// has no effect.
- document->didAddTouchEventHandler(childFrame);
- childDocument->didRemoveTouchEventHandler(childDocument);
- childDocument->didClearTouchEventHandlers(childDocument);
- document->didClearTouchEventHandlers(document);
+ registry->didAddEventHandler(*childFrame, touchEvent);
+ registry->didRemoveEventHandler(*childDocument, touchEvent);
+ registry->didRemoveAllEventHandlers(*childDocument);
+ registry->didRemoveAllEventHandlers(*document);
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
// Now removing the handler in the parent document results in a no-handlers call.
- document->didRemoveTouchEventHandler(childFrame);
+ registry->didRemoveEventHandler(*childFrame, touchEvent);
EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false));
EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true));
+
+ // Free the webView before the TouchEventHandlerWebViewClient gets freed.
+ m_webViewHelper.reset();
}
-static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor)
+// This test checks that deleting nodes which have only non-JS-registered touch
+// handlers also removes them from the event handler registry. Note that this
+// is different from detaching and re-attaching the same node, which is covered
+// by layout tests under fast/events/.
+TEST_F(WebViewTest, DeleteElementWithRegisteredHandler)
{
- WebCore::Element* element = document->getElementById("root");
+ std::string url = m_baseURL + "simple_div.html";
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "simple_div.html");
+ WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true);
+
+ RefPtrWillBePersistent<Document> document = webViewImpl->mainFrameImpl()->frame()->document();
+ Element* div = document->getElementById("div");
+ EventHandlerRegistry& registry = document->frameHost()->eventHandlerRegistry();
+
+ registry.didAddEventHandler(*div, EventHandlerRegistry::ScrollEvent);
+ EXPECT_TRUE(registry.hasEventHandlers(EventHandlerRegistry::ScrollEvent));
+
+ TrackExceptionState exceptionState;
+ div->remove(exceptionState);
+#if ENABLE(OILPAN)
+ // For oilpan we have to force a GC to ensure the event handlers have been removed when
+ // checking below. We do a precise GC (collectAllGarbage does not scan the stack)
+ // to ensure the div element dies. This is also why the Document is in a Persistent
+ // since we want that to stay around.
+ Heap::collectAllGarbage();
+#endif
+ EXPECT_FALSE(registry.hasEventHandlers(EventHandlerRegistry::ScrollEvent));
+}
+
+static WebRect ExpectedRootBounds(Document* document, float scaleFactor)
+{
+ Element* element = document->getElementById("root");
if (!element)
element = document->getElementById("target");
- if (element->hasTagName(WebCore::HTMLNames::iframeTag))
+ if (element->hasTagName(HTMLNames::iframeTag))
return ExpectedRootBounds(toHTMLIFrameElement(element)->contentDocument(), scaleFactor);
- WebCore::IntRect boundingBox;
- if (element->hasTagName(WebCore::HTMLNames::htmlTag))
- boundingBox = WebCore::IntRect(WebCore::IntPoint(0, 0), document->frame()->view()->contentsSize());
+ IntRect boundingBox;
+ if (element->hasTagName(HTMLNames::htmlTag))
+ boundingBox = IntRect(IntPoint(0, 0), document->frame()->view()->contentsSize());
else
boundingBox = element->pixelSnappedBoundingBox();
boundingBox = document->frame()->view()->contentsToWindow(boundingBox);
WebView* webView = m_webViewHelper.initializeAndLoad(url, true);
webView->resize(WebSize(640, 480));
- webView->setPageScaleFactor(pageScaleFactor, WebPoint(0, 0));
+ webView->setPageScaleFactor(pageScaleFactor);
webView->layout();
runPendingTasks();
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
EXPECT_TRUE(frame->frame()->document()->isHTMLDocument());
- WebCore::HTMLDocument* document = WebCore::toHTMLDocument(frame->frame()->document());
+ HTMLDocument* document = toHTMLDocument(frame->frame()->document());
WebRect expectedRootBounds = ExpectedRootBounds(document, webView->pageScaleFactor());
WebRect actualRootBounds;
WebRect anchor, focus;
webView->selectionBounds(anchor, focus);
- WebCore::IntRect expectedIntRect = expectedRootBounds;
+ IntRect expectedIntRect = expectedRootBounds;
ASSERT_TRUE(expectedIntRect.contains(anchor));
// The "overflow" tests have the focus boundary outside of the element box.
ASSERT_EQ(url.find("overflow") == std::string::npos, expectedIntRect.contains(focus));
webView->layout();
runPendingTasks();
- WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame());
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
EXPECT_TRUE(frame->frame()->document()->isHTMLDocument());
WebRect expectedRootBounds = WebRect(0, 0, contentSize.width, contentSize.height);
ASSERT_EQ(expectedRootBounds, actualRootBounds);
}
+class NonUserInputTextUpdateWebViewClient : public FrameTestHelpers::TestWebViewClient {
+public:
+ NonUserInputTextUpdateWebViewClient() : m_textIsUpdated(false) { }
+
+ // WebWidgetClient methods
+ virtual void didUpdateTextOfFocusedElementByNonUserInput() override
+ {
+ m_textIsUpdated = true;
+ }
+
+ void reset()
+ {
+ m_textIsUpdated = false;
+ }
+
+ bool textIsUpdated() const
+ {
+ return m_textIsUpdated;
+ }
+
+private:
+ int m_textIsUpdated;
+};
+
+// This test verifies that WebWidgetClient::didUpdateTextOfFocusedElementByNonUserInput is
+// called iff value of a focused element is modified via script.
+TEST_F(WebViewTest, NonUserInputTextUpdate)
+{
+ NonUserInputTextUpdateWebViewClient client;
+ std::string url = m_baseURL + "non_user_input_text_update.html";
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "non_user_input_text_update.html");
+ WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(url, true, 0, &client);
+ webViewImpl->setInitialFocus(false);
+
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
+ HTMLDocument* document = toHTMLDocument(frame->frame()->document());
+
+ // (A) <input>
+ // (A.1) Focused and value is changed by script.
+ client.reset();
+ EXPECT_FALSE(client.textIsUpdated());
+
+ HTMLInputElement* inputElement = toHTMLInputElement(document->getElementById("input"));
+ document->setFocusedElement(inputElement);
+ webViewImpl->setFocus(true);
+ EXPECT_EQ(document->focusedElement(), static_cast<Element*>(inputElement));
+
+ // Emulate value change from script.
+ inputElement->setValue("testA");
+ EXPECT_TRUE(client.textIsUpdated());
+ WebTextInputInfo info = webViewImpl->textInputInfo();
+ EXPECT_EQ("testA", std::string(info.value.utf8().data()));
+
+ // (A.2) Focused and user input modifies value.
+ client.reset();
+ EXPECT_FALSE(client.textIsUpdated());
+
+ WebVector<WebCompositionUnderline> emptyUnderlines;
+ webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1);
+ webViewImpl->confirmComposition(WebWidget::KeepSelection);
+ EXPECT_FALSE(client.textIsUpdated());
+ info = webViewImpl->textInputInfo();
+ EXPECT_EQ("testA2", std::string(info.value.utf8().data()));
+
+ // (A.3) Unfocused and value is changed by script.
+ client.reset();
+ EXPECT_FALSE(client.textIsUpdated());
+ document->setFocusedElement(nullptr);
+ webViewImpl->setFocus(false);
+ EXPECT_NE(document->focusedElement(), static_cast<Element*>(inputElement));
+ inputElement->setValue("testA3");
+ EXPECT_FALSE(client.textIsUpdated());
+
+ // (B) <textarea>
+ // (B.1) Focused and value is changed by script.
+ client.reset();
+ EXPECT_FALSE(client.textIsUpdated());
+ HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(document->getElementById("textarea"));
+ document->setFocusedElement(textAreaElement);
+ webViewImpl->setFocus(true);
+ EXPECT_EQ(document->focusedElement(), static_cast<Element*>(textAreaElement));
+ textAreaElement->setValue("testB");
+ EXPECT_TRUE(client.textIsUpdated());
+ info = webViewImpl->textInputInfo();
+ EXPECT_EQ("testB", std::string(info.value.utf8().data()));
+
+ // (B.2) Focused and user input modifies value.
+ client.reset();
+ EXPECT_FALSE(client.textIsUpdated());
+ webViewImpl->setComposition(WebString::fromUTF8("2"), emptyUnderlines, 1, 1);
+ webViewImpl->confirmComposition(WebWidget::KeepSelection);
+ info = webViewImpl->textInputInfo();
+ EXPECT_EQ("testB2", std::string(info.value.utf8().data()));
+
+ // (B.3) Unfocused and value is changed by script.
+ client.reset();
+ EXPECT_FALSE(client.textIsUpdated());
+ document->setFocusedElement(nullptr);
+ webViewImpl->setFocus(false);
+ EXPECT_NE(document->focusedElement(), static_cast<Element*>(textAreaElement));
+ inputElement->setValue("testB3");
+ EXPECT_FALSE(client.textIsUpdated());
+
+ // Free the webView before freeing the NonUserInputTextUpdateWebViewClient.
+ m_webViewHelper.reset();
+}
+
+// Check that the WebAutofillClient is correctly notified about first user
+// gestures after load, following various input events.
+TEST_F(WebViewTest, FirstUserGestureObservedKeyEvent)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("form.html"));
+ MockAutofillClient client;
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html", true);
+ webView->setAutofillClient(&client);
+ webView->setInitialFocus(false);
+
+ EXPECT_EQ(0, client.getUserGestureNotificationsCount());
+
+ WebKeyboardEvent keyEvent;
+ keyEvent.windowsKeyCode = VKEY_SPACE;
+ keyEvent.type = WebInputEvent::RawKeyDown;
+ keyEvent.setKeyIdentifierFromWindowsKeyCode();
+ webView->handleInputEvent(keyEvent);
+ keyEvent.type = WebInputEvent::KeyUp;
+ webView->handleInputEvent(keyEvent);
+
+ EXPECT_EQ(1, client.getUserGestureNotificationsCount());
+ webView->setAutofillClient(0);
+}
+
+TEST_F(WebViewTest, FirstUserGestureObservedMouseEvent)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("form.html"));
+ MockAutofillClient client;
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html", true);
+ webView->setAutofillClient(&client);
+ webView->setInitialFocus(false);
+
+ EXPECT_EQ(0, client.getUserGestureNotificationsCount());
+
+ WebMouseEvent mouseEvent;
+ mouseEvent.button = WebMouseEvent::ButtonLeft;
+ mouseEvent.x = 1;
+ mouseEvent.y = 1;
+ mouseEvent.clickCount = 1;
+ mouseEvent.type = WebInputEvent::MouseDown;
+ webView->handleInputEvent(mouseEvent);
+ mouseEvent.type = WebInputEvent::MouseUp;
+ webView->handleInputEvent(mouseEvent);
+
+ EXPECT_EQ(1, client.getUserGestureNotificationsCount());
+ webView->setAutofillClient(0);
+}
+
+TEST_F(WebViewTest, FirstUserGestureObservedGestureTap)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("longpress_selection.html"));
+ MockAutofillClient client;
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_selection.html", true);
+ webView->setAutofillClient(&client);
+ webView->setInitialFocus(false);
+
+ EXPECT_EQ(0, client.getUserGestureNotificationsCount());
+
+ EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fromUTF8("target")));
+
+ EXPECT_EQ(1, client.getUserGestureNotificationsCount());
+ webView->setAutofillClient(0);
+}
+
+TEST_F(WebViewTest, CompareSelectAllToContentAsText)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("longpress_selection.html"));
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_selection.html", true);
+
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
+ frame->executeScript(WebScriptSource(WebString::fromUTF8("document.execCommand('SelectAll', false, null)")));
+ std::string actual = frame->selectionAsText().utf8();
+
+ const int kMaxOutputCharacters = 1024;
+ std::string expected = frame->contentAsText(kMaxOutputCharacters).utf8();
+ EXPECT_EQ(expected, actual);
+}
+
+TEST_F(WebViewTest, AutoResizeSubtreeLayout)
+{
+ std::string url = m_baseURL + "subtree-layout.html";
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "subtree-layout.html");
+ WebView* webView = m_webViewHelper.initialize(true);
+
+ webView->enableAutoResizeMode(WebSize(200, 200), WebSize(200, 200));
+ loadFrame(webView->mainFrame(), url);
+
+ FrameView* frameView = m_webViewHelper.webViewImpl()->mainFrameImpl()->frameView();
+
+ // Auto-resizing used to ASSERT(needsLayout()) in RenderBlockFlow::layout. This EXPECT is
+ // merely a dummy. The real test is that we don't trigger asserts in debug builds.
+ EXPECT_FALSE(frameView->needsLayout());
+};
+
} // namespace