| Index: chrome/browser/resources/shared/js/cr_test.html
|
| diff --git a/chrome/browser/resources/shared/js/cr_test.html b/chrome/browser/resources/shared/js/cr_test.html
|
| index b20281c1f8d1e74a71b76b18bc2f246bdcb0d7ba..f17e1b481aff93027d91c26a5bd67fd3beeec300 100644
|
| --- a/chrome/browser/resources/shared/js/cr_test.html
|
| +++ b/chrome/browser/resources/shared/js/cr_test.html
|
| @@ -39,22 +39,27 @@ function testDefinePropertyOnClass() {
|
| cr.defineProperty(C, 'test');
|
|
|
| var obj = new C;
|
| + assertUndefined(obj.test);
|
| +
|
| obj.test = 1;
|
| assertEquals(1, obj.test);
|
| assertEquals(1, obj.test_);
|
| }
|
|
|
| -function testDefinePropertyWithDefault() {
|
| +function testDefinePropertyWithSetter() {
|
| var obj = new EventTarget;
|
|
|
| - cr.defineProperty(obj, 'test', null, 1);
|
| -
|
| - assertEquals(1, obj.test);
|
| - assertEquals(1, obj.test_);
|
| -
|
| + var hit = false;
|
| + function onTestSet(value, oldValue) {
|
| + assertEquals(obj, this);
|
| + assertEquals(2, this.test);
|
| + assertUndefined(oldValue);
|
| + assertEquals(2, value);
|
| + hit = true;
|
| + }
|
| + cr.defineProperty(obj, 'test', cr.PropertyKind.JS, onTestSet);
|
| obj.test = 2;
|
| - assertEquals(2, obj.test);
|
| - assertEquals(2, obj.test_);
|
| + assertTrue(hit);
|
| }
|
|
|
| function testDefinePropertyEvent() {
|
| @@ -82,20 +87,20 @@ function testDefinePropertyEvent() {
|
|
|
| function testDefinePropertyEventWithDefault() {
|
| var obj = new EventTarget;
|
| - cr.defineProperty(obj, 'test', cr.PropertyKind.JS, 1);
|
| + cr.defineProperty(obj, 'test', cr.PropertyKind.JS);
|
|
|
| var count = 0;
|
| function f(e) {
|
| assertEquals('testChange', e.type);
|
| assertEquals('test', e.propertyName);
|
| - assertEquals(1, e.oldValue);
|
| + assertUndefined(e.oldValue);
|
| assertEquals(2, e.newValue);
|
| count++;
|
| }
|
|
|
| obj.addEventListener('testChange', f);
|
|
|
| - obj.test = 1;
|
| + obj.test = undefined;
|
| assertEquals('Should not have called the property change listener', 0, count);
|
|
|
| obj.test = 2;
|
| @@ -119,62 +124,45 @@ function testDefinePropertyAttrOnClass() {
|
| var obj = document.createElement('button');
|
| cr.defineProperty(HTMLButtonElement, 'test', cr.PropertyKind.ATTR);
|
|
|
| + assertEquals(null, obj.test);
|
| +
|
| obj.test = 'a';
|
| assertEquals('a', obj.test);
|
| assertEquals('a', obj.getAttribute('test'));
|
| }
|
|
|
| -function testDefinePropertyAttrWithDefault() {
|
| +function testDefinePropertyAttrWithSetter() {
|
| var obj = document.createElement('div');
|
| - cr.defineProperty(obj, 'test', cr.PropertyKind.ATTR, 'a');
|
| -
|
| - assertEquals('a', obj.test);
|
| - assertFalse(obj.hasAttribute('test'));
|
|
|
| + var hit = false;
|
| + function onTestSet(value, oldValue) {
|
| + assertEquals(obj, this);
|
| + assertEquals(null, oldValue);
|
| + assertEquals('b', value);
|
| + assertEquals('b', this.test);
|
| + hit = true;
|
| + }
|
| + cr.defineProperty(obj, 'test', cr.PropertyKind.ATTR, onTestSet);
|
| obj.test = 'b';
|
| - assertEquals('b', obj.test);
|
| - assertEquals('b', obj.getAttribute('test'));
|
| + assertTrue(hit);
|
| }
|
|
|
| function testDefinePropertyAttrEvent() {
|
| var obj = document.createElement('div');
|
| cr.defineProperty(obj, 'test', cr.PropertyKind.ATTR);
|
| - obj.test = 'a';
|
| -
|
| - var count = 0;
|
| - function f(e) {
|
| - assertEquals('testChange', e.type);
|
| - assertEquals('test', e.propertyName);
|
| - assertEquals('a', e.oldValue);
|
| - assertEquals('b', e.newValue);
|
| - count++;
|
| - }
|
| -
|
| - obj.addEventListener('testChange', f);
|
| - obj.test = 'b';
|
| - assertEquals('b', obj.test);
|
| - assertEquals('Should have called the property change listener', 1, count);
|
| -
|
| - obj.test = 'b';
|
| - assertEquals(1, count);
|
| -}
|
| -
|
| -function testDefinePropertyAttrEventWithDefault() {
|
| - var obj = document.createElement('div');
|
| - cr.defineProperty(obj, 'test', cr.PropertyKind.ATTR, 'a');
|
|
|
| var count = 0;
|
| function f(e) {
|
| assertEquals('testChange', e.type);
|
| assertEquals('test', e.propertyName);
|
| - assertEquals('a', e.oldValue);
|
| + assertEquals(null, e.oldValue);
|
| assertEquals('b', e.newValue);
|
| count++;
|
| }
|
|
|
| obj.addEventListener('testChange', f);
|
|
|
| - obj.test = 'a';
|
| + obj.test = null;
|
| assertEquals('Should not have called the property change listener', 0, count);
|
|
|
| obj.test = 'b';
|
| @@ -223,6 +211,21 @@ function testDefinePropertyBoolAttrEvent() {
|
| assertEquals(1, count);
|
| }
|
|
|
| +function testDefinePropertyBoolAttrEvent() {
|
| + var obj = document.createElement('div');
|
| + var hit = false;
|
| + function onTestSet(value, oldValue) {
|
| + assertEquals(obj, this);
|
| + assertTrue(this.test);
|
| + assertFalse(oldValue);
|
| + assertTrue(value);
|
| + hit = true;
|
| + }
|
| + cr.defineProperty(obj, 'test', cr.PropertyKind.BOOL_ATTR, onTestSet);
|
| + obj.test = true;
|
| + assertTrue(hit);
|
| +}
|
| +
|
| function testAddSingletonGetter() {
|
| function Foo() {};
|
| cr.addSingletonGetter(Foo);
|
|
|