OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Namespace for test related things. | 6 * Namespace for test related things. |
7 */ | 7 */ |
8 var test = test || {}; | 8 var test = test || {}; |
9 | 9 |
10 /** | 10 /** |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 launchFileManager({defaultPath: path}, | 42 launchFileManager({defaultPath: path}, |
43 undefined, // opt_type | 43 undefined, // opt_type |
44 undefined, // opt_id | 44 undefined, // opt_id |
45 function(id) { | 45 function(id) { |
46 appId = id; | 46 appId = id; |
47 helper(); | 47 helper(); |
48 }); | 48 }); |
49 }; | 49 }; |
50 | 50 |
51 /** | 51 /** |
| 52 * Waits for a window with the specified App ID prefix. Eg. `files` will match |
| 53 * windows such as files#0, files#1, etc. |
| 54 * |
| 55 * @param {string} appIdPrefix ID prefix of the requested window. |
| 56 * @param {function(string)} callback Completion callback with the new window's |
| 57 * App ID. |
| 58 */ |
| 59 test.util.waitForWindow = function(appIdPrefix, callback) { |
| 60 var appId; |
| 61 function helper() { |
| 62 for (var appId in appWindows) { |
| 63 if (appId.indexOf(appIdPrefix) == 0) { |
| 64 callback(appId); |
| 65 return; |
| 66 } |
| 67 } |
| 68 window.setTimeout(helper, 50); |
| 69 } |
| 70 helper(); |
| 71 }; |
| 72 |
| 73 /** |
52 * Gets a document in the Files.app's window, including iframes. | 74 * Gets a document in the Files.app's window, including iframes. |
53 * | 75 * |
54 * @param {Window} contentWindow Window to be used. | 76 * @param {Window} contentWindow Window to be used. |
55 * @param {string=} opt_iframeQuery Query for the iframe. | 77 * @param {string=} opt_iframeQuery Query for the iframe. |
56 * @return {Document=} Returns the found document or undefined if not found. | 78 * @return {Document=} Returns the found document or undefined if not found. |
57 * @private | 79 * @private |
58 */ | 80 */ |
59 test.util.getDocument_ = function(contentWindow, opt_iframeQuery) { | 81 test.util.getDocument_ = function(contentWindow, opt_iframeQuery) { |
60 if (opt_iframeQuery) { | 82 if (opt_iframeQuery) { |
61 var iframe = contentWindow.document.querySelector(opt_iframeQuery); | 83 var iframe = contentWindow.document.querySelector(opt_iframeQuery); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 row.querySelector('.size').textContent, | 150 row.querySelector('.size').textContent, |
129 row.querySelector('.type').textContent, | 151 row.querySelector('.type').textContent, |
130 row.querySelector('.date').textContent | 152 row.querySelector('.date').textContent |
131 ]); | 153 ]); |
132 } | 154 } |
133 fileList.sort(); | 155 fileList.sort(); |
134 return fileList; | 156 return fileList; |
135 }; | 157 }; |
136 | 158 |
137 /** | 159 /** |
| 160 * Waits until the window is set to the specified dimensions. |
| 161 * |
| 162 * @param {Window} contentWindow Window to be tested. |
| 163 * @param {number} width Requested width. |
| 164 * @param {number} height Requested height. |
| 165 * @param {function(Object)} callback Success callback with the dimensions. |
| 166 */ |
| 167 test.util.waitForWindowGeometry = function( |
| 168 contentWindow, width, height, callback) { |
| 169 function helper() { |
| 170 if (contentWindow.innerWidth == width && |
| 171 contentWindow.innerHeight == height) { |
| 172 callback({width: width, height: height}); |
| 173 return; |
| 174 } |
| 175 window.setTimeout(helper, 50); |
| 176 } |
| 177 helper(); |
| 178 }; |
| 179 |
| 180 /** |
138 * Waits for an element and returns it as an array of it's attributes. | 181 * Waits for an element and returns it as an array of it's attributes. |
139 * | 182 * |
140 * @param {Window} contentWindow Window to be tested. | 183 * @param {Window} contentWindow Window to be tested. |
141 * @param {string} targetQuery Query to specify the element. | 184 * @param {string} targetQuery Query to specify the element. |
142 * @param {?string} iframeQuery Iframe selector or null if no iframe. | 185 * @param {?string} iframeQuery Iframe selector or null if no iframe. |
143 * @param {function(Object)} callback Callback with a hash array of attributes. | 186 * @param {function(Object)} callback Callback with a hash array of attributes |
| 187 * and contents as text. |
144 */ | 188 */ |
145 test.util.waitForElement = function( | 189 test.util.waitForElement = function( |
146 contentWindow, targetQuery, iframeQuery, callback) { | 190 contentWindow, targetQuery, iframeQuery, callback) { |
147 function helper() { | 191 function helper() { |
148 var doc = test.util.getDocument_(contentWindow, iframeQuery); | 192 var doc = test.util.getDocument_(contentWindow, iframeQuery); |
149 if (doc) { | 193 if (doc) { |
150 var element = doc.querySelector(targetQuery); | 194 var element = doc.querySelector(targetQuery); |
151 if (element) { | 195 if (element) { |
152 var attributes = {}; | 196 var attributes = {}; |
153 for (var i = 0; i < element.attributes.length; i++) { | 197 for (var i = 0; i < element.attributes.length; i++) { |
154 attributes[element.attributes[i].nodeName] = | 198 attributes[element.attributes[i].nodeName] = |
155 element.attributes[i].nodeValue; | 199 element.attributes[i].nodeValue; |
156 } | 200 } |
157 callback(attributes); | 201 var text = element.textContent; |
| 202 callback({attributes: attributes, text: text}); |
158 return; | 203 return; |
159 } | 204 } |
160 } | 205 } |
161 window.setTimeout(helper, 50); | 206 window.setTimeout(helper, 50); |
162 } | 207 } |
163 helper(); | 208 helper(); |
164 }; | 209 }; |
165 | 210 |
166 /** | 211 /** |
167 * Calls getFileList until the number of displayed files is different from | 212 * Calls getFileList until the number of displayed files is different from |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 return false; | 521 return false; |
477 } | 522 } |
478 contentWindow = appWindows[request.appId].contentWindow; | 523 contentWindow = appWindows[request.appId].contentWindow; |
479 } | 524 } |
480 if (!contentWindow) { | 525 if (!contentWindow) { |
481 // Global functions, not requiring a window. | 526 // Global functions, not requiring a window. |
482 switch (request.func) { | 527 switch (request.func) { |
483 case 'openMainWindow': | 528 case 'openMainWindow': |
484 test.util.openMainWindow(request.args[0], sendResponse); | 529 test.util.openMainWindow(request.args[0], sendResponse); |
485 return true; | 530 return true; |
| 531 case 'waitForWindow': |
| 532 test.util.waitForWindow(request.args[0], sendResponse); |
| 533 return true; |
486 case 'getErrorCount': | 534 case 'getErrorCount': |
487 sendResponse(test.util.getErrorCount()); | 535 sendResponse(test.util.getErrorCount()); |
488 return true; | 536 return true; |
489 default: | 537 default: |
490 console.error('Global function ' + request.func + ' not found.'); | 538 console.error('Global function ' + request.func + ' not found.'); |
491 } | 539 } |
492 } else { | 540 } else { |
493 // Functions working on a window. | 541 // Functions working on a window. |
494 switch (request.func) { | 542 switch (request.func) { |
495 case 'resizeWindow': | 543 case 'resizeWindow': |
496 sendResponse(test.util.resizeWindow( | 544 sendResponse(test.util.resizeWindow( |
497 contentWindow, request.args[0], request.args[1])); | 545 contentWindow, request.args[0], request.args[1])); |
498 return false; | 546 return false; |
499 case 'getSelectedFiles': | 547 case 'getSelectedFiles': |
500 sendResponse(test.util.getSelectedFiles(contentWindow)); | 548 sendResponse(test.util.getSelectedFiles(contentWindow)); |
501 return false; | 549 return false; |
502 case 'getFileList': | 550 case 'getFileList': |
503 sendResponse(test.util.getFileList(contentWindow)); | 551 sendResponse(test.util.getFileList(contentWindow)); |
504 return false; | 552 return false; |
| 553 case 'waitForWindowGeometry': |
| 554 test.util.waitForWindowGeometry( |
| 555 contentWindow, request.args[0], request.args[1], sendResponse); |
| 556 return true; |
505 case 'waitForElement': | 557 case 'waitForElement': |
506 test.util.waitForElement( | 558 test.util.waitForElement( |
507 contentWindow, request.args[0], request.args[1], sendResponse); | 559 contentWindow, request.args[0], request.args[1], sendResponse); |
508 return true; | 560 return true; |
509 case 'performAutocompleteAndWait': | 561 case 'performAutocompleteAndWait': |
510 test.util.performAutocompleteAndWait( | 562 test.util.performAutocompleteAndWait( |
511 contentWindow, request.args[0], request.args[1], sendResponse); | 563 contentWindow, request.args[0], request.args[1], sendResponse); |
512 return true; | 564 return true; |
513 case 'waitForFileListChange': | 565 case 'waitForFileListChange': |
514 test.util.waitForFileListChange( | 566 test.util.waitForFileListChange( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 default: | 604 default: |
553 console.error('Window function ' + request.func + ' not found.'); | 605 console.error('Window function ' + request.func + ' not found.'); |
554 } | 606 } |
555 } | 607 } |
556 return false; | 608 return false; |
557 }); | 609 }); |
558 }; | 610 }; |
559 | 611 |
560 // Register the test utils. | 612 // Register the test utils. |
561 test.util.registerRemoteTestUtils(); | 613 test.util.registerRemoteTestUtils(); |
OLD | NEW |