コード例 #1
0
void ImeOnFocusTest::runImeOnFocusTest(std::string fileName, int expectedImeRequestCount, IntPoint tapPoint, const AtomicString& focusElement, std::string frame)
{
    ImeRequestTrackingWebViewClient client;
    registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::fromUTF8(fileName));
    WebViewImpl* webView = m_webViewHelper.initialize(true, 0, &client);
    webView->resize(WebSize(800, 1200));
    loadFrame(webView->mainFrame(), m_baseURL + fileName);
    m_document = m_webViewHelper.webViewImpl()->mainFrameImpl()->document().unwrap<Document>();

    if (!focusElement.isNull())
        focus(focusElement);
    EXPECT_EQ(0, client.imeRequestCount());

    if (tapPoint.x() >= 0 && tapPoint.y() >= 0)
        sendGestureTap(webView, tapPoint);

    if (!frame.empty()) {
        registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::fromUTF8(frame));
        WebFrame* childFrame = webView->mainFrame()->firstChild();
        loadFrame(childFrame, m_baseURL + frame);
    }

    if (!focusElement.isNull())
        focus(focusElement);
    EXPECT_EQ(expectedImeRequestCount, client.imeRequestCount());

    m_webViewHelper.reset();
}
コード例 #2
0
TEST_F(WebFrameTest, ReloadWithOverrideURLPreservesState)
{
    const std::string firstURL = "find.html";
    const std::string secondURL = "form.html";
    const std::string thirdURL = "history.html";
    const float pageScaleFactor = 1.1684f;
    const int pageWidth = 640;
    const int pageHeight = 480;

    registerMockedHttpURLLoad(firstURL);
    registerMockedHttpURLLoad(secondURL);
    registerMockedHttpURLLoad(thirdURL);

    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + firstURL, true));
    webViewImpl->resize(WebSize(pageWidth, pageHeight));
    webViewImpl->mainFrame()->setScrollOffset(WebSize(pageWidth / 4, pageHeight / 4));
    webViewImpl->setPageScaleFactorPreservingScrollOffset(pageScaleFactor);

    WebSize previousOffset = webViewImpl->mainFrame()->scrollOffset();
    float previousScale = webViewImpl->pageScaleFactor();

    // Reload the page using the cache.
    webViewImpl->mainFrame()->reloadWithOverrideURL(toKURL(m_baseURL + secondURL), false);
    webkit_support::ServeAsynchronousMockedRequests();
    ASSERT_EQ(previousOffset, webViewImpl->mainFrame()->scrollOffset());
    ASSERT_EQ(previousScale, webViewImpl->pageScaleFactor());

    // Reload the page while ignoring the cache.
    webViewImpl->mainFrame()->reloadWithOverrideURL(toKURL(m_baseURL + thirdURL), true);
    webkit_support::ServeAsynchronousMockedRequests();
    ASSERT_EQ(previousOffset, webViewImpl->mainFrame()->scrollOffset());
    ASSERT_EQ(previousScale, webViewImpl->pageScaleFactor());
}
コード例 #3
0
TEST(LinkHighlightImplTest, verifyWebViewImplIntegration)
{
    FrameTestHelpers::UseMockScrollbarSettings mockScrollbarSettings;

    const std::string baseURL("http://www.test.com/");
    const std::string fileName("test_touch_link_highlight.html");

    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(baseURL.c_str()), WebString::fromUTF8("test_touch_link_highlight.html"));
    FrameTestHelpers::WebViewHelper webViewHelper;
    WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(baseURL + fileName, true);
    int pageWidth = 640;
    int pageHeight = 480;
    webViewImpl->resize(WebSize(pageWidth, pageHeight));
    webViewImpl->updateAllLifecyclePhases();

    WebGestureEvent touchEvent;
    touchEvent.type = WebInputEvent::GestureShowPress;
    touchEvent.sourceDevice = WebGestureDeviceTouchscreen;

    // The coordinates below are linked to absolute positions in the referenced .html file.
    touchEvent.x = 20;
    touchEvent.y = 20;

    ASSERT_TRUE(webViewImpl->bestTapNode(getTargetedEvent(webViewImpl, touchEvent)));

    touchEvent.y = 40;
    EXPECT_FALSE(webViewImpl->bestTapNode(getTargetedEvent(webViewImpl, touchEvent)));

    touchEvent.y = 20;
    // Shouldn't crash.
    webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEvent));

    EXPECT_TRUE(webViewImpl->linkHighlight(0));
    EXPECT_TRUE(webViewImpl->linkHighlight(0)->contentLayer());
    EXPECT_TRUE(webViewImpl->linkHighlight(0)->clipLayer());

    // Find a target inside a scrollable div
    touchEvent.y = 100;
    webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEvent));
    ASSERT_TRUE(webViewImpl->linkHighlight(0));

    // Don't highlight if no "hand cursor"
    touchEvent.y = 220; // An A-link with cross-hair cursor.
    webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEvent));
    ASSERT_EQ(0U, webViewImpl->numLinkHighlights());

    touchEvent.y = 260; // A text input box.
    webViewImpl->enableTapHighlightAtPoint(getTargetedEvent(webViewImpl, touchEvent));
    ASSERT_EQ(0U, webViewImpl->numLinkHighlights());

    Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
}
コード例 #4
0
TEST_F(WebFrameTest, FixedLayoutInitializeAtMinimumPageScale)
{
    registerMockedHttpURLLoad("fixed_layout.html");

    FixedLayoutTestWebViewClient client;
    client.m_screenInfo.horizontalDPI = 160;
    int viewportWidth = 640;
    int viewportHeight = 480;
    client.m_windowRect = WebRect(0, 0, viewportWidth, viewportHeight);

    // Make sure we initialize to minimum scale, even if the window size
    // only becomes available after the load begins.
    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "fixed_layout.html", true, 0, &client));
    webViewImpl->enableFixedLayoutMode(true);
    webViewImpl->settings()->setViewportEnabled(true);
    webViewImpl->resize(WebSize(viewportWidth, viewportHeight));

    int defaultFixedLayoutWidth = 980;
    float minimumPageScaleFactor = viewportWidth / (float) defaultFixedLayoutWidth;
    EXPECT_EQ(minimumPageScaleFactor, webViewImpl->pageScaleFactor());

    // Assume the user has pinch zoomed to page scale factor 2.
    float userPinchPageScaleFactor = 2;
    webViewImpl->setPageScaleFactorPreservingScrollOffset(userPinchPageScaleFactor);
    webViewImpl->mainFrameImpl()->frameView()->layout();

    // Make sure we don't reset to initial scale if the page continues to load.
    bool isNewNavigation;
    webViewImpl->didCommitLoad(&isNewNavigation, false);
    webViewImpl->didChangeContentsSize();
    EXPECT_EQ(userPinchPageScaleFactor, webViewImpl->pageScaleFactor());

    // Make sure we don't reset to initial scale if the viewport size changes.
    webViewImpl->resize(WebSize(viewportWidth, viewportHeight + 100));
    EXPECT_EQ(userPinchPageScaleFactor, webViewImpl->pageScaleFactor());
}
コード例 #5
0
TEST(RemoteFrameThrottlingTest, ThrottledLocalRoot)
{
    FrameTestHelpers::TestWebViewClient viewClient;
    WebViewImpl* webView = WebViewImpl::create(&viewClient);
    webView->resize(WebSize(640, 480));

    // Create a remote root frame with a local child frame.
    FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
    webView->setMainFrame(remoteClient.frame());
    remoteClient.frame()->setReplicatedOrigin(WebSecurityOrigin::createUnique());

    WebFrameOwnerProperties properties;
    FrameTestHelpers::TestWebFrameClient localFrameClient;
    WebRemoteFrame* rootFrame = webView->mainFrame()->toWebRemoteFrame();
    WebLocalFrame* localFrame = rootFrame->createLocalChild(WebTreeScopeType::Document, "", WebSandboxFlags::None, &localFrameClient, nullptr, properties);

    WebString baseURL("http://internal.test/");
    URLTestHelpers::registerMockedURLFromBaseURL(baseURL, "simple_div.html");
    FrameTestHelpers::loadFrame(localFrame, baseURL.utf8() + "simple_div.html");

    FrameView* frameView = toWebLocalFrameImpl(localFrame)->frameView();
    EXPECT_TRUE(frameView->frame().isLocalRoot());

    // Enable throttling for the child frame.
    frameView->setFrameRect(IntRect(0, 480, frameView->width(), frameView->height()));
    frameView->frame().securityContext()->setSecurityOrigin(SecurityOrigin::createUnique());
    frameView->updateAllLifecyclePhases();
    testing::runPendingTasks();
    EXPECT_TRUE(frameView->shouldThrottleRendering());

    Document* frameDocument = frameView->frame().document();
    if (RuntimeEnabledFeatures::slimmingPaintSynchronizedPaintingEnabled())
        EXPECT_EQ(DocumentLifecycle::PaintClean, frameDocument->lifecycle().state());
    else
        EXPECT_EQ(DocumentLifecycle::PaintInvalidationClean, frameDocument->lifecycle().state());

    // Mutate the local child frame contents.
    auto* divElement = frameDocument->getElementById("div");
    divElement->setAttribute(styleAttr, "width: 50px");
    EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle().state());

    // Update the lifecycle again. The frame's lifecycle should not advance
    // because of throttling even though it is the local root.
    frameView->updateAllLifecyclePhases();
    testing::runPendingTasks();
    EXPECT_EQ(DocumentLifecycle::VisualUpdatePending, frameDocument->lifecycle().state());
    webView->close();
}
コード例 #6
0
TEST_F(WebFrameTest, CanOverrideMaximumScaleFactor)
{
    registerMockedHttpURLLoad("no_scale_for_you.html");

    FixedLayoutTestWebViewClient client;
    client.m_screenInfo.horizontalDPI = 160;
    int viewportWidth = 640;
    int viewportHeight = 480;
    client.m_windowRect = WebRect(0, 0, viewportWidth, viewportHeight);

    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "no_scale_for_you.html", true, 0, &client));
    webViewImpl->enableFixedLayoutMode(true);
    webViewImpl->settings()->setViewportEnabled(true);
    webViewImpl->resize(WebSize(viewportWidth, viewportHeight));

    EXPECT_EQ(1.0f, webViewImpl->maximumPageScaleFactor());

    webViewImpl->setIgnoreViewportTagMaximumScale(true);

    EXPECT_EQ(4.0f, webViewImpl->maximumPageScaleFactor());
}
コード例 #7
0
TEST_F(WebFrameTest, DivAutoZoomParamsTest)
{
    registerMockedHttpURLLoad("get_scale_for_auto_zoom_into_div_test.html");

    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "get_scale_for_auto_zoom_into_div_test.html", true));
    int pageWidth = 640;
    int pageHeight = 480;
    int divPosX = 200;
    int divPosY = 200;
    int divWidth = 200;
    int divHeight = 150;
    WebRect doubleTapPoint(250, 250, 0, 0);
    webViewImpl->resize(WebSize(pageWidth, pageHeight));
    float scale;
    WebPoint scroll;

    // Test for Doubletap scaling

    // Tests for zooming in and out without clamping.
    // Set device scale and scale limits so we dont get clamped.
    webViewImpl->setDeviceScaleFactor(4);
    webViewImpl->setPageScaleFactorLimits(0, 4 / webViewImpl->deviceScaleFactor());

    // Test zooming into div.
    webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll);
    float scaledDivWidth = divWidth * scale;
    float scaledDivHeight = divHeight * scale;
    int hScroll = ((divPosX * scale) - ((pageWidth - scaledDivWidth) / 2)) / scale;
    int vScroll = ((divPosY * scale) - ((pageHeight - scaledDivHeight) / 2)) / scale;
    EXPECT_NEAR(pageWidth / divWidth, scale, 0.1);
    EXPECT_EQ(hScroll, scroll.x);
    EXPECT_EQ(vScroll, scroll.y);

    // Test zoom out to overview scale.
    webViewImpl->applyScrollAndScale(WebSize(scroll.x, scroll.y), scale / webViewImpl->pageScaleFactor());
    webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll);
    EXPECT_FLOAT_EQ(1, scale);
    EXPECT_EQ(WebPoint(0, 0), scroll);

    // Tests for clamped scaling.
    // Test clamp to device scale:
    webViewImpl->applyScrollAndScale(WebSize(scroll.x, scroll.y), scale / webViewImpl->pageScaleFactor());
    webViewImpl->setDeviceScaleFactor(2.5);
    webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll);
    EXPECT_FLOAT_EQ(2.5, scale);

    // Test clamp to minimum scale:
    webViewImpl->applyScrollAndScale(WebSize(scroll.x, scroll.y), scale / webViewImpl->pageScaleFactor());
    webViewImpl->setPageScaleFactorLimits(1.5 / webViewImpl->deviceScaleFactor(), 4 / webViewImpl->deviceScaleFactor());
    webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll);
    EXPECT_FLOAT_EQ(1.5, scale);
    EXPECT_EQ(WebPoint(0, 0), scroll);

    // Test clamp to maximum scale:
    webViewImpl->applyScrollAndScale(WebSize(scroll.x, scroll.y), scale / webViewImpl->pageScaleFactor());
    webViewImpl->setDeviceScaleFactor(4);
    webViewImpl->setPageScaleFactorLimits(0, 3 / webViewImpl->deviceScaleFactor());
    webViewImpl->computeScaleAndScrollForHitRect(doubleTapPoint, WebViewImpl::DoubleTap, scale, scroll);
    EXPECT_FLOAT_EQ(3, scale);

    // Test for Non-doubletap scaling
    webViewImpl->setPageScaleFactor(1, WebPoint(0, 0));
    webViewImpl->setDeviceScaleFactor(4);
    webViewImpl->setPageScaleFactorLimits(0, 4 / webViewImpl->deviceScaleFactor());
    // Test zooming into div.
    webViewImpl->computeScaleAndScrollForHitRect(WebRect(250, 250, 10, 10), WebViewImpl::FindInPage, scale, scroll);
    EXPECT_NEAR(pageWidth / divWidth, scale, 0.1);

    // Drop any pending fake mouse events from zooming before leaving the test.
    webViewImpl->page()->mainFrame()->eventHandler()->clear();
}