Best JavaScript code snippet using wpt
send-file-form-helper.js
Source:send-file-form-helper.js
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. ·) 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. ·) 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`);...
aflprep_send-file-form-helper.js
Source:aflprep_send-file-form-helper.js
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`);...
Using AI Code Generation
1var decoder = new TextDecoder('windows-1252', {fatal: true});2var bytes = [0x80, 0x81, 0x82, 0x83, 0x84, 0x85];3var str = decoder.decode(new Uint8Array(bytes));4console.log(str);5var decoder = new TextDecoder('windows-1252', {fatal: true});6var bytes = [0x80, 0x81, 0x82, 0x83, 0x84, 0x85];7var str = decoder.decode(new Uint8Array(bytes));8console.log(str);9var decoder = new TextDecoder('windows-1252', {fatal: true});10var bytes = [0x80, 0x81, 0x82, 0x83, 0x84, 0x85];11var str = decoder.decode(new Uint8Array(bytes));12console.log(str);
Using AI Code Generation
1var testFallback = new Array();2testFallback["\u00A0"] = "%C2%A0";3testFallback["\u00A1"] = "%C2%A1";4testFallback["\u00A2"] = "%C2%A2";5testFallback["\u00A3"] = "%C2%A3";6testFallback["\u00A4"] = "%C2%A4";7testFallback["\u00A5"] = "%C2%A5";8testFallback["\u00A6"] = "%C2%A6";9testFallback["\u00A7"] = "%C2%A7";10testFallback["\u00A8"] = "%C2%A8";11testFallback["\u00A9"] = "%C2%A9";12testFallback["\u00AA"] = "%C2%AA";13testFallback["\u00AB"] = "%C2%AB";14testFallback["\u00AC"] = "%C2%AC";15testFallback["\u00AD"] = "%C2%AD";16testFallback["\u00AE"] = "%C2%AE";17testFallback["\u00AF"] = "%C2%AF";18testFallback["\u00B0"] = "%C2%B0";19testFallback["\u00B1"] = "%C2%B1";20testFallback["\u00B2"] = "%C2%B2";21testFallback["\u00B3"] = "%C2%B3";22testFallback["\u00B4"] = "%C2%B4";23testFallback["\u00B5"] = "%C2%B5";24testFallback["\u00B6"] = "%C2%B6";25testFallback["\u00B7"] = "%C2%B7";26testFallback["\u00B8"] = "%C2%B8";27testFallback["\u00B9"] = "%C2%B9";28testFallback["\u00BA"] = "%C2%BA";29testFallback["\u00BB"] = "%C2%BB";30testFallback["\u00BC"] = "%C2%BC";31testFallback["\u00BD"] = "%C2%BD";32testFallback["\u00BE"] = "%C2%BE";
Using AI Code Generation
1var testFallbackWindows1252 = new TextDecoder("windows-1252", {fatal: false, ignoreBOM: true});2var testFallbackWindows1252Result = testFallbackWindows1252.decode([0x80, 0x81, 0x82, 0x83, 0x84, 0x85]);3shouldBe('testFallbackWindows1252Result', '"€‚ƒ„…"');4shouldBe('testFallbackWindows1252.decode([0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b])', '"†‡ˆ‰Š‹"');5shouldBe('testFallbackWindows1252.decode([0x8c, 0x8d, 0x8e, 0x8f])', '"ŒŽŽŽ"');6shouldBe('testFallbackWindows1252.decode([0x90, 0x91, 0x92, 0x93, 0x94, 0x95])', '"ŒŽŽŽ"');7shouldBe('testFallbackWindows1252.decode([0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b])', '"–—˜™š›"');8shouldBe('testFallbackWindows1252.decode([0x9c, 0x9d, 0x9e, 0x9f])', '"œžŸŸ"');9shouldBe('testFallbackWindows1252.decode([0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5])', '" ¡¢£¤¥"');10shouldBe('testFallbackWindows1252.decode([0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab])', '"¦§¨©ª«"');11shouldBe('testFallbackWindows1252.decode([0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1])', '"¬®¯°±"');12shouldBe('testFallbackWindows1252.decode([0xb2, 0xb3, 0xb4, 0xb5,
Using AI Code Generation
1var test = async_test("Test fallback of utf-8 to windows-1252");2test.step(function() {3 var iframe = document.createElement("iframe");4 iframe.src = "resources/utf8-iso-8859-1.py";5 iframe.onload = test.step_func(function() {6 var doc = iframe.contentDocument;7 assert_equals(doc.body.innerHTML, "Hello World");8 test.done();9 });10 document.body.appendChild(iframe);11});
Using AI Code Generation
1var test = new TextDecoder("windows-1252", {fatal: true});2var string = test.decode(new Uint8Array([0x80]));3console.log(string);4var test = new TextDecoder("iso-8859-1", {fatal: true});5var string = test.decode(new Uint8Array([0x80]));6console.log(string);7var test = new TextDecoder("iso-8859-2", {fatal: true});8var string = test.decode(new Uint8Array([0x80]));9console.log(string);10var test = new TextDecoder("iso-8859-3", {fatal: true});11var string = test.decode(new Uint8Array([0x80]));12console.log(string);13var test = new TextDecoder("iso-8859-4", {fatal: true});14var string = test.decode(new Uint8Array([0x80]));15console.log(string);16var test = new TextDecoder("iso-8859-5", {fatal: true});17var string = test.decode(new Uint8Array([0x80]));18console.log(string);19var test = new TextDecoder("iso-8859-6", {fatal: true});20var string = test.decode(new Uint8Array([0x80]));21console.log(string);22var test = new TextDecoder("iso-8859-7", {fatal: true});23var string = test.decode(new Uint8Array([0x80]));24console.log(string);
Using AI Code Generation
1function test_wptexturize() {2 var text = "This is a test of the emergency broadcast system. If this had been a real emergency, you would have been instructed to stay in your home and await further instructions. This is only a test.";3 var expected = "This is a test of the emergency broadcast system. If this had been a real emergency, you would have been instructed to stay in your home and await further instructions. This is only a test.";4 var result = wptexturize(text, "kTestFallbackWindows1252");5 console.log(result);6 console.log(expected);7 assert(result == expected, "wptexturize test failed");8}9function test_wptexturize() {10 var text = "This is a test of the emergency broadcast system. If this had been a real emergency, you would have been instructed to stay in your home and await further instructions. This is only a test.";11 var expected = "This is a test of the emergency broadcast system. If this had been a real emergency, you would have been instructed to stay in your home and await further instructions. This is only a test.";12 var result = wptexturize(text, "kTestFallbackWindows1252");13 console.log(result);14 console.log(expected);15 assert(result == expected, "wptexturize test failed");16}17function test_wptexturize() {18 var text = "This is a test of the emergency broadcast system. If this had been a real emergency, you would have been instructed to stay in your home and await further instructions. This is only a test.";19 var expected = "This is a test of the emergency broadcast system. If this had been a real emergency, you would have been instructed to stay in your home and await further instructions. This is only a test.";20 var result = wptexturize(text, "kTestFallbackWindows1252");21 console.log(result);22 console.log(expected);23 assert(result == expected, "wptexturize test failed");24}25function test_wptexturize() {
Using AI Code Generation
1var kTestFallbackWindows1252 = 1;2var kTestFallbackUtf8 = 2;3var kTestFallback = kTestFallbackWindows1252;4function run_test() {5 var channel = setupChannel();6 channel.asyncOpen2(new ChannelListener(checkEncoding, channel));7 do_test_pending();8}9function setupChannel() {10 var ios = Components.classes["@mozilla.org/network/io-service;1"]11 .getService(Components.interfaces.nsIIOService);12 null);13 channel.QueryInterface(Components.interfaces.nsIHttpChannel);14 return channel;15}16function checkEncoding(request, buffer) {17 .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);18 if (kTestFallback == kTestFallbackWindows1252) {19 decoder.charset = "windows-1252";20 } else {21 decoder.charset = "UTF-8";22 }23 var data = decoder.ConvertToUnicode(buffer);24 do_check_eq(data, "Iñtërnâtiônàlizætiøn☃💩");25 do_test_finished();26}
Using AI Code Generation
1function wptexturizeTestFallbackWindows1252($text) {2 $chr = array(3 "\xC2\x91" => '‘',4 "\xC2\x92" => '’',5 "\xC2\x93" => '“',6 "\xC2\x94" => '”',7 "\xC2\x95" => '•',8 "\xC2\x96" => '–',9 "\xC2\x97" => '—',10 "\xC2\x99" => '™',11 "\xC5\xA0" => 'Š',12 "\xE2\x82\xAC" => '€',13 "\xC5\xB8" => 'Ÿ',14 "\xE2\x84\xA2" => '™',15 "\xCB\x8A" => '´',16 "\xCB\x9D" => '˝',17 "\xC5\xBE" => 'ˇ',18 "\xCB\x98" => '˘',19 "\xCB\x99" => '˙',20 "\xCB\x9A" => '˛',21 "\xCB\x9C" => '˚',22 "\xCB\x9E" => '˝',23 "\xC2\xB8" => '¸',24 "\xCB\x9C" => '¯',25 "\xCB\x9C" => '¸',26 "\xCB\x9C" => 'ˇ',
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!