Index: chrome/test/data/webui/edit_search_engine_dialog_browsertest.js |
diff --git a/chrome/test/data/webui/edit_search_engine_dialog_browsertest.js b/chrome/test/data/webui/edit_search_engine_dialog_browsertest.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4823a1f29c2b40961ac0c031cb5e3727e59836a6 |
--- /dev/null |
+++ b/chrome/test/data/webui/edit_search_engine_dialog_browsertest.js |
@@ -0,0 +1,122 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+/** |
+ * Test fixture for search engine dialog tests. |
+ * @extends {testing.Test} |
+ */ |
+function EditSearchEngineDialogUITest() {}; |
+ |
+EditSearchEngineDialogUITest.prototype = { |
+ __proto__: testing.Test.prototype, |
+ |
+ /** |
+ * Define the C++ fixture class and include it. |
+ * @type {?string} |
+ * @override |
+ */ |
+ typedefCppFixture: 'EditSearchEngineDialogUITest', |
+ |
+ /** |
+ * Show the search engine dialog. |
+ */ |
+ testGenPreamble: function() { |
+ GEN('ShowSearchEngineDialog();'); |
+ }, |
+}; |
+ |
+/** |
+ * Asynchronous Test fixture for search engine dialog tests. |
+ * @extends {EditSearchEngineDialogUITest} |
+ */ |
+function EditSearchEngineDialogUITestAsync() {}; |
+ |
+EditSearchEngineDialogUITestAsync.prototype = { |
+ __proto__: EditSearchEngineDialogUITest.prototype, |
+ |
+ /** @inheritDoc */ |
+ isAsync: true, |
+}; |
+ |
+// Include the bulk of c++ code. |
+GEN('#include "chrome/test/data/webui/edit_search_engine_dialog_browsertest.h"'); |
+ |
+/** |
+ * Confirms that the data is loaded into the text fields. |
+ */ |
+TEST_F('EditSearchEngineDialogUITest', 'testData', function() { |
+ var inputFields = editSearchEngineDialog.inputFields; |
+ expectEquals(chrome.expectedUrl, window.location.href); |
+ expectEquals('short0', inputFields.description.value); |
+ expectEquals('keyword0', inputFields.keyword.value); |
+ expectEquals('http://www.test0.com/', inputFields.url.value); |
+}); |
+ |
+/** |
+ * Confirms that the field validation is working. |
+ */ |
+TEST_F('EditSearchEngineDialogUITestAsync', |
+ 'testInputValidation', |
+ function() { |
+ var inputFields = editSearchEngineDialog.inputFields; |
+ var invalidData = { |
+ description: '', |
+ keyword: '', |
+ url: '%' |
+ }; |
+ var fieldNames = Object.keys(invalidData); |
+ |
+ var index = 0; |
+ // When the dialog fields are initialized or when a field is modified, a |
+ // call to check the validity of the field is made, which in turn, calls |
+ // 'setvalidity' to update the CSS class name corresponding to each input |
+ // field. Override the method to check the status of the icons and save |
+ // button. |
+ var originalSetValidation = editSearchEngineDialog.setValidation; |
+ var validityChecker = function(opt_details) { |
+ if (opt_details) |
+ originalSetValidation(opt_details); |
+ // Ensure that all inputs are valid with the initial data, and that save |
+ // is enabled. Each subsequent call will have an additional field |
+ // containing invalid data. |
+ for (var i = 0; i < fieldNames.length; i++) { |
+ var field = fieldNames[i]; |
+ expectEquals(i >= index, |
+ inputFields[field].valid, |
+ 'field = ' + field + |
+ ', index = ' + index); |
+ } |
+ var saveButtonState = editSearchEngineDialog.getSave().disabled; |
+ if (index == 0) |
+ expectFalse(saveButtonState); |
+ else |
+ expectTrue(saveButtonState); |
+ // Once the validity of the input fields and save button are confirmed, we |
+ // invalidate a single field in the input and trigger a new call to check |
+ // the validity. We start with the first input field and increment the |
+ // index with each call in order to advance to the next field. Although |
+ // each test is asynchronous, we are gauranteed to get the calls in the |
flackr
2011/11/30 16:30:24
s/gauranteed/guaranteed
kevers
2011/11/30 21:27:29
Done.
|
+ // correct order since we wait for the previous validation to complete |
+ // before moving to the next field. |
+ if (index < fieldNames.length) { |
+ if (index == fieldNames.length - 1) { |
+ editSearchEngineDialog.setValidation = this.continueTest( |
+ WhenTestDone.ALWAYS, |
+ validityChecker); |
+ } |
+ var fieldName = fieldNames[index++]; |
+ inputFields[fieldName].value = invalidData[fieldName]; |
+ editSearchEngineDialog.validate(); |
+ } |
+ }; |
+ editSearchEngineDialog.setValidation = this.continueTest( |
+ WhenTestDone.EXPECT, |
+ validityChecker); |
+ if (!editSearchEngineDialog.isValidating()) { |
+ // Already finished validating, so we missed the trigger. Invoke the |
+ // checker for input validity directly. |
+ editSearchEngineDialog.setValidation(); |
+ } |
+}); |
+ |