Bug 1645261 [wpt PR 24128] - [XHR] Use XMLHttpRequestBodyInit in IDL, a=testonly
authorAdam Rice <ricea@chromium.org>
Mon, 22 Jun 2020 10:39:14 +0000
changeset 536807 655c8314619fe019c9234f0c3ed66bf7c84c2c09
parent 536806 232991b4fb0b2f24756620523d4c972d243f4b83
child 536808 0eca2f01818a12497339f79efeae22bf716d3745
push id119680
push userwptsync@mozilla.com
push dateTue, 23 Jun 2020 11:08:22 +0000
treeherderautoland@7ca3d4bada73 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1645261, 24128, 1091120, 2239433, 778272
milestone79.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 1645261 [wpt PR 24128] - [XHR] Use XMLHttpRequestBodyInit in IDL, a=testonly Automatic update from web-platform-tests [XHR] Use XMLHttpRequestBodyInit in IDL https://github.com/whatwg/xhr/pull/279 modified the XHR standard to use the type XMLHttpRequestBodyInit in the send() method. Update our IDL to match. Unlike in the standard, we define XMLHttpRequestBodyInit in xml_http_request.idl rather than fetch.idl. No behavioural changes. Add a web platform test for sending strings containing invalid unicode to verify that the behaviour has not changed. BUG=1091120 Change-Id: I7f26160ad925d5956bdf05b1b69572735b7d0907 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2239433 Commit-Queue: Adam Rice <ricea@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Cr-Commit-Position: refs/heads/master@{#778272} -- wpt-commits: 380639aa5117dfbbeb422a4e28d9b3c1fb43dfe1 wpt-pr: 24128
testing/web-platform/tests/xhr/send-data-string-invalid-unicode.any.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/xhr/send-data-string-invalid-unicode.any.js
@@ -0,0 +1,46 @@
+// META: title=XMLHttpRequest.send(invalidUnicodeString)
+
+const LEFT_SURROGATE = '\ud83d';
+const RIGHT_SURROGATE = '\udc94';
+
+// Unmatched surrogates should be replaced with the unicode replacement
+// character, 0xFFFD. '$' in these templates is replaced with one of
+// LEFT_SURROGATE or RIGHT_SURROGATE according to the test.
+const TEMPLATES = {
+  '$': [239, 191, 189],
+  '$ab': [239, 191, 189, 97, 98],
+  'a$b': [97, 239, 191, 189, 98],
+  'ab$': [97, 98, 239, 191, 189],
+};
+
+for (const surrogate of [LEFT_SURROGATE, RIGHT_SURROGATE]) {
+  for (const [template, expected] of Object.entries(TEMPLATES)) {
+    const invalidString = template.replace('$', surrogate);
+    const printableString = template.replace(
+        '$', '\\u{' + surrogate.charCodeAt(0).toString(16) + '}');
+    async_test(t => {
+      xhrSendStringAndCheckResponseBody(t, invalidString, expected);
+    }, `invalid unicode '${printableString}' should be fixed with ` +
+               `replacement character`);
+  }
+}
+
+// For the sake of completeness, verify that matched surrogates work.
+async_test(t => {
+  xhrSendStringAndCheckResponseBody(t, LEFT_SURROGATE + RIGHT_SURROGATE,
+                                    [240, 159, 146, 148]);
+}, 'valid unicode should be sent correctly');
+
+function xhrSendStringAndCheckResponseBody(t, string, expected) {
+  const xhr = new XMLHttpRequest();
+  xhr.responseType = 'arraybuffer';
+  xhr.onload = t.step_func(() => {
+    assert_equals(xhr.status, 200, 'status should be 200');
+    const actualBody = new Uint8Array(xhr.response);
+    assert_array_equals(actualBody, expected, 'content should match');
+    t.done();
+  });
+  xhr.onerror = t.unreached_func('no error should occur');
+  xhr.open('POST', 'resources/content.py', true);
+  xhr.send(string);
+}