OLD | NEW |
| (Empty) |
1 <html xmlns="http://www.w3.org/1999/xhtml"> | |
2 <head> | |
3 <script> | |
4 // A token assigned to the global context of this script so that subsequently | |
5 // created tabs/views may find this view. | |
6 var TESTING_TOKEN = true; | |
7 | |
8 // Constant storing the maximal size to which the popup may expand in the | |
9 // following tests: popupRectangleMaxBoundsSizing, popupChromeMaxBoundsSizing | |
10 var MAXIMAL_POPUP_SIZE = { | |
11 "width": 320, | |
12 "height": 240 | |
13 }; | |
14 | |
15 var globalValue = "I am not 42."; | |
16 | |
17 // Some helper functions that track the focus state of a form on the toolbar. | |
18 var formFocused = false; | |
19 function onFormFocused() { | |
20 formFocused = true; | |
21 } | |
22 | |
23 function onFormBlurred() { | |
24 formFocused = false; | |
25 } | |
26 | |
27 // Global variable accessed by tests that run in popup views to indicate which | |
28 // suite of tests to execute. | |
29 var currentTest = null; | |
30 | |
31 // Callback that validates popup repositioning, and is invoked during execution | |
32 // of the following tests: | |
33 // popupRectangleSizing and popupChromeSizing. | |
34 // |offset| specifies the delta in screen-space by which the browser was moved. | |
35 // |initialSize| specfies the rect of the popup before the brower move. | |
36 // |movedSize| specifies the rect of the popup after the browser move. | |
37 function onWindowMoveCompleted(offset, initialSize, movedSize) { | |
38 chrome.test.assertEq(initialSize.width, movedSize.width); | |
39 chrome.test.assertEq(initialSize.height, movedSize.height); | |
40 chrome.test.assertTrue( | |
41 initialSize.top + offset.y == movedSize.top && | |
42 initialSize.left + offset.x == movedSize.left, | |
43 "Popup repositioned incorrectly after browser move."); | |
44 } | |
45 | |
46 // Callback invoked upon completion of popup bounds validation tests. | |
47 // |newSize| is the size of the popup window after a resize operation. | |
48 function onPopupWindowResizeCompleted(newSize) { | |
49 // Note, we do not test for equality because the popup chrome may slightly | |
50 // boost the size of the popup. For example, the rectangle chrome adds | |
51 // a pixel to the dimensions of the popup. | |
52 chrome.test.assertTrue(newSize.width - MAXIMAL_POPUP_SIZE.width <= 2); | |
53 chrome.test.assertTrue(newSize.height - MAXIMAL_POPUP_SIZE.height <= 2); | |
54 } | |
55 | |
56 // Assert function used by tests executed in separate extension views. | |
57 // Used by the following test: popupTeardownDismissal | |
58 // |value| is value upon which to assert. | |
59 // |message| is displayed if |value| is false. | |
60 function assertTrue(value, message) { | |
61 chrome.test.assertTrue(value, message); | |
62 } | |
63 | |
64 // Function used to signal completion of tests run in separate extension views. | |
65 // Used by the following test: popupTeardownDismissal | |
66 function testCompleted() { | |
67 chrome.test.succeed(); | |
68 } | |
69 | |
70 window.onload = function() { | |
71 chrome.test.runTests([ | |
72 function showNoFocusShift() { | |
73 var entryForm = document.getElementById("entryForm").focus(); | |
74 chrome.test.assertTrue(formFocused); | |
75 | |
76 // Validate that displaying a pop-up with the giveFocus parameter assigned | |
77 // to false does not touch the focus setting of the input field. | |
78 var showDetails = { | |
79 "relativeTo": document.getElementById("anchorHere"), | |
80 "giveFocus": false | |
81 }; | |
82 | |
83 // The focus should also remain untouched during closing of the popup. | |
84 chrome.test.listenOnce(chrome.experimental.popup.onClosed, function() { | |
85 chrome.test.assertTrue(formFocused); | |
86 }); | |
87 | |
88 chrome.experimental.popup.show("dom_ui_popup.html", | |
89 showDetails, | |
90 chrome.test.callbackPass(function() { | |
91 chrome.test.assertTrue(formFocused); | |
92 chrome.experimental.extension.getPopupView().close(); | |
93 })); | |
94 }, | |
95 function noPopup() { | |
96 chrome.test.assertTrue( | |
97 undefined === chrome.experimental.extension.getPopupView(), | |
98 "Popup view is defined when no popup shown."); | |
99 chrome.test.succeed(); | |
100 }, | |
101 function noParentWindow() { | |
102 chrome.test.assertTrue( | |
103 undefined === chrome.experimental.popup.getParentWindow(), | |
104 "Parent window accessible outside of popup view."); | |
105 chrome.test.succeed(); | |
106 }, | |
107 function show() { | |
108 var showDetails = { | |
109 "relativeTo": document.getElementById("anchorHere") | |
110 }; | |
111 chrome.experimental.popup.show("dom_ui_popup.html", | |
112 showDetails, | |
113 chrome.test.callbackPass(function() { | |
114 chrome.test.assertTrue( | |
115 chrome.experimental.extension.getPopupView() != undefined); | |
116 })); | |
117 }, | |
118 function accessPopup() { | |
119 var popupView = chrome.experimental.extension.getPopupView(); | |
120 chrome.test.assertTrue(popupView != undefined, | |
121 "Unable to access popup view."); | |
122 | |
123 chrome.test.assertTrue(popupView.theAnswer != undefined, | |
124 "Unable to access popup contents."); | |
125 | |
126 chrome.test.assertEq(42, popupView.theAnswer()); | |
127 chrome.test.succeed(); | |
128 }, | |
129 function accessHost() { | |
130 var popupView = chrome.experimental.extension.getPopupView(); | |
131 chrome.test.assertTrue(popupView != undefined, | |
132 "Unable to access popup view."); | |
133 | |
134 chrome.test.assertTrue(popupView.manipulateHost != undefined, | |
135 "Unable to access popup contents."); | |
136 | |
137 popupView.manipulateHost(); | |
138 chrome.test.assertEq(42, globalValue); | |
139 chrome.test.succeed(); | |
140 }, | |
141 function closePopup() { | |
142 // Ensure that the test waits until the popup is dismissed. | |
143 chrome.test.listenOnce(chrome.experimental.popup.onClosed, function() { | |
144 // TODO(twiz): The following assert is disabled, because it makes | |
145 // the test flaky on the build-bots. See issue: 46601 | |
146 // The popup should not be accessible during the onClosed handler. | |
147 //chrome.test.assertTrue( | |
148 // chrome.experimental.extension.getPopupView() == undefined); | |
149 }); | |
150 chrome.experimental.extension.getPopupView().close(); | |
151 }, | |
152 function popupBlackBorder() { | |
153 // Ensure that the test waits until the popup is dismissed. | |
154 chrome.test.listenOnce(chrome.experimental.popup.onClosed); | |
155 | |
156 // Validate that displaying a pop-up with a black border still invokes | |
157 // the callback successfully. Note that this test does not validate | |
158 // the actual style of the border displayed. | |
159 var showDetails = { | |
160 "relativeTo": document.getElementById("anchorHere"), | |
161 "borderStyle": "rectangle" | |
162 }; | |
163 chrome.experimental.popup.show("dom_ui_popup.html", | |
164 showDetails, | |
165 chrome.test.callbackPass(function() { | |
166 chrome.experimental.extension.getPopupView().close(); | |
167 })); | |
168 }, | |
169 function disallowMultiplePopups() { | |
170 // This test ensures that for a given extension with a popup displayed, | |
171 // displaying a subsequent popup will dismiss the first. | |
172 var showDetails1 = { | |
173 "relativeTo": document.getElementById("anchorHere"), | |
174 }; | |
175 | |
176 var showDetails2 = { | |
177 "relativeTo": document.getElementById("anchorHere2"), | |
178 "borderStyle": "rectangle" | |
179 }; | |
180 | |
181 // Track the number of popups opened and closed, so that we can signal | |
182 // the test as completed when appropriate. | |
183 var numberClosed = 0; | |
184 var doneListening = chrome.test.listenForever( | |
185 chrome.experimental.popup.onClosed, | |
186 function() { | |
187 // This test expects to open and close two popups, so signify that | |
188 // the test has succeeded, after closing the second popup. | |
189 if (++numberClosed == 2) { | |
190 doneListening(); | |
191 } | |
192 }); | |
193 | |
194 chrome.experimental.popup.show("dom_ui_popup_a.html", | |
195 showDetails1, | |
196 function() { | |
197 // Validate that the popup view returned is the one we expect. | |
198 chrome.test.assertEq( | |
199 'a', | |
200 chrome.experimental.extension.getPopupView().getIdentity()); | |
201 | |
202 // Ensure that only one popup is open. | |
203 chrome.test.assertEq( | |
204 1, | |
205 chrome.extension.getViews({type: "popup"}).length); | |
206 | |
207 chrome.experimental.popup.show("dom_ui_popup_b.html", | |
208 showDetails2, | |
209 function() { | |
210 // Validate that the first popup view is fully closed, and that | |
211 // getPopupView returns the most recently opened popup. | |
212 chrome.test.assertEq( | |
213 'b', | |
214 chrome.experimental.extension.getPopupView().getIdentity()); | |
215 | |
216 // Ensure that only one popup is open. | |
217 chrome.test.assertEq( | |
218 1, | |
219 chrome.extension.getViews({type: 'popup'}).length); | |
220 | |
221 chrome.experimental.extension.getPopupView().close(); | |
222 }); | |
223 }); | |
224 }, | |
225 function popupChromeSizing() { | |
226 // Ensure that the test waits until the popup is dismissed. | |
227 chrome.test.listenOnce(chrome.experimental.popup.onClosed); | |
228 | |
229 // Ensure that popups with a chrome border are repositioned and sized | |
230 // correctly. | |
231 var showDetails = { | |
232 "relativeTo": document.getElementById("anchorHere") | |
233 }; | |
234 | |
235 currentTest = "doSizingValidation"; | |
236 chrome.experimental.popup.show("dom_ui_popup_sizing.html", | |
237 showDetails); | |
238 }, | |
239 function popupRectangleSizing() { | |
240 // Ensure that the test waits until the popup is dismissed. | |
241 chrome.test.listenOnce(chrome.experimental.popup.onClosed); | |
242 | |
243 // Ensure that popups with a rectangle border are repositioned and sized | |
244 // correctly. | |
245 var showDetails = { | |
246 "relativeTo": document.getElementById("anchorHere"), | |
247 "borderStyle": "rectangle" | |
248 }; | |
249 | |
250 currentTest = "doSizingValidation"; | |
251 chrome.experimental.popup.show("dom_ui_popup_sizing.html", | |
252 showDetails); | |
253 }, | |
254 function popupChromeMaxBoundsSizing() { | |
255 // Ensure that the test waits until the popup is dismissed. | |
256 chrome.test.listenOnce(chrome.experimental.popup.onClosed); | |
257 | |
258 // Ensure that popups with a chrome border are repositioned and sized | |
259 // correctly. | |
260 var showDetails = { | |
261 "relativeTo": document.getElementById("anchorHere"), | |
262 "maxSize": MAXIMAL_POPUP_SIZE | |
263 }; | |
264 | |
265 currentTest = "doMaximalBoundsValidation"; | |
266 chrome.experimental.popup.show("dom_ui_popup_sizing.html", | |
267 showDetails); | |
268 }, | |
269 function popupRectangleMaxBoundsSizing() { | |
270 // Ensure that the test waits until the popup is dismissed. | |
271 chrome.test.listenOnce(chrome.experimental.popup.onClosed); | |
272 | |
273 // Ensure that popups with a rectangle border respects the maximal bounds. | |
274 var showDetails = { | |
275 "relativeTo": document.getElementById("anchorHere"), | |
276 "borderStyle": "rectangle", | |
277 "maxSize": MAXIMAL_POPUP_SIZE | |
278 }; | |
279 | |
280 currentTest = "doMaximalBoundsValidation"; | |
281 chrome.experimental.popup.show("dom_ui_popup_sizing.html", | |
282 showDetails); | |
283 }, | |
284 function popupTeardownDismissal() { | |
285 // This test verifies that closing of views that launched active popups | |
286 // results in a popup dismissal. | |
287 var tabProperties = { | |
288 "url": "dom_ui_popup_dismissal.html" | |
289 }; | |
290 chrome.tabs.create(tabProperties); | |
291 } | |
292 ]); | |
293 } | |
294 </script> | |
295 </head> | |
296 <body> | |
297 <div id="anchorHere"> | |
298 <span>TEST</span> | |
299 </div> | |
300 <div id="anchorHere2"> | |
301 <span>TESTING 2</span> | |
302 </div> | |
303 <form> | |
304 <input id="entryForm" onfocus="onFormFocused();" onblur="onFormBlurred();"/> | |
305 </form> | |
306 </body> | |
307 </html> | |
OLD | NEW |