How to use formPostFileUploadTest method in wpt

Best JavaScript code snippet using wpt

send-file-form-helper.js

Source:send-file-form-helper.js Github

copy

Full Screen

1'use strict';2// See /FileAPI/file/resources/echo-content-escaped.py3function escapeString(string) {4 return string.replace(/\\/g, "\\\\").replace(5 /[^\x20-\x7E]/g,6 (x) => {7 let hex = x.charCodeAt(0).toString(16);8 if (hex.length < 2) hex = "0" + hex;9 return `\\x${hex}`;10 },11 ).replace(/\\x0d\\x0a/g, "\r\n");12}13// Rationale for this particular test character sequence, which is14// used in filenames and also in file contents:15//16// - ABC~ ensures the string starts with something we can read to17// ensure it is from the correct source; ~ is used because even18// some 1-byte otherwise-ASCII-like parts of ISO-2022-JP19// interpret it differently.20// - ‾¥ are inside a single-byte range of ISO-2022-JP and help21// diagnose problems due to filesystem encoding or locale22// - ≈ is inside IBM437 and helps diagnose problems due to filesystem23// encoding or locale24// - ¤ is inside Latin-1 and helps diagnose problems due to25// filesystem encoding or locale; it is also the "simplest" case26// needing substitution in ISO-2022-JP27// - ・ is inside a single-byte range of ISO-2022-JP in some variants28// and helps diagnose problems due to filesystem encoding or locale;29// on the web it is distinct when decoding but unified when encoding30// - ・ is inside a double-byte range of ISO-2022-JP and helps31// diagnose problems due to filesystem encoding or locale32// - • is inside Windows-1252 and helps diagnose problems due to33// filesystem encoding or locale and also ensures these aren't34// accidentally turned into e.g. control codes35// - ∙ is inside IBM437 and helps diagnose problems due to filesystem36// encoding or locale37// - · is inside Latin-1 and helps diagnose problems due to38// filesystem encoding or locale and also ensures HTML named39// character references (e.g. &middot;) are not used40// - ☼ is inside IBM437 shadowing C0 and helps diagnose problems due to41// filesystem encoding or locale and also ensures these aren't42// accidentally turned into e.g. control codes43// - ★ is inside ISO-2022-JP on a non-Kanji page and makes correct44// output easier to spot45// - 星 is inside ISO-2022-JP on a Kanji page and makes correct46// output easier to spot47// - 🌟 is outside the BMP and makes incorrect surrogate pair48// substitution detectable and ensures substitutions work49// correctly immediately after Kanji 2-byte ISO-2022-JP50// - 星 repeated here ensures the correct codec state is used51// after a non-BMP substitution52// - ★ repeated here also makes correct output easier to spot53// - ☼ is inside IBM437 shadowing C0 and helps diagnose problems due to54// filesystem encoding or locale and also ensures these aren't55// accidentally turned into e.g. control codes and also ensures56// substitutions work correctly immediately after non-Kanji57// 2-byte ISO-2022-JP58// - · is inside Latin-1 and helps diagnose problems due to59// filesystem encoding or locale and also ensures HTML named60// character references (e.g. &middot;) are not used61// - ∙ is inside IBM437 and helps diagnose problems due to filesystem62// encoding or locale63// - • is inside Windows-1252 and again helps diagnose problems64// due to filesystem encoding or locale65// - ・ is inside a double-byte range of ISO-2022-JP and helps66// diagnose problems due to filesystem encoding or locale67// - ・ is inside a single-byte range of ISO-2022-JP in some variants68// and helps diagnose problems due to filesystem encoding or locale;69// on the web it is distinct when decoding but unified when encoding70// - ¤ is inside Latin-1 and helps diagnose problems due to71// filesystem encoding or locale; again it is a "simple"72// substitution case73// - ≈ is inside IBM437 and helps diagnose problems due to filesystem74// encoding or locale75// - ¥‾ are inside a single-byte range of ISO-2022-JP and help76// diagnose problems due to filesystem encoding or locale77// - ~XYZ ensures earlier errors don't lead to misencoding of78// simple ASCII79//80// Overall the near-symmetry makes common I18N mistakes like81// off-by-1-after-non-BMP easier to spot. All the characters82// are also allowed in Windows Unicode filenames.83const kTestChars = 'ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ';84// The kTestFallback* strings represent the expected byte sequence from85// encoding kTestChars with the given encoding with "html" replacement86// mode, isomorphic-decoded. That means, characters that can't be87// encoded in that encoding get HTML-escaped, but no further88// `escapeString`-like escapes are needed.89const kTestFallbackUtf8 = (90 "ABC~\xE2\x80\xBE\xC2\xA5\xE2\x89\x88\xC2\xA4\xEF\xBD\xA5\xE3\x83\xBB\xE2" +91 "\x80\xA2\xE2\x88\x99\xC2\xB7\xE2\x98\xBC\xE2\x98\x85\xE6\x98\x9F\xF0\x9F" +92 "\x8C\x9F\xE6\x98\x9F\xE2\x98\x85\xE2\x98\xBC\xC2\xB7\xE2\x88\x99\xE2\x80" +93 "\xA2\xE3\x83\xBB\xEF\xBD\xA5\xC2\xA4\xE2\x89\x88\xC2\xA5\xE2\x80\xBE~XYZ"94);95const kTestFallbackIso2022jp = (96 ("ABC~\x1B(J~\\≈¤\x1B$B!&!&\x1B(B•∙·☼\x1B$B!z@1\x1B(B🌟" +97 "\x1B$B@1!z\x1B(B☼·∙•\x1B$B!&!&\x1B(B¤≈\x1B(J\\~\x1B(B~XYZ")98 .replace(/[^\0-\x7F]/gu, (x) => `&#${x.codePointAt(0)};`)99);100const kTestFallbackWindows1252 = (101 "ABC~‾\xA5≈\xA4・・\x95∙\xB7☼★星🌟星★☼\xB7∙\x95・・\xA4≈\xA5‾~XYZ".replace(102 /[^\0-\xFF]/gu,103 (x) => `&#${x.codePointAt(0)};`,104 )105);106const kTestFallbackXUserDefined = kTestChars.replace(107 /[^\0-\x7F]/gu,108 (x) => `&#${x.codePointAt(0)};`,109);110// formPostFileUploadTest - verifies multipart upload structure and111// numeric character reference replacement for filenames, field names,112// and field values using form submission.113//114// Uses /FileAPI/file/resources/echo-content-escaped.py to echo the115// upload POST with controls and non-ASCII bytes escaped. This is done116// because navigations whose response body contains [\0\b\v] may get117// treated as a download, which is not what we want. Use the118// `escapeString` function to replicate that kind of escape (note that119// it takes an isomorphic-decoded string, not a byte sequence).120//121// Fields in the parameter object:122//123// - fileNameSource: purely explanatory and gives a clue about which124// character encoding is the source for the non-7-bit-ASCII parts of125// the fileBaseName, or Unicode if no smaller-than-Unicode source126// contains all the characters. Used in the test name.127// - fileBaseName: the not-necessarily-just-7-bit-ASCII file basename128// used for the constructed test file. Used in the test name.129// - formEncoding: the acceptCharset of the form used to submit the130// test file. Used in the test name.131// - expectedEncodedBaseName: the expected formEncoding-encoded132// version of fileBaseName, isomorphic-decoded. That means, characters133// that can't be encoded in that encoding get HTML-escaped, but no134// further `escapeString`-like escapes are needed.135const formPostFileUploadTest = ({136 fileNameSource,137 fileBaseName,138 formEncoding,139 expectedEncodedBaseName,140}) => {141 promise_test(async testCase => {142 if (document.readyState !== 'complete') {143 await new Promise(resolve => addEventListener('load', resolve));144 }145 const formTargetFrame = Object.assign(document.createElement('iframe'), {146 name: 'formtargetframe',147 });148 document.body.append(formTargetFrame);149 testCase.add_cleanup(() => {150 document.body.removeChild(formTargetFrame);151 });152 const form = Object.assign(document.createElement('form'), {153 acceptCharset: formEncoding,154 action: '/FileAPI/file/resources/echo-content-escaped.py',155 method: 'POST',156 enctype: 'multipart/form-data',157 target: formTargetFrame.name,158 });159 document.body.append(form);160 testCase.add_cleanup(() => {161 document.body.removeChild(form);162 });163 // Used to verify that the browser agrees with the test about164 // which form charset is used.165 form.append(Object.assign(document.createElement('input'), {166 type: 'hidden',167 name: '_charset_',168 }));169 // Used to verify that the browser agrees with the test about170 // field value replacement and encoding independently of file system171 // idiosyncracies.172 form.append(Object.assign(document.createElement('input'), {173 type: 'hidden',174 name: 'filename',175 value: fileBaseName,176 }));177 // Same, but with name and value reversed to ensure field names178 // get the same treatment.179 form.append(Object.assign(document.createElement('input'), {180 type: 'hidden',181 name: fileBaseName,182 value: 'filename',183 }));184 const fileInput = Object.assign(document.createElement('input'), {185 type: 'file',186 name: 'file',187 });188 form.append(fileInput);189 // Removes c:\fakepath\ or other pseudofolder and returns just the190 // final component of filePath; allows both / and \ as segment191 // delimiters.192 const baseNameOfFilePath = filePath => filePath.split(/[\/\\]/).pop();193 await new Promise(resolve => {194 const dataTransfer = new DataTransfer;195 dataTransfer.items.add(196 new File([kTestChars], fileBaseName, {type: 'text/plain'}));197 fileInput.files = dataTransfer.files;198 // For historical reasons .value will be prefixed with199 // c:\fakepath\, but the basename should match the file name200 // exposed through the newer .files[0].name API. This check201 // verifies that assumption.202 assert_equals(203 baseNameOfFilePath(fileInput.files[0].name),204 baseNameOfFilePath(fileInput.value),205 `The basename of the field's value should match its files[0].name`);206 form.submit();207 formTargetFrame.onload = resolve;208 });209 const formDataText = formTargetFrame.contentDocument.body.textContent;210 const formDataLines = formDataText.split('\n');211 if (formDataLines.length && !formDataLines[formDataLines.length - 1]) {212 --formDataLines.length;213 }214 assert_greater_than(215 formDataLines.length,216 2,217 `${fileBaseName}: multipart form data must have at least 3 lines: ${218 JSON.stringify(formDataText)219 }`);220 const boundary = formDataLines[0];221 assert_equals(222 formDataLines[formDataLines.length - 1],223 boundary + '--',224 `${fileBaseName}: multipart form data must end with ${boundary}--: ${225 JSON.stringify(formDataText)226 }`);227 const asValue = expectedEncodedBaseName.replace(/\r\n?|\n/g, "\r\n");228 const asName = asValue.replace(/[\r\n"]/g, encodeURIComponent);229 const asFilename = expectedEncodedBaseName.replace(/[\r\n"]/g, encodeURIComponent);230 // The response body from echo-content-escaped.py has controls and non-ASCII231 // bytes escaped, so any caller-provided field that might contain such bytes232 // must be passed to `escapeString`, after any other expected233 // transformations.234 const expectedText = [235 boundary,236 'Content-Disposition: form-data; name="_charset_"',237 '',238 formEncoding,239 boundary,240 'Content-Disposition: form-data; name="filename"',241 '',242 // Unlike for names and filenames, multipart/form-data values don't escape243 // \r\n linebreaks, and when they're read from an iframe they become \n.244 escapeString(asValue).replace(/\r\n/g, "\n"),245 boundary,246 `Content-Disposition: form-data; name="${escapeString(asName)}"`,247 '',248 'filename',249 boundary,250 `Content-Disposition: form-data; name="file"; ` +251 `filename="${escapeString(asFilename)}"`,252 'Content-Type: text/plain',253 '',254 escapeString(kTestFallbackUtf8),255 boundary + '--',256 ].join('\n');257 assert_true(258 formDataText.startsWith(expectedText),259 `Unexpected multipart-shaped form data received:\n${260 formDataText261 }\nExpected:\n${expectedText}`);262 }, `Upload ${fileBaseName} (${fileNameSource}) in ${formEncoding} form`);...

