Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / base / properties_test.js
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 base.require('base.properties');
8 base.require('ui');
9
10 base.unittest.testSuite('base.properties', function() {
11   test('defineProperties', function() {
12     var stateChanges = [];
13
14     var ASpan = ui.define('span');
15     ASpan.prototype = {
16       __proto__: HTMLSpanElement.prototype,
17
18       jsProp_: [],
19
20       decorate: function() {
21         this.prop_ = false;
22         this.addEventListener('propChange', function(event) {
23           stateChanges.push('Internal ' + event.oldValue +
24               ' to ' + event.newValue);
25         }, true);
26       },
27
28       get prop() {
29         return this.prop_;
30       },
31
32       set prop(newValue) {
33         base.setPropertyAndDispatchChange(this, 'prop', newValue);
34       }
35     };
36
37     var aSpan = new ASpan();
38
39     aSpan.addEventListener('propChange', function(event) {
40       stateChanges.push(event.oldValue + ' to ' + event.newValue);
41     });
42
43     assertFalse(aSpan.prop);
44
45     aSpan.prop = true;
46     assertTrue(aSpan.prop);
47     assertTrue(stateChanges.length === 2);
48     assertTrue(stateChanges[0] === 'Internal false to true');
49     assertTrue(stateChanges[1] === 'false to true');
50
51     aSpan.prop = false;
52     assertFalse(aSpan.prop);
53     assertTrue(stateChanges[3] === 'true to false');
54   });
55 });