responsedocument-decoding.htm (1762B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>XMLHttpRequest: response document decoding</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 </head> 9 <body> 10 <script> 11 function request(type, input, expected) { 12 async_test((test) => { 13 const client = new XMLHttpRequest(); 14 client.responseType = 'document'; 15 client.open("GET", "resources/status.py?content=" + input + "&type=" + encodeURIComponent(type), true); 16 client.onload = test.step_func_done(() => { 17 assert_equals(client.responseXML.querySelector("x").textContent, expected); 18 }) 19 client.send(null); 20 }, document.title + " (" + type + " " + input + ")"); 21 } 22 23 const encoded_content = "%e6%a9%9f"; 24 const encoded_xml = 25 encodeURIComponent("<?xml version='1.0' encoding='windows-1252'?><x>") + encoded_content + encodeURIComponent("<\/x>"); 26 const encoded_html = 27 encodeURIComponent("<!doctype html><meta charset=windows-1252><x>") + encoded_content + encodeURIComponent("<\/x>"); 28 const decoded_as_windows_1252 = "\u00e6\u00a9\u0178"; 29 const decoded_as_utf_8 = "\u6a5f"; 30 31 request("application/xml", encoded_xml, decoded_as_windows_1252); 32 request("application/xml;charset=utf-8", encoded_xml, decoded_as_utf_8); 33 request("application/xml;charset=windows-1252", encoded_xml, decoded_as_windows_1252); 34 request("text/html", encoded_html, decoded_as_windows_1252); 35 request("text/html;charset=utf-8", encoded_html, decoded_as_utf_8); 36 request("text/html;charset=windows-1252", encoded_html, decoded_as_windows_1252); 37 </script> 38 </body> 39 </html>