Skip to content

Instantly share code, notes, and snippets.

@Adenilson
Created February 9, 2013 16:23
Show Gist options
  • Save Adenilson/4745884 to your computer and use it in GitHub Desktop.
Save Adenilson/4745884 to your computer and use it in GitHub Desktop.
Crash/Reload WK2 test
#include "config.h"
#include "PlatformUtilities.h"
#include "PlatformWebView.h"
#include "Test.h"
#include <WebKit2/WKRetainPtr.h>
#include <stdio.h>
namespace TestWebKitAPI {
static bool done = false;
static bool loaded = false;
// TODO: better naming for the callback here
static void didFailProvisionalLoadWithErrorForFrame(WKPageRef page, WKFrameRef frame, WKErrorRef error, WKTypeRef userData, const void* clientInfo)
{
// Ok, this is the first load
if (!done) {
done = true;
// TODO: remove this
fprintf(stderr, "####### here we are...\n");
EXPECT_TRUE(done);
return;
}
// Second time is the charm
fprintf(stderr, "####### Yeah! It is still alive!\n"); // Ditto!
EXPECT_EQ(static_cast<uint32_t>(kWKFrameLoadStateFinished), WKFrameGetFrameLoadState(frame));
EXPECT_TRUE(!loaded);
}
TEST(WebKit2, CrashReload)
{
WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
PlatformWebView webView(context.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::createURLForResource("simple", "html"));
WKPageLoadURL(webView.page(), url.get());
Util::run(&done);
// I wonder if/how should I wait before asking to kill WebProcess
WKPageTerminate(webView.page());
WKPageLoadURL(webView.page(), url.get());
Util::run(&loaded);
}
} // namespace TestWebKitAPI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment