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

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

Issue 1420533011: [MD settings] change dropdown to accept array of objects rather than array of tuples (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@appearance50p
Patch Set: trybot fix Created 5 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
« no previous file with comments | « chrome/browser/resources/settings/controls/settings_dropdown_menu.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
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 // Import settings_dropdown_menu.html before running suite. 9 // Import settings_dropdown_menu.html before running suite.
10 suiteSetup(function() { 10 suiteSetup(function() {
(...skipping 19 matching lines...) Expand all
30 selectable = dropdown.$$('paper-menu'); 30 selectable = dropdown.$$('paper-menu');
31 document.body.appendChild(dropdown); 31 document.body.appendChild(dropdown);
32 }); 32 });
33 33
34 test('with number options', function testNumberOptions() { 34 test('with number options', function testNumberOptions() {
35 dropdown.pref = { 35 dropdown.pref = {
36 key: 'test.number', 36 key: 'test.number',
37 type: chrome.settingsPrivate.PrefType.NUMBER, 37 type: chrome.settingsPrivate.PrefType.NUMBER,
38 value: 100, 38 value: 100,
39 }; 39 };
40 dropdown.menuOptions = [[100, 'Option 100'], [200, 'Option 200'], 40 dropdown.menuOptions = [{value: 100, name: 'Option 100'},
41 [300, 'Option 300'], [400, 'Option 400']]; 41 {value: 200, name: 'Option 200'},
42 {value: 300, name: 'Option 300'},
43 {value: 400, name: 'Option 400'}];
42 44
43 // IronSelectable uses a DOM observer, which uses a debouncer. 45 // IronSelectable uses a DOM observer, which uses a debouncer.
44 Polymer.dom.flush(); 46 Polymer.dom.flush();
45 47
46 // Initially selected item. 48 // Initially selected item.
47 assertEquals('Option 100', selectable.selectedItem.textContent.trim()); 49 assertEquals('Option 100', selectable.selectedItem.textContent.trim());
48 50
49 // Selecting an item updates the pref. 51 // Selecting an item updates the pref.
50 selectable.selected = '200'; 52 selectable.selected = '200';
51 assertEquals(200, dropdown.pref.value); 53 assertEquals(200, dropdown.pref.value);
52 54
53 // Updating the pref selects an item. 55 // Updating the pref selects an item.
54 dropdown.set('pref.value', 400); 56 dropdown.set('pref.value', 400);
55 assertEquals('400', selectable.selected); 57 assertEquals('400', selectable.selected);
56 }); 58 });
57 59
58 test('with string options', function testStringOptions() { 60 test('with string options', function testStringOptions() {
59 dropdown.pref = { 61 dropdown.pref = {
60 key: 'test.string', 62 key: 'test.string',
61 type: chrome.settingsPrivate.PrefType.STRING, 63 type: chrome.settingsPrivate.PrefType.STRING,
62 value: 'c', 64 value: 'c',
63 }; 65 };
64 dropdown.menuOptions = 66 dropdown.menuOptions =
65 [['a', 'AAA'], ['b', 'BBB'], ['c', 'CCC'], ['d', 'DDD']]; 67 [{value: 'a', name: 'AAA'},
68 {value: 'b', name: 'BBB'},
69 {value: 'c', name: 'CCC'},
70 {value: 'd', name: 'DDD'}];
66 Polymer.dom.flush(); 71 Polymer.dom.flush();
67 72
68 // Initially selected item. 73 // Initially selected item.
69 assertEquals('CCC', selectable.selectedItem.textContent.trim()); 74 assertEquals('CCC', selectable.selectedItem.textContent.trim());
70 75
71 // Selecting an item updates the pref. 76 // Selecting an item updates the pref.
72 selectable.selected = 'a'; 77 selectable.selected = 'a';
73 assertEquals('a', dropdown.pref.value); 78 assertEquals('a', dropdown.pref.value);
74 79
75 // Updating the pref selects an item. 80 // Updating the pref selects an item.
76 dropdown.set('pref.value', 'b'); 81 dropdown.set('pref.value', 'b');
77 assertEquals('b', selectable.selected); 82 assertEquals('b', selectable.selected);
78 }); 83 });
79 84
80 test('with custom value', function testCustomValue() { 85 test('with custom value', function testCustomValue() {
81 dropdown.pref = { 86 dropdown.pref = {
82 key: 'test.string', 87 key: 'test.string',
83 type: chrome.settingsPrivate.PrefType.STRING, 88 type: chrome.settingsPrivate.PrefType.STRING,
84 value: 'f', 89 value: 'f',
85 }; 90 };
86 dropdown.menuOptions = 91 dropdown.menuOptions =
87 [['a', 'AAA'], ['b', 'BBB'], ['c', 'CCC'], ['d', 'DDD']]; 92 [{value: 'a', name: 'AAA'},
93 {value: 'b', name: 'BBB'},
94 {value: 'c', name: 'CCC'},
95 {value: 'd', name: 'DDD'}];
88 Polymer.dom.flush(); 96 Polymer.dom.flush();
89 97
90 // "Custom" initially selected. 98 // "Custom" initially selected.
91 assertEquals(dropdown.notFoundValue_, selectable.selected); 99 assertEquals(dropdown.notFoundValue_, selectable.selected);
92 // Pref should not have changed. 100 // Pref should not have changed.
93 assertEquals('f', dropdown.pref.value); 101 assertEquals('f', dropdown.pref.value);
94 }); 102 });
95 }); 103 });
96 } 104 }
97 105
98 return { 106 return {
99 registerTests: registerTests, 107 registerTests: registerTests,
100 }; 108 };
101 }); 109 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/controls/settings_dropdown_menu.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698