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

Side by Side Diff: chrome/test/data/webui/cr_elements/cr_slider_tests.js

Issue 1967913002: Material WebUI: cr-slider element for intelligent range mapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@KeyboardFinish
Patch Set: rebase Created 4 years, 7 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 2016 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 cr-slider. */
6 cr.define('cr_slider', function() {
7 function registerTests() {
8 suite('cr-slider', function() {
9 /** @type {!CrSliderElement} */
10 var slider;
11
12 /**
13 * paper-slider instance wrapped by cr-slider.
14 * @type {!PaperSliderElement}
15 */
16 var paperSlider;
17
18 var tickValues = [2, 4, 8, 16, 32, 64, 128];
19
20 suiteSetup(function() {
21 return PolymerTest.importHtml(
22 'chrome://resources/cr_elements/cr_slider/cr_slider.html');
23 });
24
25 setup(function() {
26 PolymerTest.clearBody();
27 slider = document.createElement('cr-slider');
28 document.body.appendChild(slider);
29 paperSlider = slider.$$('paper-slider');
30 });
31
32 test('basic properties', function() {
33 // Default properties.
34 expectEquals(1, paperSlider.step);
35 expectEquals(0, paperSlider.min);
36
37 // Configurable properties.
38 expectFalse(paperSlider.snaps);
39 slider.setAttribute('snaps', '');
40 expectTrue(paperSlider.snaps);
41
42 slider.setAttribute('max-markers', 7);
43 expectEquals(7, paperSlider.maxMarkers);
44
45 slider.tickValues = tickValues;
46 expectEquals(6, paperSlider.max);
47 });
48
49 test('set value', function() {
50 slider.tickValues = tickValues;
51
52 slider.value = 16;
53 expectEquals(3, paperSlider.value);
54 expectEquals(3, paperSlider.immediateValue);
55
56 // Setting to an in-between value should choose an index but not change
57 // the value.
58 slider.value = 70;
59 expectEquals(5, paperSlider.value);
60 expectEquals(5, paperSlider.immediateValue);
61 expectEquals(70, slider.value);
62
63 // Setting the value out-of-range should clamp the slider.
64 slider.value = -100;
65 expectEquals(0, paperSlider.value);
66 expectEquals(0, paperSlider.immediateValue);
67 expectEquals(-100, slider.value);
68 });
69
70 test('move slider', function() {
71 slider.tickValues = tickValues;
72 slider.value = 30;
73 expectEquals(4, paperSlider.value);
74
75 MockInteractions.pressAndReleaseKeyOn(
76 paperSlider, 39 /* right */);
77 expectEquals(5, paperSlider.value);
78 expectEquals(64, slider.value);
79
80 MockInteractions.pressAndReleaseKeyOn(
81 paperSlider, 39 /* right */);
82 expectEquals(6, paperSlider.value);
83 expectEquals(128, slider.value);
84
85 MockInteractions.pressAndReleaseKeyOn(
86 paperSlider, 39 /* right */);
87 expectEquals(6, paperSlider.value);
88 expectEquals(128, slider.value);
89
90 MockInteractions.pressAndReleaseKeyOn(
91 paperSlider, 37 /* left */);
92 expectEquals(5, paperSlider.value);
93 expectEquals(64, slider.value);
94 });
95
96 test('findNearestIndex_', function() {
97 var slider = document.createElement('cr-slider');
98 var testArray = [80, 20, 350, 1000, 200, 100];
99 var testFindNearestIndex = function(expectedIndex, value) {
100 expectEquals(
101 expectedIndex, slider.findNearestIndex_(testArray, value));
102 };
103 testFindNearestIndex(0, 51);
104 testFindNearestIndex(0, 80);
105 testFindNearestIndex(0, 89);
106 testFindNearestIndex(1, -100);
107 testFindNearestIndex(1, 20);
108 testFindNearestIndex(1, 49);
109 testFindNearestIndex(2, 400);
110 testFindNearestIndex(2, 350);
111 testFindNearestIndex(2, 300);
112 testFindNearestIndex(3, 200000);
113 testFindNearestIndex(3, 1000);
114 testFindNearestIndex(3, 700);
115 testFindNearestIndex(4, 220);
116 testFindNearestIndex(4, 200);
117 testFindNearestIndex(4, 151);
118 testFindNearestIndex(5, 149);
119 testFindNearestIndex(5, 100);
120 testFindNearestIndex(5, 91);
121 });
122 });
123 }
124
125 return {
126 registerTests: registerTests,
127 };
128 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698