Bug 1402256 - Add WebExtensions API to “warm up” a tab r=mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D71873
This commit is contained in:
Mélanie Chauvel (ariasuni) 2020-05-26 02:29:45 +00:00
Родитель 7e4894ae72
Коммит a09b2821db
4 изменённых файлов: 62 добавлений и 0 удалений

Просмотреть файл

@ -912,6 +912,12 @@ this.tabs = class extends ExtensionAPI {
nativeTab.linkedBrowser.reloadWithFlags(flags);
},
async warmup(tabId) {
let nativeTab = tabTracker.getTab(tabId);
let tabbrowser = nativeTab.ownerGlobal.gBrowser;
tabbrowser.warmupTab(nativeTab);
},
async get(tabId) {
return tabManager.get(tabId).convert();
},

Просмотреть файл

@ -1023,6 +1023,21 @@
}
]
},
{
"name": "warmup",
"type": "function",
"description": "Warm up a tab",
"async": "true",
"parameters": [
{
"type": "integer",
"name": "tabId",
"minimum": 0,
"optional": false,
"description": "The ID of the tab to warm up."
}
]
},
{
"name": "remove",
"type": "function",

Просмотреть файл

@ -270,6 +270,7 @@ skip-if = os == 'mac' # Save as PDF not supported on Mac OS X
[browser_ext_tabs_update.js]
[browser_ext_tabs_update_highlighted.js]
[browser_ext_tabs_update_url.js]
[browser_ext_tabs_warmup.js]
[browser_ext_tabs_zoom.js]
[browser_ext_themes_validation.js]
[browser_ext_topSites.js]

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
add_task(async function testWarmupTab() {
let tab1 = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"http://example.net/"
);
let tab2 = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"about:blank"
);
Assert.ok(!tab1.linkedBrowser.renderLayers, "tab is not warm yet");
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["tabs"],
},
background: async function() {
let backgroundTab = (
await browser.tabs.query({
lastFocusedWindow: true,
url: "http://example.net/",
active: false,
})
)[0];
await browser.tabs.warmup(backgroundTab.id);
browser.test.notifyPass("tabs.warmup");
},
});
await extension.startup();
await extension.awaitFinish("tabs.warmup");
Assert.ok(tab1.linkedBrowser.renderLayers, "tab has been warmed up");
gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2);
await extension.unload();
});