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

Unified Diff: chrome/test/data/webui/edit_search_engine_dialog_browsertest.js

Issue 8676008: Add automated test for the edit search engine dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: File renames, address nits and add documentation. 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/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..a61c090d40e86a3ba6d2077e8fbabc42d1623860
--- /dev/null
+++ b/chrome/test/data/webui/edit_search_engine_dialog_browsertest.js
@@ -0,0 +1,115 @@
+// 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.
Sheridan Rawlins 2011/11/30 00:14:01 nit: s/generated/search engine dialog/
kevers 2011/11/30 15:54:54 Done.
kevers 2011/11/30 15:54:54 Done.
+ * @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_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
+ // 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();
+ }
+});
+

Powered by Google App Engine
This is Rietveld 408576698