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