test_bug1272623.html (3437B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1272623 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1272623</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 13 </head> 14 <body> 15 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1272623">Mozilla Bug 1272623</a> 16 <p id="display"></p> 17 <div id="content" style="display: none"> 18 19 </div> 20 <pre id="test"> 21 <div id="area" contenteditable="true"><b style="font-weight:normal;">testing <span id="misspelled">spellechek</span></b></div> 22 <div id="area2" contenteditable="true">testing <span id="misspelled2" style="font-weight:bold;">spellechek</span></div> 23 </pre> 24 <script> 25 26 /** Test for Bug 1272623 */ 27 28 var maybeOnSpellCheck; 29 30 async function performCorrection(misspelled, area) { 31 synthesizeMouseAtCenter($(misspelled), {}, window); 32 await new Promise(resolve => maybeOnSpellCheck($(area), resolve)); 33 synthesizeMouseAtCenter($(misspelled), {type: 'contextmenu'}, window); 34 35 // Perform the spelling correction 36 let mm = SpecialPowers.loadChromeScript(function() { 37 /* eslint-env mozilla/chrome-script */ 38 const {BrowserTestUtils} = ChromeUtils.importESModule( 39 "resource://testing-common/BrowserTestUtils.sys.mjs" 40 ); 41 42 // Chrome scripts are run with synchronous messages, so make sure we're completely 43 // decoupled from the content process before doing this work. 44 Cu.dispatch(async function() { 45 let chromeWin = Services.ww.activeWindow; 46 let contextMenu = chromeWin.document.getElementById("contentAreaContextMenu"); 47 let suggestion = contextMenu.querySelector(".spell-suggestion"); 48 if (!suggestion) { 49 await BrowserTestUtils.waitForMutationCondition( 50 contextMenu, 51 { childList: true }, 52 () => contextMenu.querySelector(".spell-suggestion") 53 ); 54 suggestion = contextMenu.querySelector(".spell-suggestion"); 55 } 56 suggestion.doCommand(); 57 contextMenu.hidePopup(); 58 sendAsyncMessage("spellingCorrected"); 59 }); 60 }); 61 info("Loaded chrome script"); 62 await new Promise(resolve => mm.addMessageListener('spellingCorrected', resolve)); 63 } 64 65 add_task(async function() { 66 maybeOnSpellCheck = SpecialPowers.ChromeUtils.importESModule( 67 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" 68 ).maybeOnSpellCheck; 69 70 // Wait for the page to be ready 71 await new Promise(resolve => SimpleTest.waitForFocus(() => SimpleTest.executeSoon(resolve), window)); 72 73 // Check that <b> tags aren't inserted inside of other <b> tags when it would change the style 74 await performCorrection('misspelled', 'area'); 75 is($('area').innerHTML, "<b style=\"font-weight:normal;\">testing <span id=\"misspelled\">spellcheck</span></b>"); 76 is($('area').textContent, 'testing spellcheck', "Spelling corrected properly"); 77 78 // Check that nodes aren't removed when the entire text inside of them is spelling-corrected 79 await performCorrection('misspelled2', 'area2'); 80 is($('area2').innerHTML, "testing <span id=\"misspelled2\" style=\"font-weight:bold;\">spellcheck</span>"); 81 is($('area2').textContent, 'testing spellcheck', "Spelling corrected properly"); 82 }); 83 </script> 84 </body> 85 </html>