Bug 544945: Mochitest of clipboard interaction that forces the plugin subprocess into a nested event loop on gtk2 platforms. r=karlt

This commit is contained in:
Chris Jones 2010-02-16 12:44:26 -06:00
parent a64fa515d0
commit 1c763b2c0a
5 changed files with 99 additions and 0 deletions

View File

@ -104,6 +104,12 @@ _MOCHICHROME_FILES += \
$(NULL)
endif
ifeq (gtk2,$(MOZ_WIDGET_TOOLKIT))
_MOCHITEST_FILES += \
test_copyText.html \
$(NULL)
endif
ifdef MOZ_IPC
_MOCHICHROME_FILES += \
test_crash_notify.xul \

View File

@ -0,0 +1,37 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test copying text from browser to plugin</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script class="testbody" type="text/javascript">
function runTests() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var text = " some text \n to copy 'n paste "
var textElt = document.getElementById("input");
var plugin = document.getElementById("plugin1");
textElt.focus();
textElt.value = text;
textElt.select();
textElt.QueryInterface(Components.interfaces.nsIDOMNSEditableElement)
.editor.copy();
is(plugin.getClipboardText(), text);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
</script>
</head>
<body onload="runTests()">
<embed id="plugin1" type="application/x-test" width="400" height="400"></embed>
<textarea id="input"></textarea>
</body>
</html>

View File

@ -154,6 +154,7 @@ static bool getAuthInfo(NPObject* npobj, const NPVariant* args, uint32_t argCoun
static bool asyncCallbackTest(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool checkGCRace(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool hangPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static bool getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const NPUTF8* sPluginMethodIdentifierNames[] = {
"npnEvaluateTest",
@ -193,6 +194,7 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
"asyncCallbackTest",
"checkGCRace",
"hang",
"getClipboardText",
};
static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMethodIdentifierNames)] = {
@ -233,6 +235,7 @@ static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMetho
asyncCallbackTest,
checkGCRace,
hangPlugin,
getClipboardText,
};
struct URLNotifyData
@ -2580,3 +2583,36 @@ hangPlugin(NPObject* npobj, const NPVariant* args, uint32_t argCount,
// test will fail.
return true;
}
#if defined(MOZ_WIDGET_GTK2)
bool
getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount,
NPVariant* result)
{
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
InstanceData* id = static_cast<InstanceData*>(npp->pdata);
string sel = pluginGetClipboardText(id);
uint32 len = sel.size();
char* selCopy = static_cast<char*>(NPN_MemAlloc(1 + len));
if (!selCopy)
return false;
memcpy(selCopy, sel.c_str(), len);
selCopy[len] = '\0';
STRINGN_TO_NPVARIANT(selCopy, len, *result);
// *result owns str now
return true;
}
#else
# warning "Implement pluginGetClipboardText for this platform"
bool
getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount,
NPVariant* result)
{
return false;
}
#endif

View File

@ -621,3 +621,17 @@ int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData,
void pluginDoInternalConsistencyCheck(InstanceData* instanceData, string& error)
{
}
string
pluginGetClipboardText(InstanceData* instanceData)
{
GtkClipboard* cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
// XXX this is a BAD WAY to interact with GtkClipboard. We use this
// deprecated interface only to test nested event loop handling.
gchar* text = gtk_clipboard_wait_for_text(cb);
string retText = text ? text : "";
g_free(text);
return retText;
}

View File

@ -120,4 +120,10 @@ int32_t pluginGetClipRegionRectEdge(InstanceData* instanceData,
*/
void pluginDoInternalConsistencyCheck(InstanceData* instanceData, std::string& error);
/**
* Get the current clipboard item as text. If the clipboard item
* isn't text, the returned value is undefined.
*/
std::string pluginGetClipboardText(InstanceData* instanceData);
#endif // nptest_platform_h_