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

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 fix Created 4 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 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
46 test('set value', function() {
47 slider.tickValues = tickValues;
48 slider.value = 16;
49 expectEquals(6, paperSlider.max);
50 expectEquals(3, paperSlider.value);
51 expectEquals(3, paperSlider.immediateValue);
52
53 // Setting to an in-between value should choose an index but not change
54 // the value.
55 slider.value = 70;
56 expectEquals(5, paperSlider.value);
57 expectEquals(5, paperSlider.immediateValue);
58 expectEquals(70, slider.value);
59
60 // Setting the value out-of-range should clamp the slider.
61 slider.value = -100;
62 expectEquals(0, paperSlider.value);
63 expectEquals(0, paperSlider.immediateValue);
64 expectEquals(-100, slider.value);
65 });
66
67 test('move slider', function() {
68 slider.tickValues = tickValues;
69 slider.value = 30;
70 expectEquals(4, paperSlider.value);
71
72 MockInteractions.pressAndReleaseKeyOn(
73 paperSlider, 39 /* right */);
74 expectEquals(5, paperSlider.value);
75 expectEquals(64, slider.value);
76
77 MockInteractions.pressAndReleaseKeyOn(
78 paperSlider, 39 /* right */);
79 expectEquals(6, paperSlider.value);
80 expectEquals(128, slider.value);
81
82 MockInteractions.pressAndReleaseKeyOn(
83 paperSlider, 39 /* right */);
84 expectEquals(6, paperSlider.value);
85 expectEquals(128, slider.value);
86
87 MockInteractions.pressAndReleaseKeyOn(
88 paperSlider, 37 /* left */);
89 expectEquals(5, paperSlider.value);
90 expectEquals(64, slider.value);
91 });
92
93 test('findNearestIndex_', function() {
94 var slider = document.createElement('cr-slider');
95 var testArray = [80, 20, 350, 1000, 200, 100];
96 var testFindNearestIndex = function(expectedIndex, value) {
97 expectEquals(
98 expectedIndex, slider.findNearestIndex_(testArray, value));
99 };
100 testFindNearestIndex(0, 51);
101 testFindNearestIndex(0, 80);
102 testFindNearestIndex(0, 89);
103 testFindNearestIndex(1, -100);
104 testFindNearestIndex(1, 20);
105 testFindNearestIndex(1, 49);
106 testFindNearestIndex(2, 400);
107 testFindNearestIndex(2, 350);
108 testFindNearestIndex(2, 300);
109 testFindNearestIndex(3, 200000);
110 testFindNearestIndex(3, 1000);
111 testFindNearestIndex(3, 700);
112 testFindNearestIndex(4, 220);
113 testFindNearestIndex(4, 200);
114 testFindNearestIndex(4, 151);
115 testFindNearestIndex(5, 149);
116 testFindNearestIndex(5, 100);
117 testFindNearestIndex(5, 91);
118 });
119 });
120 }
121
122 return {
123 registerTests: registerTests,
124 };
125 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698