|
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="451286test" |
|
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="451286 test (also tests bug 493658)"> |
|
15 |
|
16 <script type="application/javascript"><![CDATA[ |
|
17 const Ci = Components.interfaces; |
|
18 const Cc = Components.classes; |
|
19 const Cr = Components.results; |
|
20 const SEARCH_TEXT = "text"; |
|
21 const DATAURI = "data:text/html," + SEARCH_TEXT; |
|
22 |
|
23 var gFindBar = null; |
|
24 var gBrowser; |
|
25 var gWin; |
|
26 |
|
27 var noHighlightSnapshot; |
|
28 var findSnapshot; |
|
29 |
|
30 var imports = ["SimpleTest", "ok", "snapshotWindow", "compareSnapshots", |
|
31 "parentFinish"]; |
|
32 for each (var name in imports) { |
|
33 window[name] = window.opener.wrappedJSObject[name]; |
|
34 } |
|
35 |
|
36 function finish() { |
|
37 window.close(); |
|
38 parentFinish(); |
|
39 } |
|
40 |
|
41 function startTest() { |
|
42 gFindBar = document.getElementById("FindToolbar"); |
|
43 gBrowser = document.getElementById("content"); |
|
44 gBrowser.addEventListener("pageshow", onPageShow, false); |
|
45 |
|
46 // Bug 451286. An iframe that should be highlighted |
|
47 var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>"; |
|
48 |
|
49 // Bug 493658. An invisible iframe that shouldn't interfere with |
|
50 // highlighting matches lying after it in the document |
|
51 var invisible = "<iframe id='invisible' style='display: none;' " + |
|
52 "src='" + DATAURI + "'></iframe>"; |
|
53 |
|
54 var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT; |
|
55 gBrowser.loadURI(uri); |
|
56 } |
|
57 |
|
58 function onPageShow(aEvent) { |
|
59 // Don't respond to pageshow events coming from the <iframes> |
|
60 if (aEvent.target != gBrowser.contentDocument) |
|
61 return; |
|
62 |
|
63 gBrowser.removeEventListener("pageshow", onPageShow, false); |
|
64 |
|
65 // First, take a snapshot of the window without highlighting |
|
66 // to be used later to test the unhighlighting case |
|
67 gWin = gBrowser.contentWindow; |
|
68 noHighlightSnapshot = snapshotWindow(gWin); |
|
69 |
|
70 gFindBar.open(); |
|
71 gFindBar._findField.value = SEARCH_TEXT; |
|
72 var matchCase = gFindBar.getElement("find-case-sensitive"); |
|
73 if (matchCase.checked) |
|
74 matchCase.doCommand(); |
|
75 |
|
76 // Turn on highlighting |
|
77 gFindBar.toggleHighlight(true); |
|
78 gFindBar.close(); |
|
79 gFindBar.addEventListener('transitionend', part2); |
|
80 } |
|
81 |
|
82 function part2(aEvent) { |
|
83 if (aEvent.propertyName != 'visibility') { |
|
84 return; |
|
85 } |
|
86 gFindBar.removeEventListener('transitionend', part2); |
|
87 // Take snapshot of highlighing |
|
88 findSnapshot = snapshotWindow(gWin); |
|
89 |
|
90 // Now, remove the highlighting, and take a snapshot to compare |
|
91 // to our original state |
|
92 gFindBar.open(); |
|
93 gFindBar.toggleHighlight(false); |
|
94 gFindBar.close(); |
|
95 gFindBar.addEventListener('transitionend', part3); |
|
96 } |
|
97 |
|
98 function part3(aEvent) { |
|
99 if (aEvent.propertyName != 'visibility') { |
|
100 return; |
|
101 } |
|
102 gFindBar.removeEventListener('transitionend', part3); |
|
103 var unhighlightSnapshot = snapshotWindow(gWin); |
|
104 |
|
105 // Select the matches that should have been highlighted manually |
|
106 var doc = gBrowser.contentDocument; |
|
107 |
|
108 // Create a manual highlight in the visible iframe to test bug 451286 |
|
109 var iframe = doc.getElementById("visible"); |
|
110 var ifBody = iframe.contentDocument.body; |
|
111 var range = iframe.contentDocument.createRange(); |
|
112 range.selectNodeContents(ifBody.childNodes[0]); |
|
113 var ifWindow = iframe.contentWindow; |
|
114 var ifDocShell = ifWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
|
115 .getInterface(Ci.nsIWebNavigation) |
|
116 .QueryInterface(Ci.nsIDocShell); |
|
117 |
|
118 var ifController = ifDocShell.QueryInterface(Ci.nsIInterfaceRequestor) |
|
119 .getInterface(Ci.nsISelectionDisplay) |
|
120 .QueryInterface(Ci.nsISelectionController); |
|
121 |
|
122 var frameFindSelection = |
|
123 ifController.getSelection(ifController.SELECTION_FIND); |
|
124 frameFindSelection.addRange(range); |
|
125 |
|
126 // Create manual highlights in the main document (the matches that lie |
|
127 // before/after the iframes |
|
128 var docShell = gWin.QueryInterface(Ci.nsIInterfaceRequestor) |
|
129 .getInterface(Ci.nsIWebNavigation) |
|
130 .QueryInterface(Ci.nsIDocShell); |
|
131 |
|
132 var controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor) |
|
133 .getInterface(Ci.nsISelectionDisplay) |
|
134 .QueryInterface(Ci.nsISelectionController); |
|
135 |
|
136 var docFindSelection = |
|
137 controller.getSelection(ifController.SELECTION_FIND); |
|
138 |
|
139 range = doc.createRange(); |
|
140 range.selectNodeContents(doc.body.childNodes[0]); |
|
141 docFindSelection.addRange(range); |
|
142 range = doc.createRange(); |
|
143 range.selectNodeContents(doc.body.childNodes[2]); |
|
144 docFindSelection.addRange(range); |
|
145 range = doc.createRange(); |
|
146 range.selectNodeContents(doc.body.childNodes[4]); |
|
147 docFindSelection.addRange(range); |
|
148 |
|
149 // Take snapshot of manual highlighting |
|
150 var manualSnapshot = snapshotWindow(gBrowser.contentWindow); |
|
151 |
|
152 // Test 1: Were the matches in iframe correctly highlighted? |
|
153 var res = compareSnapshots(findSnapshot, manualSnapshot, true); |
|
154 ok(res[0], "Matches found in iframe correctly highlighted"); |
|
155 |
|
156 // Test 2: Were the matches in iframe correctly unhighlighted? |
|
157 res = compareSnapshots(noHighlightSnapshot, unhighlightSnapshot, true); |
|
158 ok(res[0], "Highlighting in iframe correctly removed"); |
|
159 |
|
160 finish(); |
|
161 } |
|
162 ]]></script> |
|
163 |
|
164 <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
|
165 <findbar id="FindToolbar" browserid="content"/> |
|
166 </window> |