summaryrefslogtreecommitdiff
path: root/chromium/third_party/trace-viewer/src/base/properties_test.js
blob: 585f5c87b2fa27ea7f3e34751ba4aa5b06d805d0 (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
// 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('base.properties');
base.require('ui');

base.unittest.testSuite('base.properties', function() {
  test('defineProperties', function() {
    var stateChanges = [];

    var ASpan = ui.define('span');
    ASpan.prototype = {
      __proto__: HTMLSpanElement.prototype,

      jsProp_: [],

      decorate: function() {
        this.prop_ = false;
        this.addEventListener('propChange', function(event) {
          stateChanges.push('Internal ' + event.oldValue +
              ' to ' + event.newValue);
        }, true);
      },

      get prop() {
        return this.prop_;
      },

      set prop(newValue) {
        base.setPropertyAndDispatchChange(this, 'prop', newValue);
      }
    };

    var aSpan = new ASpan();

    aSpan.addEventListener('propChange', function(event) {
      stateChanges.push(event.oldValue + ' to ' + event.newValue);
    });

    assertFalse(aSpan.prop);

    aSpan.prop = true;
    assertTrue(aSpan.prop);
    assertTrue(stateChanges.length === 2);
    assertTrue(stateChanges[0] === 'Internal false to true');
    assertTrue(stateChanges[1] === 'false to true');

    aSpan.prop = false;
    assertFalse(aSpan.prop);
    assertTrue(stateChanges[3] === 'true to false');
  });
});