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 URL is correct. | |
44 */ | |
45 TEST_F('EditSearchEngineDialogUITest', 'testURL', function() { | |
46 expectEquals(chrome.expectedUrl, window.location.href); | |
47 }); | |
48 | |
49 /** | |
50 * Confirms that the data is loaded into the text fields. | |
51 */ | |
52 TEST_F('EditSearchEngineDialogUITest', 'testData', function() { | |
53 expectEquals('short0', $('description-text').value); | |
54 expectEquals('keyword0', $('keyword-text').value); | |
55 expectEquals('http://www.test0.com/', $('url-text').value); | |
56 }); | |
57 | |
58 /** | |
59 * Confirms that the description validation is working. | |
60 */ | |
61 TEST_F('EditSearchEngineDialogUITestAsync', | |
62 'testDescriptionValidation', | |
63 function() { | |
64 runFieldInvalidationTest(this, 'description', ''); | |
65 }); | |
66 | |
67 /** | |
68 * Confirms that the keyword validation is working. | |
69 */ | |
70 TEST_F('EditSearchEngineDialogUITestAsync', | |
71 'testKeywordValidation', | |
72 function() { | |
73 runFieldInvalidationTest(this, 'keyword', ''); | |
74 }); | |
75 | |
76 /** | |
77 * Confirms that the url validation is working. | |
78 */ | |
79 TEST_F('EditSearchEngineDialogUITestAsync', 'testUrlValidation', function() { | |
80 runFieldInvalidationTest(this, 'url', '%'); | |
81 }); | |
flackr
2011/11/23 15:22:37
Can these three be done as one test now? I suppose
kevers
2011/11/23 20:04:53
Done.
| |
82 | |
83 //////////////////////////////////////////////////////////////////////////////// | |
84 // Support functions | |
85 | |
86 /** | |
87 * Tests that field validation is working. | |
88 * @param {Object} test Calling test. | |
89 * @param {string} baseFieldName Base name of the field. | |
90 * @param {string} testData Input for the text field. | |
91 */ | |
92 function runFieldInvalidationTest(test, baseFieldName, testData) { | |
flackr
2011/11/23 15:22:37
Change the name to something suggesting that it te
kevers
2011/11/23 20:04:53
Done.
| |
93 var textElement = $(baseFieldName + '-text'); | |
94 var iconElement = $(baseFieldName + '-icon'); | |
95 var allIcons = [$('description-icon'), $('keyword-icon'), $('url-icon')]; | |
96 var setValidation = editSearchEngineDialog.setValidation; | |
97 var callback = test.continueTest(WhenTestDone.EXPECT, function() { | |
98 // Ensure that all inputs are valid with the initial data, and that save | |
99 // is enabled. | |
100 for (var i = 0; i < allIcons.length; i++) | |
101 expectEquals('valid', allIcons[i].className); | |
102 expectFalse($('save').disabled); | |
103 // Next validation call should contain one invalid field. The | |
104 // corresponding icon should be set to 'invalid' and save disabled. | |
105 editSearchEngineDialog.setValidation = test.continueTest( | |
106 WhenTestDone.ALWAYS, | |
107 function(details) { | |
108 setValidation(details); | |
flackr
2011/11/23 15:22:37
Indent 2 from editSearchEngineDialog.setValidation
kevers
2011/11/23 20:04:53
Done.
| |
109 editSearchEngineDialog.setValidation = setValidation; | |
110 for (var i = 0; i < allIcons.length; i++) { | |
111 expectEquals(iconElement == allIcons[i] ? 'invalid' : 'valid', | |
112 allIcons[i].className); | |
113 } | |
114 expectTrue($('save').disabled); | |
115 }); | |
116 // Update a text field with an invalid value. | |
117 textElement.value = testData; | |
118 textElement.oninput(); | |
119 }); | |
120 if (editSearchEngineDialog.isValidating()) { | |
121 // Still in the process of validating, so we can safely override the | |
122 // 'setValidation' function. | |
123 editSearchEngineDialog.setValidation = function(details) { | |
124 setValidation(details); | |
125 callback(); | |
126 }; | |
127 } else { | |
128 // Initialization has already finished. It is too late to override the | |
129 // validation function so we invoke the callback directly. | |
130 callback(); | |
131 } | |
132 } | |
133 | |
OLD | NEW |