Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: chrome/test/data/webui/edit_search_engine_dialog_browsertest.js

Issue 8676008: Add automated test for the edit search engine dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use preLoad to address race condition in asynchronous test. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 * Overrides |setValidation| to address a potential race condition due to
43 * asynchronous initialization of the edit search engine dialog. The override
44 * catches the data being passed to the original |setValidation| method and
45 * defers the validation call until the test is ready to process it.
46 */
47 preLoad: function() {
48 var self = this;
49 window.addEventListener('DOMContentLoaded', function() {
50 self.originalSetValidation = editSearchEngineDialog.setValidation;
51 editSearchEngineDialog.setValidation = function(details) {
52 self.pendingDetails = details;
53 };
54 });
55 },
56 };
57
58 // Include the bulk of c++ code.
59 GEN('#include ' +
60 '"chrome/test/data/webui/edit_search_engine_dialog_browsertest.h"');
61
62 /**
63 * Confirms that the data is loaded into the text fields.
64 */
65 TEST_F('EditSearchEngineDialogUITest', 'testData', function() {
66 var inputFields = editSearchEngineDialog.inputFields;
67 expectEquals(chrome.expectedUrl, window.location.href);
68 expectEquals('short0', inputFields.description.value);
69 expectEquals('keyword0', inputFields.keyword.value);
70 expectEquals('http://www.test0.com/', inputFields.url.value);
71 });
72
73 /**
74 * Confirms that the field validation is working.
75 */
76 TEST_F('EditSearchEngineDialogUITestAsync',
77 'testInputValidation',
78 function() {
79 var inputFields = editSearchEngineDialog.inputFields;
80 var invalidData = {
81 description: '',
82 keyword: '',
83 url: '%'
84 };
85 var fieldNames = Object.keys(invalidData);
86 var index = 0;
87 var self = this;
88 var validityChecker = function(details) {
89 self.originalSetValidation(details);
90 // Ensure that all inputs are valid with the initial data, and that save
91 // is enabled. Each subsequent call will have an additional field
92 // containing invalid data.
93 for (var i = 0; i < fieldNames.length; i++) {
94 var field = fieldNames[i];
95 expectEquals(i >= index,
96 inputFields[field].valid,
97 'field = ' + field +
98 ', index = ' + index);
99 }
100 var saveButtonState = editSearchEngineDialog.getSave().disabled;
101 if (index == 0)
102 expectFalse(saveButtonState);
103 else
104 expectTrue(saveButtonState);
105 // Once the validity of the input fields and save button are confirmed, we
106 // invalidate a single field in the input and trigger a new call to check
107 // the validity. We start with the first input field and increment the
108 // index with each call in order to advance to the next field. Although
109 // each test is asynchronous, we are guaranteed to get the calls in the
110 // correct order since we wait for the previous validation to complete
111 // before moving to the next field.
112 if (index < fieldNames.length) {
113 if (index == fieldNames.length - 1) {
114 editSearchEngineDialog.setValidation = this.continueTest(
115 WhenTestDone.ALWAYS,
116 validityChecker);
117 }
118 var fieldName = fieldNames[index++];
119 inputFields[fieldName].value = invalidData[fieldName];
120 editSearchEngineDialog.validate();
121 }
122 };
123 // Override |setValidation| to check the status of the icons and save button.
124 editSearchEngineDialog.setValidation = this.continueTest(
125 WhenTestDone.EXPECT,
126 validityChecker);
127 // Check if the first call to |setValidation| tripped before being redirected
128 // to |validityChecker|.
129 if (this.pendingDetails)
Sheridan Rawlins 2011/12/02 16:37:50 This is effectively uninitialized. Please add pen
kevers 2011/12/02 18:37:29 Done.
130 editSearchEngineDialog.setValidation(this.pendingDetails);
131 });
132
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698