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

Unified Diff: chrome/test/data/webui/settings/settings_slider_tests.js

Issue 2877173002: Add scale to settings-slider (Closed)
Patch Set: Less code in the |scale| comment. Created 3 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
« no previous file with comments | « chrome/test/data/webui/settings/cr_settings_browsertest.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/settings/settings_slider_tests.js
diff --git a/chrome/test/data/webui/settings/settings_slider_tests.js b/chrome/test/data/webui/settings/settings_slider_tests.js
index 62758704c8b33bb43081930714421181276fa98e..12d0cb9d1f698c0232284d2e2395c73b00ec2c0f 100644
--- a/chrome/test/data/webui/settings/settings_slider_tests.js
+++ b/chrome/test/data/webui/settings/settings_slider_tests.js
@@ -3,124 +3,125 @@
// found in the LICENSE file.
/** @fileoverview Suite of tests for settings-slider. */
-cr.define('settings_slider', function() {
- function registerTests() {
- suite('SettingsSlider', function() {
- /** @type {!CrSliderElement} */
- var slider;
-
- /**
- * paper-slider instance wrapped by settings-slider.
- * @type {!PaperSliderElement}
- */
- var paperSlider;
-
- var tickValues = [2, 4, 8, 16, 32, 64, 128];
-
- setup(function() {
- PolymerTest.clearBody();
- slider = document.createElement('settings-slider');
- slider.pref = {
- type: chrome.settingsPrivate.PrefType.NUMBER,
- value: 16,
- };
- document.body.appendChild(slider);
- paperSlider = slider.$$('paper-slider');
- });
-
- test('enforce value', function() {
- // Test that the indicator is not present until after the pref is
- // enforced.
- indicator = slider.$$('cr-policy-pref-indicator');
- assertFalse(!!indicator);
- slider.pref = {
- controlledBy: chrome.settingsPrivate.ControlledBy.DEVICE_POLICY,
- enforcement: chrome.settingsPrivate.Enforcement.ENFORCED,
- type: chrome.settingsPrivate.PrefType.NUMBER,
- value: 16,
- };
- Polymer.dom.flush();
- indicator = slider.$$('cr-policy-pref-indicator');
- assertTrue(!!indicator);
- });
-
- test('set value', function() {
- slider.tickValues = tickValues;
- slider.set('pref.value', 16);
- expectEquals(6, paperSlider.max);
- expectEquals(3, paperSlider.value);
- expectEquals(3, paperSlider.immediateValue);
-
- // settings-slider only supports snapping to a range of tick values.
- // Setting to an in-between value should snap to an indexed value.
- slider.set('pref.value', 70);
- expectEquals(5, paperSlider.value);
- expectEquals(5, paperSlider.immediateValue);
- expectEquals(64, slider.pref.value);
-
- // Setting the value out-of-range should clamp the slider.
- slider.set('pref.value', -100);
- expectEquals(0, paperSlider.value);
- expectEquals(0, paperSlider.immediateValue);
- expectEquals(2, slider.pref.value);
- });
-
- test('move slider', function() {
- slider.tickValues = tickValues;
- slider.set('pref.value', 30);
- expectEquals(4, paperSlider.value);
-
- MockInteractions.pressAndReleaseKeyOn(
- paperSlider, 39 /* right */);
- expectEquals(5, paperSlider.value);
- expectEquals(64, slider.pref.value);
-
- MockInteractions.pressAndReleaseKeyOn(
- paperSlider, 39 /* right */);
- expectEquals(6, paperSlider.value);
- expectEquals(128, slider.pref.value);
-
- MockInteractions.pressAndReleaseKeyOn(
- paperSlider, 39 /* right */);
- expectEquals(6, paperSlider.value);
- expectEquals(128, slider.pref.value);
-
- MockInteractions.pressAndReleaseKeyOn(
- paperSlider, 37 /* left */);
- expectEquals(5, paperSlider.value);
- expectEquals(64, slider.pref.value);
- });
-
- test('findNearestIndex_', function() {
- var slider = document.createElement('settings-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,
- };
+suite('SettingsSlider', function() {
+ /** @type {!CrSliderElement} */
+ var slider;
+
+ /**
+ * paper-slider instance wrapped by settings-slider.
+ * @type {!PaperSliderElement}
+ */
+ var paperSlider;
+
+ var tickValues = [2, 4, 8, 16, 32, 64, 128];
+
+ setup(function() {
+ PolymerTest.clearBody();
+ slider = document.createElement('settings-slider');
+ slider.pref = {
+ type: chrome.settingsPrivate.PrefType.NUMBER,
+ value: 16,
+ };
+ document.body.appendChild(slider);
+ paperSlider = slider.$$('paper-slider');
+ });
+
+ test('enforce value', function() {
+ // Test that the indicator is not present until after the pref is
+ // enforced.
+ indicator = slider.$$('cr-policy-pref-indicator');
+ assertFalse(!!indicator);
+ slider.pref = {
+ controlledBy: chrome.settingsPrivate.ControlledBy.DEVICE_POLICY,
+ enforcement: chrome.settingsPrivate.Enforcement.ENFORCED,
+ type: chrome.settingsPrivate.PrefType.NUMBER,
+ value: 16,
+ };
+ Polymer.dom.flush();
+ indicator = slider.$$('cr-policy-pref-indicator');
+ assertTrue(!!indicator);
+ });
+
+ test('set value', function() {
+ slider.tickValues = tickValues;
+ slider.set('pref.value', 16);
+ expectEquals(6, paperSlider.max);
+ expectEquals(3, paperSlider.value);
+ expectEquals(3, paperSlider.immediateValue);
+
+ // settings-slider only supports snapping to a range of tick values.
+ // Setting to an in-between value should snap to an indexed value.
+ slider.set('pref.value', 70);
+ expectEquals(5, paperSlider.value);
+ expectEquals(5, paperSlider.immediateValue);
+ expectEquals(64, slider.pref.value);
+
+ // Setting the value out-of-range should clamp the slider.
+ slider.set('pref.value', -100);
+ expectEquals(0, paperSlider.value);
+ expectEquals(0, paperSlider.immediateValue);
+ expectEquals(2, slider.pref.value);
+ });
+
+ test('move slider', function() {
+ slider.tickValues = tickValues;
+ slider.set('pref.value', 30);
+ expectEquals(4, paperSlider.value);
+
+ MockInteractions.pressAndReleaseKeyOn(paperSlider, 39 /* right */);
+ expectEquals(5, paperSlider.value);
+ expectEquals(64, slider.pref.value);
+
+ MockInteractions.pressAndReleaseKeyOn(paperSlider, 39 /* right */);
+ expectEquals(6, paperSlider.value);
+ expectEquals(128, slider.pref.value);
+
+ MockInteractions.pressAndReleaseKeyOn(paperSlider, 39 /* right */);
+ expectEquals(6, paperSlider.value);
+ expectEquals(128, slider.pref.value);
+
+ MockInteractions.pressAndReleaseKeyOn(paperSlider, 37 /* left */);
+ expectEquals(5, paperSlider.value);
+ expectEquals(64, slider.pref.value);
+ });
+
+ test('findNearestIndex_', function() {
+ var slider = document.createElement('settings-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);
+ });
+
+ test('scaled slider', function() {
+ slider.scale = 10;
+ slider.set('pref.value', 2);
+ expectEquals(20, paperSlider.value);
+
+ MockInteractions.pressAndReleaseKeyOn(paperSlider, 39 /* right */);
+ expectEquals(21, paperSlider.value);
+ expectEquals(2.1, slider.pref.value);
+
+ MockInteractions.pressAndReleaseKeyOn(paperSlider, 39 /* right */);
+ expectEquals(22, paperSlider.value);
+ expectEquals(2.2, slider.pref.value);
+ });
});
« 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