--- a/services/sync/tps/extensions/tps/resource/tps.jsm
+++ b/services/sync/tps/extensions/tps/resource/tps.jsm
@@ -310,40 +310,24 @@ var TPS = {
Logger.logInfo("window finished loading");
this.FinishAsyncOperation();
});
break;
}
Logger.logPass("executing action " + action.toUpperCase() + " on windows");
},
- HandleTabs(tabs, action) {
- this._tabsAdded = tabs.length;
- this._tabsFinished = 0;
+ async HandleTabs(tabs, action) {
for (let tab of tabs) {
Logger.logInfo("executing action " + action.toUpperCase() +
" on tab " + JSON.stringify(tab));
switch (action) {
case ACTION_ADD:
- // When adding tabs, we keep track of how many tabs we're adding,
- // and wait until we've received that many onload events from our
- // new tabs before continuing
- let taburi = tab.uri;
- BrowserTabs.Add(tab.uri, () => {
- this._tabsFinished++;
- Logger.logInfo("tab for " + taburi + " finished loading");
- if (this._tabsFinished == this._tabsAdded) {
- Logger.logInfo("all tabs loaded, continuing...");
-
- // Wait some time before continuing to be sure tabs can be synced,
- // otherwise we can get 'error locating tab' (bug 1383832).
- CommonUtils.namedTimer(() => {
- this.FinishAsyncOperation();
- }, 2500, this, "postTabsOpening");
- }
+ await new Promise(resolve => {
+ BrowserTabs.Add(tab.uri, resolve);
});
break;
case ACTION_VERIFY:
Logger.AssertTrue(typeof(tab.profile) != "undefined",
"profile must be defined when verifying tabs");
Logger.AssertTrue(
BrowserTabs.Find(tab.uri, tab.title, tab.profile), "error locating tab");
break;
@@ -353,16 +337,24 @@ var TPS = {
Logger.AssertTrue(
!BrowserTabs.Find(tab.uri, tab.title, tab.profile),
"tab found which was expected to be absent");
break;
default:
Logger.AssertTrue(false, "invalid action: " + action);
}
}
+ if (action === ACTION_ADD) {
+ // Ideally we'd do the right thing (probably resolving bug 1383832, or
+ // waiting for sessionstore events in TPS), but waiting enough time to
+ // be reasonably confident the sessionstore time has fired is simpler.
+ // Without this timeout, we are likely to see "error locating tab"
+ // on subsequent syncs.
+ await new Promise(resolve => setTimeout(resolve, 2500));
+ }
Logger.logPass("executing action " + action.toUpperCase() + " on tabs");
},
HandlePrefs(prefs, action) {
for (let pref of prefs) {
Logger.logInfo("executing action " + action.toUpperCase() +
" on pref " + JSON.stringify(pref));
let preference = new Preference(pref);
@@ -1307,25 +1299,24 @@ var Prefs = {
TPS.HandlePrefs(prefs, ACTION_MODIFY);
},
verify: function Prefs__verify(prefs) {
TPS.HandlePrefs(prefs, ACTION_VERIFY);
}
};
var Tabs = {
- add: function Tabs__add(tabs) {
- TPS.StartAsyncOperation();
- TPS.HandleTabs(tabs, ACTION_ADD);
+ async add(tabs) {
+ await TPS.HandleTabs(tabs, ACTION_ADD);
},
- verify: function Tabs__verify(tabs) {
- TPS.HandleTabs(tabs, ACTION_VERIFY);
+ async verify(tabs) {
+ await TPS.HandleTabs(tabs, ACTION_VERIFY);
},
- verifyNot: function Tabs__verifyNot(tabs) {
- TPS.HandleTabs(tabs, ACTION_VERIFY_NOT);
+ async verifyNot(tabs) {
+ await TPS.HandleTabs(tabs, ACTION_VERIFY_NOT);
}
};
var Windows = {
add: function Window__add(aWindow) {
TPS.StartAsyncOperation();
TPS.HandleWindows(aWindow, ACTION_ADD);
},