OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Test fixture for search engine dialog tests. |
| 7 * @extends {testing.Test} |
| 8 */ |
| 9 function EditSearchEngineDialogUITest() {}; |
| 10 |
| 11 EditSearchEngineDialogUITest.prototype = { |
| 12 __proto__: testing.Test.prototype, |
| 13 |
| 14 /** |
| 15 * Define the C++ fixture class and include it. |
| 16 * @type {?string} |
| 17 * @override |
| 18 */ |
| 19 typedefCppFixture: 'EditSearchEngineDialogUITest', |
| 20 |
| 21 /** |
| 22 * Show the search engine dialog. |
| 23 */ |
| 24 testGenPreamble: function() { |
| 25 GEN('ShowSearchEngineDialog();'); |
| 26 }, |
| 27 }; |
| 28 |
| 29 /** |
| 30 * Asynchronous Test fixture for search engine dialog tests. |
| 31 * @extends {EditSearchEngineDialogUITest} |
| 32 */ |
| 33 function EditSearchEngineDialogUITestAsync() {}; |
| 34 |
| 35 EditSearchEngineDialogUITestAsync.prototype = { |
| 36 __proto__: EditSearchEngineDialogUITest.prototype, |
| 37 |
| 38 /** @inheritDoc */ |
| 39 isAsync: true, |
| 40 }; |
| 41 |
| 42 // Include the bulk of c++ code. |
| 43 GEN('#include "chrome/test/data/webui/edit_search_engine_dialog_browsertest.h"')
; |
| 44 |
| 45 /** |
| 46 * Confirms that the data is loaded into the text fields. |
| 47 */ |
| 48 TEST_F('EditSearchEngineDialogUITest', 'testData', function() { |
| 49 var inputFields = editSearchEngineDialog.inputFields; |
| 50 expectEquals(chrome.expectedUrl, window.location.href); |
| 51 expectEquals('short0', inputFields.description.value); |
| 52 expectEquals('keyword0', inputFields.keyword.value); |
| 53 expectEquals('http://www.test0.com/', inputFields.url.value); |
| 54 }); |
| 55 |
| 56 /** |
| 57 * Confirms that the field validation is working. |
| 58 */ |
| 59 TEST_F('EditSearchEngineDialogUITestAsync', |
| 60 'testInputValidation', |
| 61 function() { |
| 62 var inputFields = editSearchEngineDialog.inputFields; |
| 63 var invalidData = { |
| 64 description: '', |
| 65 keyword: '', |
| 66 url: '%' |
| 67 }; |
| 68 var fieldNames = Object.keys(invalidData); |
| 69 |
| 70 var index = 0; |
| 71 // When the dialog fields are initialized or when a field is modified, a |
| 72 // call to check the validity of the field is made, which in turn, calls |
| 73 // 'setvalidity' to update the CSS class name corresponding to each input |
| 74 // field. Override the method to check the status of the icons and save |
| 75 // button. |
| 76 var originalSetValidation = editSearchEngineDialog.setValidation; |
| 77 var validityChecker = function(opt_details) { |
| 78 if (opt_details) |
| 79 originalSetValidation(opt_details); |
| 80 // Ensure that all inputs are valid with the initial data, and that save |
| 81 // is enabled. Each subsequent call will have an additional field |
| 82 // containing invalid data. |
| 83 for (var i = 0; i < fieldNames.length; i++) { |
| 84 var field = fieldNames[i]; |
| 85 expectEquals(i >= index, |
| 86 inputFields[field].valid, |
| 87 'field = ' + field + |
| 88 ', index = ' + index); |
| 89 } |
| 90 var saveButtonState = editSearchEngineDialog.getSave().disabled; |
| 91 if (index == 0) |
| 92 expectFalse(saveButtonState); |
| 93 else |
| 94 expectTrue(saveButtonState); |
| 95 // Once the validity of the input fields and save button are confirmed, we |
| 96 // invalidate a single field in the input and trigger a new call to check |
| 97 // the validity. We start with the first input field and increment the |
| 98 // index with each call in order to advance to the next field. Although |
| 99 // each test is asynchronous, we are guaranteed to get the calls in the |
| 100 // correct order since we wait for the previous validation to complete |
| 101 // before moving to the next field. |
| 102 if (index < fieldNames.length) { |
| 103 if (index == fieldNames.length - 1) { |
| 104 editSearchEngineDialog.setValidation = this.continueTest( |
| 105 WhenTestDone.ALWAYS, |
| 106 validityChecker); |
| 107 } |
| 108 var fieldName = fieldNames[index++]; |
| 109 inputFields[fieldName].value = invalidData[fieldName]; |
| 110 editSearchEngineDialog.validate(); |
| 111 } |
| 112 }; |
| 113 editSearchEngineDialog.setValidation = this.continueTest( |
| 114 WhenTestDone.EXPECT, |
| 115 validityChecker); |
| 116 if (!editSearchEngineDialog.isValidating()) { |
| 117 // Already finished validating, so we missed the trigger. Invoke the |
| 118 // checker for input validity directly. |
| 119 editSearchEngineDialog.setValidation(); |
| 120 } |
| 121 }); |
| 122 |
OLD | NEW |