TEST(WebKit2, WKStringJSString) { WKStringRef wkString = WKStringCreateWithUTF8CString("hello"); JSStringRef jsString = JSStringCreateWithUTF8CString("hello"); WKStringRef convertedJSString = WKStringCreateWithJSString(jsString); EXPECT_TRUE(WKStringIsEqual(wkString, convertedJSString)); JSStringRef convertedWKString = WKStringCopyJSString(wkString); EXPECT_TRUE(JSStringIsEqual(jsString, convertedWKString)); WKRelease(wkString); WKRelease(convertedJSString); JSStringRelease(jsString); JSStringRelease(convertedWKString); }
static JSValueRef runPasteTestCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { gtk_widget_grab_focus(GTK_WIDGET(currentFixture->webView)); // Simulate a paste keyboard sequence. GdkEvent* event = gdk_event_new(GDK_KEY_PRESS); event->key.keyval = gdk_unicode_to_keyval('v'); event->key.state = GDK_CONTROL_MASK; event->key.window = gtk_widget_get_window(GTK_WIDGET(currentFixture->webView)); g_object_ref(event->key.window); #ifndef GTK_API_VERSION_2 GdkDeviceManager* manager = gdk_display_get_device_manager(gdk_window_get_display(event->key.window)); gdk_event_set_device(event, gdk_device_manager_get_client_pointer(manager)); #endif GdkKeymapKey* keys; gint n_keys; if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), event->key.keyval, &keys, &n_keys)) { event->key.hardware_keycode = keys[0].keycode; g_free(keys); } gtk_main_do_event(event); event->key.type = GDK_KEY_RELEASE; gtk_main_do_event(event); gdk_event_free(event); JSStringRef scriptString = JSStringCreateWithUTF8CString("document.body.innerHTML;"); JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0); JSStringRelease(scriptString); g_assert(JSValueIsString(context, value)); JSStringRef actual = JSValueToStringCopy(context, value, exception); g_assert(!exception || !*exception); g_assert(currentFixture->info->expectedContent); JSStringRef expected = JSStringCreateWithUTF8CString(currentFixture->info->expectedContent); g_assert(JSStringIsEqual(expected, actual)); JSStringRelease(expected); JSStringRelease(actual); g_main_loop_quit(currentFixture->loop); return JSValueMakeUndefined(context); }
static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); static JSStringRef ctrlKey = JSStringCreateWithUTF8CString("ctrlKey"); static JSStringRef shiftKey = JSStringCreateWithUTF8CString("shiftKey"); static JSStringRef altKey = JSStringCreateWithUTF8CString("altKey"); static JSStringRef metaKey = JSStringCreateWithUTF8CString("metaKey"); static JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); COMPtr<IWebFramePrivate> framePrivate; if (SUCCEEDED(frame->QueryInterface(&framePrivate))) framePrivate->layout(); JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); ASSERT(!exception || !*exception); int charCode = JSStringGetCharactersPtr(character)[0]; int virtualKeyCode = toupper(LOBYTE(VkKeyScan(charCode))); JSStringRelease(character); // Hack to map option-delete to ctrl-delete // Remove this when we fix <rdar://problem/5102974> layout tests need a way to decide how to choose the appropriate modifier keys bool convertOptionToCtrl = false; if (virtualKeyCode == VK_DELETE || virtualKeyCode == VK_BACK) convertOptionToCtrl = true; BYTE keyState[256]; if (argumentCount > 1) { ::GetKeyboardState(keyState); BYTE newKeyState[256]; memcpy(newKeyState, keyState, sizeof(keyState)); JSObjectRef modifiersArray = JSValueToObject(context, arguments[1], exception); if (modifiersArray) { int modifiersCount = JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty, 0), 0); for (int i = 0; i < modifiersCount; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0); JSStringRef string = JSValueToStringCopy(context, value, 0); if (JSStringIsEqual(string, ctrlKey)) newKeyState[VK_CONTROL] = 0x80; else if (JSStringIsEqual(string, shiftKey)) newKeyState[VK_SHIFT] = 0x80; else if (JSStringIsEqual(string, altKey)) { if (convertOptionToCtrl) newKeyState[VK_CONTROL] = 0x80; else newKeyState[VK_MENU] = 0x80; } else if (JSStringIsEqual(string, metaKey)) newKeyState[VK_MENU] = 0x80; JSStringRelease(string); } } ::SetKeyboardState(newKeyState); } MSG msg = makeMsg(webViewWindow, WM_KEYDOWN, virtualKeyCode, 0); dispatchMessage(&msg); if (argumentCount > 1) ::SetKeyboardState(keyState); return JSValueMakeUndefined(context); }