test_no_find_showDialog.html (2857B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test for Bug 1348409</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 8 <iframe src="about:blank"></iframe> 9 <script type="text/javascript"> 10 11 async function checkForFindDialog() { 12 let chromeScript = SpecialPowers.loadChromeScript(_ => { 13 /* eslint-env mozilla/chrome-script */ 14 addMessageListener("test:check", () => { 15 let sawFind = false; 16 let findDialog = Services.wm.getMostRecentWindow("findInPage"); 17 if (findDialog) { 18 findDialog.close(); 19 sawFind = true; 20 } 21 22 return sawFind; 23 }); 24 25 }); 26 27 let sawFind = await chromeScript.sendQuery("test:check"); 28 chromeScript.destroy(); 29 return sawFind; 30 } 31 32 function ensureFinished(chromeScript) { 33 return new Promise(resolve => { 34 chromeScript.addMessageListener("test:disarm:done", (sawWindow) => { 35 resolve(sawWindow); 36 }); 37 chromeScript.sendAsyncMessage("test:disarm"); 38 }); 39 } 40 41 function doWraparoundFind(findString, showDialog) { 42 let result = window.find(findString, 43 false /* aCaseSensitive */, 44 false /* aBackwards*/, 45 true /* aWrapAround */, 46 false /* aWholeWord */, 47 false /* aSearchInFrames */, 48 showDialog /* aShowInDialog */) 49 // Collapse selection so that we can do another find outside 50 // of the selection result. 51 document.getSelection().collapseToStart(); 52 return result; 53 } 54 55 function startTest() { 56 add_task(async function() { 57 ok(doWraparoundFind("text to search for", false), 58 "Found the text in the document body."); 59 60 // We're asking for the dialog now. We should just ignore that request. 61 ok(doWraparoundFind("fhqwhgads", true), 62 "Should return true and not show a dialog if the string exists in the page."); 63 ok(!doWraparoundFind(null, true), 64 "Should return false and not show a dialog if we pass a null string."); 65 ok(!doWraparoundFind("", true), 66 "Should return false and not show a dialog if we pass an empty string."); 67 68 // Double check to ensure that the parent didn't open a find dialog 69 let sawWindow = await checkForFindDialog(); 70 ok(!sawWindow, "Should never have seen the dialog."); 71 }); 72 } 73 </script> 74 </head> 75 <body onload="startTest()"> 76 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1348409">Mozilla Bug 1348409</a> 77 78 <p> 79 Here's some text to search for: fhqwhgads! A hovercraft full of eels! 80 </p> 81 82 <p id="display"></p> 83 <div id="content" style="display: none"> 84 </div> 85 <pre id="test"> 86 </pre> 87 </body> 88 </html>