Bug 90268 mochitest - test that we only deliver an <object data=""> stream once, because on Windows in windowed mode (only!) this causes Flash to stop working. r=josh
authorBenjamin Smedberg <benjamin@smedbergs.us>
Wed, 11 Jan 2012 15:33:48 -0500
changeset 84308 baa88d873a77108f9976178772b424bd1947af06
parent 84307 8f2f9ffb6ca4e315334ca4f5b9ed82d7d16db887
child 84309 1d1938bb244d2a2082b128dc4ae6fe4e7d04e927
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjosh
bugs90268
milestone12.0a1
Bug 90268 mochitest - test that we only deliver an <object data=""> stream once, because on Windows in windowed mode (only!) this causes Flash to stop working. r=josh
dom/plugins/test/mochitest/Makefile.in
dom/plugins/test/mochitest/pluginstream.js
dom/plugins/test/mochitest/test_pluginstream_poststream.html
dom/plugins/test/mochitest/test_pluginstream_src_dynamic.html
dom/plugins/test/testplugin/nptest.cpp
--- a/dom/plugins/test/mochitest/Makefile.in
+++ b/dom/plugins/test/mochitest/Makefile.in
@@ -59,16 +59,17 @@ include $(topsrcdir)/config/rules.mk
   loremipsum_nocache.txt \
   loremipsum_nocache.txt^headers^ \
   post.sjs \
   pluginstream.js \
   plugin_window.html \
   test_painting.html \
   test_pluginstream_err.html \
   test_pluginstream_src.html \
+  test_pluginstream_src_dynamic.html \
   test_pluginstream_geturl.html \
   test_pluginstream_geturlnotify.html \
   test_pluginstream_asfile.html \
   test_pluginstream_asfileonly.html \
   test_pluginstream_post.html \
   test_pluginstream_poststream.html \
   test_pluginstream_seek.html \
   test_pluginstream_newstream.html \
--- a/dom/plugins/test/mochitest/pluginstream.js
+++ b/dom/plugins/test/mochitest/pluginstream.js
@@ -1,21 +1,24 @@
   SimpleTest.waitForExplicitFinish();
 
   function frameLoaded() {
     var testframe = document.getElementById('testframe');
     var embed = document.getElementsByTagName('embed')[0];
+    if (undefined === embed)
+      embed = document.getElementsByTagName('object')[0];
     try {
       var content = testframe.contentDocument.body.innerHTML;
       if (!content.length)
         return;
 
       var filename = embed.getAttribute("src") ||
           embed.getAttribute("geturl") ||
-          embed.getAttribute("geturlnotify");
+          embed.getAttribute("geturlnotify") ||
+          embed.getAttribute("data");
       
       var req = new XMLHttpRequest();
       req.open('GET', filename, false);
       req.overrideMimeType('text/plain; charset=x-user-defined');
       req.send(null);
       is(req.status, 200, "bad XMLHttpRequest status");
       is(content, req.responseText.replace(/\r\n/g, "\n"),
          "content doesn't match");
--- a/dom/plugins/test/mochitest/test_pluginstream_poststream.html
+++ b/dom/plugins/test/mochitest/test_pluginstream_poststream.html
@@ -19,9 +19,9 @@
    - plugin via NPP_NewStream. Once this stream is received, it's displayed
    - in a frame in the browser via a call to NPN_GetURL.
    -->
   <embed src="loremipsum.txt" streammode="normal"
          frame="testframe" posturl="post.sjs" postmode="stream"
          id="embedtest" style="width: 400px; height: 100px;"
          type="application/x-test"></embed>
 </body>
-</html>
\ No newline at end of file
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/mochitest/test_pluginstream_src_dynamic.html
@@ -0,0 +1,39 @@
+<html>
+<head>
+  <title>NPAPI src="" NPStream Test</title>
+  <script type="text/javascript" 
+          src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" 
+          src="pluginstream.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>
+
+  <!--
+   - A stream is sent to the browser via NPP_NewStream, NP_NORMAL.
+   - The plugin reports that data can only be sent to it in 100-byte
+   - chunks.  When NPP_DestroyStream is called, the plugin sends the stream
+   - content back to the browser by passing it as a data: url to
+   - NPN_GetURL, using a frame, so that the stream content should 
+   - be displayed in the frame in the browser.
+   -
+   - We create the object element dynamically, which in some cases has caused us to deliver the data=""
+   - stream twice. This verifies that we only deliver the data="" stream once.
+   -->
+
+  <script type="text/javascript">
+    var e = document.createElement('object');
+    e.setAttribute('data', 'loremipsum.xtest');
+    e.setAttribute('type', 'application/x-test');
+    e.setAttribute('streammode', 'normal');
+    e.setAttribute('streamchunksize', '100');
+    e.setAttribute('frame', 'testframe');
+    e.setAttribute('style', 'width: 400px; height: 100px;');
+    document.body.appendChild(e);
+  </script>
+</body>
+</html>
--- a/dom/plugins/test/testplugin/nptest.cpp
+++ b/dom/plugins/test/testplugin/nptest.cpp
@@ -1028,16 +1028,20 @@ NPP_NewStream(NPP instance, NPMIMEType t
 
     if (instanceData->streamBufSize) {
       free(instanceData->streamBuf);
       instanceData->streamBufSize = 0;
       if (instanceData->testFunction == FUNCTION_NPP_POSTURL &&
           instanceData->postMode == POSTMODE_STREAM) {
         instanceData->testFunction = FUNCTION_NPP_GETURL;
       }
+      else {
+        // We already got a stream and didn't ask for another one.
+        instanceData->err << "Received unexpected multiple NPP_NewStream";
+      }
     }
   }
   return NPERR_NO_ERROR;
 }
 
 NPError
 NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
 {