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 | <?xml version="1.0"?> |
michael@0 | 2 | |
michael@0 | 3 | <!-- This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | - License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
michael@0 | 6 | |
michael@0 | 7 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 8 | |
michael@0 | 9 | <window id="FindbarTest" |
michael@0 | 10 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 11 | width="600" |
michael@0 | 12 | height="600" |
michael@0 | 13 | onload="SimpleTest.executeSoon(startTest);" |
michael@0 | 14 | title="findbar events test"> |
michael@0 | 15 | |
michael@0 | 16 | <script type="application/javascript"><![CDATA[ |
michael@0 | 17 | const Ci = Components.interfaces; |
michael@0 | 18 | const Cc = Components.classes; |
michael@0 | 19 | const Cr = Components.results; |
michael@0 | 20 | |
michael@0 | 21 | var gFindBar = null; |
michael@0 | 22 | var gBrowser; |
michael@0 | 23 | |
michael@0 | 24 | var imports = ["SimpleTest", "ok"]; |
michael@0 | 25 | for each (var name in imports) { |
michael@0 | 26 | window[name] = window.opener.wrappedJSObject[name]; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function finish() { |
michael@0 | 30 | window.close(); |
michael@0 | 31 | SimpleTest.finish(); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function startTest() { |
michael@0 | 35 | gFindBar = document.getElementById("FindToolbar"); |
michael@0 | 36 | gBrowser = document.getElementById("content"); |
michael@0 | 37 | gBrowser.addEventListener("pageshow", onPageShow, false); |
michael@0 | 38 | gBrowser.loadURI('data:text/html,hello there'); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | var tests = [ |
michael@0 | 42 | testFind, |
michael@0 | 43 | testFindAgain, |
michael@0 | 44 | testCaseSensitivity, |
michael@0 | 45 | testHighlight, |
michael@0 | 46 | finish |
michael@0 | 47 | ]; |
michael@0 | 48 | |
michael@0 | 49 | // Iterates through the above tests and takes care of passing the done |
michael@0 | 50 | // callback for any async tests. |
michael@0 | 51 | function nextTest() { |
michael@0 | 52 | if (!tests.length) { |
michael@0 | 53 | return; |
michael@0 | 54 | } |
michael@0 | 55 | var func = tests.shift(); |
michael@0 | 56 | if (!func.length) { |
michael@0 | 57 | // Test isn't async advance to the next test here. |
michael@0 | 58 | func(); |
michael@0 | 59 | SimpleTest.executeSoon(nextTest); |
michael@0 | 60 | } else { |
michael@0 | 61 | func(nextTest); |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function onPageShow() { |
michael@0 | 66 | gFindBar.open(); |
michael@0 | 67 | gFindBar.onFindCommand(); |
michael@0 | 68 | nextTest(); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function checkSelection(done) { |
michael@0 | 72 | SimpleTest.executeSoon(function() { |
michael@0 | 73 | var selected = gBrowser.contentWindow.getSelection(); |
michael@0 | 74 | ok(selected == "", "No text is selected"); |
michael@0 | 75 | |
michael@0 | 76 | var controller = gFindBar.browser.docShell.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 77 | .getInterface(Ci.nsISelectionDisplay) |
michael@0 | 78 | .QueryInterface(Ci.nsISelectionController); |
michael@0 | 79 | var selection = controller.getSelection(controller.SELECTION_FIND); |
michael@0 | 80 | ok(selection.rangeCount == 0, "No text is highlighted"); |
michael@0 | 81 | done(); |
michael@0 | 82 | }); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function testFind(done) { |
michael@0 | 86 | var findTriggered = false; |
michael@0 | 87 | var query = "t"; |
michael@0 | 88 | gFindBar.addEventListener("find", function(e) { |
michael@0 | 89 | eventTriggered = true; |
michael@0 | 90 | ok(e.detail.query === query, "find event query should match '" + query + "'"); |
michael@0 | 91 | e.preventDefault(); |
michael@0 | 92 | // Since we're preventing the default make sure nothing was selected. |
michael@0 | 93 | checkSelection(done); |
michael@0 | 94 | }); |
michael@0 | 95 | |
michael@0 | 96 | // Put some text in the find box. |
michael@0 | 97 | var event = document.createEvent("KeyEvents"); |
michael@0 | 98 | event.initKeyEvent("keypress", true, true, null, false, false, |
michael@0 | 99 | false, false, 0, query.charCodeAt(0)); |
michael@0 | 100 | gFindBar._findField.inputField.dispatchEvent(event); |
michael@0 | 101 | ok(eventTriggered, "find event should be triggered"); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | function testFindAgain(done) { |
michael@0 | 105 | var eventTriggered = false; |
michael@0 | 106 | gFindBar.addEventListener("findagain", function(e) { |
michael@0 | 107 | eventTriggered = true; |
michael@0 | 108 | e.preventDefault(); |
michael@0 | 109 | // Since we're preventing the default make sure nothing was selected. |
michael@0 | 110 | checkSelection(done); |
michael@0 | 111 | }); |
michael@0 | 112 | |
michael@0 | 113 | gFindBar.onFindAgainCommand(); |
michael@0 | 114 | ok(eventTriggered, "findagain event should be triggered"); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function testCaseSensitivity() { |
michael@0 | 118 | var eventTriggered = false; |
michael@0 | 119 | gFindBar.addEventListener("findcasesensitivitychange", function(e) { |
michael@0 | 120 | eventTriggered = true; |
michael@0 | 121 | ok(e.detail.caseSensitive, "find should be case sensitive"); |
michael@0 | 122 | }); |
michael@0 | 123 | |
michael@0 | 124 | var matchCaseCheckbox = gFindBar.getElement("find-case-sensitive"); |
michael@0 | 125 | matchCaseCheckbox.click(); |
michael@0 | 126 | ok(eventTriggered, "findcasesensitivitychange should be triggered"); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | function testHighlight(done) { |
michael@0 | 130 | // Update the find state so the highlight button is clickable. |
michael@0 | 131 | gFindBar.updateControlState(Ci.nsITypeAheadFind.FIND_FOUND, false); |
michael@0 | 132 | var eventTriggered = false; |
michael@0 | 133 | gFindBar.addEventListener("findhighlightallchange", function(e) { |
michael@0 | 134 | eventTriggered = true; |
michael@0 | 135 | ok(e.detail.highlightAll, "find event should have highlight all set"); |
michael@0 | 136 | e.preventDefault(); |
michael@0 | 137 | // Since we're preventing the default make sure nothing was highlighted. |
michael@0 | 138 | SimpleTest.executeSoon(function() { |
michael@0 | 139 | checkSelection(done); |
michael@0 | 140 | }); |
michael@0 | 141 | }); |
michael@0 | 142 | |
michael@0 | 143 | var highlightButton = gFindBar.getElement("highlight"); |
michael@0 | 144 | if (!highlightButton.checked) { |
michael@0 | 145 | highlightButton.click(); |
michael@0 | 146 | } |
michael@0 | 147 | ok(eventTriggered, "findhighlightallchange should be triggered"); |
michael@0 | 148 | } |
michael@0 | 149 | ]]></script> |
michael@0 | 150 | |
michael@0 | 151 | <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
michael@0 | 152 | <findbar id="FindToolbar" browserid="content"/> |
michael@0 | 153 | </window> |