michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: const {Ci: interfaces, Cc: classes} = Components; michael@0: michael@0: let Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard); michael@0: let HasFindClipboard = Clipboard.supportsFindClipboard(); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: whenNewWindowLoaded(undefined, function (win) { michael@0: whenDelayedStartupFinished(win, function () { michael@0: let selectedBrowser = win.gBrowser.selectedBrowser; michael@0: selectedBrowser.addEventListener("pageshow", function() { michael@0: selectedBrowser.removeEventListener("pageshow", arguments.callee, true); michael@0: ok(true, "pageshow listener called: " + win.content.location); michael@0: waitForFocus(function () { michael@0: onFocus(win); michael@0: }, selectedBrowser.contentWindow); michael@0: }, true); michael@0: selectedBrowser.loadURI("data:text/html,

Select Me

"); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function selectText(win) { michael@0: let elt = win.document.getElementById("h1"); michael@0: let selection = win.getSelection(); michael@0: let range = win.document.createRange(); michael@0: range.setStart(elt, 0); michael@0: range.setEnd(elt, 1); michael@0: selection.removeAllRanges(); michael@0: selection.addRange(range); michael@0: } michael@0: michael@0: function onFocus(win) { michael@0: ok(!win.gFindBarInitialized, "find bar is not yet initialized"); michael@0: let findBar = win.gFindBar; michael@0: selectText(win.content); michael@0: findBar.onFindCommand(); michael@0: // When the OS supports the Find Clipboard (OSX), the find field value is michael@0: // persisted across Fx sessions, thus not useful to test. michael@0: if (!HasFindClipboard) michael@0: is(findBar._findField.value, "Select Me", "Findbar is initialized with selection"); michael@0: findBar.close(); michael@0: win.close(); michael@0: finish(); michael@0: }