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

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: Style fixes. 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
« no previous file with comments | « chrome/test/data/webui/edit_search_engine_dialog_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * Argument to pass through to |setValidation| once the test is ready to
43 * process it. The argument consists of a mapping between field names and
44 * contents.
45 * @type{Object.<string, string>}
46 */
47 pendingDetails: null,
48
49 /**
50 * Overrides |setValidation| to address a potential race condition due to
51 * asynchronous initialization of the edit search engine dialog. The override
52 * catches the data being passed to the original |setValidation| method and
53 * defers the validation call until the test is ready to process it.
54 */
55 preLoad: function() {
56 var self = this;
57 window.addEventListener('DOMContentLoaded', function() {
58 self.originalSetValidation = editSearchEngineDialog.setValidation;
59 editSearchEngineDialog.setValidation = function(details) {
60 self.pendingDetails = details;
61 };
62 });
63 },
64 };
65
66 // Include the bulk of c++ code.
67 GEN('#include ' +
68 '"chrome/test/data/webui/edit_search_engine_dialog_browsertest.h"');
69
70 /**
71 * Confirms that the data is loaded into the text fields.
72 */
73 TEST_F('EditSearchEngineDialogUITest', 'testData', function() {
74 var inputFields = editSearchEngineDialog.inputFields;
75 expectEquals(chrome.expectedUrl, window.location.href);
76 expectEquals('short0', inputFields.description.value);
77 expectEquals('keyword0', inputFields.keyword.value);
78 expectEquals('http://www.test0.com/', inputFields.url.value);
79 });
80
81 /**
82 * Confirms that the field validation is working.
83 */
84 TEST_F('EditSearchEngineDialogUITestAsync',
85 'testInputValidation',
86 function() {
87 var inputFields = editSearchEngineDialog.inputFields;
88 var invalidData = {
89 description: '',
90 keyword: '',
91 url: '%'
92 };
93 var fieldNames = Object.keys(invalidData);
94 var index = 0;
95 var self = this;
96 var validityChecker = function(details) {
97 self.originalSetValidation(details);
98 // Ensure that all inputs are valid with the initial data, and that save
99 // is enabled. Each subsequent call will have an additional field
100 // containing invalid data.
101 for (var i = 0; i < fieldNames.length; i++) {
102 var field = fieldNames[i];
103 expectEquals(i >= index,
104 inputFields[field].valid,
105 'field = ' + field +
106 ', index = ' + index);
107 }
108 var saveButtonState = editSearchEngineDialog.getSave().disabled;
109 if (index == 0)
110 expectFalse(saveButtonState);
111 else
112 expectTrue(saveButtonState);
113 // Once the validity of the input fields and save button are confirmed, we
114 // invalidate a single field in the input and trigger a new call to check
115 // the validity. We start with the first input field and increment the
116 // index with each call in order to advance to the next field. Although
117 // each test is asynchronous, we are guaranteed to get the calls in the
118 // correct order since we wait for the previous validation to complete
119 // before moving to the next field.
120 if (index < fieldNames.length) {
121 if (index == fieldNames.length - 1) {
122 editSearchEngineDialog.setValidation = this.continueTest(
123 WhenTestDone.ALWAYS,
124 validityChecker);
125 }
126 var fieldName = fieldNames[index++];
127 inputFields[fieldName].value = invalidData[fieldName];
128 editSearchEngineDialog.validate();
129 }
130 };
131 // Override |setValidation| to check the status of the icons and save button.
132 editSearchEngineDialog.setValidation = this.continueTest(
133 WhenTestDone.EXPECT,
134 validityChecker);
135 // Check if the first call to |setValidation| tripped before being redirected
136 // to |validityChecker|.
137 if (this.pendingDetails)
138 editSearchEngineDialog.setValidation(this.pendingDetails);
139 });
140
OLDNEW
« no previous file with comments | « chrome/test/data/webui/edit_search_engine_dialog_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698