From 418afd356b6677230a2cea1afd3cba27822d54c6 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Thu, 21 Apr 2011 08:54:43 +0900 Subject: [PATCH] Bug 347185 Adding automated tests r=roc --- layout/generic/nsObjectFrame.cpp | 4 +- modules/plugin/test/testplugin/README | 7 +++ modules/plugin/test/testplugin/nptest.cpp | 19 +++++- modules/plugin/test/testplugin/nptest.h | 1 + .../plugin/test/testplugin/nptest_windows.cpp | 21 +++++++ widget/src/windows/nsWindow.cpp | 20 ++++-- widget/src/windows/nsWindow.h | 4 +- widget/src/windows/nsWindowDefs.h | 12 ++++ widget/tests/Makefile.in | 1 + widget/tests/test_plugin_input_event.html | 63 +++++++++++++++++++ 10 files changed, 144 insertions(+), 8 deletions(-) create mode 100644 widget/tests/test_plugin_input_event.html diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index 0be218f4bed..94934d2e3e5 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -446,8 +446,10 @@ public: PRBool SendNativeEvents() { #ifdef XP_WIN + // XXX we should remove the plugin name check return mPluginWindow->type == NPWindowTypeDrawable && - MatchPluginName("Shockwave Flash"); + (MatchPluginName("Shockwave Flash") || + MatchPluginName("Test Plug-in")); #elif defined(MOZ_X11) || defined(XP_MACOSX) return PR_TRUE; #else diff --git a/modules/plugin/test/testplugin/README b/modules/plugin/test/testplugin/README index c623d94a9d2..876cdebafeb 100644 --- a/modules/plugin/test/testplugin/README +++ b/modules/plugin/test/testplugin/README @@ -225,6 +225,13 @@ getClipRegionRectCount(), this will throw an error. The coordinates are the same as for getEdge. See getClipRegionRectCount() above for notes on platform plugin limitations. +== Keyboard events == + +* getLastKeyText() +Returns the text which was inputted by last keyboard events. This is cleared at +every keydown event. +NOTE: Currently, this is implemented only on Windows. + == Mouse events == The test plugin supports the following scriptable methods: diff --git a/modules/plugin/test/testplugin/nptest.cpp b/modules/plugin/test/testplugin/nptest.cpp index b7e6e7c46bc..5d0e404401c 100644 --- a/modules/plugin/test/testplugin/nptest.cpp +++ b/modules/plugin/test/testplugin/nptest.cpp @@ -165,6 +165,7 @@ static bool getWindowPosition(NPObject* npobj, const NPVariant* args, uint32_t a static bool constructObject(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool setSitesWithData(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool setSitesWithDataCapabilities(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); +static bool getLastKeyText(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static const NPUTF8* sPluginMethodIdentifierNames[] = { "npnEvaluateTest", @@ -221,7 +222,8 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = { "getWindowPosition", "constructObject", "setSitesWithData", - "setSitesWithDataCapabilities" + "setSitesWithDataCapabilities", + "getLastKeyText" }; static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)]; static const ScriptableFunction sPluginMethodFunctions[] = { @@ -279,7 +281,8 @@ static const ScriptableFunction sPluginMethodFunctions[] = { getWindowPosition, constructObject, setSitesWithData, - setSitesWithDataCapabilities + setSitesWithDataCapabilities, + getLastKeyText }; STATIC_ASSERT(ARRAY_LENGTH(sPluginMethodIdentifierNames) == @@ -3436,3 +3439,15 @@ bool setSitesWithDataCapabilities(NPObject* npobj, const NPVariant* args, uint32 return true; } +bool getLastKeyText(NPObject* npobj, const NPVariant* args, uint32_t argCount, + NPVariant* result) +{ + if (argCount != 0) { + return false; + } + + NPP npp = static_cast(npobj)->npp; + InstanceData* id = static_cast(npp->pdata); + STRINGZ_TO_NPVARIANT(NPN_StrDup(id->lastKeyText.c_str()), *result); + return true; +} diff --git a/modules/plugin/test/testplugin/nptest.h b/modules/plugin/test/testplugin/nptest.h index a198d07fd47..d91975b31e5 100644 --- a/modules/plugin/test/testplugin/nptest.h +++ b/modules/plugin/test/testplugin/nptest.h @@ -138,6 +138,7 @@ typedef struct InstanceData { int32_t focusEventCount; int32_t eventModel; bool closeStream; + std::string lastKeyText; } InstanceData; void notifyDidPaint(InstanceData* instanceData); diff --git a/modules/plugin/test/testplugin/nptest_windows.cpp b/modules/plugin/test/testplugin/nptest_windows.cpp index 6816c7fca0e..0c4c2e2bee1 100644 --- a/modules/plugin/test/testplugin/nptest_windows.cpp +++ b/modules/plugin/test/testplugin/nptest_windows.cpp @@ -458,6 +458,27 @@ handleEventInternal(InstanceData* instanceData, NPEvent* pe, LRESULT* result) return true; } + case WM_KEYDOWN: + instanceData->lastKeyText.erase(); + *result = 0; + return true; + + case WM_CHAR: { + *result = 0; + wchar_t uniChar = static_cast(pe->wParam); + if (!uniChar) { + return true; + } + char utf8Char[6]; + int len = + ::WideCharToMultiByte(CP_UTF8, 0, &uniChar, 1, utf8Char, 6, NULL, NULL); + if (len == 0 || len > 6) { + return true; + } + instanceData->lastKeyText.append(utf8Char, len); + return true; + } + default: return false; } diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 8953adb17be..2ee73beada0 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -3993,10 +3993,17 @@ PRBool nsWindow::DispatchPluginEvent(UINT aMessage, } void nsWindow::RemoveMessageAndDispatchPluginEvent(UINT aFirstMsg, - UINT aLastMsg) + UINT aLastMsg, nsFakeCharMessage* aFakeCharMessage) { MSG msg; - ::GetMessageW(&msg, mWnd, aFirstMsg, aLastMsg); + if (aFakeCharMessage) { + if (aFirstMsg > WM_CHAR || aLastMsg < WM_CHAR) { + return; + } + msg = aFakeCharMessage->GetCharMessage(mWnd); + } else { + ::GetMessageW(&msg, mWnd, aFirstMsg, aLastMsg); + } DispatchPluginEvent(msg); } @@ -6986,6 +6993,8 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg, PRBool anyCharMessagesRemoved = PR_FALSE; if (aFakeCharMessage) { + RemoveMessageAndDispatchPluginEvent(WM_KEYFIRST, WM_KEYLAST, + aFakeCharMessage); anyCharMessagesRemoved = PR_TRUE; } else { while (gotMsg && (msg.message == WM_CHAR || msg.message == WM_SYSCHAR)) @@ -7010,9 +7019,12 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg, else if (gotMsg && (aFakeCharMessage || msg.message == WM_CHAR || msg.message == WM_SYSCHAR || msg.message == WM_DEADCHAR)) { - if (aFakeCharMessage) + if (aFakeCharMessage) { + MSG msg = aFakeCharMessage->GetCharMessage(mWnd); return OnCharRaw(aFakeCharMessage->mCharCode, - aFakeCharMessage->mScanCode, aModKeyState, extraFlags); + aFakeCharMessage->mScanCode, + aModKeyState, extraFlags, &msg); + } // If prevent default set for keydown, do same for keypress ::GetMessageW(&msg, mWnd, msg.message, msg.message); diff --git a/widget/src/windows/nsWindow.h b/widget/src/windows/nsWindow.h index d145343d0cc..63ec62311ba 100644 --- a/widget/src/windows/nsWindow.h +++ b/widget/src/windows/nsWindow.h @@ -355,7 +355,9 @@ protected: PRBool DispatchCommandEvent(PRUint32 aEventCommand); void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam); static void RemoveNextCharMessage(HWND aWnd); - void RemoveMessageAndDispatchPluginEvent(UINT aFirstMsg, UINT aLastMsg); + void RemoveMessageAndDispatchPluginEvent(UINT aFirstMsg, + UINT aLastMsg, + nsFakeCharMessage* aFakeCharMessage = nsnull); static MSG InitMSG(UINT aMessage, WPARAM wParam, LPARAM lParam); virtual PRBool ProcessMessage(UINT msg, WPARAM &wParam, LPARAM &lParam, LRESULT *aRetValue); diff --git a/widget/src/windows/nsWindowDefs.h b/widget/src/windows/nsWindowDefs.h index 1dc97098a80..fb06e3a2d71 100644 --- a/widget/src/windows/nsWindowDefs.h +++ b/widget/src/windows/nsWindowDefs.h @@ -244,6 +244,18 @@ struct nsAlternativeCharCode; // defined in nsGUIEvent.h struct nsFakeCharMessage { UINT mCharCode; UINT mScanCode; + + MSG GetCharMessage(HWND aWnd) + { + MSG msg; + msg.hwnd = aWnd; + msg.message = WM_CHAR; + msg.wParam = static_cast(mCharCode); + msg.lParam = static_cast(mScanCode); + msg.time = 0; + msg.pt.x = msg.pt.y = 0; + return msg; + } }; // Used in char processing diff --git a/widget/tests/Makefile.in b/widget/tests/Makefile.in index ff94397e759..5b3775a3a85 100644 --- a/widget/tests/Makefile.in +++ b/widget/tests/Makefile.in @@ -113,6 +113,7 @@ _CHROME_FILES += taskbar_previews.xul \ window_state_windows.xul \ taskbar_progress.xul \ test_chrome_context_menus_win.xul \ + test_plugin_input_event.html \ chrome_context_menus_win.xul \ $(NULL) diff --git a/widget/tests/test_plugin_input_event.html b/widget/tests/test_plugin_input_event.html new file mode 100644 index 00000000000..f8bfc806722 --- /dev/null +++ b/widget/tests/test_plugin_input_event.html @@ -0,0 +1,63 @@ + + + + Test for plugin input event + + + + + + +

+ +

+ +
+
+ + + +