Example #1
0
TEST(WebKit2, SpacebarScrolling)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextWithInjectedBundle());
    PlatformWebView webView(context.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);

    EXPECT_JS_FALSE(webView.page(), "isDocumentScrolled()");
    EXPECT_JS_FALSE(webView.page(), "textFieldContainsSpace()");

    webView.simulateSpacebarKeyPress();

    EXPECT_JS_FALSE(webView.page(), "isDocumentScrolled()");
    EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()");

    // 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)
    EXPECT_FALSE(didNotHandleKeyDownEvent);
#elif PLATFORM(WIN)
    EXPECT_TRUE(didNotHandleKeyDownEvent);
#endif

    EXPECT_JS_EQ(webView.page(), "blurTextField()", "undefined");

    didNotHandleKeyDownEvent = false;
    webView.simulateSpacebarKeyPress();

    EXPECT_JS_TRUE(webView.page(), "isDocumentScrolled()");
    EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()");

#if PLATFORM(MAC)
    EXPECT_FALSE(didNotHandleKeyDownEvent);
#elif PLATFORM(WIN)
    EXPECT_TRUE(didNotHandleKeyDownEvent);
#endif
}
TEST(WebKit2, MouseMoveAfterCrash)
#endif
{
    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("MouseMoveAfterCrashTest"));

    PlatformWebView webView(context.get());
    setPageLoaderClient(webView.page());

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

    didFinishLoad = false;

    WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("Pause").get(), 0);

    webView.simulateSpacebarKeyPress();

    // Move the mouse once we are hung.
    webView.simulateMouseMove(10, 10);
    webView.simulateMouseMove(20, 20);

    // After moving the mouse (while the web process was hung on the Pause message), kill the web process. It is restarted by reloading the page.
    WKPageTerminate(webView.page());
    WKPageReload(webView.page());

    // Wait until we load the page a second time.
    Util::run(&didFinishLoad);

    EXPECT_JS_FALSE(webView.page(), "didMoveMouse()");

    // Once the page has reloaded, try moving the mouse to verify that we get mouse move events.
    webView.simulateMouseMove(10, 10);
    webView.simulateMouseMove(20, 20);

    EXPECT_JS_TRUE(webView.page(), "didMoveMouse()");
}