Commit 258b0c4b authored by dtseng's avatar dtseng Committed by Commit bot

Fix tests flakes.

BUG=623727
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2103053006
Cr-Commit-Position: refs/heads/master@{#403227}
parent f23de8c5
...@@ -25,6 +25,9 @@ BackgroundTest.prototype = { ...@@ -25,6 +25,9 @@ BackgroundTest.prototype = {
ChromeVoxState.instance.toggleNext(true); ChromeVoxState.instance.toggleNext(true);
window.RoleType = chrome.automation.RoleType; window.RoleType = chrome.automation.RoleType;
window.doCmd = this.doCmd; window.doCmd = this.doCmd;
// Reset notifications so only explicit mode changes can cause them to trigger.
Notifications.reset();
}, },
/** /**
......
...@@ -35,10 +35,8 @@ UpdateNotification.prototype = { ...@@ -35,10 +35,8 @@ UpdateNotification.prototype = {
if (!this.shouldShow()) if (!this.shouldShow())
return; return;
chrome.notifications.create('update', this.data); chrome.notifications.create('update', this.data);
chrome.notifications.onClicked.addListener( chrome.notifications.onClicked.addListener(this.onClicked);
this.onClicked.bind(this)); chrome.notifications.onClosed.addListener(this.onClosed);
chrome.notifications.onClosed.addListener(
this.onClosed.bind(this));
}, },
/** /**
...@@ -55,24 +53,42 @@ UpdateNotification.prototype = { ...@@ -55,24 +53,42 @@ UpdateNotification.prototype = {
*/ */
onClosed: function(id) { onClosed: function(id) {
localStorage['notifications_update_notification_shown'] = true; localStorage['notifications_update_notification_shown'] = true;
},
/**
* Removes all listeners added by this object.
*/
removeAllListeners: function() {
chrome.notifications.onClicked.removeListener(this.onClicked);
chrome.notifications.onClosed.removeListener(this.onClosed);
} }
}; };
/**
* Set after an update is shown.
* @type {UpdateNotification}
*/
Notifications.currentUpdate;
/** /**
* Runs notifications that should be shown for startup. * Runs notifications that should be shown for startup.
*/ */
Notifications.onStartup = function() { Notifications.onStartup = function() {
return;
// Only run on background page. // Only run on background page.
if (document.location.href.indexOf('background.html') == -1) if (document.location.href.indexOf('background.html') == -1)
return; return;
new UpdateNotification().show(); Notifications.reset();
Notifications.currentUpdate = new UpdateNotification();
Notifications.currentUpdate.show();
}; };
/** /**
* Runs notifications that should be shown for mode changes. * Runs notifications that should be shown for mode changes.
*/ */
Notifications.onModeChange = function() { Notifications.onModeChange = function() {
return;
// Only run on background page. // Only run on background page.
if (document.location.href.indexOf('background.html') == -1) if (document.location.href.indexOf('background.html') == -1)
return; return;
...@@ -80,5 +96,16 @@ Notifications.onModeChange = function() { ...@@ -80,5 +96,16 @@ Notifications.onModeChange = function() {
if (ChromeVoxState.instance.mode !== ChromeVoxMode.FORCE_NEXT) if (ChromeVoxState.instance.mode !== ChromeVoxMode.FORCE_NEXT)
return; return;
new UpdateNotification().show(); Notifications.reset();
Notifications.currentUpdate = new UpdateNotification();
Notifications.currentUpdate.show();
};
/**
* Resets to a clean state. Future events will trigger update notifications.
*/
Notifications.reset = function() {
if (Notifications.currentUpdate)
Notifications.currentUpdate.removeAllListeners();
delete localStorage['notifications_update_notification_shown'];
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment