summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/bugs/test_no_find_showDialog.html
blob: 5cfa36ebc0778d536fb54b8dee4ca3b7c3966b94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1348409</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <iframe src="about:blank"></iframe>
  <script type="text/javascript">

  async function checkForFindDialog() {
    let chromeScript = SpecialPowers.loadChromeScript(_ => {
      /* eslint-env mozilla/chrome-script */
      addMessageListener("test:check", () => {
        let sawFind = false;
        let findDialog = Services.wm.getMostRecentWindow("findInPage");
        if (findDialog) {
          findDialog.close();
          sawFind = true;
        }

        return sawFind;
      });

    });

    let sawFind = await chromeScript.sendQuery("test:check");
    chromeScript.destroy();
    return sawFind;
  }

  function ensureFinished(chromeScript) {
    return new Promise(resolve => {
      chromeScript.addMessageListener("test:disarm:done", (sawWindow) => {
        resolve(sawWindow);
      });
      chromeScript.sendAsyncMessage("test:disarm");
    });
  }

  function doWraparoundFind(findString, showDialog) {
    let result = window.find(findString,
                             false /* aCaseSensitive */,
                             false /* aBackwards*/,
                             true /* aWrapAround */,
                             false /* aWholeWord */,
                             false /* aSearchInFrames */,
                             showDialog /* aShowInDialog */)
    // Collapse selection so that we can do another find outside
    // of the selection result.
    document.getSelection().collapseToStart();
    return result;
  }

  function startTest() {
    add_task(async function() {
      ok(doWraparoundFind("text to search for", false),
         "Found the text in the document body.");

      // We're asking for the dialog now. We should just ignore that request.
      ok(doWraparoundFind("fhqwhgads", true),
         "Should return true and not show a dialog if the string exists in the page.");
      ok(!doWraparoundFind(null, true),
         "Should return false and not show a dialog if we pass a null string.");
      ok(!doWraparoundFind("", true),
         "Should return false and not show a dialog if we pass an empty string.");

      // Double check to ensure that the parent didn't open a find dialog
      let sawWindow = await checkForFindDialog();
      ok(!sawWindow, "Should never have seen the dialog.");
    });
  }
  </script>
</head>
<body onload="startTest()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1348409">Mozilla Bug 1348409</a>

<p>
  Here's some text to search for: fhqwhgads! A hovercraft full of eels!
</p>

<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>