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

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

Issue 1422023012: MD Settings: Simplify settings-dropdown-menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
« no previous file with comments | « chrome/test/data/webui/settings/cr_settings_browsertest.js ('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 2015 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 /** @fileoverview Suite of tests for settings-dropdown-menu. */
6 cr.define('settings_dropdown_menu', function() {
7 function registerTests() {
8 suite('SettingsDropdownMenu', function() {
9 // Import settings_dropdown_menu.html before running suite.
10 suiteSetup(function() {
11 return Promise.all([
12 PolymerTest.importHtml('chrome://md-settings/i18n_setup.html'),
13 PolymerTest.importHtml(
14 'chrome://md-settings/controls/settings_dropdown_menu.html'),
15 ]);
16 });
17
18 /** @type {SettingsDropdownMenu} */
19 var dropdown;
20
21 /**
22 * The IronSelectable (paper-menu) used internally by the dropdown menu.
23 * @type {Polymer.IronSelectableBehavior}
24 */
25 var selectable;
26
27 setup(function() {
28 PolymerTest.clearBody();
29 dropdown = document.createElement('settings-dropdown-menu');
30 selectable = dropdown.$$('paper-menu');
31 document.body.appendChild(dropdown);
32 });
33
34 test('with number options', function testNumberOptions() {
35 dropdown.pref = {
36 key: 'test.number',
37 type: chrome.settingsPrivate.PrefType.NUMBER,
38 value: 100,
39 };
40 dropdown.menuOptions = [[100, 'Option 100'], [200, 'Option 200'],
41 [300, 'Option 300'], [400, 'Option 400']];
42
43 // IronSelectable uses a DOM observer, which uses a debouncer.
44 Polymer.dom.flush();
45
46 // Initially selected item.
47 assertEquals('Option 100', selectable.selectedItem.textContent.trim());
48
49 // Selecting an item updates the pref.
50 selectable.selected = '200';
51 assertEquals(200, dropdown.pref.value);
52
53 // Updating the pref selects an item.
54 dropdown.set('pref.value', 400);
55 assertEquals('400', selectable.selected);
56 });
57
58 test('with string options', function testStringOptions() {
59 dropdown.pref = {
60 key: 'test.string',
61 type: chrome.settingsPrivate.PrefType.STRING,
62 value: 'c',
63 };
64 dropdown.menuOptions =
65 [['a', 'AAA'], ['b', 'BBB'], ['c', 'CCC'], ['d', 'DDD']];
66 Polymer.dom.flush();
67
68 // Initially selected item.
69 assertEquals('CCC', selectable.selectedItem.textContent.trim());
70
71 // Selecting an item updates the pref.
72 selectable.selected = 'a';
73 assertEquals('a', dropdown.pref.value);
74
75 // Updating the pref selects an item.
76 dropdown.set('pref.value', 'b');
77 assertEquals('b', selectable.selected);
78 });
79
80 test('with custom value', function testCustomValue() {
81 dropdown.pref = {
82 key: 'test.string',
83 type: chrome.settingsPrivate.PrefType.STRING,
84 value: 'f',
85 };
86 dropdown.menuOptions =
87 [['a', 'AAA'], ['b', 'BBB'], ['c', 'CCC'], ['d', 'DDD']];
88 Polymer.dom.flush();
89
90 // "Custom" initially selected.
91 assertEquals(dropdown.notFoundValue_, selectable.selected);
92 // Pref should not have changed.
93 assertEquals('f', dropdown.pref.value);
94 });
95 });
96 }
97
98 return {
99 registerTests: registerTests,
100 };
101 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/settings/cr_settings_browsertest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698