зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1559216 - Let tabs API wait until tab has been restored r=zombie
Differential Revision: https://phabricator.services.mozilla.com/D37323 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
705b5ce214
Коммит
b1082cb25d
|
@ -100,6 +100,9 @@ function showHiddenTabs(id) {
|
|||
|
||||
let tabListener = {
|
||||
tabReadyInitialized: false,
|
||||
// Map[tab -> Promise]
|
||||
tabBlockedPromises: new WeakMap(),
|
||||
// Map[tab -> Deferred]
|
||||
tabReadyPromises: new WeakMap(),
|
||||
initializingTabs: new WeakSet(),
|
||||
|
||||
|
@ -128,6 +131,17 @@ let tabListener = {
|
|||
}
|
||||
},
|
||||
|
||||
blockTabUntilRestored(nativeTab) {
|
||||
let promise = ExtensionUtils.promiseEvent(nativeTab, "SSTabRestored").then(
|
||||
({ target }) => {
|
||||
this.tabBlockedPromises.delete(target);
|
||||
return target;
|
||||
}
|
||||
);
|
||||
|
||||
this.tabBlockedPromises.set(nativeTab, promise);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves when the tab is ready.
|
||||
* Tabs created via the `tabs.create` method are "ready" once the location
|
||||
|
@ -140,6 +154,10 @@ let tabListener = {
|
|||
awaitTabReady(nativeTab) {
|
||||
let deferred = this.tabReadyPromises.get(nativeTab);
|
||||
if (!deferred) {
|
||||
let promise = this.tabBlockedPromises.get(nativeTab);
|
||||
if (promise) {
|
||||
return promise;
|
||||
}
|
||||
deferred = PromiseUtils.defer();
|
||||
if (
|
||||
!this.initializingTabs.has(nativeTab) &&
|
||||
|
@ -1081,6 +1099,8 @@ this.tabs = class extends ExtensionAPI {
|
|||
let gBrowser = nativeTab.ownerGlobal.gBrowser;
|
||||
let newTab = gBrowser.duplicateTab(nativeTab);
|
||||
|
||||
tabListener.blockTabUntilRestored(newTab);
|
||||
|
||||
return new Promise(resolve => {
|
||||
// We need to use SSTabRestoring because any attributes set before
|
||||
// are ignored. SSTabRestored is too late and results in a jump in
|
||||
|
|
|
@ -182,7 +182,8 @@ add_task(async function testDuplicateResolvePromiseRightAway() {
|
|||
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
permissions: ["tabs"],
|
||||
// The host permission matches the above URL. No :8888 due to bug 1468162.
|
||||
permissions: ["tabs", "http://mochi.test/"],
|
||||
},
|
||||
|
||||
background: async function() {
|
||||
|
@ -208,6 +209,12 @@ add_task(async function testDuplicateResolvePromiseRightAway() {
|
|||
resolvedRightAway = true;
|
||||
}
|
||||
|
||||
// Regression test for bug 1559216: APIs such as tabs.executeScript
|
||||
// should be queued until tabs.duplicate has restored the tab.
|
||||
let code = "document.URL";
|
||||
let [result] = await browser.tabs.executeScript(tab.id, { code });
|
||||
browser.test.assertEq(tab.url, result, "executeScript result");
|
||||
|
||||
await browser.tabs.remove([tabs[1].id, tab.id]);
|
||||
if (resolvedRightAway) {
|
||||
browser.test.notifyPass("tabs.duplicate.resolvePromiseRightAway");
|
||||
|
|
Загрузка…
Ссылка в новой задаче