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..3e23075a78e7dc9ceaf1af6fbbd224abeef8421a |
--- /dev/null |
+++ b/chrome/test/data/webui/edit_search_engine_dialog_test.js |
@@ -0,0 +1,107 @@ |
+// 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() { |
+ expectEquals(chrome.expectedUrl, window.location.href); |
+ expectEquals('short0', $('description-text').value); |
Sheridan Rawlins
2011/11/23 20:36:26
Please decouple the presentation from tests - one
kevers
2011/11/24 20:03:25
Added accesssors for each entry field to the dialo
|
+ expectEquals('keyword0', $('keyword-text').value); |
+ expectEquals('http://www.test0.com/', $('url-text').value); |
+}); |
+ |
+/** |
+ * Confirms that the field validation is working. |
+ */ |
+TEST_F('EditSearchEngineDialogUITestAsync', |
+ 'testInputValidation', |
+ function() { |
+ var invalidData = { |
+ description: '', |
+ keyword: '', |
+ url: '%' |
+ }; |
+ var fieldNames = []; |
flackr
2011/11/23 20:22:00
Does var fieldNames = Object.keys(invalidData) wor
kevers
2011/11/24 20:03:25
Done.
|
+ var allIcons = []; |
+ for (var field in invalidData) { |
+ fieldNames.push(field); |
+ allIcons.push($(field + '-icon')); |
+ } |
flackr
2011/11/23 20:22:00
If above works, then you can probably remove this
kevers
2011/11/24 20:03:25
Done.
|
+ var index = 0; |
+ var setValidation = editSearchEngineDialog.setValidation; |
Sheridan Rawlins
2011/11/23 20:36:26
I'm kind of confused by what you're doing here - m
kevers
2011/11/24 20:03:25
Renamed the variable and added documentation.
|
+ var validityChecker = function(opt_details) { |
+ if (opt_details) |
+ setValidation(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 < allIcons.length; i++) { |
+ expectEquals(i < index ? 'invalid' : 'valid', |
+ allIcons[i].className, |
+ 'field = ' + fieldNames[i]); |
Sheridan Rawlins
2011/11/23 20:36:26
Would index = be helpful too?
kevers
2011/11/24 20:03:25
Done.
|
+ } |
+ if (index == 0) |
+ expectFalse($('save').disabled); |
Sheridan Rawlins
2011/11/23 20:36:26
provide/use accessor here too & below a la getSave
kevers
2011/11/24 20:03:25
Done.
|
+ else |
+ expectTrue($('save').disabled); |
+ if (index < fieldNames.length) { |
+ if (index == fieldNames.length - 1) { |
+ editSearchEngineDialog.setValidation = this.continueTest( |
+ WhenTestDone.ALWAYS, |
+ validityChecker); |
+ } |
+ var fieldName = fieldNames[index++]; |
+ var textElement = $(fieldName + '-text'); |
+ textElement.value = invalidData[fieldName]; |
+ textElement.oninput(); |
+ } |
+ }; |
+ 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(); |
+ } |
+}); |
+ |