summaryrefslogtreecommitdiffstats
path: root/toolkit/components/perfmonitoring/tests/browser/browser_addonPerformanceAlerts_2.js
blob: d39c38b1f67c3e29724e63a149d5fb37ef5a0096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"use strict";

/**
 * Tests for PerformanceWatcher watching slow addons.
 */

add_task(function* test_watch_addon_then_install_it() {
  for (let topic of ["burnCPU", "promiseBurnContentCPU", "promiseBurnCPOW"]) {
    let addonId = "addon:test_watch_addons_before_installing" + Math.random();
    let realListener = new AddonListener(addonId, (group, details) => {
      if (group.addonId == addonId) {
        return details.highestJank;
      }
      throw new Error(`I shouldn't have been called with addon ${group.addonId}`);
    });

    info("Now install the add-on, *after* having installed the listener");
    let addon = new AddonBurner(addonId);

    Assert.ok((yield addon.run(topic, 10, realListener)), `5. The real listener was triggered ${topic}`);
    Assert.ok(realListener.result >= addon.jankThreshold, `5. jank is at least ${addon.jankThreshold/1000}ms (${realListener.result}µs) ${topic}`);
    realListener.unregister();
    addon.dispose();
  }
});