gecko-dev/browser/base/content/test/tabs/browser_tabSpinnerProbe.js
Ryan Hunt 3675f2449b Bug 1534395 - Rename nsITabParent to nsIRemoteTab. r=nika,mconley
nsITabParent is exposed to frontend code and is generally used as a representation of a remote tab. We could just rename the interface to nsIBrowserParent and worry about it later, but I think it's better to rename the interface to nsIRemoteTab so that we can later work on splitting the interface away from the PBrowser protocol.

Note: Some frontend code refers to a TabParentId. This commit renames this to RemoteTabId. We need to figure out the purpose of TabId with fission.

Differential Revision: https://phabricator.services.mozilla.com/D28132

--HG--
rename : dom/interfaces/base/nsITabParent.idl => dom/interfaces/base/nsIRemoteTab.idl
extra : rebase_source : 9d8a1790a7bb10195ad063644d1a93d63b2afb72
2019-04-09 15:59:37 -05:00

97 lines
3.3 KiB
JavaScript

"use strict";
/**
* Tests the FX_TAB_SWITCH_SPINNER_VISIBLE_MS and
* FX_TAB_SWITCH_SPINNER_VISIBLE_LONG_MS telemetry probes
*/
const MIN_HANG_TIME = 500; // ms
const MAX_HANG_TIME = 5 * 1000; // ms
/**
* Returns the sum of all values in an array.
* @param {Array} aArray An array of integers
* @return {Number} The sum of the integers in the array
*/
function sum(aArray) {
return aArray.reduce(function(previousValue, currentValue) {
return previousValue + currentValue;
});
}
/**
* Causes the content process for a remote <xul:browser> to run
* some busy JS for aMs milliseconds.
*
* @param {<xul:browser>} browser
* The browser that's running in the content process that we're
* going to hang.
* @param {int} aMs
* The amount of time, in milliseconds, to hang the content process.
*
* @return {Promise}
* Resolves once the hang is done.
*/
function hangContentProcess(browser, aMs) {
return ContentTask.spawn(browser, aMs, async function(ms) {
let then = Date.now();
while (Date.now() - then < ms) {
// Let's burn some CPU...
}
});
}
/**
* A generator intended to be run as a Task. It tests one of the tab spinner
* telemetry probes.
* @param {String} aProbe The probe to test. Should be one of:
* - FX_TAB_SWITCH_SPINNER_VISIBLE_MS
* - FX_TAB_SWITCH_SPINNER_VISIBLE_LONG_MS
*/
async function testProbe(aProbe) {
info(`Testing probe: ${aProbe}`);
let histogram = Services.telemetry.getHistogramById(aProbe);
let delayTime = MIN_HANG_TIME + 1; // Pick a bucket arbitrarily
// The tab spinner does not show up instantly. We need to hang for a little
// bit of extra time to account for the tab spinner delay.
delayTime += gBrowser.selectedTab.linkedBrowser.getTabBrowser()._getSwitcher().TAB_SWITCH_TIMEOUT;
// In order for a spinner to be shown, the tab must have presented before.
let origTab = gBrowser.selectedTab;
let hangTab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
let hangBrowser = hangTab.linkedBrowser;
ok(hangBrowser.isRemoteBrowser, "New tab should be remote.");
ok(hangBrowser.frameLoader.remoteTab.hasPresented, "New tab has presented.");
// Now switch back to the original tab and set up our hang.
await BrowserTestUtils.switchTab(gBrowser, origTab);
let tabHangPromise = hangContentProcess(hangBrowser, delayTime);
histogram.clear();
let hangTabSwitch = BrowserTestUtils.switchTab(gBrowser, hangTab);
await tabHangPromise;
await hangTabSwitch;
// Now we should have a hang in our histogram.
let snapshot = histogram.snapshot();
BrowserTestUtils.removeTab(hangTab);
ok(sum(Object.values(snapshot.values)) > 0,
`Spinner probe should now have a value in some bucket`);
}
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
["dom.ipc.processCount", 1],
// We can interrupt JS to paint now, which is great for
// users, but bad for testing spinners. We temporarily
// disable that feature for this test so that we can
// easily get ourselves into a predictable tab spinner
// state.
["browser.tabs.remote.force-paint", false],
],
});
});
add_task(testProbe.bind(null, "FX_TAB_SWITCH_SPINNER_VISIBLE_MS"));
add_task(testProbe.bind(null, "FX_TAB_SWITCH_SPINNER_VISIBLE_LONG_MS"));