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

Side by Side Diff: chrome/test/data/webui/settings/dropdown_menu_tests.js

Issue 2446003002: settings-dropdown-menu must set <select>#value after its options change (Closed)
Patch Set: Created 4 years, 1 month 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** @fileoverview Suite of tests for settings-dropdown-menu. */ 5 /** @fileoverview Suite of tests for settings-dropdown-menu. */
6 cr.define('settings_dropdown_menu', function() { 6 cr.define('settings_dropdown_menu', function() {
7 function registerTests() { 7 function registerTests() {
8 suite('SettingsDropdownMenu', function() { 8 suite('SettingsDropdownMenu', function() {
9 /** @type {SettingsDropdownMenu} */ 9 /** @type {SettingsDropdownMenu} */
10 var dropdown; 10 var dropdown;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return waitUntilDropdownUpdated().then(function() { 77 return waitUntilDropdownUpdated().then(function() {
78 // Initially selected item. 78 // Initially selected item.
79 assertEquals( 79 assertEquals(
80 'CCC', selectElement.selectedOptions[0].textContent.trim()); 80 'CCC', selectElement.selectedOptions[0].textContent.trim());
81 81
82 // Selecting an item updates the pref. 82 // Selecting an item updates the pref.
83 return simulateChangeEvent('a'); 83 return simulateChangeEvent('a');
84 }).then(function() { 84 }).then(function() {
85 assertEquals('a', dropdown.pref.value); 85 assertEquals('a', dropdown.pref.value);
86 86
87 // Updating the pref selects an item. 87 // Item remains selected after updating menu items.
88 dropdown.set('pref.value', 'b'); 88 var newMenuOptions = dropdown.menuOptions.slice().reverse();
89 dropdown.menuOptions = newMenuOptions;
89 return waitUntilDropdownUpdated(); 90 return waitUntilDropdownUpdated();
90 }).then(function() { 91 }).then(function() {
91 assertEquals('b', selectElement.value); 92 assertEquals('AAA',
93 selectElement.selectedOptions[0].textContent.trim());
92 }); 94 });
93 }); 95 });
94 96
95 test('with custom value', function testCustomValue() { 97 test('with custom value', function testCustomValue() {
96 dropdown.pref = { 98 dropdown.pref = {
97 key: 'test.string', 99 key: 'test.string',
98 type: chrome.settingsPrivate.PrefType.STRING, 100 type: chrome.settingsPrivate.PrefType.STRING,
99 value: 'f', 101 value: 'f',
100 }; 102 };
101 dropdown.menuOptions = 103 dropdown.menuOptions =
(...skipping 14 matching lines...) Expand all
116 return new Promise(function(resolve) { setTimeout(resolve, timeMs); }); 118 return new Promise(function(resolve) { setTimeout(resolve, timeMs); });
117 } 119 }
118 120
119 test('delay setting options', function testDelayedOptions() { 121 test('delay setting options', function testDelayedOptions() {
120 dropdown.pref = { 122 dropdown.pref = {
121 key: 'test.number2', 123 key: 'test.number2',
122 type: chrome.settingsPrivate.PrefType.NUMBER, 124 type: chrome.settingsPrivate.PrefType.NUMBER,
123 value: 200, 125 value: 200,
124 }; 126 };
125 127
126 console.log('running test');
127 return waitForTimeout(100).then(function() { 128 return waitForTimeout(100).then(function() {
128 return waitUntilDropdownUpdated(); 129 return waitUntilDropdownUpdated();
129 }).then(function() { 130 }).then(function() {
130 assertTrue(dropdown.$.dropdownMenu.disabled); 131 assertTrue(selectElement.disabled);
131 assertEquals('SETTINGS_DROPDOWN_NOT_FOUND_ITEM', selectElement.value); 132 assertEquals('SETTINGS_DROPDOWN_NOT_FOUND_ITEM', selectElement.value);
132 133
133 dropdown.menuOptions = [{value: 100, name: 'Option 100'}, 134 dropdown.menuOptions = [{value: 100, name: 'Option 100'},
134 {value: 200, name: 'Option 200'}, 135 {value: 200, name: 'Option 200'},
135 {value: 300, name: 'Option 300'}, 136 {value: 300, name: 'Option 300'},
136 {value: 400, name: 'Option 400'}]; 137 {value: 400, name: 'Option 400'}];
137 return waitUntilDropdownUpdated(); 138 return waitUntilDropdownUpdated();
138 }).then(function() { 139 }).then(function() {
139 // Dropdown menu enables itself and selects the new menu option 140 // Dropdown menu enables itself and selects the new menu option
140 // correpsonding to the pref value. 141 // correpsonding to the pref value.
141 assertFalse(dropdown.$.dropdownMenu.disabled); 142 assertFalse(selectElement.disabled);
142 assertEquals('200', selectElement.value); 143 assertEquals('200', selectElement.value);
144
145 // The "Custom" option should not show up in the dropdown list or be
146 // reachable via type-ahead.
147 var options = selectElement.options;
148 var customOption = assert(options[options.length - 1]);
149 assertTrue(customOption.hidden);
150 assertTrue(customOption.disabled);
143 }); 151 });
144 }); 152 });
145 }); 153 });
146 } 154 }
147 155
148 return { 156 return {
149 registerTests: registerTests, 157 registerTests: registerTests,
150 }; 158 };
151 }); 159 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698