summaryrefslogtreecommitdiffstats
path: root/testing/talos/talos/tests/twinopen/api.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/talos/talos/tests/twinopen/api.js')
-rw-r--r--testing/talos/talos/tests/twinopen/api.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/testing/talos/talos/tests/twinopen/api.js b/testing/talos/talos/tests/twinopen/api.js
new file mode 100644
index 0000000000..e991a7bdd3
--- /dev/null
+++ b/testing/talos/talos/tests/twinopen/api.js
@@ -0,0 +1,70 @@
+"use strict";
+
+/* globals AppConstants, Services */
+
+ChromeUtils.defineESModuleGetters(this, {
+ TalosParentProfiler: "resource://talos-powers/TalosParentProfiler.sys.mjs",
+});
+
+var OPENER_DELAY = 1000; // ms delay between tests
+
+async function openDelay(win) {
+ return new Promise(resolve => {
+ win.setTimeout(resolve, OPENER_DELAY);
+ });
+}
+
+function waitForBrowserPaint() {
+ return new Promise(resolve => {
+ let observer = {
+ observe(doc) {
+ if (
+ !doc.location ||
+ doc.location.href != AppConstants.BROWSER_CHROME_URL
+ ) {
+ return;
+ }
+ Services.obs.removeObserver(observer, "document-element-inserted");
+ doc.ownerGlobal.addEventListener(
+ "MozAfterPaint",
+ evt => {
+ resolve(
+ doc.ownerGlobal.performance.timing.fetchStart + evt.paintTimeStamp
+ );
+ },
+ { once: true }
+ );
+ },
+ };
+ Services.obs.addObserver(observer, "document-element-inserted");
+ });
+}
+
+async function startTest(context) {
+ await TalosParentProfiler.resume("twinopen", true);
+ Cu.forceGC();
+ Cu.forceCC();
+ Cu.forceShrinkingGC();
+ let win = context.appWindow;
+ await openDelay(win);
+ let mozAfterPaint = waitForBrowserPaint();
+
+ // We have to compare time measurements across two windows so we must use
+ // the absolute time.
+ let start = win.performance.timing.fetchStart + win.performance.now();
+ let newWin = win.OpenBrowserWindow();
+ let end = await mozAfterPaint;
+ newWin.close();
+ return end - start;
+}
+
+/* globals ExtensionAPI */
+this.twinopen = class extends ExtensionAPI {
+ getAPI(context) {
+ return {
+ twinopen: {
+ startTest: () => startTest(context),
+ },
+ };
+ }
+};