browser/base/content/test/general/browser_bug567306.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug567306.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +const {Ci: interfaces, Cc: classes} = Components;
     1.9 +
    1.10 +let Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
    1.11 +let HasFindClipboard = Clipboard.supportsFindClipboard();
    1.12 +
    1.13 +function test() {
    1.14 +  waitForExplicitFinish();
    1.15 +
    1.16 +  whenNewWindowLoaded(undefined, function (win) {
    1.17 +    whenDelayedStartupFinished(win, function () {
    1.18 +      let selectedBrowser = win.gBrowser.selectedBrowser;
    1.19 +      selectedBrowser.addEventListener("pageshow", function() {
    1.20 +        selectedBrowser.removeEventListener("pageshow", arguments.callee, true);
    1.21 +        ok(true, "pageshow listener called: " + win.content.location);
    1.22 +        waitForFocus(function () {
    1.23 +          onFocus(win);
    1.24 +        }, selectedBrowser.contentWindow);
    1.25 +      }, true);
    1.26 +      selectedBrowser.loadURI("data:text/html,<h1 id='h1'>Select Me</h1>");
    1.27 +    });
    1.28 +  });
    1.29 +}
    1.30 +
    1.31 +function selectText(win) {
    1.32 +  let elt = win.document.getElementById("h1");
    1.33 +  let selection = win.getSelection();
    1.34 +  let range = win.document.createRange();
    1.35 +  range.setStart(elt, 0);
    1.36 +  range.setEnd(elt, 1);
    1.37 +  selection.removeAllRanges();
    1.38 +  selection.addRange(range);
    1.39 +}
    1.40 +
    1.41 +function onFocus(win) {
    1.42 +  ok(!win.gFindBarInitialized, "find bar is not yet initialized");
    1.43 +  let findBar = win.gFindBar;
    1.44 +  selectText(win.content);
    1.45 +  findBar.onFindCommand();
    1.46 +  // When the OS supports the Find Clipboard (OSX), the find field value is
    1.47 +  // persisted across Fx sessions, thus not useful to test.
    1.48 +  if (!HasFindClipboard)
    1.49 +    is(findBar._findField.value, "Select Me", "Findbar is initialized with selection");
    1.50 +  findBar.close();
    1.51 +  win.close();
    1.52 +  finish();
    1.53 +}

mercurial