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

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

Issue 22185002: Add browser test to the sharing dialog feature in Files.app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 7 years, 4 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 07005a3d7d85d155382ded3981e8209e0e68a3d7..1dac4bd4bf51e5e83393175717aa048236433182 100644
--- a/chrome/browser/resources/file_manager/js/test_util.js
+++ b/chrome/browser/resources/file_manager/js/test_util.js
@@ -221,18 +221,20 @@ test.util.async.waitForWindowGeometry = function(
* @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 {opt_boolean=} opt_inverse True if the function should return if the
+ * element disappears, instead of appearing.
* @param {function(Object)} callback Callback with a hash array of attributes
* and contents as text.
*/
test.util.async.waitForElement = function(
- contentWindow, targetQuery, iframeQuery, callback) {
+ contentWindow, targetQuery, iframeQuery, opt_inverse, callback) {
test.util.repeatUntilTrue_(function() {
var doc = test.util.sync.getDocument_(contentWindow, iframeQuery);
if (!doc)
return false;
var element = doc.querySelector(targetQuery);
if (!element)
- return false;
+ return opt_inverse ? true : false;
var attributes = {};
for (var i = 0; i < element.attributes.length; i++) {
attributes[element.attributes[i].nodeName] =
@@ -240,7 +242,7 @@ test.util.async.waitForElement = function(
}
var text = element.textContent;
callback({attributes: attributes, text: text});
- return true;
+ return opt_inverse ? false : true;
});
};
@@ -350,23 +352,28 @@ test.util.async.waitAndAcceptDialog = function(contentWindow, callback) {
};
/**
- * Fakes pressing the down arrow until the given |filename| is selected.
+ * Fakes pressing the down arrow until the given |filename| is selected. Zero
+ * timer is used to allow to handle the selection events in Files.app, before
+ * returning the result.
*
* @param {Window} contentWindow Window to be tested.
* @param {string} filename Name of the file to be selected.
- * @return {boolean} True if file got selected, false otherwise.
+ * @param {function(boolean)} callback Completion callback with true for success
+ * and false for a failure.
*/
-test.util.sync.selectFile = function(contentWindow, filename) {
+test.util.async.selectFile = function(contentWindow, filename, callback) {
var table = contentWindow.document.querySelector('#detail-table');
var rows = table.querySelectorAll('li');
for (var index = 0; index < rows.length; ++index) {
test.util.sync.fakeKeyDown(contentWindow, '#file-list', 'Down', false);
var selection = test.util.sync.getSelectedFiles(contentWindow);
- if (selection.length === 1 && selection[0] === filename)
- return true;
+ if (selection.length === 1 && selection[0] === filename) {
+ setTimeout(callback.bind(null, true), 0);
+ return;
+ }
}
console.error('Failed to select file "' + filename + '"');
- return false;
+ setTimeout(callback.bind(null, false), 0);
};
/**
@@ -441,6 +448,21 @@ test.util.async.waitForFiles = function(
};
/**
+ * Executes Javascript code on a webview and returns the result.
+ *
+ * @param {Window} contentWindow Window to be tested.
+ * @param {string} webViewQuery Selector for the web view.
+ * @param {string} code Javascript code to be executed within the web view.
+ * @param {function(*)} callback Callback function with results returned by the
+ * script.
+ */
+test.util.async.executeScriptInWebView = function(
+ contentWindow, webViewQuery, code, callback) {
+ var webView = contentWindow.document.querySelector(webViewQuery);
+ webView.executeScript({code: code}, callback);
+};
+
+/**
* Sends an event to the element specified by |targetQuery|.
*
* @param {Window} contentWindow Window to be tested.
@@ -663,6 +685,9 @@ test.util.registerRemoteTestUtils = function() {
console.error('The testing extension must be white-listed.');
return false;
}
+ // Set a global flag that we are in tests, so other components are aware
+ // of it.
+ window.IN_TEST = true;
// Check the function name.
if (!request.func || request.func[request.func.length - 1] == '_') {
request.func = '';

Powered by Google App Engine
This is Rietveld 408576698