Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | const {Ci: interfaces, Cc: classes} = Components; |
michael@0 | 6 | |
michael@0 | 7 | let Clipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard); |
michael@0 | 8 | let HasFindClipboard = Clipboard.supportsFindClipboard(); |
michael@0 | 9 | |
michael@0 | 10 | function test() { |
michael@0 | 11 | waitForExplicitFinish(); |
michael@0 | 12 | |
michael@0 | 13 | whenNewWindowLoaded(undefined, function (win) { |
michael@0 | 14 | whenDelayedStartupFinished(win, function () { |
michael@0 | 15 | let selectedBrowser = win.gBrowser.selectedBrowser; |
michael@0 | 16 | selectedBrowser.addEventListener("pageshow", function() { |
michael@0 | 17 | selectedBrowser.removeEventListener("pageshow", arguments.callee, true); |
michael@0 | 18 | ok(true, "pageshow listener called: " + win.content.location); |
michael@0 | 19 | waitForFocus(function () { |
michael@0 | 20 | onFocus(win); |
michael@0 | 21 | }, selectedBrowser.contentWindow); |
michael@0 | 22 | }, true); |
michael@0 | 23 | selectedBrowser.loadURI("data:text/html,<h1 id='h1'>Select Me</h1>"); |
michael@0 | 24 | }); |
michael@0 | 25 | }); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function selectText(win) { |
michael@0 | 29 | let elt = win.document.getElementById("h1"); |
michael@0 | 30 | let selection = win.getSelection(); |
michael@0 | 31 | let range = win.document.createRange(); |
michael@0 | 32 | range.setStart(elt, 0); |
michael@0 | 33 | range.setEnd(elt, 1); |
michael@0 | 34 | selection.removeAllRanges(); |
michael@0 | 35 | selection.addRange(range); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function onFocus(win) { |
michael@0 | 39 | ok(!win.gFindBarInitialized, "find bar is not yet initialized"); |
michael@0 | 40 | let findBar = win.gFindBar; |
michael@0 | 41 | selectText(win.content); |
michael@0 | 42 | findBar.onFindCommand(); |
michael@0 | 43 | // When the OS supports the Find Clipboard (OSX), the find field value is |
michael@0 | 44 | // persisted across Fx sessions, thus not useful to test. |
michael@0 | 45 | if (!HasFindClipboard) |
michael@0 | 46 | is(findBar._findField.value, "Select Me", "Findbar is initialized with selection"); |
michael@0 | 47 | findBar.close(); |
michael@0 | 48 | win.close(); |
michael@0 | 49 | finish(); |
michael@0 | 50 | } |