summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/XMLHttpRequest/send-data-es-object.htm
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/XMLHttpRequest/send-data-es-object.htm
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/XMLHttpRequest/send-data-es-object.htm')
-rw-r--r--testing/web-platform/tests/XMLHttpRequest/send-data-es-object.htm61
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/web-platform/tests/XMLHttpRequest/send-data-es-object.htm b/testing/web-platform/tests/XMLHttpRequest/send-data-es-object.htm
new file mode 100644
index 000000000..6f7743286
--- /dev/null
+++ b/testing/web-platform/tests/XMLHttpRequest/send-data-es-object.htm
@@ -0,0 +1,61 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>XMLHttpRequest: passing objects to send()</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::ol/li[4]" />
+<link rel="help" href="https://heycam.github.io/webidl/#es-union" data-tested-assertations="following::ol/li[16]" />
+
+<div id="log"></div>
+
+<script>
+ function do_test(obj, expected, name) {
+ var test = async_test(name)
+ test.step(function() {
+ var client = new XMLHttpRequest()
+ client.onload = test.step_func(function () {
+ assert_equals(client.responseText, expected)
+ test.done()
+ });
+ client.open('POST', 'resources/content.py')
+ if (expected.exception) {
+ assert_throws(expected.exception, function(){client.send(obj)})
+ test.done()
+ } else {
+ client.send(obj)
+ }
+ });
+ }
+
+ do_test({}, '[object Object]', 'sending a plain empty object')
+ do_test(Math, '[object Math]', 'sending the ES Math object')
+ do_test(new XMLHttpRequest, '[object XMLHttpRequest]', 'sending a new XHR instance')
+ do_test({toString:function(){}}, 'undefined', 'sending object that stringifies to undefined')
+ do_test({toString:function(){return null}}, 'null', 'sending object that stringifies to null')
+ var ancestor = {toString: function(){
+ var ar=[]
+ for (var prop in this) {
+ if (this.hasOwnProperty(prop)) {
+ ar.push(prop+'='+this[prop])
+ }
+ };
+ return ar.join('&')
+ }};
+
+ var myObj = Object.create(ancestor, {foo:{value:1, enumerable: true}, bar:{value:'foo', enumerable:true}})
+ do_test(myObj, 'foo=1&bar=foo', 'object that stringifies to query string')
+
+ var myFakeJSON = {a:'a', b:'b', toString:function(){ return JSON.stringify(this, function(key, val){ return key ==='toString'?undefined:val; }) }}
+ do_test(myFakeJSON, '{"a":"a","b":"b"}', 'object that stringifies to JSON string')
+
+ var myFakeDoc1 = {valueOf:function(){return document}}
+ do_test(myFakeDoc1, '[object Object]', 'object whose valueOf() returns a document - ignore valueOf(), stringify')
+
+ var myFakeDoc2 = {toString:function(){return document}}
+ do_test(myFakeDoc2, {exception:new TypeError()}, 'object whose toString() returns a document, expected to throw')
+
+ var myThrower = {toString:function(){throw {name:'FooError', message:'bar'}}}
+ do_test(myThrower, {exception:{name:'FooError'}}, 'object whose toString() throws, expected to throw')
+
+
+</script>