Bug 1096263 - XMLHttpRequest.send({}) should not throw, tests. r=bz, a=lmandel
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 11 Nov 2014 13:41:20 +0200
changeset 226035 0197e9eb324f
parent 226034 9e57cec588a9
child 226036 9f14f2af8bf7
push id4118
push userryanvm@gmail.com
push date2014-11-12 21:56 +0000
treeherdermozilla-beta@0197e9eb324f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, lmandel
bugs1096263
milestone34.0
Bug 1096263 - XMLHttpRequest.send({}) should not throw, tests. r=bz, a=lmandel
content/base/test/echo.sjs
content/base/test/mochitest.ini
content/base/test/test_xhr_send.html
new file mode 100644
--- /dev/null
+++ b/content/base/test/echo.sjs
@@ -0,0 +1,21 @@
+const CC = Components.Constructor;
+const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
+                             "nsIBinaryInputStream",
+                             "setInputStream");
+
+function handleRequest(request, response)
+{
+  response.setHeader("Content-Type", "text/plain");
+  if (request.method == "GET") {
+     response.write(request.queryString);
+     return;
+  }
+
+  var bodyStream = new BinaryInputStream(request.bodyInputStream);
+  var body = "";
+  var bodyAvail;
+  while ((bodyAvail = bodyStream.available()) > 0)
+    body += String.fromCharCode.apply(null, bodyStream.readByteArray(bodyAvail));
+  
+  response.write(body);
+}
--- a/content/base/test/mochitest.ini
+++ b/content/base/test/mochitest.ini
@@ -40,16 +40,17 @@ support-files =
   bug682592-subframe.html
   bug696301-script-1.js
   bug696301-script-1.js^headers^
   bug696301-script-2.js
   bug803225_test_mailto.html
   bug819051.sjs
   copypaste.js
   delayedServerEvents.sjs
+  echo.sjs
   eventsource.resource
   eventsource.resource^headers^
   eventsource_redirect.resource
   eventsource_redirect.resource^headers^
   eventsource_redirect_to.resource
   eventsource_redirect_to.resource^headers^
   file_CrossSiteXHR_cache_server.sjs
   file_CrossSiteXHR_inner.html
@@ -635,16 +636,17 @@ skip-if = buildapp == 'b2g' || toolkit =
 [test_x-frame-options.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s # b2g(observerservice issue) b2g-debug(observerservice issue) b2g-desktop(observerservice issue)
 [test_xbl_userdata.xhtml]
 [test_xhr_abort_after_load.html]
 skip-if = toolkit == 'android'
 [test_xhr_forbidden_headers.html]
 [test_xhr_progressevents.html]
 skip-if = toolkit == 'android'
+[test_xhr_send.html]
 [test_xhr_send_readystate.html]
 [test_xhr_withCredentials.html]
 [test_file_from_blob.html]
 [test_warning_for_blocked_cross_site_request.html]
 [test_bug444546.html]
 disabled = Disabled for now. Mochitest isn't reliable enough for these.
 support-files = bug444546.sjs
 [test_bug503473.html]
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_xhr_send.html
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1096263
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1096263</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1096263 **/
+
+SimpleTest.waitForExplicitFinish();
+
+function simpleGetTest() {
+  var x = new XMLHttpRequest();
+  x.open("GET", "echo.sjs");
+  x.onload = function() {
+      ok(true, "Should have processed GET");
+      simplePostTest();
+    }
+  x.send({});
+}
+
+function simplePostTest() {
+  var x = new XMLHttpRequest();
+  x.open("POST", "echo.sjs");
+  x.onload = function() {
+      ise(x.responseText, "somedata", "Should have processed POST");
+      undefinedPostTest();
+    }
+    x.send({toString: function() { return "somedata"; }});
+}
+
+function undefinedPostTest() {
+  var x = new XMLHttpRequest();
+  x.open("POST", "echo.sjs");
+  x.onload = function() {
+      ise(x.responseText, "undefined", "Should have processed POST");
+      nullPostTest();
+    }
+    x.send({toString: function() { return undefined; }});
+}
+
+function nullPostTest() {
+  var x = new XMLHttpRequest();
+  x.open("POST", "echo.sjs");
+  x.onload = function() {
+      ise(x.responseText, "null", "Should have processed POST");
+      testExceptionInToString();
+    }
+    x.send({toString: function() { return null; }});
+}
+
+function testExceptionInToString() {
+  var x = new XMLHttpRequest();
+  x.open("GET", "echo.sjs");
+  x.onload = function() {
+    ok(false);
+    SimpleTest.finish();
+  }
+  try {
+    x.send({toString: function() { throw "dummy"; }});
+  } catch(ex) {
+    ise(ex, "dummy");
+    SimpleTest.finish();
+  }
+}
+
+  </script>
+</head>
+<body onload="simpleGetTest()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1096263">Mozilla Bug 1096263</a>
+<p id="display"></p>
+<div id="content">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>