Full Screen

Full Screen

12478.js

Source:12478.js Github

copy

Full Screen

1'use strict';2// See /FileAPI/file/resources/echo-content-escaped.py3function escapeString(string) {4 return string.replace(/\\/g, "\\\\").replace(5 /[^\x20-\x7E]/g,6 (x) => {7 let hex = x.charCodeAt(0).toString(16);8 if (hex.length < 2) hex = "0" + hex;9 return `\\x${hex}`;10 },11 ).replace(/\\x0d\\x0a/g, "\r\n");12}13// Rationale for this particular test character sequence, which is14// used in filenames and also in file contents:15//16// - ABC~ ensures the string starts with something we can read to17// ensure it is from the correct source; ~ is used because even18// some 1-byte otherwise-ASCII-like parts of ISO-2022-JP19// interpret it differently.20// - ‾¥ are inside a single-byte range of ISO-2022-JP and help21// diagnose problems due to filesystem encoding or locale22// - ≈ is inside IBM437 and helps diagnose problems due to filesystem23// encoding or locale24// - ¤ is inside Latin-1 and helps diagnose problems due to25// filesystem encoding or locale; it is also the "simplest" case26// needing substitution in ISO-2022-JP27// - ・ is inside a single-byte range of ISO-2022-JP in some variants28// and helps diagnose problems due to filesystem encoding or locale;29// on the web it is distinct when decoding but unified when encoding30// - ・ is inside a double-byte range of ISO-2022-JP and helps31// diagnose problems due to filesystem encoding or locale32// - • is inside Windows-1252 and helps diagnose problems due to33// filesystem encoding or locale and also ensures these aren't34// accidentally turned into e.g. control codes35// - ∙ is inside IBM437 and helps diagnose problems due to filesystem36// encoding or locale37// - · is inside Latin-1 and helps diagnose problems due to38// filesystem encoding or locale and also ensures HTML named39// character references (e.g. &middot;) are not used40// - ☼ is inside IBM437 shadowing C0 and helps diagnose problems due to41// filesystem encoding or locale and also ensures these aren't42// accidentally turned into e.g. control codes43// - ★ is inside ISO-2022-JP on a non-Kanji page and makes correct44// output easier to spot45// - 星 is inside ISO-2022-JP on a Kanji page and makes correct46// output easier to spot47// - 🌟 is outside the BMP and makes incorrect surrogate pair48// substitution detectable and ensures substitutions work49// correctly immediately after Kanji 2-byte ISO-2022-JP50// - 星 repeated here ensures the correct codec state is used51// after a non-BMP substitution52// - ★ repeated here also makes correct output easier to spot53// - ☼ is inside IBM437 shadowing C0 and helps diagnose problems due to54// filesystem encoding or locale and also ensures these aren't55// accidentally turned into e.g. control codes and also ensures56// substitutions work correctly immediately after non-Kanji57// 2-byte ISO-2022-JP58// - · is inside Latin-1 and helps diagnose problems due to59// filesystem encoding or locale and also ensures HTML named60// character references (e.g. &middot;) are not used61// - ∙ is inside IBM437 and helps diagnose problems due to filesystem62// encoding or locale63// - • is inside Windows-1252 and again helps diagnose problems64// due to filesystem encoding or locale65// - ・ is inside a double-byte range of ISO-2022-JP and helps66// diagnose problems due to filesystem encoding or locale67// - ・ is inside a single-byte range of ISO-2022-JP in some variants68// and helps diagnose problems due to filesystem encoding or locale;69// on the web it is distinct when decoding but unified when encoding70// - ¤ is inside Latin-1 and helps diagnose problems due to71// filesystem encoding or locale; again it is a "simple"72// substitution case73// - ≈ is inside IBM437 and helps diagnose problems due to filesystem74// encoding or locale75// - ¥‾ are inside a single-byte range of ISO-2022-JP and help76// diagnose problems due to filesystem encoding or locale77// - ~XYZ ensures earlier errors don't lead to misencoding of78// simple ASCII79//80// Overall the near-symmetry makes common I18N mistakes like81// off-by-1-after-non-BMP easier to spot. All the characters82// are also allowed in Windows Unicode filenames.83const kTestChars = 'ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ';84// The kTestFallback* strings represent the expected byte sequence from85// encoding kTestChars with the given encoding with "html" replacement86// mode, isomorphic-decoded. That means, characters that can't be87// encoded in that encoding get HTML-escaped, but no further88// `escapeString`-like escapes are needed.89const kTestFallbackUtf8 = (90 "ABC~\xE2\x80\xBE\xC2\xA5\xE2\x89\x88\xC2\xA4\xEF\xBD\xA5\xE3\x83\xBB\xE2" +91 "\x80\xA2\xE2\x88\x99\xC2\xB7\xE2\x98\xBC\xE2\x98\x85\xE6\x98\x9F\xF0\x9F" +92 "\x8C\x9F\xE6\x98\x9F\xE2\x98\x85\xE2\x98\xBC\xC2\xB7\xE2\x88\x99\xE2\x80" +93 "\xA2\xE3\x83\xBB\xEF\xBD\xA5\xC2\xA4\xE2\x89\x88\xC2\xA5\xE2\x80\xBE~XYZ"94);95const kTestFallbackIso2022jp = (96 ("ABC~\x1B(J~\\≈¤\x1B$B!&!&\x1B(B•∙·☼\x1B$B!z@1\x1B(B🌟" +97 "\x1B$B@1!z\x1B(B☼·∙•\x1B$B!&!&\x1B(B¤≈\x1B(J\\~\x1B(B~XYZ")98 .replace(/[^\0-\x7F]/gu, (x) => `&#${x.codePointAt(0)};`)99);100const kTestFallbackWindows1252 = (101 "ABC~‾\xA5≈\xA4・・\x95∙\xB7☼★星🌟星★☼\xB7∙\x95・・\xA4≈\xA5‾~XYZ".replace(102 /[^\0-\xFF]/gu,103 (x) => `&#${x.codePointAt(0)};`,104 )105);106const kTestFallbackXUserDefined = kTestChars.replace(107 /[^\0-\x7F]/gu,108 (x) => `&#${x.codePointAt(0)};`,109);110// formPostFileUploadTest - verifies multipart upload structure and111// numeric character reference replacement for filenames, field names,112// and field values using form submission.113//114// Uses /FileAPI/file/resources/echo-content-escaped.py to echo the115// upload POST with controls and non-ASCII bytes escaped. This is done116// because navigations whose response body contains [\0\b\v] may get117// treated as a download, which is not what we want. Use the118// `escapeString` function to replicate that kind of escape (note that119// it takes an isomorphic-decoded string, not a byte sequence).120//121// Fields in the parameter object:122//123// - fileNameSource: purely explanatory and gives a clue about which124// character encoding is the source for the non-7-bit-ASCII parts of125// the fileBaseName, or Unicode if no smaller-than-Unicode source126// contains all the characters. Used in the test name.127// - fileBaseName: the not-necessarily-just-7-bit-ASCII file basename128// used for the constructed test file. Used in the test name.129// - formEncoding: the acceptCharset of the form used to submit the130// test file. Used in the test name.131// - expectedEncodedBaseName: the expected formEncoding-encoded132// version of fileBaseName, isomorphic-decoded. That means, characters133// that can't be encoded in that encoding get HTML-escaped, but no134// further `escapeString`-like escapes are needed.135const formPostFileUploadTest = ({136 fileNameSource,137 fileBaseName,138 formEncoding,139 expectedEncodedBaseName,140}) => {141 promise_test(async testCase => {142 if (document.readyState !== 'complete') {143 await new Promise(resolve => addEventListener('load', resolve));144 }145 const formTargetFrame = Object.assign(document.createElement('iframe'), {146 name: 'formtargetframe',147 });148 document.body.append(formTargetFrame);149 testCase.add_cleanup(() => {150 document.body.removeChild(formTargetFrame);151 });152 const form = Object.assign(document.createElement('form'), {153 acceptCharset: formEncoding,154 action: '/FileAPI/file/resources/echo-content-escaped.py',155 method: 'POST',156 enctype: 'multipart/form-data',157 target: formTargetFrame.name,158 });159 document.body.append(form);160 testCase.add_cleanup(() => {161 document.body.removeChild(form);162 });163 // Used to verify that the browser agrees with the test about164 // which form charset is used.165 form.append(Object.assign(document.createElement('input'), {166 type: 'hidden',167 name: '_charset_',168 }));169 // Used to verify that the browser agrees with the test about170 // field value replacement and encoding independently of file system171 // idiosyncracies.172 form.append(Object.assign(document.createElement('input'), {173 type: 'hidden',174 name: 'filename',175 value: fileBaseName,176 }));177 // Same, but with name and value reversed to ensure field names178 // get the same treatment.179 form.append(Object.assign(document.createElement('input'), {180 type: 'hidden',181 name: fileBaseName,182 value: 'filename',183 }));184 const fileInput = Object.assign(document.createElement('input'), {185 type: 'file',186 name: 'file',187 });188 form.append(fileInput);189 // Removes c:\fakepath\ or other pseudofolder and returns just the190 // final component of filePath; allows both / and \ as segment191 // delimiters.192 const baseNameOfFilePath = filePath => filePath.split(/[\/\\]/).pop();193 await new Promise(resolve => {194 const dataTransfer = new DataTransfer;195 dataTransfer.items.add(196 new File([kTestChars], fileBaseName, {type: 'text/plain'}));197 fileInput.files = dataTransfer.files;198 // For historical reasons .value will be prefixed with199 // c:\fakepath\, but the basename should match the file name200 // exposed through the newer .files[0].name API. This check201 // verifies that assumption.202 assert_equals(203 baseNameOfFilePath(fileInput.files[0].name),204 baseNameOfFilePath(fileInput.value),205 `The basename of the field's value should match its files[0].name`);206 form.submit();207 formTargetFrame.onload = resolve;208 });209 const formDataText = formTargetFrame.contentDocument.body.textContent;210 const formDataLines = formDataText.split('\n');211 if (formDataLines.length && !formDataLines[formDataLines.length - 1]) {212 --formDataLines.length;213 }214 assert_greater_than(215 formDataLines.length,216 2,217 `${fileBaseName}: multipart form data must have at least 3 lines: ${218 JSON.stringify(formDataText)219 }`);220 const boundary = formDataLines[0];221 assert_equals(222 formDataLines[formDataLines.length - 1],223 boundary + '--',224 `${fileBaseName}: multipart form data must end with ${boundary}--: ${225 JSON.stringify(formDataText)226 }`);227 const asValue = expectedEncodedBaseName.replace(/\r\n?|\n/g, "\r\n");228 const asName = asValue.replace(/[\r\n"]/g, encodeURIComponent);229 const asFilename = expectedEncodedBaseName.replace(/[\r\n"]/g, encodeURIComponent);230 // The response body from echo-content-escaped.py has controls and non-ASCII231 // bytes escaped, so any caller-provided field that might contain such bytes232 // must be passed to `escapeString`, after any other expected233 // transformations.234 const expectedText = [235 boundary,236 'Content-Disposition: form-data; name="_charset_"',237 '',238 formEncoding,239 boundary,240 'Content-Disposition: form-data; name="filename"',241 '',242 // Unlike for names and filenames, multipart/form-data values don't escape243 // \r\n linebreaks, and when they're read from an iframe they become \n.244 escapeString(asValue).replace(/\r\n/g, "\n"),245 boundary,246 `Content-Disposition: form-data; name="${escapeString(asName)}"`,247 '',248 'filename',249 boundary,250 `Content-Disposition: form-data; name="file"; ` +251 `filename="${escapeString(asFilename)}"`,252 'Content-Type: text/plain',253 '',254 escapeString(kTestFallbackUtf8),255 boundary + '--',256 ].join('\n');257 assert_true(258 formDataText.startsWith(expectedText),259 `Unexpected multipart-shaped form data received:\n${260 formDataText261 }\nExpected:\n${expectedText}`);262 }, `Upload ${fileBaseName} (${fileNameSource}) in ${formEncoding} form`);...

