| <!DOCTYPE html> |
| <meta charset="windows-1252"> |
| <title>Default encodings of XML/JSON resources with Windows-1252 page</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <body> |
| <script> |
| |
| async_test(t => { |
| const iframe = document.createElement('iframe'); |
| iframe.src = 'resources/undeclared-encoding.xhtml' |
| iframe.onload = t.step_func_done(() => { |
| const doc = iframe.contentDocument; |
| assert_equals(doc.contentType, 'application/xhtml+xml', |
| 'Resource should be parsed as XHTML'); |
| assert_equals(doc.characterSet, 'UTF-8', |
| 'Resource should use default encoding for XML'); |
| }); |
| document.body.appendChild(iframe); |
| t.add_cleanup(() => iframe.remove()); |
| }, 'Default encoding of XML resource'); |
| |
| async_test(t => { |
| const iframe = document.createElement('iframe'); |
| iframe.src = 'resources/undeclared-encoding.json' |
| iframe.onload = t.step_func_done(() => { |
| const doc = iframe.contentDocument; |
| assert_equals(doc.contentType, 'application/json', |
| 'Resource should be parsed as JSON'); |
| assert_equals(doc.characterSet, 'UTF-8', |
| 'Resource should use default encoding for JSON'); |
| |
| // For good measure, parse as JSON and verify the content. |
| const data = JSON.parse(doc.body.innerText); |
| assert_true(data.parsed); |
| // File contains "À" (U+00C0), encoded in UTF-8 (0xC3 0x80). If |
| // misparsed as windows-1252, this would be "Ã". |
| assert_equals(data.text, '\u00C0'); |
| }); |
| document.body.appendChild(iframe); |
| t.add_cleanup(() => iframe.remove()); |
| }, 'Default encoding of JSON resource'); |
| |
| </script> |
| </body> |