Exemplo n.º 1
0
TEST(WebKit2, Find)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    WKRetainPtr<WKPageNamespaceRef> pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get()));
    
    PlatformWebView webView(pageNamespace.get());
    
    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    
    loaderClient.version = 0;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient);

    WKPageFindClient findClient;
    memset(&findClient, 0, sizeof(findClient));

    findClient.version = 0;
    findClient.didCountStringMatches = didCountStringMatches;
    WKPageSetPageFindClient(webView.page(), &findClient);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("find", "html"));
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&didFinishLoad);

    WKRetainPtr<WKStringRef> findString(AdoptWK, WKStringCreateWithUTF8CString("Hello"));
    WKPageCountStringMatches(webView.page(), findString.get(), true, 100);

    Util::run(&didCallCountStringMatches);
}
Exemplo n.º 2
0
void BrowserView::create(RECT webViewRect, BrowserWindow* parentWindow)
{
    assert(!m_webView);

    bool isShiftKeyDown = ::GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT;

    WKContextRef context;
    if (isShiftKeyDown)
        context = WKContextGetSharedThreadContext();
    else
        context = WKContextGetSharedProcessContext();

    WKPageNamespaceRef pageNamespace = WKPageNamespaceCreate(context);

    m_webView = WKViewCreate(webViewRect, pageNamespace, parentWindow->window());

    WKPageUIClient uiClient = {
        0,              /* version */
        parentWindow,   /* clientInfo */
        createNewPage,
        showPage,
        closePage,
        runJavaScriptAlert,
        runJavaScriptConfirm,
        runJavaScriptPrompt,
        setStatusText,
        contentsSizeChanged
    };

    WKPageSetPageUIClient(WKViewGetPage(m_webView), &uiClient);
}
Exemplo n.º 3
0
void BrowserView::create(RECT webViewRect, HWND parentWindow)
{
    assert(!m_webView);

    WKContextRef context = WKContextCreateWithProcessModel(kWKProcessModelSecondaryProcess);
    WKPageNamespaceRef pageNamespace = WKPageNamespaceCreate(context);

    m_webView = WKViewCreate(webViewRect, pageNamespace, parentWindow);
}
Exemplo n.º 4
0
TEST(WebKit2, SpacebarScrolling)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    WKRetainPtr<WKPageNamespaceRef> pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get()));

    PlatformWebView webView(pageNamespace.get());

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    
    loaderClient.version = 0;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient);

    WKPageUIClient uiClient;
    memset(&uiClient, 0, sizeof(uiClient));

    uiClient.didNotHandleKeyEvent = didNotHandleKeyEventCallback;
    WKPageSetPageUIClient(webView.page(), &uiClient);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("spacebar-scrolling", "html"));
    WKPageLoadURL(webView.page(), url.get());
    Util::run(&didFinishLoad);

    TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "false"));
    TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "false"));

    webView.simulateSpacebarKeyPress();

    TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "false"));
    TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "true"));

    // On Mac, a key down event represents both a raw key down and a key press. On Windows, a key
    // down event only represents a raw key down. We expect the key press to be handled (because it
    // inserts text into the text field). But the raw key down should not be handled.
#if PLATFORM(MAC)
    TEST_ASSERT(!didNotHandleKeyDownEvent);
#elif PLATFORM(WIN)
    TEST_ASSERT(didNotHandleKeyDownEvent);
#endif

    TEST_ASSERT(runJSTest(webView.page(), "blurTextField()", "undefined"));

    didNotHandleKeyDownEvent = false;
    webView.simulateSpacebarKeyPress();

    TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "true"));
    TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "true"));
#if PLATFORM(MAC)
    TEST_ASSERT(!didNotHandleKeyDownEvent);
#elif PLATFORM(WIN)
    TEST_ASSERT(didNotHandleKeyDownEvent);
#endif
}
Exemplo n.º 5
0
TEST(WebKit2, FailedLoad)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    WKRetainPtr<WKPageNamespaceRef> pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get()));
    PlatformWebView webView(pageNamespace.get());

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));

    loaderClient.version = 0;
    loaderClient.clientInfo = 0;
    loaderClient.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::URLForNonExistentResource());
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&testDone);
}
Exemplo n.º 6
0
TEST(WebKit2, FrameMIMETypePNG)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    WKRetainPtr<WKPageNamespaceRef> pageNamespace(AdoptWK, WKPageNamespaceCreate(context.get()));
    PlatformWebView webView(pageNamespace.get());

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));

    loaderClient.version = 0;
    loaderClient.clientInfo = 0;
    loaderClient.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame;
    loaderClient.didCommitLoadForFrame = didCommitLoadForFrame;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("icon", "png"));
    WKPageLoadURL(webView.page(), url.get());

    Util::run(&testDone);
}