blob: 693bd14d487cf0996f76c7de581f959b188d2843 [file] [log] [blame]
<!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/properties.html">
<script>
'use strict';
tr.b.unittest.testSuite(function() {
test('defineProperties', function() {
var stateChanges = [];
var ASpan = tr.b.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) {
tr.b.setPropertyAndDispatchChange(this, 'prop', newValue);
}
};
var aSpan = new ASpan();
aSpan.addEventListener('propChange', function(event) {
stateChanges.push(event.oldValue + ' to ' + event.newValue);
});
assert.isFalse(aSpan.prop);
aSpan.prop = true;
assert.isTrue(aSpan.prop);
assert.strictEqual(stateChanges.length, 2);
assert.strictEqual(stateChanges[0], 'Internal false to true');
assert.strictEqual(stateChanges[1], 'false to true');
aSpan.prop = false;
assert.isFalse(aSpan.prop);
assert.strictEqual(stateChanges[3], 'true to false');
});
});
</script>