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

Side by Side Diff: chrome/browser/ui/webui/options/settings_format_browsertest.js

Issue 2919343005: Remove tests for deprecated Options UI (Closed)
Patch Set: and more Created 3 years, 6 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 GEN_INCLUDE(['options_browsertest_base.js']);
6
7 /**
8 * TestFixture for testing the formatting of settings pages.
9 * @extends {testing.Test}
10 * @constructor
11 */
12 function SettingsFormatWebUITest() {}
13
14 /**
15 * Map of rule exemptions grouped by test.
16 * @const
17 */
18 SettingsFormatWebUITest.Filters = {
19 /**
20 * Exemption for checkboxes that do not require an id or pref property.
21 * Input methods use inputMethodId instead of id for unique identification.
22 */
23 'pref': ['language-options-input-method-template',
24 'language-options-input-method-list']
25 };
26
27 /**
28 * Collection of error messages.
29 * @const
30 */
31 SettingsFormatWebUITest.Messages = {
32 MISSING_CHECK_WRAPPER: 'Element $1 should be enclosed in <div class="$2">',
33 MISSING_ID_OR_PREF: 'Missing id or pref preoperty for checkbox $1.',
34 MISSING_RADIO_BUTTON_NAME: 'Radio button $1 is missing the name property',
35 MISSING_RADIO_BUTTON_VALUE: 'Radio button $1 is missing the value property',
36 };
37
38 SettingsFormatWebUITest.prototype = {
39 __proto__: OptionsBrowsertestBase.prototype,
40
41 /**
42 * Navigate to browser settings.
43 */
44 browsePreload: 'chrome://settings-frame/',
45
46 /**
47 * List of errors generated during a test. Used instead of expect* functions
48 * to suppress verbosity. The implementation of errorsToMessage in the
49 * testing API generates a call stack for each error produced which greatly
50 * reduces readability.
51 * @type {Array<string>}
52 */
53 errors: null,
54
55 /** @override */
56 setUp: function() {
57 OptionsBrowsertestBase.prototype.setUp.call(this);
58
59 this.errors = [];
60
61 // Enable when failure is resolved.
62 // AX_TEXT_04: http://crbug.com/570727
63 this.accessibilityAuditConfig.ignoreSelectors(
64 'linkWithUnclearPurpose',
65 '#sync-overview > A');
66
67 // Enable when failure is resolved.
68 // AX_ARIA_10: http://crbug.com/570725
69 this.accessibilityAuditConfig.ignoreSelectors(
70 'unsupportedAriaAttribute',
71 '#profiles-list');
72 },
73
74 tearDown: function() {
75 assertTrue(this.errors.length == 0, '\n' + this.errors.join('\n'));
76 },
77
78 /**
79 * Generates a failure message. During tear down of the test, the accumulation
80 * of pending messages triggers a test failure.
81 * @param {string} key Label of the message formatting string.
82 * @param {!Element} element The element that triggered the failure.
83 * @param {...string} args Additional arguments for formatting the message.
84 */
85 fail: function(key, element, args) {
86 var subs = [this.getLabel(element)].concat(
87 Array.prototype.slice.call(arguments, 2));
88 var message = SettingsFormatWebUITest.Messages[key].replace(
89 /\$\d/g,
90 function(m) {
91 return subs[m[1] - 1] || '$' + m[1];
92 });
93 assertFalse(/\$\d/.test(message), 'found unreplaced subs');
94 this.errors.push(message);
95 },
96
97 /**
98 * String for identifying a node within an error message.
99 * @param {!Element} element The target element to identify.
100 * @return {string} Name to facilitate tracking down the element.
101 */
102 getLabel: function(element) {
103 if (element.id)
104 return element.id;
105
106 if (element.pref)
107 return element.pref;
108
109 if (element.name && element.value)
110 return element.name + '-' + element.value;
111
112 return this.getLabel(element.parentNode);
113 },
114
115
116 /**
117 * Checks if the node is exempt from following the formatting rule.
118 * @param {!Element} element The candidate element.
119 * @param {Array<string>} filters List of exemptions.
120 * @return {boolean} True if the element is exempt.
121 */
122 isExempt: function(element, filters) {
123 var target = this.getLabel(element);
124 for (var i = 0; i < filters.length; i++) {
125 if (filters[i] == target)
126 return true;
127 }
128 return false;
129 }
130 };
131
132 /**
133 * Ensure that radio and checkbox buttons have consistent layout.
134 */
135 TEST_F('SettingsFormatWebUITest', 'RadioCheckboxStyleCheck', function() {
136 var settings = $('settings');
137 assertTrue(settings != null, 'Unable to access settings');
138 var query = 'input[type=checkbox], input[type=radio]';
139 var elements = document.querySelectorAll(query);
140 assertTrue(elements.length > 0);
141 for (var i = 0; i < elements.length; i++) {
142 var element = elements[i];
143 if (!findAncestorByClass(element, element.type))
144 this.fail('MISSING_CHECK_WRAPPER', element, element.type);
145 }
146 });
147
148 /**
149 * Each checkbox requires an id or pref property.
150 */
151 // Flaky crashes on all platforms; http://crbug.com/613034.
152 TEST_F('SettingsFormatWebUITest', 'DISABLED_CheckboxIdOrPrefCheck', function() {
153 var query =
154 'input[type=checkbox]:not([pref]):not([id]):not(.spacer-checkbox)';
155 var elements = document.querySelectorAll(query);
156 for (var i = 0; i < elements.length; i++) {
157 var element = elements[i];
158 if (!this.isExempt(element, SettingsFormatWebUITest.Filters['pref']))
159 this.fail('MISSING_ID_OR_PREF', element);
160 }
161 });
162
163 /**
164 * Each radio button requires name and value properties.
165 */
166 TEST_F('SettingsFormatWebUITest', 'RadioButtonNameValueCheck', function() {
167 var elements = document.querySelectorAll('input[type=radio]');
168 for (var i = 0; i < elements.length; i++) {
169 var element = elements[i];
170 if (!element.name)
171 this.fail('MISSING_RADIO_BUTTON_NAME', element);
172
173 if (!element.getAttribute('value'))
174 this.fail('MISSING_RADIO_BUTTON_VALUE', element);
175 }
176 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698