7 const TOOLARGE = 'toolarge';
9 const STRING = 'string';
10 const ARRAYBUFFER = 'arraybuffer';
14 function getContentType(type) {
17 return 'text/plain;charset=UTF-8';
21 return 'multipart/form-data';
25 throw Error(`invalid type: ${type}`);
29 // Create a payload with the given size and type.
30 // `sizeString` must be one of EMPTY, SMALL, LARGE, MAX, TOOLARGE.
31 // `type` must be one of STRING, ARRAYBUFFER, FORM, BLOB.
32 // `contentType` is effective only if `type` is BLOB.
33 function makePayload(sizeString, type, contentType) {
47 throw Error('Not supported');
55 throw Error('invalid size');
60 const prefix = String(size) + ':';
61 data = prefix + Array(size - prefix.length).fill('*').join('');
68 return new TextEncoder().encode(data).buffer;
70 const formData = new FormData();
72 formData.append('payload', data);
76 const options = contentType ? {type: contentType} : undefined;
77 const blob = new Blob([data], options);
80 throw Error('invalid type');
84 function parallelPromiseTest(func, description) {
86 Promise.resolve(func(t)).then(() => t.done()).catch(t.step_func((e) => {
92 // Poll the server for the test result.
93 async function waitForResult(id, expectedError = null) {
94 const url = `/beacon/resources/beacon.py?cmd=stat&id=${id}`;
95 for (let i = 0; i < 30; ++i) {
96 const response = await fetch(url);
97 const text = await response.text();
98 const results = JSON.parse(text);
100 if (results.length === 0) {
101 await new Promise(resolve => step_timeout(resolve, 100));
104 assert_equals(results.length, 1, `bad response: '${text}'`);
105 const result = results[0];
106 // null JSON values parse as null, not undefined
107 assert_equals(result.error, expectedError, 'error recorded in stash');
110 assert_true(false, 'timeout');