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 generated 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 /** | |
23 * Asynchronous Test fixture for generated tests. | |
24 * @extends {testing.Test} | |
25 */ | |
26 function EditSearchEngineDialogUITestAsync() {}; | |
27 | |
28 EditSearchEngineDialogUITestAsync.prototype = { | |
29 __proto__: EditSearchEngineDialogUITest.prototype, | |
30 | |
31 /** @inheritDoc */ | |
32 isAsync: true, | |
33 }; | |
34 | |
35 // Include the bulk of c++ code. | |
36 GEN('#include "chrome/test/data/webui/edit_search_engine_dialog_ui_test-inl.h"') ; | |
37 | |
38 // Constructors and destructors must be provided in .cc to prevent clang errors. | |
39 GEN('EditSearchEngineDialogUITest::EditSearchEngineDialogUITest() {}'); | |
40 GEN('EditSearchEngineDialogUITest::~EditSearchEngineDialogUITest() {}'); | |
41 | |
42 /** | |
43 * Confirms that the data is loaded into the text fields. | |
44 */ | |
45 TEST_F('EditSearchEngineDialogUITest', 'testData', function() { | |
46 var InputFields = editSearchEngineDialog.InputFields; | |
47 expectEquals(chrome.expectedUrl, window.location.href); | |
48 expectEquals('short0', InputFields.description.value); | |
49 expectEquals('keyword0', InputFields.keyword.value); | |
50 expectEquals('http://www.test0.com/', InputFields.url.value); | |
51 }); | |
52 | |
53 /** | |
54 * Confirms that the field validation is working. | |
55 */ | |
56 TEST_F('EditSearchEngineDialogUITestAsync', | |
57 'testInputValidation', | |
58 function() { | |
59 var InputFields = editSearchEngineDialog.InputFields; | |
60 var invalidData = { | |
61 description: '', | |
62 keyword: '', | |
63 url: '%' | |
64 }; | |
65 var fieldNames = Object.keys(invalidData); | |
66 | |
67 var index = 0; | |
68 // When the dialog fields are initialized or when a field is modified, a | |
69 // call to check the validity of the field is made, which in turn, calls | |
70 // 'setvalidity' to update the CSS class name corresponding to each input | |
71 // field. Override the method to check the status of the icons and save | |
72 // button. | |
73 var originalSetValidation = editSearchEngineDialog.setValidation; | |
74 var validityChecker = function(opt_details) { | |
75 if (opt_details) | |
76 originalSetValidation(opt_details); | |
77 // Ensure that all inputs are valid with the initial data, and that save | |
78 // is enabled. Each subsequent call will have an additional field | |
79 // containing invalid data. | |
80 for (var i = 0; i < fieldNames.length; i++) { | |
81 var field = fieldNames[i]; | |
82 expectEquals(i >= index, | |
83 InputFields[field].valid, | |
84 'field = ' + field + | |
85 ', index = ' + index); | |
86 } | |
87 var saveButtonState = editSearchEngineDialog.getSave().disabled; | |
88 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
| |
89 expectFalse(saveButtonState); | |
90 else | |
91 expectTrue(saveButtonState); | |
92 if (index < fieldNames.length) { | |
93 if (index == fieldNames.length - 1) { | |
94 editSearchEngineDialog.setValidation = this.continueTest( | |
95 WhenTestDone.ALWAYS, | |
96 validityChecker); | |
97 } | |
98 var fieldName = fieldNames[index++]; | |
99 InputFields[fieldName].value = invalidData[fieldName]; | |
100 editSearchEngineDialog.validate(); | |
101 } | |
102 }; | |
103 editSearchEngineDialog.setValidation = this.continueTest( | |
104 WhenTestDone.EXPECT, | |
105 validityChecker); | |
106 if (!editSearchEngineDialog.isValidating()) { | |
107 // Already finished validating, so we missed the trigger. Invoke the | |
108 // checker for input validity directly. | |
109 editSearchEngineDialog.setValidation(); | |
110 } | |
111 }); | |
112 | |
OLD | NEW |