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..935db913e4fcbadc95031c8d953e177491c105b1 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/edit_search_engine_dialog_test.js |
| @@ -0,0 +1,133 @@ |
| +// 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 URL is correct. |
| + */ |
| +TEST_F('EditSearchEngineDialogUITest', 'testURL', function() { |
| + expectEquals(chrome.expectedUrl, window.location.href); |
| +}); |
| + |
| +/** |
| + * Confirms that the data is loaded into the text fields. |
| + */ |
| +TEST_F('EditSearchEngineDialogUITest', 'testData', function() { |
| + expectEquals('short0', $('description-text').value); |
| + expectEquals('keyword0', $('keyword-text').value); |
| + expectEquals('http://www.test0.com/', $('url-text').value); |
| +}); |
| + |
| +/** |
| + * Confirms that the description validation is working. |
| + */ |
| +TEST_F('EditSearchEngineDialogUITestAsync', |
| + 'testDescriptionValidation', |
| + function() { |
| + runFieldInvalidationTest(this, 'description', ''); |
| +}); |
| + |
| +/** |
| + * Confirms that the keyword validation is working. |
| + */ |
| +TEST_F('EditSearchEngineDialogUITestAsync', |
| + 'testKeywordValidation', |
| + function() { |
| + runFieldInvalidationTest(this, 'keyword', ''); |
| +}); |
| + |
| +/** |
| + * Confirms that the url validation is working. |
| + */ |
| +TEST_F('EditSearchEngineDialogUITestAsync', 'testUrlValidation', function() { |
| + runFieldInvalidationTest(this, 'url', '%'); |
| +}); |
|
flackr
2011/11/23 15:22:37
Can these three be done as one test now? I suppose
kevers
2011/11/23 20:04:53
Done.
|
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// Support functions |
| + |
| +/** |
| + * Tests that field validation is working. |
| + * @param {Object} test Calling test. |
| + * @param {string} baseFieldName Base name of the field. |
| + * @param {string} testData Input for the text field. |
| + */ |
| +function runFieldInvalidationTest(test, baseFieldName, testData) { |
|
flackr
2011/11/23 15:22:37
Change the name to something suggesting that it te
kevers
2011/11/23 20:04:53
Done.
|
| + var textElement = $(baseFieldName + '-text'); |
| + var iconElement = $(baseFieldName + '-icon'); |
| + var allIcons = [$('description-icon'), $('keyword-icon'), $('url-icon')]; |
| + var setValidation = editSearchEngineDialog.setValidation; |
| + var callback = test.continueTest(WhenTestDone.EXPECT, function() { |
| + // Ensure that all inputs are valid with the initial data, and that save |
| + // is enabled. |
| + for (var i = 0; i < allIcons.length; i++) |
| + expectEquals('valid', allIcons[i].className); |
| + expectFalse($('save').disabled); |
| + // Next validation call should contain one invalid field. The |
| + // corresponding icon should be set to 'invalid' and save disabled. |
| + editSearchEngineDialog.setValidation = test.continueTest( |
| + WhenTestDone.ALWAYS, |
| + function(details) { |
| + setValidation(details); |
|
flackr
2011/11/23 15:22:37
Indent 2 from editSearchEngineDialog.setValidation
kevers
2011/11/23 20:04:53
Done.
|
| + editSearchEngineDialog.setValidation = setValidation; |
| + for (var i = 0; i < allIcons.length; i++) { |
| + expectEquals(iconElement == allIcons[i] ? 'invalid' : 'valid', |
| + allIcons[i].className); |
| + } |
| + expectTrue($('save').disabled); |
| + }); |
| + // Update a text field with an invalid value. |
| + textElement.value = testData; |
| + textElement.oninput(); |
| + }); |
| + if (editSearchEngineDialog.isValidating()) { |
| + // Still in the process of validating, so we can safely override the |
| + // 'setValidation' function. |
| + editSearchEngineDialog.setValidation = function(details) { |
| + setValidation(details); |
| + callback(); |
| + }; |
| + } else { |
| + // Initialization has already finished. It is too late to override the |
| + // validation function so we invoke the callback directly. |
| + callback(); |
| + } |
| +} |
| + |