| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 test.util.async.openMainWindow = function(appState, callback) { | 46 test.util.async.openMainWindow = function(appState, callback) { |
| 47 launchFileManager(appState, | 47 launchFileManager(appState, |
| 48 undefined, // opt_type | 48 undefined, // opt_type |
| 49 undefined, // opt_id | 49 undefined, // opt_id |
| 50 callback); | 50 callback); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Obtains window information. | 54 * Obtains window information. |
| 55 * | 55 * |
| 56 * @param {string} appIdPrefix ID prefix of the requested window. | |
| 57 * @param {function(Array.<{innerWidth:number, innerHeight:number}>)} callback | |
| 58 * Completion callback with the window information. | |
| 59 * @return {Object.<string, {innerWidth:number, innerHeight:number}>} Map window | 56 * @return {Object.<string, {innerWidth:number, innerHeight:number}>} Map window |
| 60 * ID and window information. | 57 * ID and window information. |
| 61 */ | 58 */ |
| 62 test.util.sync.getWindows = function() { | 59 test.util.sync.getWindows = function() { |
| 63 var windows = {}; | 60 var windows = {}; |
| 64 for (var id in background.appWindows) { | 61 for (var id in background.appWindows) { |
| 65 var windowWrapper = background.appWindows[id]; | 62 var windowWrapper = background.appWindows[id]; |
| 66 windows[id] = { | 63 windows[id] = { |
| 67 innerWidth: windowWrapper.contentWindow.innerWidth, | 64 innerWidth: windowWrapper.contentWindow.innerWidth, |
| 68 innerHeight: windowWrapper.contentWindow.innerHeight | 65 innerHeight: windowWrapper.contentWindow.innerHeight |
| 69 }; | 66 }; |
| 70 } | 67 } |
| 68 for (var id in background.dialogs) { |
| 69 windows[id] = { |
| 70 innerWidth: background.dialogs[id].innerWidth, |
| 71 innerHeight: background.dialogs[id].innerHeight |
| 72 }; |
| 73 } |
| 71 return windows; | 74 return windows; |
| 72 }; | 75 }; |
| 73 | 76 |
| 74 /** | 77 /** |
| 75 * Closes the specified window. | 78 * Closes the specified window. |
| 76 * | 79 * |
| 77 * @param {string} appId AppId of window to be closed. | 80 * @param {string} appId AppId of window to be closed. |
| 78 * @return {boolean} Result: True if success, false otherwise. | 81 * @return {boolean} Result: True if success, false otherwise. |
| 79 */ | 82 */ |
| 80 test.util.sync.closeWindow = function(appId) { | 83 test.util.sync.closeWindow = function(appId) { |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 // Set a global flag that we are in tests, so other components are aware | 680 // Set a global flag that we are in tests, so other components are aware |
| 678 // of it. | 681 // of it. |
| 679 window.IN_TEST = true; | 682 window.IN_TEST = true; |
| 680 // Check the function name. | 683 // Check the function name. |
| 681 if (!request.func || request.func[request.func.length - 1] == '_') { | 684 if (!request.func || request.func[request.func.length - 1] == '_') { |
| 682 request.func = ''; | 685 request.func = ''; |
| 683 } | 686 } |
| 684 // Prepare arguments. | 687 // Prepare arguments. |
| 685 var args = request.args.slice(); // shallow copy | 688 var args = request.args.slice(); // shallow copy |
| 686 if (request.appId) { | 689 if (request.appId) { |
| 687 if (!background.appWindows[request.appId]) { | 690 if (background.appWindows[request.appId]) { |
| 691 args.unshift(background.appWindows[request.appId].contentWindow); |
| 692 } else if (background.dialogs[request.appId]) { |
| 693 args.unshift(background.dialogs[request.appId]); |
| 694 } else { |
| 688 console.error('Specified window not found: ' + request.appId); | 695 console.error('Specified window not found: ' + request.appId); |
| 689 return false; | 696 return false; |
| 690 } | 697 } |
| 691 args.unshift(background.appWindows[request.appId].contentWindow); | |
| 692 } | 698 } |
| 693 // Call the test utility function and respond the result. | 699 // Call the test utility function and respond the result. |
| 694 if (test.util.async[request.func]) { | 700 if (test.util.async[request.func]) { |
| 695 args[test.util.async[request.func].length - 1] = function() { | 701 args[test.util.async[request.func].length - 1] = function() { |
| 696 console.debug('Received the result of ' + request.func); | 702 console.debug('Received the result of ' + request.func); |
| 697 sendResponse.apply(null, arguments); | 703 sendResponse.apply(null, arguments); |
| 698 }; | 704 }; |
| 699 console.debug('Waiting for the result of ' + request.func); | 705 console.debug('Waiting for the result of ' + request.func); |
| 700 test.util.async[request.func].apply(null, args); | 706 test.util.async[request.func].apply(null, args); |
| 701 return true; | 707 return true; |
| 702 } else if (test.util.sync[request.func]) { | 708 } else if (test.util.sync[request.func]) { |
| 703 sendResponse(test.util.sync[request.func].apply(null, args)); | 709 sendResponse(test.util.sync[request.func].apply(null, args)); |
| 704 return false; | 710 return false; |
| 705 } else { | 711 } else { |
| 706 console.error('Invalid function name.'); | 712 console.error('Invalid function name.'); |
| 707 return false; | 713 return false; |
| 708 } | 714 } |
| 709 }); | 715 }); |
| 710 }; | 716 }; |
| 711 | 717 |
| 712 // Register the test utils. | 718 // Register the test utils. |
| 713 test.util.registerRemoteTestUtils(); | 719 test.util.registerRemoteTestUtils(); |
| OLD | NEW |