/* WKConnectionClient */ static void connectionDidReceiveMessage(WKConnectionRef connection, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo) { // We only expect to get the "Pong" message. EXPECT_WK_STREQ(messageName, "PongMessageName"); EXPECT_WK_STREQ((WKStringRef)messageBody, "PongMessageBody"); messageReceived = true; }
static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef response, WKURLRequestRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*) { EXPECT_WK_STREQ("text/html", Util::MIMETypeForWKURLResponse(response)); WKFramePolicyListenerUse(listener); done = true; }
static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) { WKRetainPtr<WKStringRef> wkMIME = adoptWK(WKFrameCopyMIMEType(frame)); EXPECT_WK_STREQ("image/png", wkMIME); testDone = true; }
static void didCountStringMatches(WKPageRef page, WKStringRef string, unsigned numMatches, const void* clientInfo) { EXPECT_WK_STREQ("Hello", string); EXPECT_EQ(3u, numMatches); didCallCountStringMatches = true; }
static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*) { didReceiveMessage = true; EXPECT_WK_STREQ("DidCheckCanHandleRequest", messageName); EXPECT_EQ(WKBooleanGetTypeID(), WKGetTypeID(body)); canHandleRequest = WKBooleanGetValue(static_cast<WKBooleanRef>(body)); }
static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo) { ASSERT_NOT_NULL(frame); EXPECT_EQ(page, WKFrameGetPage(frame)); EXPECT_WK_STREQ("an alert", alertText); done = true; }
TEST(WebKit2, DISABLED_DOMWindowExtensionBasic) { WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DOMWindowExtensionBasicPageGroup"))); WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("DOMWindowExtensionBasic", pageGroup.get())); WKContextInjectedBundleClientV0 injectedBundleClient; memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); injectedBundleClient.base.version = 0; injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base); // The default cache model has a capacity of 0, so it is necessary to switch to a cache // model that actually allows for a page cache. WKContextSetCacheModel(context.get(), kWKCacheModelDocumentBrowser); PlatformWebView webView(context.get(), pageGroup.get()); // Make sure the extensions for each frame are installed in each world. WKRetainPtr<WKURLRef> url1(AdoptWK, Util::createURLForResource("simple-iframe", "html")); WKPageLoadURL(webView.page(), url1.get()); Util::run(&finished); finished = false; // Make sure those first 4 extensions are disconnected, and 2 new ones are installed. WKRetainPtr<WKURLRef> url2(AdoptWK, Util::createURLForResource("simple", "html")); WKPageLoadURL(webView.page(), url2.get()); Util::run(&finished); finished = false; // Make sure those two are disconnected, and the first four are reconnected. WKPageGoBack(webView.page()); Util::run(&finished); finished = false; // Make sure the 2 disconnected extensions in the page cache and the 4 active extensions are all removed. WKPageClose(webView.page()); Util::run(&finished); const size_t expectedSize = sizeof(expectedMessages) / sizeof(const char*); EXPECT_EQ(expectedSize, messages.size()); if (messages.size() != expectedSize) return; for (size_t i = 0; i < messages.size(); ++i) EXPECT_WK_STREQ(expectedMessages[i], messages[i].get()); }
static void runJavaScriptAlert(WKPageRef page, WKStringRef alertText, WKFrameRef frame, const void* clientInfo) { ASSERT_NOT_NULL(frame); EXPECT_EQ(page, WKFrameGetPage(frame)); switch (++testNumber) { case 1: EXPECT_WK_STREQ("PASS: shadowRoot created in injected bundle", alertText); break; case 2: EXPECT_WK_STREQ("PASS: shadowRoot created by normal world", alertText); break; case 3: EXPECT_WK_STREQ("PASS: query method exists", alertText); break; case 4: EXPECT_WK_STREQ("PASS: query method was not present in the normal world", alertText); break; case 5: EXPECT_WK_STREQ("Found:1,2,3,4,5,6", alertText); break; case 6: EXPECT_WK_STREQ("Found:2,3,4", alertText); done = true; break; } }
TEST(WebKit2, DISABLED_DOMWindowExtensionNoCache) { WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DOMWindowExtensionNoCachePageGroup"))); WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("DOMWindowExtensionNoCache", pageGroup.get())); WKContextInjectedBundleClientV1 injectedBundleClient; memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); injectedBundleClient.base.version = 1; injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base); // Disable the page cache. WKContextSetCacheModel(context.get(), kWKCacheModelDocumentViewer); PlatformWebView webView(context.get(), pageGroup.get()); // Make sure the extensions for each frame are installed in each world. WKRetainPtr<WKURLRef> url1(AdoptWK, Util::createURLForResource("simple-iframe", "html")); WKPageLoadURL(webView.page(), url1.get()); Util::run(&finished); finished = false; // Make sure those first 4 extensions are destroyed, and 2 new ones are installed. WKRetainPtr<WKURLRef> url2(AdoptWK, Util::createURLForResource("simple", "html")); WKPageLoadURL(webView.page(), url2.get()); Util::run(&finished); finished = false; // Make sure those 2 are destroyed, and the first 4 are recreated. WKPageGoBack(webView.page()); Util::run(&finished); finished = false; WKPageClose(webView.page()); Util::run(&finished); const size_t expectedSize = sizeof(expectedMessages) / sizeof(const char*); EXPECT_EQ(expectedSize, messages.size()); if (messages.size() != expectedSize) return; for (size_t i = 0; i < messages.size(); ++i) EXPECT_WK_STREQ(expectedMessages[i], messages[i].get()); }
static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*) { didReceiveMessage = true; EXPECT_WK_STREQ("DidReceiveWillSendSubmitEvent", messageName); EXPECT_EQ(WKDictionaryGetTypeID(), WKGetTypeID(body)); WKDictionaryRef values = static_cast<WKDictionaryRef>(body); WKRetainPtr<WKStringRef> textFieldKey(AdoptWK, WKStringCreateWithUTF8CString("textField")); WKStringRef textFieldValueWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(values, textFieldKey.get())); EXPECT_WK_STREQ("text field", textFieldValueWK); WKRetainPtr<WKStringRef> passwordFieldKey(AdoptWK, WKStringCreateWithUTF8CString("passwordField")); WKStringRef passwordFieldValueWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(values, passwordFieldKey.get())); EXPECT_WK_STREQ("password field", passwordFieldValueWK); // <input type="hidden"> fields are not sent. WKRetainPtr<WKStringRef> hiddenFieldKey(AdoptWK, WKStringCreateWithUTF8CString("hiddenField")); WKStringRef hiddenFieldValueWK = static_cast<WKStringRef>(WKDictionaryGetItemForKey(values, hiddenFieldKey.get())); EXPECT_NULL(hiddenFieldValueWK); }
static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo) { WKRetainPtr<WKStringRef> mimeType = adoptWK(WKFrameCopyMIMEType(frame)); EXPECT_WK_STREQ("text/html", mimeType); done = true; }
static void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef, WKTypeRef messageBody, const void* clientInfo) { EXPECT_WK_STREQ("Extra initialization data", static_cast<WKStringRef>(messageBody)); done = true; }