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

var {Ci: interfaces, Cc: classes} = Components;

var Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
var HasFindClipboard = Clipboard.supportsFindClipboard();

add_task(function* () {
  let newwindow = yield BrowserTestUtils.openNewBrowserWindow();

  let selectedBrowser = newwindow.gBrowser.selectedBrowser;
  yield new Promise((resolve, reject) => {
    selectedBrowser.addEventListener("pageshow", function pageshowListener() {
      if (selectedBrowser.currentURI.spec == "about:blank")
        return;

      selectedBrowser.removeEventListener("pageshow", pageshowListener, true);
      ok(true, "pageshow listener called: " + newwindow.content.location);
      resolve();
    }, true);
    selectedBrowser.loadURI("data:text/html,<h1 id='h1'>Select Me</h1>");
  });

  yield SimpleTest.promiseFocus(newwindow);

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

  yield ContentTask.spawn(selectedBrowser, { }, 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);
  });

  yield 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();
  yield promiseWindowClosed(newwindow);
});