summaryrefslogtreecommitdiff
path: root/chromium/third_party/trace-viewer/src/ui/dom_helpers_test.js
blob: b760bfbc4f17b2d3a2af4adc366989f9a1dae739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) 2013 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.

'use strict';

base.require('ui.dom_helpers');

base.unittest.testSuite('ui.dom_helpers', function() {

  test('simpleSpanAndDiv', function() {
    var divEl = ui.createDiv({
      className: 'a-div-class', parent: document.body
    });
    var testText = 'some span text';
    var spanEl = ui.createSpan({
      className: 'a-span-class',
      textContent: testText,
      parent: divEl
    });
    var eltInDocument = document.querySelector('.a-div-class>.a-span-class');
    assertEquals(eltInDocument.textContent, testText);
    eltInDocument.parentElement.removeChild(eltInDocument);
  });

  test('checkboxFromDefaults', function() {
    var target = {foo: undefined};
    var cb = ui.createCheckBox(target, 'foo', 'myCheckBox', false, 'Foo');
    assertEquals(false, target.foo);
  });

  test('checkboxFromSettings', function() {
    base.Settings.set('myCheckBox', true);
    var target = {foo: undefined};
    var cb = ui.createCheckBox(target, 'foo', 'myCheckBox', false, 'Foo');
    assertEquals(true, target.foo);
  });

  test('checkboxChanged', function() {
    var target = {foo: undefined};
    var cb = ui.createCheckBox(target, 'foo', 'myCheckBox', false, 'Foo');
    cb.checked = true;

    assertEquals(true, base.Settings.get('myCheckBox', undefined));
    assertEquals(true, target.foo);
  });

  test('selectorSettingsAlreaySet', function() {
    base.Settings.set('myScale', 0.25);

    var target = {
      scale: 314
    };
    var sel = 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}
        ]);
    assertEquals(0.25, target.scale);
    assertEquals(2, sel.selectedIndex);
  });

  test('selectorSettingsDefault', function() {
    var target = {
      scale: 314
    };
    var sel = 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}
        ]);
    assertEquals(0.375, target.scale);
    assertEquals(3, sel.selectedIndex);
  });

  test('selectorSettingsChanged', function() {
    var target = {
      scale: 314
    };
    var sel = 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}
        ]);
    assertEquals(0.375, sel.selectedValue);
    sel.selectedValue = 0.75;
    assertEquals(0.75, target.scale);
    assertEquals(0.75, sel.selectedValue);
    assertEquals(0.75, base.Settings.get('myScale', undefined));
  });
});