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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/cr_elements/cr_slider_tests.js
diff --git a/chrome/test/data/webui/cr_elements/cr_slider_tests.js b/chrome/test/data/webui/cr_elements/cr_slider_tests.js
new file mode 100644
index 0000000000000000000000000000000000000000..d4711ae41dfed81acca397805a9ca2def90709a9
--- /dev/null
+++ b/chrome/test/data/webui/cr_elements/cr_slider_tests.js
@@ -0,0 +1,128 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/** @fileoverview Suite of tests for cr-slider. */
+cr.define('cr_slider', function() {
+ function registerTests() {
+ suite('cr-slider', function() {
+ /** @type {!CrSliderElement} */
+ var slider;
+
+ /**
+ * paper-slider instance wrapped by cr-slider.
+ * @type {!PaperSliderElement}
+ */
+ var paperSlider;
+
+ var tickValues = [2, 4, 8, 16, 32, 64, 128];
+
+ suiteSetup(function() {
+ return PolymerTest.importHtml(
+ 'chrome://resources/cr_elements/cr_slider/cr_slider.html');
+ });
+
+ setup(function() {
+ PolymerTest.clearBody();
+ slider = document.createElement('cr-slider');
+ document.body.appendChild(slider);
+ paperSlider = slider.$$('paper-slider');
+ });
+
+ test('basic properties', function() {
+ // Default properties.
+ expectEquals(1, paperSlider.step);
+ expectEquals(0, paperSlider.min);
+
+ // Configurable properties.
+ expectFalse(paperSlider.snaps);
+ slider.setAttribute('snaps', '');
+ expectTrue(paperSlider.snaps);
+
+ slider.setAttribute('max-markers', 7);
+ expectEquals(7, paperSlider.maxMarkers);
+
+ slider.tickValues = tickValues;
+ expectEquals(6, paperSlider.max);
+ });
+
+ test('set value', function() {
+ slider.tickValues = tickValues;
+
+ slider.value = 16;
+ expectEquals(3, paperSlider.value);
+ expectEquals(3, paperSlider.immediateValue);
+
+ // Setting to an in-between value should choose an index but not change
+ // the value.
+ slider.value = 70;
+ expectEquals(5, paperSlider.value);
+ expectEquals(5, paperSlider.immediateValue);
+ expectEquals(70, slider.value);
+
+ // Setting the value out-of-range should clamp the slider.
+ slider.value = -100;
+ expectEquals(0, paperSlider.value);
+ expectEquals(0, paperSlider.immediateValue);
+ expectEquals(-100, slider.value);
+ });
+
+ test('move slider', function() {
+ slider.tickValues = tickValues;
+ slider.value = 30;
+ expectEquals(4, paperSlider.value);
+
+ MockInteractions.pressAndReleaseKeyOn(
+ paperSlider, 39 /* right */);
+ expectEquals(5, paperSlider.value);
+ expectEquals(64, slider.value);
+
+ MockInteractions.pressAndReleaseKeyOn(
+ paperSlider, 39 /* right */);
+ expectEquals(6, paperSlider.value);
+ expectEquals(128, slider.value);
+
+ MockInteractions.pressAndReleaseKeyOn(
+ paperSlider, 39 /* right */);
+ expectEquals(6, paperSlider.value);
+ expectEquals(128, slider.value);
+
+ MockInteractions.pressAndReleaseKeyOn(
+ paperSlider, 37 /* left */);
+ expectEquals(5, paperSlider.value);
+ expectEquals(64, slider.value);
+ });
+
+ test('findNearestIndex_', function() {
+ var slider = document.createElement('cr-slider');
+ var testArray = [80, 20, 350, 1000, 200, 100];
+ var testFindNearestIndex = function(expectedIndex, value) {
+ expectEquals(
+ expectedIndex, slider.findNearestIndex_(testArray, value));
+ };
+ testFindNearestIndex(0, 51);
+ testFindNearestIndex(0, 80);
+ testFindNearestIndex(0, 89);
+ testFindNearestIndex(1, -100);
+ testFindNearestIndex(1, 20);
+ testFindNearestIndex(1, 49);
+ testFindNearestIndex(2, 400);
+ testFindNearestIndex(2, 350);
+ testFindNearestIndex(2, 300);
+ testFindNearestIndex(3, 200000);
+ testFindNearestIndex(3, 1000);
+ testFindNearestIndex(3, 700);
+ testFindNearestIndex(4, 220);
+ testFindNearestIndex(4, 200);
+ testFindNearestIndex(4, 151);
+ testFindNearestIndex(5, 149);
+ testFindNearestIndex(5, 100);
+ testFindNearestIndex(5, 91);
+ });
+ });
+ }
+
+ return {
+ registerTests: registerTests,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698