mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
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:
parent
a64fa515d0
commit
1c763b2c0a
@ -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 \
|
||||
|
37
modules/plugin/test/mochitest/test_copyText.html
Normal file
37
modules/plugin/test/mochitest/test_copyText.html
Normal 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>
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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_
|
||||
|
Loading…
Reference in New Issue
Block a user