Full Screen

Full Screen

aflprep_send-file-form-helper.js

Source:aflprep_send-file-form-helper.js Github

copy

Full Screen

1'use strict';2function escapeString(string) {3 (x) => {4 let hex = x.charCodeAt(0).toString(16);5 if (hex.length < 2) hex = "0" + hex;6 return `\\x${hex}`;7 },8}9const kTestChars = 'ABC~‾¥≈¤・・•∙·☼★星🌟星★☼·∙•・・¤≈¥‾~XYZ';10const kTestFallbackUtf8 = (11 "ABC~\xE2\x80\xBE\xC2\xA5\xE2\x89\x88\xC2\xA4\xEF\xBD\xA5\xE3\x83\xBB\xE2" +12 "\x80\xA2\xE2\x88\x99\xC2\xB7\xE2\x98\xBC\xE2\x98\x85\xE6\x98\x9F\xF0\x9F" +13 "\x8C\x9F\xE6\x98\x9F\xE2\x98\x85\xE2\x98\xBC\xC2\xB7\xE2\x88\x99\xE2\x80" +14 "\xA2\xE3\x83\xBB\xEF\xBD\xA5\xC2\xA4\xE2\x89\x88\xC2\xA5\xE2\x80\xBE~XYZ"15);16const kTestFallbackIso2022jp = (17 ("ABC~\x1B(J~\\≈¤\x1B$B!&!&\x1B(B•∙·☼\x1B$B!z@1\x1B(B🌟" +18 "\x1B$B@1!z\x1B(B☼·∙•\x1B$B!&!&\x1B(B¤≈\x1B(J\\~\x1B(B~XYZ")19);20const kTestFallbackWindows1252 = (21 "ABC~‾\xA5≈\xA4・・\x95∙\xB7☼★星🌟星★☼\xB7∙\x95・・\xA4≈\xA5‾~XYZ".replace(22 (x) => `&#${x.codePointAt(0)};`,23 )24);25const kTestFallbackXUserDefined = kTestChars.replace(26 (x) => `&#${x.codePointAt(0)};`,27);28const formPostFileUploadTest = ({29 fileNameSource,30 fileBaseName,31 formEncoding,32 expectedEncodedBaseName,33}) => {34 promise_test(async testCase => {35 if (document.readyState !== 'complete') {36 await new Promise(resolve => addEventListener('load', resolve));37 }38 const formTargetFrame = Object.assign(document.createElement('iframe'), {39 name: 'formtargetframe',40 });41 document.body.append(formTargetFrame);42 testCase.add_cleanup(() => {43 document.body.removeChild(formTargetFrame);44 });45 const form = Object.assign(document.createElement('form'), {46 acceptCharset: formEncoding,47 method: 'POST',48 target: formTargetFrame.name,49 });50 document.body.append(form);51 testCase.add_cleanup(() => {52 document.body.removeChild(form);53 });54 form.append(Object.assign(document.createElement('input'), {55 type: 'hidden',56 name: '_charset_',57 }));58 form.append(Object.assign(document.createElement('input'), {59 type: 'hidden',60 name: 'filename',61 value: fileBaseName,62 }));63 form.append(Object.assign(document.createElement('input'), {64 type: 'hidden',65 name: fileBaseName,66 value: 'filename',67 }));68 const fileInput = Object.assign(document.createElement('input'), {69 type: 'file',70 name: 'file',71 });72 form.append(fileInput);73 await new Promise(resolve => {74 const dataTransfer = new DataTransfer;75 dataTransfer.items.add(76 fileInput.files = dataTransfer.files;77 assert_equals(78 baseNameOfFilePath(fileInput.files[0].name),79 baseNameOfFilePath(fileInput.value),80 `The basename of the field's value should match its files[0].name`);81 form.submit();82 formTargetFrame.onload = resolve;83 });84 const formDataText = formTargetFrame.contentDocument.body.textContent;85 const formDataLines = formDataText.split('\n');86 if (formDataLines.length && !formDataLines[formDataLines.length - 1]) {87 --formDataLines.length;88 }89 assert_greater_than(90 formDataLines.length,91 2,92 `${fileBaseName}: multipart form data must have at least 3 lines: ${93 JSON.stringify(formDataText)94 }`);95 const boundary = formDataLines[0];96 assert_equals(97 formDataLines[formDataLines.length - 1],98 boundary + '--',99 `${fileBaseName}: multipart form data must end with ${boundary}--: ${100 JSON.stringify(formDataText)101 }`);102 const expectedText = [103 boundary,104 'Content-Disposition: form-data; name="_charset_"',105 '',106 formEncoding,107 boundary,108 'Content-Disposition: form-data; name="filename"',109 '',110 boundary,111 `Content-Disposition: form-data; name="${escapeString(asName)}"`,112 '',113 'filename',114 boundary,115 `Content-Disposition: form-data; name="file"; ` +116 `filename="${escapeString(asFilename)}"`,117 '',118 escapeString(kTestFallbackUtf8),119 boundary + '--',120 ].join('\n');121 assert_true(122 formDataText.startsWith(expectedText),123 `Unexpected multipart-shaped form data received:\n${124 formDataText125 }\nExpected:\n${expectedText}`);126 }, `Upload ${fileBaseName} (${fileNameSource}) in ${formEncoding} form`);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options.key);5 if (err) console.log(err);6 else console.log(data);7});8{ [Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' }9var wpt = require('webpagetest');10var options = {11};12var wpt = new WebPageTest('www.webpagetest.org', options.key);13 if (err) console.log(err);14 else console.log(data);15});16{ [Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' }17var wpt = require('webpagetest');18var options = {19};20var wpt = new WebPageTest('www.webpagetest.org', options.key);21 if (err) console.log(err);22 else console.log(data);23});24{ [Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptUtils = require('wptUtils');2wptUtils.formPostFileUploadTest();3exports.formPostFileUploadTest = function () {4}5var wpt = require('webpagetest');6var wptUtils = require('wptUtils');7var wpt = new WebPageTest('www.mywebsite.com', 'A.1234567890');8wpt.runTest('www.mywebsite.com', {9}, function(err, data) {10 if (err) return console.error(err);11 console.log('Test Status: ' + data.statusText);12 console.log('Test ID: ' + data.data.testId);13 console.log('Test URL: ' + data.data.summary);14 console.log('Test results will be available at: ' + data.data.userUrl);15});16{ [Error: ENOENT, no such file or directory 'fileUploadTest.txt']17 path: 'fileUploadTest.txt' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4 videoParams: {5 }6};7wpt.formPostFileUploadTest(options, function(err, data) {8 if (err) {9 console.log(err);10 } else {11 console.log(data);12 }13});14var wpt = require('wpt.js');15var wpt = new WebPageTest('www.webpagetest.org');16var options = {17 videoParams: {18 }19};20wpt.formPostFileUploadTest(options, function(err, data) {21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('wpt.js');28var wpt = new WebPageTest('www.webpagetest.org');29var options = {30 videoParams: {31 }32};33wpt.formPostFileUploadTest(options, function(err, data) {34 if (err) {35 console.log(err);36 } else {37 console.log(data);38 }39});40var wpt = require('wpt.js');41var wpt = new WebPageTest('www.webpagetest.org');42var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = new wptools('MyTestFile');3wp.formPostFileUploadTest(function(err, res) {4 console.log(err, res);5});6var Wptools = function() {7 this._config = {8 };9};10Wptools.prototype.formPostFileUploadTest = function(callback) {11 var self = this;12 var options = {13 headers: {14 }15 };16 var req = http.request(options, function(res) {17 console.log('STATUS: ' + res.statusCode);18 console.log('HEADERS: ' + JSON.stringify(res.headers));19 res.setEncoding('utf8');20 res.on('data', function(chunk) {21 console.log('BODY: ' + chunk);22 });23 res.on('end', function() {24 callback(null, res);25 });26 });27 req.on('error', function(e) {28 console.log('problem with request: ' + e.message);29 callback(e);30 });31 req.write('data\n');32 req.write('data\n');33 req.end();34};35module.exports = Wptools;36I am trying to upload a file to the server using the formPostFileUploadTest method of wptools. I am using the following code. But I am getting error as "TypeError: Cannot call method 'write' of undefined" in the line "req.write('data\n');". I am not sure what I am doing wrong. Can anyone help me?37I have a problem with my form. I am using a form to upload a file and then submit it. The form is working fine if I am uploading a file with a small size (around 5 MB). But if I am uploading a file with a larger size (around 30 MB), it is giving me an error. Can anyone help me with this?38var http = require('http');39var fs = require('fs');40var querystring = require('querystring');41var file = fs.createReadStream('C:\\Users

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require('wptdriver');2 if (error) {3 console.log(error);4 }5 else {6 console.log(result);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1 if (err) {2 console.log(err);3 }4 else {5 console.log(data);6 }7});8 if (err) {9 console.log(err);10 }11 else {12 console.log(data);13 }14});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful