Merge pull request #2657 from JeremybellEU/malformed-observer-message

Produce nicer error on malformed observer
This commit is contained in:
Daniel Freedman 2015-12-09 11:46:29 -08:00
commit a0565a8984
3 changed files with 119 additions and 387 deletions

View File

@ -106,6 +106,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_addComplexObserverEffect: function(observer) {
var sig = this._parseMethod(observer);
if (!sig) {
throw new Error("Malformed observer expression '" + observer + "'");
}
for (var i=0, arg; (i<sig.args.length) && (arg=sig.args[i]); i++) {
this._addPropertyEffect(arg.model, 'complexObserver', {
method: sig.method,

View File

@ -230,4 +230,4 @@
cChanged: function() {}
});
</script>
</dom-module>
</dom-module>

View File

@ -47,6 +47,80 @@ suite('basic path bindings', function() {
document.body.removeChild(el);
});
function setupNested() {
var nested = {
obj: {
value: 41
}
};
el.nested = nested;
el.expectedNestedSubpath = 'nested.obj.value';
el.expectedNestedValue = 42;
el.expectedNestedObjSubpath = 'nested.obj.value';
el.expectedNestedObjValue = 42;
el.$.compose.expectedObjSubpath = 'obj.value';
el.$.compose.expectedObjValue = 42;
el.$.forward.expectedObjSubpath = 'obj.value';
el.$.forward.expectedObjValue = 42;
el.$.forward.$.compose.expectedObjSubpath = 'obj.value';
el.$.forward.$.compose.expectedObjValue = 42;
el.clearObserverCounts();
}
function setupComposedAndGetObject() {
el.nested = {
obj: {
value: 41
}
};
var obj = {
value: 42
};
el.expectedNestedSubpath = 'nested.obj';
el.expectedNestedValue = obj;
el.expectedNestedObjSubpath = 'nested.obj';
el.expectedNestedObjValue = obj;
el.$.compose.expectedObjSubpath = 'obj';
el.$.compose.expectedObjValue = obj;
el.$.forward.expectedObjSubpath = 'obj';
el.$.forward.expectedObjValue = obj;
el.$.forward.$.compose.expectedObjSubpath = 'obj';
el.$.forward.$.compose.expectedObjValue = obj;
el.clearObserverCounts();
return obj;
}
function verifyObserverOutput(expectedNestedObjChanged) {
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, expectedNestedObjChanged);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
}
function verifyNestedObserversOutput() {
verifyObserverOutput(0);
}
function verifyNonNestedObserversOutput() {
verifyObserverOutput(1);
}
test('downward data flow', function() {
// Setup
var nested = {
@ -67,462 +141,97 @@ suite('basic path bindings', function() {
// Do the thing
el.nested = nested;
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 1);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.obj, nested.obj);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.obj, nested.obj);
assert.equal(el.$.forward.$.compose.obj, nested.obj);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNonNestedObserversOutput();
});
test('notification from basic element property change', function() {
// Setup
var nested = {
obj: {
value: 41
}
};
el.nested = nested;
el.expectedNestedSubpath = 'nested.obj.value';
el.expectedNestedValue = 42;
el.expectedNestedObjSubpath = 'nested.obj.value';
el.expectedNestedObjValue = 42;
el.$.compose.expectedObjSubpath = 'obj.value';
el.$.compose.expectedObjValue = 42;
el.$.forward.expectedObjSubpath = 'obj.value';
el.$.forward.expectedObjValue = 42;
el.$.forward.$.compose.expectedObjSubpath = 'obj.value';
el.$.forward.$.compose.expectedObjValue = 42;
el.clearObserverCounts();
setupNested();
// Do the thing
el.$.basic.notifyingValue = 42;
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 0);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNestedObserversOutput();
});
test('notification from composed element property change', function() {
// Setup
var nested = {
obj: {
value: 41
}
};
el.nested = nested;
el.expectedNestedSubpath = 'nested.obj.value';
el.expectedNestedValue = 42;
el.expectedNestedObjSubpath = 'nested.obj.value';
el.expectedNestedObjValue = 42;
el.$.compose.expectedObjSubpath = 'obj.value';
el.$.compose.expectedObjValue = 42;
el.$.forward.expectedObjSubpath = 'obj.value';
el.$.forward.expectedObjValue = 42;
el.$.forward.$.compose.expectedObjSubpath = 'obj.value';
el.$.forward.$.compose.expectedObjValue = 42;
el.clearObserverCounts();
setupNested();
// Do the thing
el.$.compose.$.basic1.notifyingValue = 42;
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 0);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNestedObserversOutput();
});
test('notification from forward\'s composed element property change', function() {
// Setup
var nested = {
obj: {
value: 41
}
};
el.nested = nested;
el.expectedNestedSubpath = 'nested.obj.value';
el.expectedNestedValue = 42;
el.expectedNestedObjSubpath = 'nested.obj.value';
el.expectedNestedObjValue = 42;
el.$.compose.expectedObjSubpath = 'obj.value';
el.$.compose.expectedObjValue = 42;
el.$.forward.expectedObjSubpath = 'obj.value';
el.$.forward.expectedObjValue = 42;
el.$.forward.$.compose.expectedObjSubpath = 'obj.value';
el.$.forward.$.compose.expectedObjValue = 42;
el.clearObserverCounts();
setupNested();
// Do the thing
el.$.forward.$.compose.$.basic1.notifyingValue = 42;
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 0);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNestedObserversOutput();
});
test('notification from set in top element', function() {
// Setup
var nested = {
obj: {
value: 41
}
};
el.nested = nested;
el.expectedNestedSubpath = 'nested.obj.value';
el.expectedNestedValue = 42;
el.expectedNestedObjSubpath = 'nested.obj.value';
el.expectedNestedObjValue = 42;
el.$.compose.expectedObjSubpath = 'obj.value';
el.$.compose.expectedObjValue = 42;
el.$.forward.expectedObjSubpath = 'obj.value';
el.$.forward.expectedObjValue = 42;
el.$.forward.$.compose.expectedObjSubpath = 'obj.value';
el.$.forward.$.compose.expectedObjValue = 42;
el.clearObserverCounts();
setupNested();
// Do the thing
el.set('nested.obj.value', 42);
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 0);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNestedObserversOutput();
});
test('notification from set in composed element', function() {
// Setup
var nested = {
obj: {
value: 41
}
};
el.nested = nested;
el.expectedNestedSubpath = 'nested.obj.value';
el.expectedNestedValue = 42;
el.expectedNestedObjSubpath = 'nested.obj.value';
el.expectedNestedObjValue = 42;
el.$.compose.expectedObjSubpath = 'obj.value';
el.$.compose.expectedObjValue = 42;
el.$.forward.expectedObjSubpath = 'obj.value';
el.$.forward.expectedObjValue = 42;
el.$.forward.$.compose.expectedObjSubpath = 'obj.value';
el.$.forward.$.compose.expectedObjValue = 42;
el.clearObserverCounts();
setupNested();
// Do the thing
el.$.compose.set('obj.value', 42);
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 0);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNestedObserversOutput();
});
test('notification from set in forward element', function() {
// Setup
var nested = {
obj: {
value: 41
}
};
el.nested = nested;
el.expectedNestedSubpath = 'nested.obj.value';
el.expectedNestedValue = 42;
el.expectedNestedObjSubpath = 'nested.obj.value';
el.expectedNestedObjValue = 42;
el.$.compose.expectedObjSubpath = 'obj.value';
el.$.compose.expectedObjValue = 42;
el.$.forward.expectedObjSubpath = 'obj.value';
el.$.forward.expectedObjValue = 42;
el.$.forward.$.compose.expectedObjSubpath = 'obj.value';
el.$.forward.$.compose.expectedObjValue = 42;
el.clearObserverCounts();
setupNested();
// Do the thing
el.$.forward.set('obj.value', 42);
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 0);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNestedObserversOutput();
});
test('notification from set in forward\'s composed element', function() {
// Setup
var nested = {
obj: {
value: 41
}
};
el.nested = nested;
el.expectedNestedSubpath = 'nested.obj.value';
el.expectedNestedValue = 42;
el.expectedNestedObjSubpath = 'nested.obj.value';
el.expectedNestedObjValue = 42;
el.$.compose.expectedObjSubpath = 'obj.value';
el.$.compose.expectedObjValue = 42;
el.$.forward.expectedObjSubpath = 'obj.value';
el.$.forward.expectedObjValue = 42;
el.$.forward.$.compose.expectedObjSubpath = 'obj.value';
el.$.forward.$.compose.expectedObjValue = 42;
el.clearObserverCounts();
setupNested();
// Do the thing
el.$.forward.$.compose.set('obj.value', 42);
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 0);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNestedObserversOutput();
});
test('notification from object change in compose element', function() {
// Setup
el.nested = {
obj: {
value: 41
}
};
var obj = {
value: 42
};
el.expectedNestedSubpath = 'nested.obj';
el.expectedNestedValue = obj;
el.expectedNestedObjSubpath = 'nested.obj';
el.expectedNestedObjValue = obj;
el.$.compose.expectedObjSubpath = 'obj';
el.$.compose.expectedObjValue = obj;
el.$.forward.expectedObjSubpath = 'obj';
el.$.forward.expectedObjValue = obj;
el.$.forward.$.compose.expectedObjSubpath = 'obj';
el.$.forward.$.compose.expectedObjValue = obj;
el.clearObserverCounts();
var obj = setupComposedAndGetObject();
// Do the thing
el.$.compose.obj = obj;
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 1);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNonNestedObserversOutput();
});
test('notification from object change in forward element', function() {
// Setup
el.nested = {
obj: {
value: 41
}
};
var obj = {
value: 42
};
el.expectedNestedSubpath = 'nested.obj';
el.expectedNestedValue = obj;
el.expectedNestedObjSubpath = 'nested.obj';
el.expectedNestedObjValue = obj;
el.$.compose.expectedObjSubpath = 'obj';
el.$.compose.expectedObjValue = obj;
el.$.forward.expectedObjSubpath = 'obj';
el.$.forward.expectedObjValue = obj;
el.$.forward.$.compose.expectedObjSubpath = 'obj';
el.$.forward.$.compose.expectedObjValue = obj;
el.clearObserverCounts();
var obj = setupComposedAndGetObject();
// Do the thing
el.$.forward.obj = obj;
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 1);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNonNestedObserversOutput();
});
test('notification from object change in forward\'s compose element', function() {
// Setup
el.nested = {
obj: {
value: 41
}
};
var obj = {
value: 42
};
el.expectedNestedSubpath = 'nested.obj';
el.expectedNestedValue = obj;
el.expectedNestedObjSubpath = 'nested.obj';
el.expectedNestedObjValue = obj;
el.$.compose.expectedObjSubpath = 'obj';
el.$.compose.expectedObjValue = obj;
el.$.forward.expectedObjSubpath = 'obj';
el.$.forward.expectedObjValue = obj;
el.$.forward.$.compose.expectedObjSubpath = 'obj';
el.$.forward.$.compose.expectedObjValue = obj;
el.clearObserverCounts();
var obj = setupComposedAndGetObject();
// Do the thing
el.$.forward.$.compose.obj = obj;
// Verify
assert.equal(el.observerCounts.nestedSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjChanged, 1);
assert.equal(el.observerCounts.nestedObjSubpathChanged, 1);
assert.equal(el.observerCounts.nestedObjValueChanged, 1);
assert.equal(el.$.compose.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.compose.observerCounts.objValueChanged, 1);
assert.equal(el.$.forward.observerCounts.objSubpathChanged, 1);
assert.equal(el.$.forward.observerCounts.objValueChanged, 1);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.basic.notifyingValue, 42);
assert.equal(el.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42);
assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42);
assert.equal(el.$.basic.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic1.getAttribute('attrvalue'), '42');
assert.equal(el.$.forward.$.compose.$.basic2.getAttribute('attrvalue'), '42');
verifyNonNestedObserversOutput();
});
test('negation', function() {
@ -1335,6 +1044,24 @@ suite('path API', function() {
});
suite('malformed observers', function() {
test('has nice message on failure', function() {
var thrown = false;
try {
Polymer({
is: 'x-broken',
observers: ['foo(missingParenthesis']
});
} catch (e) {
assert.equal(e.message, "Malformed observer expression 'foo(missingParenthesis'");
thrown = true;
}
assert.equal(thrown, true, "No exception thrown when parsing malformed observer");
});
});
</script>
</body>