Bug 347185 Adding automated tests r=roc

This commit is contained in:
Masayuki Nakano 2011-04-21 08:54:43 +09:00
parent 7b44ff8cc2
commit 1f33181162
10 changed files with 144 additions and 8 deletions

View File

@ -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

View File

@ -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:

View File

@ -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<TestNPObject*>(npobj)->npp;
InstanceData* id = static_cast<InstanceData*>(npp->pdata);
STRINGZ_TO_NPVARIANT(NPN_StrDup(id->lastKeyText.c_str()), *result);
return true;
}

View File

@ -138,6 +138,7 @@ typedef struct InstanceData {
int32_t focusEventCount;
int32_t eventModel;
bool closeStream;
std::string lastKeyText;
} InstanceData;
void notifyDidPaint(InstanceData* instanceData);

View File

@ -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<wchar_t>(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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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<WPARAM>(mCharCode);
msg.lParam = static_cast<LPARAM>(mScanCode);
msg.time = 0;
msg.pt.x = msg.pt.y = 0;
return msg;
}
};
// Used in char processing

View File

@ -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)

View File

@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for plugin input event</title>
<script type="text/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="text/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display">
<embed id="plugin" type="application/x-test" wmode="opaque">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
var gPlugin = document.getElementById("plugin");
var gUtils = window.
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIDOMWindowUtils);
function doTest() {
gPlugin.focus();
is(gUtils.IMEStatus, gUtils.IME_STATUS_PLUGIN,
"Plugin failed to get focus");
is(gPlugin.getLastKeyText(), "", "Must be empty before first key test");
gUtils.sendNativeKeyEvent(0x409 /* US */,
0x41, 0,
"a", "a");
is(gPlugin.getLastKeyText(), "a", "Invalid character was inputted");
gUtils.sendNativeKeyEvent(0x407 /* German */,
0xBB, 0,
"+", "+");
is(gPlugin.getLastKeyText(), "+", "Invalid character was inputted");
gUtils.sendNativeKeyEvent(0x407 /* German */,
0xBB, 0x1400 /* Ctrl + Alt (AltGr) */,
"~", "+");
is(gPlugin.getLastKeyText(), "~", "Invalid character was inputted");
SimpleTest.finish();
}
SimpleTest.waitForFocus(doTest);
</script>
</body>
</html>