| Hallvord R. M. Steen | fe69bb4 | 2014-11-10 22:35:19 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <meta charset=utf-8> |
| 3 | <title>XMLHttpRequest: passing objects that interfere with the XHR instance to send()</title> |
| 4 | <script src="/resources/testharness.js"></script> |
| 5 | <script src="/resources/testharnessreport.js"></script> |
| Hallvord R. M. Steen | 7b40041 | 2014-11-11 12:00:54 | [diff] [blame] | 6 | <link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::ol/li[4]" /> |
| 7 | <link rel="help" href="https://heycam.github.io/webidl/#es-union" data-tested-assertations="following::ol/li[16]" /> |
| 8 | |
| Hallvord R. M. Steen | fe69bb4 | 2014-11-10 22:35:19 | [diff] [blame] | 9 | |
| 10 | <div id="log"></div> |
| 11 | |
| 12 | <script> |
| 13 | var test1 = async_test('abort() called from data stringification') |
| 14 | test1.step(function() { |
| 15 | var client = new XMLHttpRequest() |
| 16 | var objAbortsOnStringification = {toString:function(){ |
| 17 | client.abort(); |
| 18 | }} |
| 19 | client.open('POST', 'resources/content.py') |
| Anne van Kesteren | 06ae26c | 2016-10-24 13:05:17 | [diff] [blame] | 20 | client.send(objAbortsOnStringification) |
| 21 | assert_equals(client.readyState, 1) |
| Hallvord R. M. Steen | fe69bb4 | 2014-11-10 22:35:19 | [diff] [blame] | 22 | test1.done() |
| 23 | }); |
| 24 | |
| 25 | var test2 = async_test('open() called from data stringification') |
| 26 | test2.step(function() { |
| 27 | var client = new XMLHttpRequest() |
| 28 | var objOpensOnStringification = {toString:function(){ |
| 29 | client.open('POST', 'resources/status.py?text=second_open_wins'); |
| 30 | }} |
| 31 | client.onloadend = test2.step_func(function(){ |
| 32 | assert_equals(client.statusText, 'second_open_wins') |
| 33 | test2.done() |
| 34 | }) |
| Hallvord R. M. Steen | 7b40041 | 2014-11-11 12:00:54 | [diff] [blame] | 35 | client.open('POST', 'resources/status.py?text=first_open_wins') |
| Hallvord R. M. Steen | fe69bb4 | 2014-11-10 22:35:19 | [diff] [blame] | 36 | client.send(objOpensOnStringification) |
| 37 | }); |
| 38 | |
| 39 | var test3 = async_test('send() called from data stringification') |
| 40 | test3.step(function() { |
| 41 | var client = new XMLHttpRequest() |
| 42 | var objSendsOnStringification = {toString:function(){ |
| 43 | client.send('bomb!'); |
| 44 | }} |
| 45 | client.onload = test3.step_func(function(){ |
| 46 | assert_equals(client.responseText, 'bomb!') |
| 47 | test3.done() |
| 48 | }) |
| 49 | client.open('POST', 'resources/content.py') |
| 50 | assert_throws('InvalidStateError', function(){ |
| 51 | client.send(objSendsOnStringification) |
| 52 | }) |
| 53 | }); |
| 54 | |
| 55 | |
| 56 | </script> |