Chromium Code Reviews| Index: chrome/test/data/webui/edit_search_engine_dialog_test.js |
| diff --git a/chrome/test/data/webui/edit_search_engine_dialog_test.js b/chrome/test/data/webui/edit_search_engine_dialog_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..098d64e2dda714a0c0c5c410ab20b3523fc6a183 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/edit_search_engine_dialog_test.js |
| @@ -0,0 +1,112 @@ |
| +// 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 generated 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', |
| +}; |
| + |
| +/** |
| + * Asynchronous Test fixture for generated tests. |
| + * @extends {testing.Test} |
| + */ |
| +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_ui_test-inl.h"'); |
| + |
| +// Constructors and destructors must be provided in .cc to prevent clang errors. |
| +GEN('EditSearchEngineDialogUITest::EditSearchEngineDialogUITest() {}'); |
| +GEN('EditSearchEngineDialogUITest::~EditSearchEngineDialogUITest() {}'); |
| + |
| +/** |
| + * 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) |
|
Sheridan Rawlins
2011/11/28 22:32:45
This use of |index| is confusing to me because it
kevers
2011/11/29 17:36:37
Added a comment before the invalidate and retest c
|
| + expectFalse(saveButtonState); |
| + else |
| + expectTrue(saveButtonState); |
| + 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(); |
| + } |
| +}); |
| + |