white-space-handling-in-mail-editor.html (12344B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="timeout" content="long"> 6 <meta name="variant" content="?plaintext=true"> 7 <meta name="variant" content="?plaintext=false"> 8 <title>Testing white-space handling in mail editor mode</title> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 </head> 12 <body> 13 <div contenteditable></div> 14 <script> 15 "use strict"; 16 17 const params = new URLSearchParams(location.search); 18 const inPlaintextMode = params.get("plaintext") === "true"; 19 20 const editingHost = document.querySelector("div[contenteditable]"); 21 // To show white-spaces as-is, editing host should have "pre-wrap" style. 22 // Then, editor does not need to convert white-spaces. 23 editingHost.style.whiteSpace = "pre-wrap"; 24 25 const editor = SpecialPowers.wrap(window).docShell.editingSession.getEditorForWindow(window); 26 editor.flags |= SpecialPowers.Ci.nsIEditor.eEditorMailMask; 27 if (inPlaintextMode) { 28 editor.flags |= SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask; 29 } 30 31 test(() => { 32 editingHost.innerHTML = "<p><br></p>"; 33 getSelection().collapse(editingHost.querySelector("p"), 0); 34 document.execCommand("insertText", false, " "); 35 assert_in_array( 36 editingHost.innerHTML, 37 [ 38 "<p> </p>", 39 "<p> <br></p>", 40 ] 41 ); 42 }, "Inserting first white-space into empty paragraph shouldn't convert the inserting white-space to an NBSP"); 43 44 test(() => { 45 editingHost.innerHTML = "<p> </p>"; 46 getSelection().collapse(editingHost.querySelector("p").firstChild, 1); 47 document.execCommand("insertText", false, " "); 48 assert_in_array( 49 editingHost.innerHTML, 50 [ 51 "<p> </p>", 52 "<p> <br></p>", 53 ] 54 ); 55 }, "Inserting second white-space next to a white-space shouldn't convert the inserting white-space nor the existing white-space to NBSP"); 56 57 test(() => { 58 editingHost.innerHTML = "<p> </p>"; 59 getSelection().collapse(editingHost.querySelector("p").firstChild, 1); 60 document.execCommand("insertText", false, " "); 61 assert_in_array( 62 editingHost.innerHTML, 63 [ 64 "<p> </p>", 65 "<p> <br></p>", 66 ] 67 ); 68 }, "Inserting 3rd white-space into middle of white-spaces shouldn't convert the inserting white-space nor the existing white-spaces to NBSPs"); 69 70 test(() => { 71 editingHost.innerHTML = "<p> </p>"; 72 getSelection().collapse(editingHost.querySelector("p").firstChild, 2); 73 document.execCommand("insertText", false, "a"); 74 assert_in_array( 75 editingHost.innerHTML, 76 [ 77 "<p> a </p>", 78 "<p> a <br></p>", 79 ] 80 ); 81 }, "Inserting a character into middle of white-spaces shouldn't convert the existing white-spaces to NBSPs"); 82 83 test(() => { 84 editingHost.innerHTML = "<p> a </p>"; 85 getSelection().collapse(editingHost.querySelector("p").firstChild, 3); 86 document.execCommand("delete"); 87 assert_in_array( 88 editingHost.innerHTML, 89 [ 90 "<p> </p>", 91 "<p> <br></p>", 92 ] 93 ); 94 }, "Deleting a character at middle of white-spaces shouldn't convert the existing white-spaces to NBSPs"); 95 96 test(() => { 97 editingHost.innerHTML = "<p> </p>"; 98 getSelection().collapse(editingHost.querySelector("p").firstChild, 3); 99 document.execCommand("delete"); 100 assert_in_array( 101 editingHost.innerHTML, 102 [ 103 "<p> </p>", 104 "<p> <br></p>", 105 ] 106 ); 107 }, "Deleting a white-space at middle of white-spaces shouldn't convert the existing white-spaces to NBSPs"); 108 109 test(() => { 110 editingHost.innerHTML = "<p> a </p>"; 111 getSelection().collapse(editingHost.querySelector("p").firstChild, 2); 112 document.execCommand("forwardDelete"); 113 assert_in_array( 114 editingHost.innerHTML, 115 [ 116 "<p> </p>", 117 "<p> <br></p>", 118 ] 119 ); 120 }, "Forward deleting a character at middle of white-spaces shouldn't convert the existing white-spaces to NBSPs"); 121 122 test(() => { 123 editingHost.innerHTML = "<p> </p>"; 124 getSelection().collapse(editingHost.querySelector("p").firstChild, 2); 125 document.execCommand("forwardDelete"); 126 assert_in_array( 127 editingHost.innerHTML, 128 [ 129 "<p> </p>", 130 "<p> <br></p>", 131 ] 132 ); 133 }, "Forward deleting at middle of white-spaces shouldn't convert the existing white-spaces to NBSPs"); 134 135 test(() => { 136 editingHost.innerHTML = "<p><br></p>"; 137 getSelection().collapse(editingHost.querySelector("p"), 0); 138 document.execCommand("insertText", false, "\xA0"); 139 assert_in_array( 140 editingHost.innerHTML, 141 [ 142 "<p> </p>", 143 "<p> <br></p>", 144 ] 145 ); 146 }, "Inserting first NBSP into empty paragraph shouldn't convert the inserting NBSP to a white-space"); 147 148 test(() => { 149 editingHost.innerHTML = "<p>\xA0</p>"; 150 getSelection().collapse(editingHost.querySelector("p").firstChild, 1); 151 document.execCommand("insertText", false, "\xA0"); 152 assert_in_array( 153 editingHost.innerHTML, 154 [ 155 "<p> </p>", 156 "<p> <br></p>", 157 ] 158 ); 159 }, "Inserting second NBSP next to an NBSP shouldn't convert the inserting NBSP nor the existing NBSP to white-space"); 160 161 test(() => { 162 editingHost.innerHTML = "<p>\xA0\xA0</p>"; 163 getSelection().collapse(editingHost.querySelector("p").firstChild, 1); 164 document.execCommand("insertText", false, "\xA0"); 165 assert_in_array( 166 editingHost.innerHTML, 167 [ 168 "<p> </p>", 169 "<p> <br></p>", 170 ] 171 ); 172 }, "Inserting 3rd NBSP into middle of NBSPs shouldn't convert the inserting NBSP nor the existing NBSPs to white-spaces"); 173 174 test(() => { 175 editingHost.innerHTML = "<p>\xA0\xA0\xA0\xA0</p>"; 176 getSelection().collapse(editingHost.querySelector("p").firstChild, 2); 177 document.execCommand("insertText", false, "a"); 178 assert_in_array( 179 editingHost.innerHTML, 180 [ 181 "<p> a </p>", 182 "<p> a <br></p>", 183 ] 184 ); 185 }, "Inserting a character into middle of NBSPs shouldn't convert the existing NBSPs to white-spaces"); 186 187 test(() => { 188 editingHost.innerHTML = "<p>\xA0\xA0a\xA0\xA0</p>"; 189 getSelection().collapse(editingHost.querySelector("p").firstChild, 3); 190 document.execCommand("delete"); 191 assert_in_array( 192 editingHost.innerHTML, 193 [ 194 "<p> </p>", 195 "<p> <br></p>", 196 ] 197 ); 198 }, "Deleting a character at middle of NBSPs shouldn't convert the existing NBSPs to white-spaces"); 199 200 test(() => { 201 editingHost.innerHTML = "<p>\xA0\xA0\xA0\xA0\xA0</p>"; 202 getSelection().collapse(editingHost.querySelector("p").firstChild, 3); 203 document.execCommand("delete"); 204 assert_in_array( 205 editingHost.innerHTML, 206 [ 207 "<p> </p>", 208 "<p> <br></p>", 209 ] 210 ); 211 }, "Deleting an NBSP at middle of NBSPs shouldn't convert the existing NBSPs to white-spaces"); 212 213 test(() => { 214 editingHost.innerHTML = "<p>\xA0\xA0a\xA0\xA0</p>"; 215 getSelection().collapse(editingHost.querySelector("p").firstChild, 2); 216 document.execCommand("forwardDelete"); 217 assert_in_array( 218 editingHost.innerHTML, 219 [ 220 "<p> </p>", 221 "<p> <br></p>", 222 ] 223 ); 224 }, "Forward deleting a character at middle of NBSPs shouldn't convert the existing NBSPs to white-spaces"); 225 226 test(() => { 227 editingHost.innerHTML = "<p>\xA0\xA0\xA0\xA0\xA0</p>"; 228 getSelection().collapse(editingHost.querySelector("p").firstChild, 2); 229 document.execCommand("forwardDelete"); 230 assert_in_array( 231 editingHost.innerHTML, 232 [ 233 "<p> </p>", 234 "<p> <br></p>", 235 ] 236 ); 237 }, "Forward deleting at middle of NBSPs shouldn't convert the existing NBSPs to white-spaces"); 238 239 test(() => { 240 editingHost.innerHTML = "<p><br></p>"; 241 getSelection().collapse(editingHost.querySelector("p"), 0); 242 document.execCommand("insertHTML", false, " "); 243 assert_in_array( 244 editingHost.innerHTML, 245 [ 246 "<p> </p>", 247 "<p> <br></p>", 248 ] 249 ); 250 }, "Inserting first white-space with insertHTML command into empty paragraph shouldn't convert the inserting white-space to an NBSP"); 251 252 test(() => { 253 editingHost.innerHTML = "<p> </p>"; 254 getSelection().collapse(editingHost.querySelector("p").firstChild, 1); 255 document.execCommand("insertHTML", false, " "); 256 assert_in_array( 257 editingHost.innerHTML, 258 [ 259 "<p> </p>", 260 "<p> <br></p>", 261 ] 262 ); 263 }, "Inserting second white-space with insertHTML command next to a white-space shouldn't convert the inserting white-space nor the existing white-space to NBSP"); 264 265 test(() => { 266 editingHost.innerHTML = "<p> </p>"; 267 getSelection().collapse(editingHost.querySelector("p").firstChild, 1); 268 document.execCommand("insertHTML", false, " "); 269 assert_in_array( 270 editingHost.innerHTML, 271 [ 272 "<p> </p>", 273 "<p> <br></p>", 274 ] 275 ); 276 }, "Inserting 3rd white-space with insertHTML command into middle of white-spaces shouldn't convert the inserting white-space nor the existing white-spaces to NBSPs"); 277 278 test(() => { 279 editingHost.innerHTML = "<p> </p>"; 280 getSelection().collapse(editingHost.querySelector("p").firstChild, 2); 281 document.execCommand("insertHTML", false, "a"); 282 assert_in_array( 283 editingHost.innerHTML, 284 [ 285 "<p> a </p>", 286 "<p> a <br></p>", 287 ] 288 ); 289 }, "Inserting a character with insertHTML command into middle of white-spaces shouldn't convert the existing white-spaces to NBSPs"); 290 291 test(() => { 292 editingHost.innerHTML = "<p><br></p>"; 293 getSelection().collapse(editingHost.querySelector("p"), 0); 294 document.execCommand("insertHTML", false, "\xA0"); 295 assert_in_array( 296 editingHost.innerHTML, 297 [ 298 "<p> </p>", 299 "<p> <br></p>", 300 ] 301 ); 302 }, "Inserting first NBSP with insertHTML command into empty paragraph shouldn't convert the inserting NBSP to a white-space"); 303 304 test(() => { 305 editingHost.innerHTML = "<p>\xA0</p>"; 306 getSelection().collapse(editingHost.querySelector("p").firstChild, 1); 307 document.execCommand("insertHTML", false, "\xA0"); 308 assert_in_array( 309 editingHost.innerHTML, 310 [ 311 "<p> </p>", 312 "<p> <br></p>", 313 ] 314 ); 315 }, "Inserting second NBSP with insertHTML command next to an NBSP shouldn't convert the inserting NBSP nor the existing NBSP to white-space"); 316 317 test(() => { 318 editingHost.innerHTML = "<p>\xA0\xA0</p>"; 319 getSelection().collapse(editingHost.querySelector("p").firstChild, 1); 320 document.execCommand("insertHTML", false, "\xA0"); 321 assert_in_array( 322 editingHost.innerHTML, 323 [ 324 "<p> </p>", 325 "<p> <br></p>", 326 ] 327 ); 328 }, "Inserting 3rd NBSP with insertHTML command into middle of NBSPs shouldn't convert the inserting NBSP nor the existing NBSPs to white-spaces"); 329 330 test(() => { 331 editingHost.innerHTML = "<p>\xA0\xA0\xA0\xA0</p>"; 332 getSelection().collapse(editingHost.querySelector("p").firstChild, 2); 333 document.execCommand("insertHTML", false, "a"); 334 assert_in_array( 335 editingHost.innerHTML, 336 [ 337 "<p> a </p>", 338 "<p> a <br></p>", 339 ] 340 ); 341 }, "Inserting a character with insertHTML command into middle of NBSPs shouldn't convert the existing NBSPs to white-spaces"); 342 343 test(() => { 344 editingHost.innerHTML = "<p>abc</p>"; 345 getSelection().collapse(editingHost.querySelector("p").firstChild, "abc".length); 346 document.execCommand("insertHTML", false, "def "); 347 assert_in_array( 348 editingHost.innerHTML, 349 [ 350 "<p>abcdef </p>", 351 "<p>abcdef <br></p>", 352 ] 353 ); 354 }, "Inserting multiple white-spaces with insertHTML command shouldn't convert the white-spaces to NBSPs"); 355 356 test(() => { 357 editingHost.innerHTML = "<p>abc</p>"; 358 getSelection().collapse(editingHost.querySelector("p").firstChild, "abc".length); 359 document.execCommand("insertHTML", false, "def "); 360 assert_in_array( 361 editingHost.innerHTML, 362 [ 363 "<p>abcdef </p>", 364 "<p>abcdef <br></p>", 365 ] 366 ); 367 }, "Inserting multiple NBSPs with insertHTML command shouldn't convert the NBSPs to white-spaces"); 368 369 </script> 370 </body> 371 </html>