Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4165)

Unified Diff: chrome/browser/resources/file_manager/js/test_util.js

Issue 15984003: Add tests for the video player in Files.app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/file_manager/js/test_util.js
diff --git a/chrome/browser/resources/file_manager/js/test_util.js b/chrome/browser/resources/file_manager/js/test_util.js
index c5c7c450b269491dcdda9e932e26d700cb8df56f..3bf80fad5399b63a2abf090c1ed0022304490ad4 100644
--- a/chrome/browser/resources/file_manager/js/test_util.js
+++ b/chrome/browser/resources/file_manager/js/test_util.js
@@ -49,6 +49,28 @@ test.util.openMainWindow = function(path, callback) {
};
/**
+ * Waits for a window with the specified App ID prefix. Eg. `files` will match
+ * windows such as files#0, files#1, etc.
+ *
+ * @param {string} appIdPrefix ID prefix of the requested window.
+ * @param {function(string)} callback Completion callback with the new window's
+ * App ID.
+ */
+test.util.waitForWindow = function(appIdPrefix, callback) {
+ var appId;
+ function helper() {
+ for (var appId in appWindows) {
+ if (appId.indexOf(appIdPrefix) == 0) {
+ callback(appId);
+ return;
+ }
+ }
+ window.setTimeout(helper, 50);
+ }
+ helper();
+};
+
+/**
* Gets a document in the Files.app's window, including iframes.
*
* @param {Window} contentWindow Window to be used.
@@ -135,12 +157,34 @@ test.util.getFileList = function(contentWindow) {
};
/**
+ * Waits until the window is set to the specified dimensions.
+ *
+ * @param {Window} contentWindow Window to be tested.
+ * @param {number} width Requested width.
+ * @param {number} height Requested height.
+ * @param {function(Object)} callback Success callback with the dimensions.
+ */
+test.util.waitForWindowGeometry = function(
+ contentWindow, width, height, callback) {
+ function helper() {
+ if (contentWindow.innerWidth == width &&
+ contentWindow.innerHeight == height) {
+ callback({width: width, height: height});
+ return;
+ }
+ window.setTimeout(helper, 50);
+ }
+ helper();
+};
+
+/**
* Waits for an element and returns it as an array of it's attributes.
*
* @param {Window} contentWindow Window to be tested.
* @param {string} targetQuery Query to specify the element.
* @param {?string} iframeQuery Iframe selector or null if no iframe.
- * @param {function(Object)} callback Callback with a hash array of attributes.
+ * @param {function(Object)} callback Callback with a hash array of attributes
+ * and contents as text.
*/
test.util.waitForElement = function(
contentWindow, targetQuery, iframeQuery, callback) {
@@ -154,7 +198,8 @@ test.util.waitForElement = function(
attributes[element.attributes[i].nodeName] =
element.attributes[i].nodeValue;
}
- callback(attributes);
+ var text = element.textContent;
+ callback({attributes: attributes, text: text});
return;
}
}
@@ -483,6 +528,9 @@ test.util.registerRemoteTestUtils = function() {
case 'openMainWindow':
test.util.openMainWindow(request.args[0], sendResponse);
return true;
+ case 'waitForWindow':
+ test.util.waitForWindow(request.args[0], sendResponse);
+ return true;
case 'getErrorCount':
sendResponse(test.util.getErrorCount());
return true;
@@ -502,6 +550,10 @@ test.util.registerRemoteTestUtils = function() {
case 'getFileList':
sendResponse(test.util.getFileList(contentWindow));
return false;
+ case 'waitForWindowGeometry':
+ test.util.waitForWindowGeometry(
+ contentWindow, request.args[0], request.args[1], sendResponse);
+ return true;
case 'waitForElement':
test.util.waitForElement(
contentWindow, request.args[0], request.args[1], sendResponse);

Powered by Google App Engine
This is Rietveld 408576698