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

Unified Diff: chrome/browser/resources/edit_search_engine_dialog.js

Issue 8676008: Add automated test for the edit search engine dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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/edit_search_engine_dialog.js
diff --git a/chrome/browser/resources/edit_search_engine_dialog.js b/chrome/browser/resources/edit_search_engine_dialog.js
index 0d9cdb375966bb2343c7f488b399d1e0e2922773..6cc8bbfed5b0af3c8049b0e1b93f1bb66113c3d1 100644
--- a/chrome/browser/resources/edit_search_engine_dialog.js
+++ b/chrome/browser/resources/edit_search_engine_dialog.js
@@ -6,6 +6,22 @@ cr.define('editSearchEngineDialog', function() {
'use strict';
/**
+ * Flag inidicating if we are in the process of validating input. While
+ * validating, the validity of the inputs is indeterminate.
+ * @type {boolean}
+ * @private
+ */
+ var isValidating_ = false;
+
+ /**
+ * Flag indicating if 'setValidation' should reset the 'isValidating_' flag.
+ * We do not reset the flag during initialization.
+ * @type {boolean}
+ * @private
+ */
+ var armRevalidation_ = false;
+
+ /**
* Disables the controls while the dialog is busy.
*/
function disableControls() {
@@ -50,16 +66,20 @@ cr.define('editSearchEngineDialog', function() {
* by calling setValidation.
*/
function validate() {
+ isValidating_ = true;
chrome.send('requestValidation', [$('description-text').value,
$('keyword-text').value, $('url-text').value]);
}
/**
* Sets dialog state given the results of the validation of input by Chrome.
- * @param {{description: boolean, details: boolean, url: boolean, ok:boolean}}
- * details A dictionary of booleans indicating the validation results of
- * various parts of the UI. |description|, |details| and |url| indicate
- * the validity of the respective text fields, and |ok| indicates whether
+ * @param {{description: boolean,
+ keyword: boolean,
+ url: boolean,
+ ok: boolean}} details
+ * A dictionary of booleans indicating the validation results of various
+ * parts of the UI. |description|, |keyword| and |url| indicate the
+ * validity of the respective text fields, and |ok| indicates whether
* the OK/Save button can be pressed.
*/
function setValidation(details) {
@@ -67,6 +87,8 @@ cr.define('editSearchEngineDialog', function() {
setValidImage($('keyword-icon'), details.keyword);
setValidImage($('url-icon'), details.url);
$('save').disabled = !details.ok;
+ if (armRevalidation_)
+ isValidating_ = false;
}
/**
@@ -86,6 +108,11 @@ cr.define('editSearchEngineDialog', function() {
* Inserts translated strings on loading.
*/
function initialize() {
+ // The initialization process triggers asynchronous calls. Until these
+ // calls complete, the validity of the inputs is in an indeterminate
+ // state.
+ isValidating_ = true;
+
i18nTemplate.process(document, templateData);
document.title = chrome.dialogArguments == 'add' ? templateData.titleNew :
@@ -105,15 +132,28 @@ cr.define('editSearchEngineDialog', function() {
$('keyword-text').oninput = validate;
$('url-text').oninput = validate;
+ // Do not mark the input as validated during the initial reset.
+ armRevalidation_ = false;
setValidation({description: false, keyword: false, url: false});
if (cr.isViews)
forEach(document.querySelectorAll('.button-strip'), reverseChildren);
- chrome.send('requestDetails')
+ // The next call to set validation will have the correct flags.
+ armRevalidation_ = true;
flackr 2011/11/23 15:22:37 Is there any reason we can't set isValidating_ her
kevers 2011/11/23 20:04:53 Done.
+ chrome.send('requestDetails');
+ }
+
+ /**
+ * Indicates if we are in the process of validating input.
+ * @return {boolean} True if validation is in progress.
+ */
+ function isValidating() {
+ return isValidating_;
}
document.addEventListener('DOMContentLoaded', initialize);
return {
+ isValidating: isValidating,
setDetails: setDetails,
setValidation: setValidation,
};

Powered by Google App Engine
This is Rietveld 408576698