TEST(WebKit2, WKPageCopySessionStateWithFiltering) { WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); createSessionStates(context.get()); EXPECT_NOT_NULL(sessionStateWithFirstItemRemoved); PlatformWebView webView1(context.get()); setPageLoaderClient(webView1.page()); WKPageRestoreFromSessionState(webView1.page(), sessionStateWithFirstItemRemoved.get()); Util::run(&didFinishLoad); didFinishLoad = false; WKBackForwardListRef backForwardList1 = WKPageGetBackForwardList(webView1.page()); EXPECT_EQ(0u, WKBackForwardListGetBackListCount(backForwardList1)); EXPECT_EQ(1u, WKBackForwardListGetForwardListCount(backForwardList1)); EXPECT_NOT_NULL(sessionStateWithAllItemsRemoved); PlatformWebView webView2(context.get()); setPageLoaderClient(webView2.page()); WKPageRestoreFromSessionState(webView2.page(), sessionStateWithAllItemsRemoved.get()); // Because the session state ends up being empty, nothing is actually loaded. WKBackForwardListRef backForwardList2 = WKPageGetBackForwardList(webView2.page()); EXPECT_EQ(0u, WKBackForwardListGetBackListCount(backForwardList2)); EXPECT_EQ(0u, WKBackForwardListGetForwardListCount(backForwardList2)); }
static void createSessionStates(WKContextRef context) { PlatformWebView webView(context); setPageLoaderClient(webView.page()); WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); Util::run(&didFinishLoad); didFinishLoad = false; WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple2", "html")).get()); Util::run(&didFinishLoad); didFinishLoad = false; WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple3", "html")).get()); Util::run(&didFinishLoad); didFinishLoad = false; WKPageGoBack(webView.page()); Util::run(&didFinishLoad); didFinishLoad = false; WKPageGoBack(webView.page()); Util::run(&didFinishLoad); didFinishLoad = false; // Should be back on simple.html at this point. sessionStateWithFirstItemRemoved = adoptWK(static_cast<WKSessionStateRef>(WKPageCopySessionState(webView.page(), reinterpret_cast<void*>(1), filterFirstItemCallback))); sessionStateWithAllItemsRemoved = adoptWK(static_cast<WKSessionStateRef>(WKPageCopySessionState(webView.page(), reinterpret_cast<void*>(1), filterAllItemsCallback))); }
static WKRetainPtr<WKDataRef> createSessionState(WKContextRef context) { PlatformWebView webView(context); setPageLoaderClient(webView.page()); WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); Util::run(&didFinishLoad); didFinishLoad = false; return adoptWK(WKPageCopySessionState(webView.page(), 0, 0)); }
// FIXME: This test has been broken since http://trac.webkit.org/changeset/115752 It's failing because // the frame load is completing before didLayout() manages to unlock the // kWKDidHitRelevantRepaintedObjectsAreaThreshold achievement. We probably need to fix this by making // this test have a long-running resource. TEST(WebKit2, DISABLED_NewFirstVisuallyNonEmptyLayout) { WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("NewFirstVisuallyNonEmptyLayoutTest")); PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); // This test is expected to succeed because lots-of-text.html is a large document and the relevant painted // objects take up more than 10% of the view. WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("lots-of-text", "html")).get()); Util::run(&didUnlockAllLayoutMilestones); EXPECT_TRUE(didUnlockAllLayoutMilestones); }
static WKRetainPtr<WKDataRef> createSessionStateContainingFormData(WKContextRef context) { PlatformWebView webView(context); setPageLoaderClient(webView.page()); WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-form", "html")).get()); Util::run(&didFinishLoad); didFinishLoad = false; TEST_ASSERT_RETURN(runJSTest(webView.page(), "submitForm()", "undefined"), 0); Util::run(&didFinishLoad); didFinishLoad = false; return adoptWK(WKPageCopySessionState(webView.page(), 0, 0)); }
TEST(WebKit2, WKPageGetScaleFactorNotZero) { WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); WKRetainPtr<WKDataRef> data = createSessionState(context.get()); EXPECT_NOT_NULL(data); WKPageRestoreFromSessionState(webView.page(), data.get()); Util::run(&didFinishLoad); EXPECT_TRUE(WKPageGetScaleFactor(webView.page()) == 1.0); }
virtual void SetUp() { context = adoptWK(Util::createContextForInjectedBundleTest("UserMessageTest")); setInjectedBundleClient(context.get(), this); webView = std::make_unique<PlatformWebView>(context.get()); setPageLoaderClient(webView->page(), this); didFinishLoad = false; didReceiveMessage = false; // Force the creation of the WKPageLoadURL(webView->page(), adoptWK(Util::createURLForResource("simple", "html")).get()); Util::run(&didFinishLoad); }
TEST(WebKit2, HitTestResultNodeHandle) { WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("HitTestResultNodeHandleTest")); setInjectedBundleClient(context.get()); PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); Util::run(&didFinishLoad); didFinishLoad = false; webView.simulateRightClick(10, 10); Util::run(&done); }
TEST(WebKit2, NewFirstVisuallyNonEmptyLayoutFrames) { didHitRelevantRepaintedObjectsAreaThresholdCounter = 0; WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("NewFirstVisuallyNonEmptyLayoutFramesTest")); PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("lots-of-iframes", "html")).get()); Util::run(&test1Done); Util::run(&test2Done); // By the time the forced repaint has finished, the counter would have been hit // if it was sized reasonably for the page. EXPECT_FALSE(didHitRelevantRepaintedObjectsAreaThresholdMoreThanOnce); }
TEST(WebKit2, RestoreSessionStateContainingFormData) { WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); // FIXME: Once <rdar://problem/8708435> is fixed, we can move the creation of this // PlatformWebView after the call to createSessionStaetContainingFormData. Until then, it must // remain here to avoid a race condition between the UI and web processes. PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); WKRetainPtr<WKDataRef> data = createSessionStateContainingFormData(context.get()); EXPECT_NOT_NULL(data); WKPageRestoreFromSessionState(webView.page(), data.get()); Util::run(&didFinishLoad); EXPECT_TRUE(WKPageCanGoBack(webView.page())); }
TEST(WebKit2, NewFirstVisuallyNonEmptyLayoutFails) { WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("NewFirstVisuallyNonEmptyLayoutFailsTest")); PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); // This test is expected to fail because simple.html is a small document and the relevant painted // objects take up less than 10% of the view. WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); Util::run(&test1Done); Util::run(&test2Done); // By the time the forced repaint has finished, the counter would have been hit // if it was sized reasonably for the page. EXPECT_FALSE(didHitRelevantRepaintedObjectsAreaThresholdAchieved); }
TEST(WebKit2, WKViewClientWebProcessCallbacks) { WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate()); WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html")); PlatformWebView view(context.get()); TestStatesData states = TestStatesData(view.platformView(), url.get()); setPageLoaderClient(view.page(), &states); setViewClient(view.platformView(), &states); WKPageLoadURL(view.page(), url.get()); Util::run(&states.didFinishLoad); WKPageTerminate(view.page()); Util::run(&states.didCrash); WKPageReload(view.page()); Util::run(&states.didRelaunch); }
TEST(WebKit2, ShouldGoToBackForwardListItem) { WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("ShouldGoToBackForwardListItemTest")); // Enable the page cache so we can test the WKBundleBackForwardListItemIsInPageCache API WKContextSetCacheModel(context.get(), kWKCacheModelDocumentBrowser); PlatformWebView webView(context.get()); setPageLoaderClient(webView.page()); WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get()); Util::run(&finished); finished = false; WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple-iframe", "html")).get()); Util::run(&finished); finished = false; WKPageGoBack(webView.page()); Util::run(&finished); EXPECT_EQ(receivedProperBackForwardCallbacks, true); }
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()"); }