| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2014 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. |
| --> |
| <link rel="import" href="/base/ui/dom_helpers.html"> |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| |
| test('simpleSpanAndDiv', function() { |
| var divEl = tr.b.ui.createDiv({ |
| className: 'a-div-class', parent: document.body |
| }); |
| var testText = 'some span text'; |
| var spanEl = tr.b.ui.createSpan({ |
| className: 'a-span-class', |
| textContent: testText, |
| parent: divEl |
| }); |
| var eltInDocument = document.querySelector('.a-div-class>.a-span-class'); |
| assert.equal(eltInDocument.textContent, testText); |
| eltInDocument.parentElement.removeChild(eltInDocument); |
| }); |
| |
| test('checkboxFromDefaults', function() { |
| var target = {foo: undefined}; |
| var cb = tr.b.ui.createCheckBox(target, 'foo', 'myCheckBox', false, 'Foo'); |
| assert.isFalse(target.foo); |
| }); |
| |
| test('checkboxFromSettings', function() { |
| tr.b.Settings.set('myCheckBox', true); |
| var target = {foo: undefined}; |
| var cb = tr.b.ui.createCheckBox(target, 'foo', 'myCheckBox', false, 'Foo'); |
| assert.isTrue(target.foo); |
| }); |
| |
| test('checkboxChanged', function() { |
| var target = {foo: undefined}; |
| var cb = tr.b.ui.createCheckBox(target, 'foo', 'myCheckBox', false, 'Foo'); |
| cb.checked = true; |
| |
| assert.isTrue(tr.b.Settings.get('myCheckBox', undefined)); |
| assert.isTrue(target.foo); |
| }); |
| |
| test('selectorSettingsAlreaySet', function() { |
| tr.b.Settings.set('myScale', 0.25); |
| |
| var target = { |
| scale: 314 |
| }; |
| var sel = tr.b.ui.createSelector( |
| target, 'scale', |
| 'myScale', 0.375, |
| [{label: '6.25%', value: 0.0625}, |
| {label: '12.5%', value: 0.125}, |
| {label: '25%', value: 0.25}, |
| {label: '37.5%', value: 0.375}, |
| {label: '50%', value: 0.5}, |
| {label: '75%', value: 0.75}, |
| {label: '100%', value: 1}, |
| {label: '200%', value: 2} |
| ]); |
| assert.equal(target.scale, 0.25); |
| assert.equal(sel.selectedIndex, 2); |
| }); |
| |
| test('selectorSettingsDefault', function() { |
| var target = { |
| scale: 314 |
| }; |
| var sel = tr.b.ui.createSelector( |
| target, 'scale', |
| 'myScale', 0.375, |
| [{label: '6.25%', value: 0.0625}, |
| {label: '12.5%', value: 0.125}, |
| {label: '25%', value: 0.25}, |
| {label: '37.5%', value: 0.375}, |
| {label: '50%', value: 0.5}, |
| {label: '75%', value: 0.75}, |
| {label: '100%', value: 1}, |
| {label: '200%', value: 2} |
| ]); |
| assert.equal(target.scale, 0.375); |
| assert.equal(sel.selectedIndex, 3); |
| }); |
| |
| test('selectorSettingsChanged', function() { |
| var target = { |
| scale: 314 |
| }; |
| var sel = tr.b.ui.createSelector( |
| target, 'scale', |
| 'myScale', 0.375, |
| [{label: '6.25%', value: 0.0625}, |
| {label: '12.5%', value: 0.125}, |
| {label: '25%', value: 0.25}, |
| {label: '37.5%', value: 0.375}, |
| {label: '50%', value: 0.5}, |
| {label: '75%', value: 0.75}, |
| {label: '100%', value: 1}, |
| {label: '200%', value: 2} |
| ]); |
| assert.equal(sel.selectedValue, 0.375); |
| sel.selectedValue = 0.75; |
| assert.equal(target.scale, 0.75); |
| assert.equal(sel.selectedValue, 0.75); |
| assert.equal(undefined), 0.75, tr.b.Settings.get('myScale'); |
| }); |
| }); |
| </script> |