Commit 748ed604 authored by andersca@apple.com's avatar andersca@apple.com

Test that we call NPP_DestroyStream if a plug-in returns -1 from its NPP_Write function

https://bugs.webkit.org/show_bug.cgi?id=41821

Reviewed by Sam Weinig.

WebKitTools:

* DumpRenderTree/TestNetscapePlugIn/PluginObject.cpp:
(pluginGetProperty):
(pluginSetProperty):
(pluginAllocate):
* DumpRenderTree/TestNetscapePlugIn/PluginObject.h:
Add and initialize the returnNegativeOneFromWrite property.

* DumpRenderTree/TestNetscapePlugIn/main.cpp:
(NPP_NewStream):
Set the stream type to NP_NORMAL so we'll get write callbacks.

(NPP_DestroyStream):
Treat the onstreamdestroy attribute as a function name and not a string.

(NPP_WriteReady):
Have this return a nonzero value.

(NPP_Write):
If returnNegativeOneFromWrite is true return -1.

LayoutTests:

* plugins/return-error-from-new-stream-doesnt-invoke-destroy-stream.html:
Update for changes to onstreamdestroy.

* plugins/return-negative-one-from-write-expected.txt: Added.
* plugins/return-negative-one-from-write.html: Added.
Add new test.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@62739 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent df83114e
2010-07-07 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
Test that we call NPP_DestroyStream if a plug-in returns -1 from its NPP_Write function
https://bugs.webkit.org/show_bug.cgi?id=41821
* plugins/return-error-from-new-stream-doesnt-invoke-destroy-stream.html:
Update for changes to onstreamdestroy.
* plugins/return-negative-one-from-write-expected.txt: Added.
* plugins/return-negative-one-from-write.html: Added.
Add new test.
2010-07-07 Chris Fleizach <cfleizach@apple.com>
Reviewed by Darin Adler.
......@@ -38,7 +38,7 @@
<embed
type="application/x-webkit-test-netscape"
onStreamLoad="streamStarted()"
onStreamDestroy="streamDestroyed()"
onStreamDestroy="streamDestroyed"
onURLNotify="requestCompleted()"
id="plugin">
</body>
......
This tests that NPP_DestroyStream is called with NPRES_NETWORK_ERR not called if a plug-in returns -1 its NPP_Write callback.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS plugin.returnNegativeOneFromWrite is true
PASS newStreamCalled is false
PASS newStreamCalled is true
PASS reason is 1
TEST COMPLETE
<html>
<head>
<link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
<script src="../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
var newStreamCalled = false;
var destroyStreamCalled = false;
function main() {
if (!window.layoutTestController) {
debug("This test can only run from within DumpRenderTree, because it requires TestNetscapePlugin.\n");
return;
}
layoutTestController.waitUntilDone();
}
main();
function streamStarted() {
shouldBeFalse('newStreamCalled');
newStreamCalled = true;
}
function streamDestroyed(reason) {
window.reason = reason;
shouldBeTrue('newStreamCalled')
shouldBe('reason', '1');
debug('<br><span class="pass">TEST COMPLETE</span>');
layoutTestController.notifyDone();
}
</script>
<embed
type="application/x-webkit-test-netscape"
onStreamLoad="streamStarted()"
onStreamDestroy="streamDestroyed"
id="plugin">
</body>
<script>
description("This tests that NPP_DestroyStream is called with NPRES_NETWORK_ERR not called if a plug-in returns -1 its NPP_Write callback.");
var plugin = document.getElementById("plugin");
plugin.returnNegativeOneFromWrite = true;
shouldBeTrue("plugin.returnNegativeOneFromWrite");
plugin.getURLNotify("data:text/html,Test", null, "callback");
</script>
</html>
2010-07-07 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
Test that we call NPP_DestroyStream if a plug-in returns -1 from its NPP_Write function
https://bugs.webkit.org/show_bug.cgi?id=41821
* DumpRenderTree/TestNetscapePlugIn/PluginObject.cpp:
(pluginGetProperty):
(pluginSetProperty):
(pluginAllocate):
* DumpRenderTree/TestNetscapePlugIn/PluginObject.h:
Add and initialize the returnNegativeOneFromWrite property.
* DumpRenderTree/TestNetscapePlugIn/main.cpp:
(NPP_NewStream):
Set the stream type to NP_NORMAL so we'll get write callbacks.
(NPP_DestroyStream):
Treat the onstreamdestroy attribute as a function name and not a string.
(NPP_WriteReady):
Have this return a nonzero value.
(NPP_Write):
If returnNegativeOneFromWrite is true return -1.
2010-07-07 Kevin Ollivier <kevino@theolliviers.com>
[wx] Build fix for machines with both MSVC 2005 and 2008 installed. Ensures the
......
......@@ -132,6 +132,7 @@ enum {
ID_PROPERTY_TEST_OBJECT,
ID_PROPERTY_LOG_DESTROY,
ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM,
ID_PROPERTY_RETURN_NEGATIVE_ONE_FROM_WRITE,
ID_PROPERTY_PRIVATE_BROWSING_ENABLED,
ID_PROPERTY_CACHED_PRIVATE_BROWSING_ENABLED,
ID_PROPERTY_THROW_EXCEPTION_PROPERTY,
......@@ -147,6 +148,7 @@ static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
"testObject",
"logDestroy",
"returnErrorFromNewStream",
"returnNegativeOneFromWrite",
"privateBrowsingEnabled",
"cachedPrivateBrowsingEnabled",
"testThrowExceptionProperty",
......@@ -282,6 +284,9 @@ static bool pluginGetProperty(NPObject* obj, NPIdentifier name, NPVariant* resul
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM]) {
BOOLEAN_TO_NPVARIANT(plugin->returnErrorFromNewStream, *result);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_NEGATIVE_ONE_FROM_WRITE]) {
BOOLEAN_TO_NPVARIANT(plugin->returnNegativeOneFromWrite, *result);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_PRIVATE_BROWSING_ENABLED]) {
NPBool privateBrowsingEnabled = FALSE;
browser->getvalue(plugin->npp, NPNVprivateModeBool, &privateBrowsingEnabled);
......@@ -317,6 +322,9 @@ static bool pluginSetProperty(NPObject* obj, NPIdentifier name, const NPVariant*
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM]) {
plugin->returnErrorFromNewStream = NPVARIANT_TO_BOOLEAN(*variant);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_NEGATIVE_ONE_FROM_WRITE]) {
plugin->returnNegativeOneFromWrite = NPVARIANT_TO_BOOLEAN(*variant);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_THROW_EXCEPTION_PROPERTY]) {
browser->setexception(obj, "plugin object testThrowExceptionProperty SUCCESS");
return true;
......@@ -967,6 +975,7 @@ static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
newInstance->logDestroy = FALSE;
newInstance->logSetWindow = FALSE;
newInstance->returnErrorFromNewStream = FALSE;
newInstance->returnNegativeOneFromWrite = FALSE;
newInstance->stream = 0;
newInstance->firstUrl = NULL;
......
......@@ -34,6 +34,7 @@ typedef struct {
NPBool eventLogging;
NPBool logSetWindow;
NPBool logDestroy;
NPBool returnNegativeOneFromWrite;
NPBool returnErrorFromNewStream;
NPBool cachedPrivateBrowsingMode;
NPObject* testObject;
......
......@@ -239,7 +239,7 @@ NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool se
{
PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
obj->stream = stream;
*stype = NP_ASFILEONLY;
*stype = NP_NORMAL;
if (obj->returnErrorFromNewStream)
return NPERR_GENERIC_ERROR;
......@@ -257,8 +257,28 @@ NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
{
PluginObject* obj = (PluginObject*)instance->pdata;
if (obj->onStreamDestroy)
executeScript(obj, obj->onStreamDestroy);
if (obj->onStreamDestroy) {
NPObject* windowObject = 0;
NPError error = browser->getvalue(instance, NPNVWindowNPObject, &windowObject);
if (error == NPERR_NO_ERROR) {
NPVariant onStreamDestroyVariant;
if (browser->getproperty(instance, windowObject, browser->getstringidentifier(obj->onStreamDestroy), &onStreamDestroyVariant)) {
if (NPVARIANT_IS_OBJECT(onStreamDestroyVariant)) {
NPObject* onStreamDestroyFunction = NPVARIANT_TO_OBJECT(onStreamDestroyVariant);
NPVariant reasonVariant;
INT32_TO_NPVARIANT(reason, reasonVariant);
NPVariant result;
browser->invokeDefault(instance, onStreamDestroyFunction, &reasonVariant, 1, &result);
browser->releasevariantvalue(&result);
}
browser->releasevariantvalue(&onStreamDestroyVariant);
}
browser->releaseobject(windowObject);
}
}
if (obj->testDocumentOpenInDestroyStream) {
testDocumentOpen(instance);
......@@ -270,12 +290,17 @@ NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
int32_t NPP_WriteReady(NPP instance, NPStream *stream)
{
return 0;
return 4096;
}
int32_t NPP_Write(NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
{
return 0;
PluginObject* obj = (PluginObject*)instance->pdata;
if (obj->returnNegativeOneFromWrite)
return -1;
return len;
}
void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment