|
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="360437Test" |
|
10 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
11 width="600" |
|
12 height="600" |
|
13 onload="onLoad();" |
|
14 title="360437 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 function ok(condition, message) { |
|
25 window.opener.wrappedJSObject.SimpleTest.ok(condition, message); |
|
26 } |
|
27 function finish() { |
|
28 window.close(); |
|
29 window.opener.wrappedJSObject.SimpleTest.finish(); |
|
30 } |
|
31 |
|
32 function onLoad() { |
|
33 var _delayedOnLoad = function() { |
|
34 gFindBar = document.getElementById("FindToolbar"); |
|
35 gBrowser = document.getElementById("content"); |
|
36 gBrowser.addEventListener("pageshow", onPageShow, false); |
|
37 gBrowser.loadURI("data:text/html,<form><input id='input' type='text' value='text inside an input element'></form>"); |
|
38 } |
|
39 setTimeout(_delayedOnLoad, 1000); |
|
40 } |
|
41 |
|
42 function onPageShow() { |
|
43 testNormalFind(); |
|
44 } |
|
45 |
|
46 function enterStringIntoFindField(aString) { |
|
47 for (var i=0; i < aString.length; i++) { |
|
48 var event = document.createEvent("KeyEvents"); |
|
49 event.initKeyEvent("keypress", true, true, null, false, false, |
|
50 false, false, 0, aString.charCodeAt(i)); |
|
51 gFindBar._findField.inputField.dispatchEvent(event); |
|
52 } |
|
53 } |
|
54 |
|
55 function testNormalFind() { |
|
56 gFindBar.onFindCommand(); |
|
57 |
|
58 // Make sure the findfield is correctly focused on open |
|
59 var searchStr = "text inside an input element"; |
|
60 enterStringIntoFindField(searchStr); |
|
61 ok(document.commandDispatcher.focusedElement == |
|
62 gFindBar._findField.inputField, "Find field isn't focused"); |
|
63 |
|
64 // Make sure "find again" correctly transfers focus to the content element |
|
65 // when the find bar is closed. |
|
66 gFindBar.close(); |
|
67 gFindBar.onFindAgainCommand(false); |
|
68 ok(document.commandDispatcher.focusedElement == |
|
69 gBrowser.contentDocument.getElementById("input"), |
|
70 "Input Element isn't focused"); |
|
71 |
|
72 // Make sure "find again" doesn't focus the content element if focus |
|
73 // isn't in the content document. |
|
74 var textbox = document.getElementById("textbox"); |
|
75 textbox.focus(); |
|
76 gFindBar.close(); |
|
77 gFindBar.onFindAgainCommand(false); |
|
78 ok(textbox.hasAttribute("focused"), |
|
79 "Focus was stolen from a chrome element"); |
|
80 finish(); |
|
81 } |
|
82 ]]></script> |
|
83 <textbox id="textbox"/> |
|
84 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
85 <findbar id="FindToolbar" browserid="content"/> |
|
86 </window> |