Bug 1347983 - Part 2: Add a test to ensure that forms submitted from a large-allocation page behave correctly, r=smaug
authorMichael Layzell <michael@thelayzells.com>
Thu, 16 Mar 2017 14:32:30 -0400
changeset 348176 38ecd019ecebe7533852db0253393d2708527437
parent 348175 3b2c7853ae71bd4ec36eb0c8be1a5a4200ade4f8
child 348177 0c5daa842570a6841b78a816cf60b5f17db7bbb3
push id39092
push userkwierso@gmail.com
push dateFri, 17 Mar 2017 18:14:05 +0000
treeherderautoland@88576fd417e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1347983
milestone55.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 1347983 - Part 2: Add a test to ensure that forms submitted from a large-allocation page behave correctly, r=smaug MozReview-Commit-ID: Af44H11AFMf
dom/tests/browser/browser.ini
dom/tests/browser/helper_largeAllocation.js
dom/tests/browser/test_largeAllocation.html
dom/tests/browser/test_largeAllocationFormSubmit.sjs
--- a/dom/tests/browser/browser.ini
+++ b/dom/tests/browser/browser.ini
@@ -8,16 +8,17 @@ support-files =
   test_bug1004814.html
   worker_bug1004814.js
   geo_leak_test.html
   dummy.html
   test_largeAllocation.html
   test_largeAllocation.html^headers^
   test_largeAllocation2.html
   test_largeAllocation2.html^headers^
+  test_largeAllocationFormSubmit.sjs
   helper_largeAllocation.js
   !/dom/tests/mochitest/geolocation/network_geolocation.sjs
 
 [browser_allocateGigabyte.js]
 disabled = Does not reliably pass on 32-bit systems - bug 1314098
 skip-if = !e10s
 [browser_autofocus_background.js]
 [browser_autofocus_preference.js]
--- a/dom/tests/browser/helper_largeAllocation.js
+++ b/dom/tests/browser/helper_largeAllocation.js
@@ -489,16 +489,56 @@ function* largeAllocSuccessTests() {
     let pid3 = yield getPID(newTab.linkedBrowser);
 
     is(pid2, pid3, "PIDs 2 and 3 should match");
     is(true, yield getInLAProc(newTab.linkedBrowser));
 
     yield BrowserTestUtils.closeWindow(newWindow);
   });
 
+  // XXX: Important - reset the process count, as it was set to 1 by the
+  // previous test.
+  yield SpecialPowers.pushPrefEnv({
+    set: [["dom.ipc.processCount.webLargeAllocation", 20]],
+  });
+
+  yield BrowserTestUtils.withNewTab("about:blank", function*(aBrowser) {
+    info("Starting test 11");
+
+    let pid1 = yield getPID(aBrowser);
+    is(false, yield getInLAProc(aBrowser));
+
+    let ready = Promise.all([expectProcessCreated(),
+                             BrowserTestUtils.browserLoaded(aBrowser)]);
+    yield ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
+      content.document.location = TEST_URI;
+    });
+
+    yield ready;
+
+    let pid2 = yield getPID(aBrowser);
+
+    isnot(pid1, pid2, "PIDs 1 and 2 should not match");
+    is(true, yield getInLAProc(aBrowser));
+
+    yield Promise.all([
+      ContentTask.spawn(aBrowser, null, () => {
+        content.document.querySelector("#submit").click();
+      }),
+      BrowserTestUtils.browserLoaded(aBrowser)
+    ]);
+
+    let innerText = yield ContentTask.spawn(aBrowser, null, () => {
+      return content.document.body.innerText;
+    });
+    isnot(innerText, "FAIL", "We should not have sent a get request!");
+    is(innerText, "textarea=default+value&button=submit",
+       "The post data should be received by the callee");
+  });
+
   // XXX: Make sure to reset dom.ipc.processCount.webLargeAllocation if adding a
   // test after the above test.
 }
 
 function* largeAllocFailTests() {
   yield BrowserTestUtils.withNewTab("http://example.com", function*(aBrowser) {
     info("Starting test 1");
     let pid1 = yield getPID(aBrowser);
--- a/dom/tests/browser/test_largeAllocation.html
+++ b/dom/tests/browser/test_largeAllocation.html
@@ -1,4 +1,10 @@
 <!doctype html>
 <html>
-  <body>Loaded in a new process!</body>
+  <body>
+    Loaded in a new process!
+    <form action="test_largeAllocationFormSubmit.sjs" method="POST">
+      <input type="text" name="textarea" value="default value">
+      <input type="submit" name="button" value="submit" id="submit">
+    </form>
+  </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/tests/browser/test_largeAllocationFormSubmit.sjs
@@ -0,0 +1,24 @@
+const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
+                                                 "nsIBinaryInputStream",
+                                                 "setInputStream");
+
+function handleRequest(request, response) {
+  response.setHeader("Large-Allocation", "0", false);
+  response.setHeader("Content-Type", "text/plain", false);
+  response.setStatusLine(request.httpVersion, "200", "Found");
+  if (request.method == "GET") {
+    response.write("FAIL");
+    return;
+  }
+
+  var body = new BinaryInputStream(request.bodyInputStream);
+
+  var avail;
+  var bytes = [];
+
+  while ((avail = body.available()) > 0)
+    Array.prototype.push.apply(bytes, body.readByteArray(avail));
+
+  var data = String.fromCharCode.apply(null, bytes);
+  response.bodyOutputStream.write(data, data.length);
+}