Bug 1212223 - Update |bufLen| as well when we probed the multipart preamble. r=valentin.
authorhchang <hchang@mozilla.com>
Wed, 07 Oct 2015 17:06:00 +0200
changeset 266847 fe4a2767f51f2ff38b639b74aed16d04d82acf39
parent 266846 b185293e7db6b8a3f48389e457ba1edc71327bc8
child 266848 390a24a7d8264290efbfb08440faba9bd5df782c
push id29499
push userkwierso@gmail.com
push dateThu, 08 Oct 2015 21:29:10 +0000
treeherdermozilla-central@46da59584acb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1212223
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1212223 - Update |bufLen| as well when we probed the multipart preamble. r=valentin.
netwerk/streamconv/converters/nsMultiMixedConv.cpp
netwerk/test/unit/test_multipart_streamconv_application_package.js
--- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp
+++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp
@@ -659,16 +659,20 @@ nsMultiMixedConv::OnDataAvailable(nsIReq
                 } else {
                     // Token is probed.
                     mToken = Substring(tokenPos, mTokenLen);
                     mPreamble = nsCString(Substring(buffer, tokenPos));
 
                     // Push the cursor to the token so that the while loop below will
                     // find token from the right position.
                     cursor = tokenPos;
+
+                    // Update bufLen to exlude the preamble. Otherwise, the first
+                    // |SendData| would claim longer buffer length.
+                    bufLen -= mPreamble.Length();
                 }
             } else {
                 // If the boundary was set in the header,
                 // we need to check it matches with the one in the file.
                 if (mTokenLen &&
                     !StringBeginsWith(Substring(firstBuffer, 2), mToken)) {
                     return NS_ERROR_FAILURE;
                 }
--- a/netwerk/test/unit/test_multipart_streamconv_application_package.js
+++ b/netwerk/test/unit/test_multipart_streamconv_application_package.js
@@ -71,21 +71,27 @@ function contentHandler_chunked_headers(
 
 function contentHandler_type_missing(metadata, response)
 {
   response.setHeader("Content-Type", 'text/plain');
   var body = testData.getData();
   response.bodyOutputStream.write(body, body.length);
 }
 
-function contentHandler_with_package_header(metadata, response)
+function contentHandler_with_package_header(chunkSize, metadata, response)
 {
   response.setHeader("Content-Type", 'application/package');
   var body = testData.packageHeader + testData.getData();
-  response.bodyOutputStream.write(body, body.length);
+
+  response.bodyOutputStream.write(body.substring(0,chunkSize), chunkSize);
+  response.processAsync();
+  do_timeout(5, function() {
+    response.bodyOutputStream.write(body.substring(chunkSize), body.length-chunkSize);
+    response.finish();
+  });
 }
 
 var testData = {
   packageHeader: 'manifest-signature: dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk\r\n',
   content: [
    { headers: ["Content-Location: /index.html", "Content-Type: text/html"], data: "<html>\r\n  <head>\r\n    <script src=\"/scripts/app.js\"></script>\r\n    ...\r\n  </head>\r\n  ...\r\n</html>\r\n", type: "text/html" },
    { headers: ["Content-Location: /scripts/app.js", "Content-Type: text/javascript"], data: "module Math from '/scripts/helpers/math.js';\r\n...\r\n", type: "text/javascript" },
    { headers: ["Content-Location: /scripts/helpers/math.js", "Content-Type: text/javascript"], data: "export function sum(nums) { ... }\r\n...\r\n", type: "text/javascript" }
@@ -239,39 +245,69 @@ function test_multipart_content_type_oth
            "*/*",
            new multipartListener(testData, true),
            null);
 
   var chan = make_channel(uri + "/multipart4");
   chan.asyncOpen(conv, null);
 }
 
-function test_multipart_package_header() {
+function test_multipart_package_header(aChunkSize) {
   var streamConv = Cc["@mozilla.org/streamConverters;1"]
                      .getService(Ci.nsIStreamConverterService);
 
   var conv = streamConv.asyncConvertData("application/package",
            "*/*",
            new multipartListener(testData, false, true),
            null);
 
-  var chan = make_channel(uri + "/multipart5");
+  var chan = make_channel(uri + "/multipart5_" + aChunkSize);
   chan.asyncOpen(conv, null);
 }
 
+// Bug 1212223 - Test multipart with package header and different chunk size.
+// Use explict function name to make the test case log more readable.
+
+function test_multipart_package_header_50() {
+  return test_multipart_package_header(50);
+}
+
+function test_multipart_package_header_100() {
+  return test_multipart_package_header(100);
+}
+
+function test_multipart_package_header_150() {
+  return test_multipart_package_header(150);
+}
+
+function test_multipart_package_header_200() {
+  return test_multipart_package_header(200);
+}
+
 function run_test()
 {
   httpserver = new HttpServer();
   httpserver.registerPathHandler("/multipart", contentHandler);
   httpserver.registerPathHandler("/multipart2", contentHandler_with_boundary);
   httpserver.registerPathHandler("/multipart3", contentHandler_chunked_headers);
   httpserver.registerPathHandler("/multipart4", contentHandler_type_missing);
-  httpserver.registerPathHandler("/multipart5", contentHandler_with_package_header);
+
+  // Bug 1212223 - Test multipart with package header and different chunk size.
+  httpserver.registerPathHandler("/multipart5_50", contentHandler_with_package_header.bind(null, 50));
+  httpserver.registerPathHandler("/multipart5_100", contentHandler_with_package_header.bind(null, 100));
+  httpserver.registerPathHandler("/multipart5_150", contentHandler_with_package_header.bind(null, 150));
+  httpserver.registerPathHandler("/multipart5_200", contentHandler_with_package_header.bind(null, 200));
+
   httpserver.start(-1);
 
   run_next_test();
 }
 
 add_test(test_multipart);
 add_test(test_multipart_with_boundary);
 add_test(test_multipart_chunked_headers);
 add_test(test_multipart_content_type_other);
-add_test(test_multipart_package_header);
+
+// Bug 1212223 - Test multipart with package header and different chunk size.
+add_test(test_multipart_package_header_50);
+add_test(test_multipart_package_header_100);
+add_test(test_multipart_package_header_150);
+add_test(test_multipart_package_header_200);