summaryrefslogtreecommitdiffstats
path: root/toolkit/content/tests/browser/browser_bug982298.js
blob: 94846ff1cdd3129bf74de3c38e126048a2749d11 (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
const scrollHtml =
  '<textarea id="textarea1" row=2>Firefox\n\nFirefox\n\n\n\n\n\n\n\n\n\n' +
  '</textarea><a href="about:blank">blank</a>';

add_task(async function () {
  let url = "data:text/html;base64," + btoa(scrollHtml);
  await BrowserTestUtils.withNewTab(
    { gBrowser, url },
    async function (browser) {
      let awaitFindResult = new Promise(resolve => {
        let listener = {
          onFindResult(aData) {
            info("got find result");
            browser.finder.removeResultListener(listener);

            ok(
              aData.result == Ci.nsITypeAheadFind.FIND_FOUND,
              "should find string"
            );
            resolve();
          },
          onCurrentSelection() {},
          onMatchesCountResult() {},
        };
        info(
          "about to add results listener, open find bar, and send 'F' string"
        );
        browser.finder.addResultListener(listener);
      });
      await gFindBarPromise;
      gFindBar.onFindCommand();
      EventUtils.sendString("F");
      info("added result listener and sent string 'F'");
      await awaitFindResult;

      // scroll textarea to bottom
      await SpecialPowers.spawn(browser, [], () => {
        let textarea = content.document.getElementById("textarea1");
        textarea.scrollTop = textarea.scrollHeight;
      });
      BrowserTestUtils.loadURIString(browser, "about:blank");
      await BrowserTestUtils.browserLoaded(browser);

      ok(
        browser.currentURI.spec == "about:blank",
        "got load event for about:blank"
      );

      let awaitFindResult2 = new Promise(resolve => {
        let listener = {
          onFindResult(aData) {
            info("got find result #2");
            browser.finder.removeResultListener(listener);
            resolve();
          },
          onCurrentSelection() {},
          onMatchesCountResult() {},
        };

        browser.finder.addResultListener(listener);
        info("added result listener");
      });
      // find again needs delay for crash test
      setTimeout(function () {
        // ignore exception if occured
        try {
          info("about to send find again command");
          gFindBar.onFindAgainCommand(false);
          info("sent find again command");
        } catch (e) {
          info("got exception from onFindAgainCommand: " + e);
        }
      }, 0);
      await awaitFindResult2;
    }
  );
});