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. | |
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.
| |
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_browsertest.h"') ; | |
37 | |
38 /** | |
39 * Confirms that the data is loaded into the text fields. | |
40 */ | |
41 TEST_F('EditSearchEngineDialogUITest', 'testData', function() { | |
42 var inputFields = editSearchEngineDialog.inputFields; | |
43 expectEquals(chrome.expectedUrl, window.location.href); | |
44 expectEquals('short0', inputFields.description.value); | |
45 expectEquals('keyword0', inputFields.keyword.value); | |
46 expectEquals('http://www.test0.com/', inputFields.url.value); | |
47 }); | |
48 | |
49 /** | |
50 * Confirms that the field validation is working. | |
51 */ | |
52 TEST_F('EditSearchEngineDialogUITestAsync', | |
53 'testInputValidation', | |
54 function() { | |
55 var inputFields = editSearchEngineDialog.inputFields; | |
56 var invalidData = { | |
57 description: '', | |
58 keyword: '', | |
59 url: '%' | |
60 }; | |
61 var fieldNames = Object.keys(invalidData); | |
62 | |
63 var index = 0; | |
64 // When the dialog fields are initialized or when a field is modified, a | |
65 // call to check the validity of the field is made, which in turn, calls | |
66 // 'setvalidity' to update the CSS class name corresponding to each input | |
67 // field. Override the method to check the status of the icons and save | |
68 // button. | |
69 var originalSetValidation = editSearchEngineDialog.setValidation; | |
70 var validityChecker = function(opt_details) { | |
71 if (opt_details) | |
72 originalSetValidation(opt_details); | |
73 // Ensure that all inputs are valid with the initial data, and that save | |
74 // is enabled. Each subsequent call will have an additional field | |
75 // containing invalid data. | |
76 for (var i = 0; i < fieldNames.length; i++) { | |
77 var field = fieldNames[i]; | |
78 expectEquals(i >= index, | |
79 inputFields[field].valid, | |
80 'field = ' + field + | |
81 ', index = ' + index); | |
82 } | |
83 var saveButtonState = editSearchEngineDialog.getSave().disabled; | |
84 if (index == 0) | |
85 expectFalse(saveButtonState); | |
86 else | |
87 expectTrue(saveButtonState); | |
88 // Once the validity of the input fields and save button are confirmed, we | |
89 // invalidate a single field in the input and trigger a new call to check | |
90 // the validity. We start with the first input field and increment the | |
91 // index with each call in order to advance to the next field. Although | |
92 // each test is asynchronous, we are gauranteed to get the calls in the | |
93 // correct order since we wait for the previous validation to complete | |
94 // before moving to the next field. | |
95 if (index < fieldNames.length) { | |
96 if (index == fieldNames.length - 1) { | |
97 editSearchEngineDialog.setValidation = this.continueTest( | |
98 WhenTestDone.ALWAYS, | |
99 validityChecker); | |
100 } | |
101 var fieldName = fieldNames[index++]; | |
102 inputFields[fieldName].value = invalidData[fieldName]; | |
103 editSearchEngineDialog.validate(); | |
104 } | |
105 }; | |
106 editSearchEngineDialog.setValidation = this.continueTest( | |
107 WhenTestDone.EXPECT, | |
108 validityChecker); | |
109 if (!editSearchEngineDialog.isValidating()) { | |
110 // Already finished validating, so we missed the trigger. Invoke the | |
111 // checker for input validity directly. | |
112 editSearchEngineDialog.setValidation(); | |
113 } | |
114 }); | |
115 | |
OLD | NEW |