mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-09 21:00:42 +02:00
Automatic update from web-platform-tests Fixup indentation from PR 21353 https://github.com/web-platform-tests/wpt/pull/21353 used an approach which was known to cause indentation problems in some cases. This commit is an attempt to fixup any indentation issues, by running a (hacky) script to parse the diff and locate places where indentation was broken. -- Fixup indentation from PR 21354 https://github.com/web-platform-tests/wpt/pull/21354 used an approach which was known to cause indentation problems in some cases. This commit is an attempt to fixup any indentation issues, by running a (hacky) script to parse the diff and locate places where indentation was broken. -- Fixup indentation from PR 21378 https://github.com/web-platform-tests/wpt/pull/21378 used an approach which was known to cause indentation problems in some cases. This commit is an attempt to fixup any indentation issues, by running a (hacky) script to parse the diff and locate places where indentation was broken. -- Fixup indentation from PR 21379 https://github.com/web-platform-tests/wpt/pull/21379 used an approach which was known to cause indentation problems in some cases. This commit is an attempt to fixup any indentation issues, by running a (hacky) script to parse the diff and locate places where indentation was broken. -- Fixup indentation from PR 21377 https://github.com/web-platform-tests/wpt/pull/21377 used an approach which was known to cause indentation problems in some cases. This commit is an attempt to fixup any indentation issues, by running a (hacky) script to parse the diff and locate places where indentation was broken. -- Fixup indentation from PR 21390 https://github.com/web-platform-tests/wpt/pull/21390 used an approach which was known to cause indentation problems in some cases. This commit is an attempt to fixup any indentation issues, by running a (hacky) script to parse the diff and locate places where indentation was broken. -- Fixup indentation from PR 21392 https://github.com/web-platform-tests/wpt/pull/21392 used an approach which was known to cause indentation problems in some cases. This commit is an attempt to fixup any indentation issues, by running a (hacky) script to parse the diff and locate places where indentation was broken. -- wpt-commits: e4499c8ff1ecf603ecbda020102ec9c956d594f6, 88ab2f0e4965b8e6ea61d3ff4f90ff5215de8a4e, 21578f29a8e82eff91c0fd43ad709fbf3fbe9e72, e836541f46abbd9272233578ad4e8ac0867bde15, f2961a22018844dae808cb12af6774ba8b435773, 597c0519c494486d18ab81a32a7206014ee23b5a, 63c2f7190b779112aa79d28a51cc29b98ca381dc wpt-pr: 21422
104 lines
3.6 KiB
HTML
104 lines
3.6 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset=utf-8>
|
|
<title>File constructor: endings option</title>
|
|
<link rel=help href="https://w3c.github.io/FileAPI/#file-constructor">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script>
|
|
|
|
// Windows platforms use CRLF as the native line ending. All others use LF.
|
|
const crlf = navigator.platform.startsWith('Win');
|
|
const native_ending = crlf ? '\r\n' : '\n';
|
|
|
|
function readBlobAsPromise(blob) {
|
|
return new Promise((resolve, reject) => {
|
|
const reader = new FileReader();
|
|
reader.readAsText(blob);
|
|
reader.onload = e => resolve(reader.result);
|
|
reader.onerror = e => reject(reader.error);
|
|
});
|
|
}
|
|
|
|
[
|
|
'transparent',
|
|
'native'
|
|
].forEach(value => test(t => {
|
|
assert_class_string(new File([], "name", {endings: value}), 'File',
|
|
`Constructor should allow "${value}" endings`);
|
|
}, `Valid "endings" value: ${JSON.stringify(value)}`));
|
|
|
|
[
|
|
null,
|
|
'',
|
|
'invalidEnumValue',
|
|
'Transparent',
|
|
'NATIVE',
|
|
0,
|
|
{}
|
|
].forEach(value => test(t => {
|
|
assert_throws_js(TypeError, () => new File([], "name", {endings: value}),
|
|
'File constructor should throw');
|
|
}, `Invalid "endings" value: ${JSON.stringify(value)}`));
|
|
|
|
test(t => {
|
|
const test_error = {name: 'test'};
|
|
assert_throws_exactly(
|
|
test_error,
|
|
() => new File([], "name", { get endings() { throw test_error; }}),
|
|
'File constructor should propagate exceptions from "endings" property');
|
|
}, 'Exception propagation from options');
|
|
|
|
test(t => {
|
|
let got = false;
|
|
new File([], "name", { get endings() { got = true; } });
|
|
assert_true(got, 'The "endings" property was accessed during construction.');
|
|
}, 'The "endings" options property is used');
|
|
|
|
[
|
|
{name: 'LF', input: '\n', native: native_ending},
|
|
{name: 'CR', input: '\r', native: native_ending},
|
|
|
|
{name: 'CRLF', input: '\r\n', native: native_ending},
|
|
{name: 'CRCR', input: '\r\r', native: native_ending.repeat(2)},
|
|
{name: 'LFCR', input: '\n\r', native: native_ending.repeat(2)},
|
|
{name: 'LFLF', input: '\n\n', native: native_ending.repeat(2)},
|
|
|
|
{name: 'CRCRLF', input: '\r\r\n', native: native_ending.repeat(2)},
|
|
{name: 'CRLFLF', input: '\r\n\n', native: native_ending.repeat(2)},
|
|
{name: 'CRLFCR', input: '\r\n\r\n', native: native_ending.repeat(2)},
|
|
|
|
{name: 'CRLFCRLF', input: '\r\n\r\n', native: native_ending.repeat(2)},
|
|
{name: 'LFCRLFCR', input: '\n\r\n\r', native: native_ending.repeat(3)},
|
|
|
|
].forEach(testCase => {
|
|
promise_test(async t => {
|
|
const file = new File([testCase.input], "name");
|
|
assert_equals(
|
|
await readBlobAsPromise(file), testCase.input,
|
|
'Newlines should not change with endings unspecified');
|
|
}, `Input ${testCase.name} with endings unspecified`);
|
|
|
|
promise_test(async t => {
|
|
const file = new File([testCase.input], "name", {endings: 'transparent'});
|
|
assert_equals(
|
|
await readBlobAsPromise(file), testCase.input,
|
|
'Newlines should not change with endings "transparent"');
|
|
}, `Input ${testCase.name} with endings 'transparent'`);
|
|
|
|
promise_test(async t => {
|
|
const file = new File([testCase.input], "name", {endings: 'native'});
|
|
assert_equals(
|
|
await readBlobAsPromise(file), testCase.native,
|
|
'Newlines should match the platform with endings "native"');
|
|
}, `Input ${testCase.name} with endings 'native'`);
|
|
});
|
|
|
|
promise_test(async t => {
|
|
const file = new File(['\r', '\n'], "name", {endings: 'native'});
|
|
const expected = native_ending.repeat(2);
|
|
assert_equals(
|
|
await readBlobAsPromise(file), expected,
|
|
'CR/LF in adjacent strings should be converted to two platform newlines');
|
|
}, `CR/LF in adjacent input strings`);
|
|
|
|
</script>
|