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:
Tao Zhou
2019-08-14 17:41:26 +02:00
parent d5e6101a8e
commit d8c2e3b1c8
18 changed files with 46 additions and 6 deletions

View File

@@ -51,19 +51,23 @@ limitations under the License.
test('_handleConfirmTap', () => {
const confirmHandler = sandbox.stub();
element.addEventListener('confirm', confirmHandler);
sandbox.stub(element, '_handleConfirmTap');
sandbox.spy(element, '_handleConfirmTap');
element.$$('gr-dialog').fire('confirm');
assert.isTrue(confirmHandler.called);
assert.isTrue(confirmHandler.calledOnce);
assert.isTrue(element._handleConfirmTap.called);
assert.isTrue(element._handleConfirmTap.calledOnce);
});
test('_handleCancelTap', () => {
const cancelHandler = sandbox.stub();
element.addEventListener('cancel', cancelHandler);
sandbox.stub(element, '_handleCancelTap');
sandbox.spy(element, '_handleCancelTap');
element.$$('gr-dialog').fire('cancel');
assert.isTrue(cancelHandler.called);
assert.isTrue(cancelHandler.calledOnce);
assert.isTrue(element._handleCancelTap.called);
assert.isTrue(element._handleCancelTap.calledOnce);
});
test('_computeItemName function for branches', () => {

View File

@@ -56,6 +56,7 @@
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this._confirm();
},
@@ -65,6 +66,7 @@
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
},
});

View File

@@ -51,19 +51,26 @@ limitations under the License.
test('_handleConfirmTap', () => {
const confirmHandler = sandbox.stub();
element.addEventListener('confirm', confirmHandler);
sandbox.stub(element, '_confirm');
sandbox.spy(element, '_handleConfirmTap');
sandbox.spy(element, '_confirm');
element.$$('gr-dialog').fire('confirm');
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.calledOnce);
});
test('_handleCancelTap', () => {
const cancelHandler = sandbox.stub();
element.addEventListener('cancel', cancelHandler);
sandbox.stub(element, '_handleCancelTap');
sandbox.spy(element, '_handleCancelTap');
element.$$('gr-dialog').fire('cancel');
assert.isTrue(cancelHandler.called);
assert.isTrue(cancelHandler.calledOnce);
assert.isTrue(element._handleCancelTap.called);
assert.isTrue(element._handleCancelTap.calledOnce);
});
});
</script>

View File

@@ -39,11 +39,13 @@
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('confirm', null, {bubbles: false});
},
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
},
});

View File

@@ -49,19 +49,23 @@ limitations under the License.
test('_handleConfirmTap', () => {
const confirmHandler = sandbox.stub();
element.addEventListener('confirm', confirmHandler);
sandbox.stub(element, '_handleConfirmTap');
sandbox.spy(element, '_handleConfirmTap');
element.$$('gr-dialog').fire('confirm');
assert.isTrue(confirmHandler.called);
assert.isTrue(confirmHandler.calledOnce);
assert.isTrue(element._handleConfirmTap.called);
assert.isTrue(element._handleConfirmTap.calledOnce);
});
test('_handleCancelTap', () => {
const cancelHandler = sandbox.stub();
element.addEventListener('cancel', cancelHandler);
sandbox.stub(element, '_handleCancelTap');
sandbox.spy(element, '_handleCancelTap');
element.$$('gr-dialog').fire('cancel');
assert.isTrue(cancelHandler.called);
assert.isTrue(cancelHandler.calledOnce);
assert.isTrue(element._handleCancelTap.called);
assert.isTrue(element._handleCancelTap.calledOnce);
});
});
</script>

View File

@@ -79,11 +79,13 @@
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('confirm', null, {bubbles: false});
},
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
},

View File

@@ -53,11 +53,13 @@
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('confirm', null, {bubbles: false});
},
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
},

View File

@@ -120,6 +120,7 @@
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this.dispatchEvent(new CustomEvent('confirm',
{detail: {base: this._getSelectedBase()}}));
this._text = '';
@@ -127,6 +128,7 @@
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.dispatchEvent(new CustomEvent('cancel'));
this._text = '';
},

View File

@@ -60,11 +60,13 @@
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('confirm', null, {bubbles: false});
},
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
},
});

View File

@@ -56,11 +56,13 @@
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this.dispatchEvent(new CustomEvent('confirm', {bubbles: false}));
},
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.dispatchEvent(new CustomEvent('cancel', {bubbles: false}));
},
});

View File

@@ -181,6 +181,7 @@
_handleCloseTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('close', null, {bubbles: false});
},

View File

@@ -227,6 +227,7 @@
_handleDownloadTap(e) {
e.preventDefault();
e.stopPropagation();
this.dispatchEvent(
new CustomEvent('open-download-dialog', {bubbles: false}));
},
@@ -249,6 +250,7 @@
_handleUploadTap(e) {
e.preventDefault();
e.stopPropagation();
this.dispatchEvent(
new CustomEvent('open-upload-help-dialog', {bubbles: false}));
},

View File

@@ -88,6 +88,7 @@
_handleCloseTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('close', null, {bubbles: false});
},

View File

@@ -77,6 +77,7 @@
_handleCloseTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('close', null, {bubbles: false});
},

View File

@@ -71,6 +71,7 @@
_handleCloseTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('close', null, {bubbles: false});
},

View File

@@ -330,6 +330,7 @@
_onMobileSearchTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('mobile-search', null, {bubbles: false});
},

View File

@@ -47,11 +47,13 @@
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('confirm', {reason: this.message}, {bubbles: false});
},
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
},
});

View File

@@ -65,11 +65,13 @@
if (this.disabled) { return; }
e.preventDefault();
e.stopPropagation();
this.fire('confirm', null, {bubbles: false});
},
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
},