Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2032)

Unified Diff: chrome/browser/resources/bluetooth_internals/snackbar.js

Issue 2602503002: bluetooth: Fix flaky bluetooth internals browser test. (Closed)
Patch Set: Simplify snackbar and test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/webui/bluetooth_internals_browsertest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/bluetooth_internals/snackbar.js
diff --git a/chrome/browser/resources/bluetooth_internals/snackbar.js b/chrome/browser/resources/bluetooth_internals/snackbar.js
index 9cca49e23420cdf81f5cd01551ce2acb0a2e3e16..a13859ba4cf18397059c9f9a2c7d78633fa462a5 100644
--- a/chrome/browser/resources/bluetooth_internals/snackbar.js
+++ b/chrome/browser/resources/bluetooth_internals/snackbar.js
@@ -17,6 +17,7 @@ cr.define('snackbar', function() {
var SnackbarOptions;
/** @const {number} */ var SHOW_DURATION = 5000;
+ /** @const {number} */ var TRANSITION_DURATION = 225;
/**
* Enum of Snackbar types. Used by Snackbar to determine the styling for the
@@ -77,7 +78,7 @@ cr.define('snackbar', function() {
},
/**
- * Shows the Snackbar.
+ * Shows the Snackbar and dispatches the 'showed' event.
*/
show: function() {
this.classList.add('open');
@@ -86,23 +87,33 @@ cr.define('snackbar', function() {
document.addEventListener('contentfocus', this.boundStartTimeout_);
document.addEventListener('contentblur', this.boundStopTimeout_);
+ this.dispatchEvent(new CustomEvent('showed'));
},
/**
* Dismisses the Snackbar. Once the Snackbar is completely hidden, the
- * 'dismissed' event is fired.
+ * 'dismissed' event is fired and the returned Promise is resolved. If the
+ * snackbar is already hidden, a resolved Promise is returned.
+ * @return {!Promise}
*/
dismiss: function() {
- this.addEventListener('webkitTransitionEnd', function(event) {
- if (event.propertyName === 'transform')
+ this.stopTimeout_();
+
+ if (!this.classList.contains('open'))
+ return Promise.resolve();
+
+ return new Promise(function(resolve) {
+ listenOnce(this, 'webkitTransitionEnd', function() {
this.dispatchEvent(new CustomEvent('dismissed'));
- }.bind(this));
+ resolve();
+ }.bind(this));
- ensureTransitionEndEvent(this, SHOW_DURATION);
- this.classList.remove('open');
+ ensureTransitionEndEvent(this, TRANSITION_DURATION);
+ this.classList.remove('open');
- document.removeEventListener('contentfocus', this.boundStartTimeout_);
- document.removeEventListener('contentblur', this.boundStopTimeout_);
+ document.removeEventListener('contentfocus', this.boundStartTimeout_);
+ document.removeEventListener('contentblur', this.boundStopTimeout_);
+ }.bind(this));
},
/**
@@ -214,7 +225,8 @@ cr.define('snackbar', function() {
*/
Snackbar.dismiss = function(clearQueue) {
if (clearQueue) Snackbar.queue_ = [];
- if (Snackbar.current_) Snackbar.current_.dismiss();
+ if (Snackbar.current_) return Snackbar.current_.dismiss();
+ return Promise.resolve();
};
« no previous file with comments | « no previous file | chrome/test/data/webui/bluetooth_internals_browsertest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698