Test for bug 550944 - When a stream is alive when a plugin instance is destroyed, NPP_DestroyStream and NPP_URLNotify are never called

--HG--
extra : rebase_source : cd5a5bca0964294fd74ab70123e805c4e0f9deac
This commit is contained in:
Benjamin Smedberg 2010-03-08 12:16:35 -05:00
Родитель f621b49574
Коммит 21fd7095ee
7 изменённых файлов: 131 добавлений и 0 удалений

Просмотреть файл

@ -77,6 +77,9 @@ _MOCHITEST_FILES = \
test_bug532208.html \
large-pic.jpg \
test_twostreams.html \
test_streamatclose.html \
neverending.sjs \
test_newstreamondestroy.html \
$(NULL)
# test_npruntime_npnsetexception.html \ Disabled for e10s

Просмотреть файл

@ -0,0 +1,15 @@
function handleRequest(request, response)
{
response.processAsync();
response.setHeader("Content-Type", "text/plain", false);
for (var i = 0; i < 1000; ++i)
response.write("Hello... ");
var timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
timer.initWithCallback(function() {
response.write("world.\n");
response.finish();
}, 10 * 1000 /* 10 secs */, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
}

Просмотреть файл

@ -0,0 +1,34 @@
<head>
<title>NPN_GetURL called from NPP_Destroy</title>
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css"
href="/tests/SimpleTest/test.css">
<body onload="runTest()">
<p id="display"></p>
<embed id="plugin1" type="application/x-test"></embed>
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
function runTest() {
var p = document.getElementById('plugin1');
var destroyed = false;
p.callOnDestroy(function() {
destroyed = true;
ok(!p.streamTest('loremipsum.txt', false, null,
function(r, t) {
ok(false, "get-during-destroy should have failed");
}), "NPN_GetURLNotify should fail during NPP_Destroy");
});
document.body.removeChild(p);
setTimeout(function() {
ok(destroyed, "callback was fired as expected");
SimpleTest.finish();
}, 1000);
}
</script>

Просмотреть файл

@ -0,0 +1,44 @@
<html>
<head>
<title>Stream open at NPP_Destroy</title>
<script type="text/javascript"
src="/MochiKit/packed.js"></script>
<script type="text/javascript"
src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css"
href="/tests/SimpleTest/test.css">
<body onload="startTest()">
<p id="display"></p>
<embed id="embedtest"
style="width: 400px; height: 100px;" type="application/x-test"></embed>
<script type="text/javascript">
SimpleTest.waitForExplicitFinish();
var urlnotified = false;
var p = document.getElementById('embedtest');
function startTest() {
ok(p.streamTest("neverending.sjs", false, null,
function(r, t) {
is(r, 2, "Stream should have failed");
urlnotified = true;
}), "neverending.sjs started successfully");
setTimeout(removePlugin, 500);
}
function removePlugin() {
document.body.removeChild(p); // Fires NPP_Destroy immediately
SimpleTest.executeSoon(done);
}
function done() {
ok(urlnotified, "NPP_URLNotify should be called if streams are active at NPP_Destroy");
SimpleTest.finish();
}
</script>

Просмотреть файл

@ -80,6 +80,8 @@ arguments passed to the method.
the object is passed to the same plugin instance, and false when passed
to other plugin instances, see bug 532246 and
test_multipleinstanceobjects.html.
* callOnDestroy(fn) - Calls `fn` when the plugin instance is being destroyed
* getAuthInfo(protocol, host, port, scheme, realm) - a wrapper for
NPN_GetAuthenticationInfo(). Returns a string "username|password" for

Просмотреть файл

@ -155,6 +155,7 @@ static bool asyncCallbackTest(NPObject* npobj, const NPVariant* args, uint32_t a
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 bool callOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
static const NPUTF8* sPluginMethodIdentifierNames[] = {
"npnEvaluateTest",
@ -195,6 +196,7 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
"checkGCRace",
"hang",
"getClipboardText",
"callOnDestroy",
};
static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMethodIdentifierNames)] = {
@ -236,6 +238,7 @@ static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMetho
checkGCRace,
hangPlugin,
getClipboardText,
callOnDestroy,
};
struct URLNotifyData
@ -592,6 +595,7 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char*
instanceData->testFunction = FUNCTION_NONE;
instanceData->functionToFail = FUNCTION_NONE;
instanceData->failureCode = 0;
instanceData->callOnDestroy = NULL;
instanceData->streamChunkSize = 1024;
instanceData->streamBuf = NULL;
instanceData->streamBufSize = 0;
@ -786,6 +790,13 @@ NPP_Destroy(NPP instance, NPSavedData** save)
if (instanceData->crashOnDestroy)
IntentionalCrash();
if (instanceData->callOnDestroy) {
NPVariant result;
NPN_InvokeDefault(instance, instanceData->callOnDestroy, NULL, 0, &result);
NPN_ReleaseVariantValue(&result);
NPN_ReleaseObject(instanceData->callOnDestroy);
}
if (instanceData->streamBuf) {
free(instanceData->streamBuf);
}
@ -2629,3 +2640,24 @@ getClipboardText(NPObject* npobj, const NPVariant* args, uint32_t argCount,
return false;
}
#endif
bool
callOnDestroy(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
InstanceData* id = static_cast<InstanceData*>(npp->pdata);
if (id->callOnDestroy)
return false;
if (1 != argCount || !NPVARIANT_IS_OBJECT(args[0]))
return false;
id->callOnDestroy = NPVARIANT_TO_OBJECT(args[0]);
NPN_RetainObject(id->callOnDestroy);
return true;
}

Просмотреть файл

@ -108,6 +108,7 @@ typedef struct InstanceData {
TestFunction testFunction;
TestFunction functionToFail;
NPError failureCode;
NPObject* callOnDestroy;
PostMode postMode;
std::string testUrl;
std::string frame;