summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/browser_bug567306.js
blob: 3d3e47e17d0dffd6f0d6c5059114e4631452ebec (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

var HasFindClipboard = Services.clipboard.isClipboardTypeSupported(
  Services.clipboard.kFindClipboard
);

add_task(async function () {
  let newwindow = await BrowserTestUtils.openNewBrowserWindow();

  let selectedBrowser = newwindow.gBrowser.selectedBrowser;
  await new Promise((resolve, reject) => {
    BrowserTestUtils.waitForContentEvent(
      selectedBrowser,
      "pageshow",
      true,
      event => {
        return event.target.location != "about:blank";
      }
    ).then(function pageshowListener() {
      ok(
        true,
        "pageshow listener called: " + newwindow.gBrowser.currentURI.spec
      );
      resolve();
    });
    selectedBrowser.loadURI(
      Services.io.newURI("data:text/html,<h1 id='h1'>Select Me</h1>"),
      {
        triggeringPrincipal:
          Services.scriptSecurityManager.getSystemPrincipal(),
      }
    );
  });

  await SimpleTest.promiseFocus(newwindow);

  ok(!newwindow.gFindBarInitialized, "find bar is not yet initialized");
  let findBar = await newwindow.gFindBarPromise;

  await SpecialPowers.spawn(selectedBrowser, [], async function () {
    let elt = content.document.getElementById("h1");
    let selection = content.getSelection();
    let range = content.document.createRange();
    range.setStart(elt, 0);
    range.setEnd(elt, 1);
    selection.removeAllRanges();
    selection.addRange(range);
  });

  await findBar.onFindCommand();

  // When the OS supports the Find Clipboard (OSX), the find field value is
  // persisted across Fx sessions, thus not useful to test.
  if (!HasFindClipboard) {
    is(
      findBar._findField.value,
      "Select Me",
      "Findbar is initialized with selection"
    );
  }
  findBar.close();
  await promiseWindowClosed(newwindow);
});