Tests for bug 634534 (destroy a stream while a part-request has been requested but OnStartRequest has not yet fired)

--HG--
extra : rebase_source : b29a496f75aacb57b8b9f285358278380580babd
This commit is contained in:
Benjamin Smedberg 2011-02-23 10:47:17 -05:00
parent 6381337493
commit d2f71a77df
4 changed files with 54 additions and 4 deletions

View File

@ -70,6 +70,7 @@ _MOCHITEST_FILES = \
test_pluginstream_poststream.html \
test_pluginstream_seek.html \
test_pluginstream_newstream.html \
test_pluginstream_seek_close.html \
test_fullpage.html \
loremipsum.xtest \
loremipsum.xtest^headers^ \

View File

@ -0,0 +1,38 @@
<body>
<head>
<title>NPAPI Seekable NPStream Test</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" />
</head>
<body>
<p id="display"></p>
<iframe id="testframe" name="testframe" onload="frameLoaded()"></iframe>
<!--
- Tests a seekable stream. Calls NPN_RequestRead with the specified
- range, and verifies that an NPP_Write call is made with the correct
- parameters, including the buffer data for the byte range. Once all
- calls to NPP_Write have finished, the plugin calls NPN_DestroyStream
- and then displays the entire stream's content in a browser frame via
- NPN_GetURL.
-->
<embed src="neverending.sjs" streammode="seek" closestream
frame="testframe" streamchunksize="1024" range="100,100"
id="embedtest" style="width: 400px; height: 100px;"
type="application/x-test"></embed>
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
function frameLoaded() {
ok(true, "We didn't crash");
SimpleTest.finish();
}
</script>
</body>
</html>

View File

@ -739,6 +739,7 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char*
instanceData->focusState = ACTIVATION_STATE_UNKNOWN;
instanceData->focusEventCount = 0;
instanceData->eventModel = 0;
instanceData->closeStream = false;
instance->pdata = instanceData;
TestNPObject* scriptableObject = (TestNPObject*)NPN_CreateObject(instance, &sNPClass);
@ -854,6 +855,9 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char*
strcmp(argv[i], "false") == 0) {
instanceData->cleanupWidget = false;
}
if (!strcmp(argn[i], "closestream")) {
instanceData->closeStream = true;
}
}
if (!browserSupportsWindowless || !pluginSupportsWindowlessMode()) {
@ -1116,7 +1120,6 @@ NPP_WriteReady(NPP instance, NPStream* stream)
int32_t
NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer)
{
printf("NPP_Write, offset=%d, len=%d, end=%d\n", offset, len, stream->end);
InstanceData* instanceData = (InstanceData*)(instance->pdata);
instanceData->writeCount++;
@ -1163,11 +1166,18 @@ NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buf
return len;
}
// If the complete stream has been written, and we're doing a seek test,
// then call NPN_RequestRead.
if (instanceData->streamMode == NP_SEEK &&
if (instanceData->closeStream) {
instanceData->closeStream = false;
if (instanceData->testrange != NULL) {
NPError err = NPN_RequestRead(stream, instanceData->testrange);
}
NPN_DestroyStream(instance, stream, NPRES_USER_BREAK);
}
else if (instanceData->streamMode == NP_SEEK &&
stream->end != 0 &&
stream->end == ((uint32_t)instanceData->streamBufSize + len)) {
// If the complete stream has been written, and we're doing a seek test,
// then call NPN_RequestRead.
// prevent recursion
instanceData->streamMode = NP_NORMAL;

View File

@ -137,6 +137,7 @@ typedef struct InstanceData {
ActivationState focusState;
int32_t focusEventCount;
int32_t eventModel;
bool closeStream;
} InstanceData;
void notifyDidPaint(InstanceData* instanceData);