summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/browser_perf-theme-toggle.js
blob: b866e59b6a96c312df8cc0f8cd03de2024a62935 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* eslint-disable */
/**
 * Tests if the markers and memory overviews render with the correct
 * theme on load, and rerenders when changed.
 */

const { setTheme } = require("devtools/client/shared/theme");

const LIGHT_BG = "white";
const DARK_BG = "#14171a";

setTheme("dark");
Services.prefs.setBoolPref(MEMORY_PREF, false);

requestLongerTimeout(2);

async function spawnTest() {
  let { panel } = await initPerformance(SIMPLE_URL);
  let { EVENTS, $, OverviewView, document: doc } = panel.panelWin;

  await startRecording(panel);
  let markers = OverviewView.graphs.get("timeline");
  is(markers.backgroundColor, DARK_BG,
    "correct theme on load for markers.");
  await stopRecording(panel);

  let refreshed = once(markers, "refresh");
  setTheme("light");
  await refreshed;

  ok(true, "markers were rerendered after theme change.");
  is(markers.backgroundColor, LIGHT_BG,
    "correct theme on after toggle for markers.");

  // reset back to dark
  refreshed = once(markers, "refresh");
  setTheme("dark");
  await refreshed;

  info("Testing with memory overview");

  Services.prefs.setBoolPref(MEMORY_PREF, true);

  await startRecording(panel);
  let memory = OverviewView.graphs.get("memory");
  is(memory.backgroundColor, DARK_BG,
    "correct theme on load for memory.");
  await stopRecording(panel);

  refreshed = Promise.all([
    once(markers, "refresh"),
    once(memory, "refresh"),
  ]);
  setTheme("light");
  await refreshed;

  ok(true, "Both memory and markers were rerendered after theme change.");
  is(markers.backgroundColor, LIGHT_BG,
    "correct theme on after toggle for markers.");
  is(memory.backgroundColor, LIGHT_BG,
    "correct theme on after toggle for memory.");

  refreshed = Promise.all([
    once(markers, "refresh"),
    once(memory, "refresh"),
  ]);

  // Set theme back to light
  setTheme("light");
  await refreshed;

  await teardown(panel);
  finish();
}
/* eslint-enable */