Chromium Code Reviews| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 fileList.sort(); | 155 fileList.sort(); |
| 134 return fileList; | 156 return fileList; |
| 135 }; | 157 }; |
| 136 | 158 |
| 137 /** | 159 /** |
| 138 * Waits for an element and returns it as an array of it's attributes. | 160 * Waits for an element and returns it as an array of it's attributes. |
| 139 * | 161 * |
| 140 * @param {Window} contentWindow Window to be tested. | 162 * @param {Window} contentWindow Window to be tested. |
| 141 * @param {string} targetQuery Query to specify the element. | 163 * @param {string} targetQuery Query to specify the element. |
| 142 * @param {?string} iframeQuery Iframe selector or null if no iframe. | 164 * @param {?string} iframeQuery Iframe selector or null if no iframe. |
| 143 * @param {function(Object)} callback Callback with a hash array of attributes. | 165 * @param {function(Object)} callback Callback with a hash array of attributes |
| 166 * and contents as text. | |
| 144 */ | 167 */ |
| 145 test.util.waitForElement = function( | 168 test.util.waitForElement = function( |
| 146 contentWindow, targetQuery, iframeQuery, callback) { | 169 contentWindow, targetQuery, iframeQuery, callback) { |
| 147 function helper() { | 170 function helper() { |
| 148 var doc = test.util.getDocument_(contentWindow, iframeQuery); | 171 var doc = test.util.getDocument_(contentWindow, iframeQuery); |
| 149 if (doc) { | 172 if (doc) { |
| 150 var element = doc.querySelector(targetQuery); | 173 var element = doc.querySelector(targetQuery); |
| 151 if (element) { | 174 if (element) { |
| 152 var attributes = {}; | 175 var attributes = {}; |
| 153 for (var i = 0; i < element.attributes.length; i++) { | 176 for (var i = 0; i < element.attributes.length; i++) { |
| 154 attributes[element.attributes[i].nodeName] = | 177 attributes[element.attributes[i].nodeName] = |
| 155 element.attributes[i].nodeValue; | 178 element.attributes[i].nodeValue; |
| 156 } | 179 } |
| 157 callback(attributes); | 180 var text = element.textContent; |
| 181 callback({attributes: attributes, text: text}); | |
| 158 return; | 182 return; |
| 159 } | 183 } |
| 160 } | 184 } |
| 161 window.setTimeout(helper, 50); | 185 window.setTimeout(helper, 50); |
| 162 } | 186 } |
| 163 helper(); | 187 helper(); |
| 164 }; | 188 }; |
| 165 | 189 |
| 166 /** | 190 /** |
| 167 * Calls getFileList until the number of displayed files is different from | 191 * Calls getFileList until the number of displayed files is different from |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 return false; | 494 return false; |
| 471 } | 495 } |
| 472 var contentWindow; | 496 var contentWindow; |
| 473 if (request.appId) { | 497 if (request.appId) { |
| 474 if (!appWindows[request.appId]) { | 498 if (!appWindows[request.appId]) { |
| 475 console.error('Specified window not found.'); | 499 console.error('Specified window not found.'); |
| 476 return false; | 500 return false; |
| 477 } | 501 } |
| 478 contentWindow = appWindows[request.appId].contentWindow; | 502 contentWindow = appWindows[request.appId].contentWindow; |
| 479 } | 503 } |
| 480 if (!contentWindow) { | 504 if (!request.appId) { |
|
hashimoto
2013/05/27 08:17:27
Why this 'if' is changed but not merged with the '
mtomasz
2013/05/27 09:14:26
Reverted this line, since it is not related to thi
| |
| 481 // Global functions, not requiring a window. | 505 // Global functions, not requiring a window. |
| 482 switch (request.func) { | 506 switch (request.func) { |
| 483 case 'openMainWindow': | 507 case 'openMainWindow': |
| 484 test.util.openMainWindow(request.args[0], sendResponse); | 508 test.util.openMainWindow(request.args[0], sendResponse); |
| 485 return true; | 509 return true; |
| 510 case 'waitForWindow': | |
| 511 test.util.waitForWindow(request.args[0], sendResponse); | |
| 512 return true; | |
| 486 case 'getErrorCount': | 513 case 'getErrorCount': |
| 487 sendResponse(test.util.getErrorCount()); | 514 sendResponse(test.util.getErrorCount()); |
| 488 return true; | 515 return true; |
| 489 default: | 516 default: |
| 490 console.error('Global function ' + request.func + ' not found.'); | 517 console.error('Global function ' + request.func + ' not found.'); |
| 491 } | 518 } |
| 492 } else { | 519 } else { |
| 493 // Functions working on a window. | 520 // Functions working on a window. |
| 494 switch (request.func) { | 521 switch (request.func) { |
| 495 case 'resizeWindow': | 522 case 'resizeWindow': |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 default: | 579 default: |
| 553 console.error('Window function ' + request.func + ' not found.'); | 580 console.error('Window function ' + request.func + ' not found.'); |
| 554 } | 581 } |
| 555 } | 582 } |
| 556 return false; | 583 return false; |
| 557 }); | 584 }); |
| 558 }; | 585 }; |
| 559 | 586 |
| 560 // Register the test utils. | 587 // Register the test utils. |
| 561 test.util.registerRemoteTestUtils(); | 588 test.util.registerRemoteTestUtils(); |
| OLD | NEW |