Fix duplicate events when revert in polymer 2
Due to event retargetting, in shadow DOM, event will be fired both from the first element and the shadowroot host. Bug: Issue 11322 Change-Id: I52fbc0fac9dfdaf945dce3da0a266bfe58b0bd38
This commit is contained in:
@@ -51,19 +51,23 @@ limitations under the License.
|
|||||||
test('_handleConfirmTap', () => {
|
test('_handleConfirmTap', () => {
|
||||||
const confirmHandler = sandbox.stub();
|
const confirmHandler = sandbox.stub();
|
||||||
element.addEventListener('confirm', confirmHandler);
|
element.addEventListener('confirm', confirmHandler);
|
||||||
sandbox.stub(element, '_handleConfirmTap');
|
sandbox.spy(element, '_handleConfirmTap');
|
||||||
element.$$('gr-dialog').fire('confirm');
|
element.$$('gr-dialog').fire('confirm');
|
||||||
assert.isTrue(confirmHandler.called);
|
assert.isTrue(confirmHandler.called);
|
||||||
|
assert.isTrue(confirmHandler.calledOnce);
|
||||||
assert.isTrue(element._handleConfirmTap.called);
|
assert.isTrue(element._handleConfirmTap.called);
|
||||||
|
assert.isTrue(element._handleConfirmTap.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_handleCancelTap', () => {
|
test('_handleCancelTap', () => {
|
||||||
const cancelHandler = sandbox.stub();
|
const cancelHandler = sandbox.stub();
|
||||||
element.addEventListener('cancel', cancelHandler);
|
element.addEventListener('cancel', cancelHandler);
|
||||||
sandbox.stub(element, '_handleCancelTap');
|
sandbox.spy(element, '_handleCancelTap');
|
||||||
element.$$('gr-dialog').fire('cancel');
|
element.$$('gr-dialog').fire('cancel');
|
||||||
assert.isTrue(cancelHandler.called);
|
assert.isTrue(cancelHandler.called);
|
||||||
|
assert.isTrue(cancelHandler.calledOnce);
|
||||||
assert.isTrue(element._handleCancelTap.called);
|
assert.isTrue(element._handleCancelTap.called);
|
||||||
|
assert.isTrue(element._handleCancelTap.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_computeItemName function for branches', () => {
|
test('_computeItemName function for branches', () => {
|
||||||
|
@@ -56,6 +56,7 @@
|
|||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this._confirm();
|
this._confirm();
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@
|
|||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('cancel', null, {bubbles: false});
|
this.fire('cancel', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -51,19 +51,26 @@ limitations under the License.
|
|||||||
test('_handleConfirmTap', () => {
|
test('_handleConfirmTap', () => {
|
||||||
const confirmHandler = sandbox.stub();
|
const confirmHandler = sandbox.stub();
|
||||||
element.addEventListener('confirm', confirmHandler);
|
element.addEventListener('confirm', confirmHandler);
|
||||||
sandbox.stub(element, '_confirm');
|
sandbox.spy(element, '_handleConfirmTap');
|
||||||
|
sandbox.spy(element, '_confirm');
|
||||||
element.$$('gr-dialog').fire('confirm');
|
element.$$('gr-dialog').fire('confirm');
|
||||||
assert.isTrue(confirmHandler.called);
|
assert.isTrue(confirmHandler.called);
|
||||||
|
assert.isTrue(confirmHandler.calledOnce);
|
||||||
|
assert.isTrue(element._handleConfirmTap.called);
|
||||||
assert.isTrue(element._confirm.called);
|
assert.isTrue(element._confirm.called);
|
||||||
|
assert.isTrue(element._confirm.called);
|
||||||
|
assert.isTrue(element._confirm.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_handleCancelTap', () => {
|
test('_handleCancelTap', () => {
|
||||||
const cancelHandler = sandbox.stub();
|
const cancelHandler = sandbox.stub();
|
||||||
element.addEventListener('cancel', cancelHandler);
|
element.addEventListener('cancel', cancelHandler);
|
||||||
sandbox.stub(element, '_handleCancelTap');
|
sandbox.spy(element, '_handleCancelTap');
|
||||||
element.$$('gr-dialog').fire('cancel');
|
element.$$('gr-dialog').fire('cancel');
|
||||||
assert.isTrue(cancelHandler.called);
|
assert.isTrue(cancelHandler.called);
|
||||||
|
assert.isTrue(cancelHandler.calledOnce);
|
||||||
assert.isTrue(element._handleCancelTap.called);
|
assert.isTrue(element._handleCancelTap.called);
|
||||||
|
assert.isTrue(element._handleCancelTap.calledOnce);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -39,11 +39,13 @@
|
|||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('confirm', null, {bubbles: false});
|
this.fire('confirm', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('cancel', null, {bubbles: false});
|
this.fire('cancel', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -49,19 +49,23 @@ limitations under the License.
|
|||||||
test('_handleConfirmTap', () => {
|
test('_handleConfirmTap', () => {
|
||||||
const confirmHandler = sandbox.stub();
|
const confirmHandler = sandbox.stub();
|
||||||
element.addEventListener('confirm', confirmHandler);
|
element.addEventListener('confirm', confirmHandler);
|
||||||
sandbox.stub(element, '_handleConfirmTap');
|
sandbox.spy(element, '_handleConfirmTap');
|
||||||
element.$$('gr-dialog').fire('confirm');
|
element.$$('gr-dialog').fire('confirm');
|
||||||
assert.isTrue(confirmHandler.called);
|
assert.isTrue(confirmHandler.called);
|
||||||
|
assert.isTrue(confirmHandler.calledOnce);
|
||||||
assert.isTrue(element._handleConfirmTap.called);
|
assert.isTrue(element._handleConfirmTap.called);
|
||||||
|
assert.isTrue(element._handleConfirmTap.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_handleCancelTap', () => {
|
test('_handleCancelTap', () => {
|
||||||
const cancelHandler = sandbox.stub();
|
const cancelHandler = sandbox.stub();
|
||||||
element.addEventListener('cancel', cancelHandler);
|
element.addEventListener('cancel', cancelHandler);
|
||||||
sandbox.stub(element, '_handleCancelTap');
|
sandbox.spy(element, '_handleCancelTap');
|
||||||
element.$$('gr-dialog').fire('cancel');
|
element.$$('gr-dialog').fire('cancel');
|
||||||
assert.isTrue(cancelHandler.called);
|
assert.isTrue(cancelHandler.called);
|
||||||
|
assert.isTrue(cancelHandler.calledOnce);
|
||||||
assert.isTrue(element._handleCancelTap.called);
|
assert.isTrue(element._handleCancelTap.called);
|
||||||
|
assert.isTrue(element._handleCancelTap.calledOnce);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -79,11 +79,13 @@
|
|||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('confirm', null, {bubbles: false});
|
this.fire('confirm', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('cancel', null, {bubbles: false});
|
this.fire('cancel', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -53,11 +53,13 @@
|
|||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('confirm', null, {bubbles: false});
|
this.fire('confirm', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('cancel', null, {bubbles: false});
|
this.fire('cancel', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -120,6 +120,7 @@
|
|||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.dispatchEvent(new CustomEvent('confirm',
|
this.dispatchEvent(new CustomEvent('confirm',
|
||||||
{detail: {base: this._getSelectedBase()}}));
|
{detail: {base: this._getSelectedBase()}}));
|
||||||
this._text = '';
|
this._text = '';
|
||||||
@@ -127,6 +128,7 @@
|
|||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.dispatchEvent(new CustomEvent('cancel'));
|
this.dispatchEvent(new CustomEvent('cancel'));
|
||||||
this._text = '';
|
this._text = '';
|
||||||
},
|
},
|
||||||
|
@@ -60,11 +60,13 @@
|
|||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('confirm', null, {bubbles: false});
|
this.fire('confirm', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('cancel', null, {bubbles: false});
|
this.fire('cancel', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -56,11 +56,13 @@
|
|||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.dispatchEvent(new CustomEvent('confirm', {bubbles: false}));
|
this.dispatchEvent(new CustomEvent('confirm', {bubbles: false}));
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.dispatchEvent(new CustomEvent('cancel', {bubbles: false}));
|
this.dispatchEvent(new CustomEvent('cancel', {bubbles: false}));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -181,6 +181,7 @@
|
|||||||
|
|
||||||
_handleCloseTap(e) {
|
_handleCloseTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('close', null, {bubbles: false});
|
this.fire('close', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -227,6 +227,7 @@
|
|||||||
|
|
||||||
_handleDownloadTap(e) {
|
_handleDownloadTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new CustomEvent('open-download-dialog', {bubbles: false}));
|
new CustomEvent('open-download-dialog', {bubbles: false}));
|
||||||
},
|
},
|
||||||
@@ -249,6 +250,7 @@
|
|||||||
|
|
||||||
_handleUploadTap(e) {
|
_handleUploadTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new CustomEvent('open-upload-help-dialog', {bubbles: false}));
|
new CustomEvent('open-upload-help-dialog', {bubbles: false}));
|
||||||
},
|
},
|
||||||
|
@@ -88,6 +88,7 @@
|
|||||||
|
|
||||||
_handleCloseTap(e) {
|
_handleCloseTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('close', null, {bubbles: false});
|
this.fire('close', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -77,6 +77,7 @@
|
|||||||
|
|
||||||
_handleCloseTap(e) {
|
_handleCloseTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('close', null, {bubbles: false});
|
this.fire('close', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -71,6 +71,7 @@
|
|||||||
|
|
||||||
_handleCloseTap(e) {
|
_handleCloseTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('close', null, {bubbles: false});
|
this.fire('close', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -330,6 +330,7 @@
|
|||||||
|
|
||||||
_onMobileSearchTap(e) {
|
_onMobileSearchTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('mobile-search', null, {bubbles: false});
|
this.fire('mobile-search', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -47,11 +47,13 @@
|
|||||||
|
|
||||||
_handleConfirmTap(e) {
|
_handleConfirmTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('confirm', {reason: this.message}, {bubbles: false});
|
this.fire('confirm', {reason: this.message}, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('cancel', null, {bubbles: false});
|
this.fire('cancel', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -65,11 +65,13 @@
|
|||||||
if (this.disabled) { return; }
|
if (this.disabled) { return; }
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('confirm', null, {bubbles: false});
|
this.fire('confirm', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleCancelTap(e) {
|
_handleCancelTap(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
this.fire('cancel', null, {bubbles: false});
|
this.fire('cancel', null, {bubbles: false});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user