コード例 #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(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithoutScale)
{
    registerMockedHttpURLLoad("long_scroll.html");

    FrameTestHelpers::WebViewHelper webViewHelper;
    WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.html", true, 0, 0);
    webView->resize(WebSize(1000, 1000));
    webView->updateAllLifecyclePhases();

    WebViewImpl* webViewImpl = toWebViewImpl(webView);
    FrameLoader& loader = webViewImpl->mainFrameImpl()->frame()->loader();
    loader.setLoadType(FrameLoadTypeBackForward);

    webViewImpl->setPageScaleFactor(3.0f);
    webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 500));
    loader.documentLoader()->initialScrollState().wasScrolledByUser = false;
    loader.currentItem()->setPageScaleFactor(0);
    loader.currentItem()->setScrollPoint(WebPoint(0, 400));

    // FrameLoader::restoreScrollPositionAndViewState flows differently if scale is zero.
    loader.restoreScrollPositionAndViewState();

    // Expect that only the scroll position was restored.
    EXPECT_EQ(3.0f, webViewImpl->pageScaleFactor());
    EXPECT_EQ(400, webViewImpl->mainFrameImpl()->scrollOffset().height);
}
コード例 #3
0
TEST_F(ProgrammaticScrollTest, RestoreScrollPositionAndViewStateWithScale)
{
    registerMockedHttpURLLoad("long_scroll.html");

    FrameTestHelpers::WebViewHelper webViewHelper;
    WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "long_scroll.html", true, 0, 0);
    webView->resize(WebSize(1000, 1000));
    webView->updateAllLifecyclePhases();

    WebViewImpl* webViewImpl = toWebViewImpl(webView);
    FrameLoader& loader = webViewImpl->mainFrameImpl()->frame()->loader();
    loader.setLoadType(FrameLoadTypeBackForward);

    webViewImpl->setPageScaleFactor(3.0f);
    webViewImpl->mainFrame()->setScrollOffset(WebSize(0, 500));
    loader.documentLoader()->initialScrollState().wasScrolledByUser = false;
    loader.currentItem()->setPageScaleFactor(2);
    loader.currentItem()->setScrollPoint(WebPoint(0, 200));

    // Flip back the wasScrolledByUser flag which was set to true by setPageScaleFactor
    // because otherwise FrameLoader::restoreScrollPositionAndViewState does nothing.
    loader.documentLoader()->initialScrollState().wasScrolledByUser = false;
    loader.restoreScrollPositionAndViewState();

    // Expect that both scroll and scale were restored.
    EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor());
    EXPECT_EQ(200, webViewImpl->mainFrameImpl()->scrollOffset().height);
}
コード例 #4
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());
}
コード例 #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
Page* ChromeClientImpl::createWindow(
    Frame* frame, const FrameLoadRequest& r, const WindowFeatures& features)
{
    if (!m_webView->client())
        return 0;

    WebViewImpl* newView = static_cast<WebViewImpl*>(
        m_webView->client()->createView(WebFrameImpl::fromFrame(frame), features, r.frameName()));
    if (!newView)
        return 0;

    // The request is empty when we are just being asked to open a blank window.
    // This corresponds to window.open(""), for example.
    if (!r.resourceRequest().isEmpty()) {
        WrappedResourceRequest request(r.resourceRequest());
        newView->mainFrame()->loadRequest(request);
    }

    return newView->page();
}