summaryrefslogtreecommitdiff
path: root/toolkit/devtools/timeline/test/browser_timeline_overview-theme.js
blob: 4a45bef6a59b4bec8a8e74ec171052449410de5a (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
79
80
81
82
83
84
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests if the markers and memory overviews render with the correct
 * theme on load, and rerenders when changed.
 */

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

add_task(function*() {
  let { target, panel } = yield initTimelinePanel("about:blank");
  let { $, EVENTS, TimelineView, TimelineController } = panel.panelWin;

  $("#memory-checkbox").checked = true;

  setTheme("dark");

  yield TimelineController.updateMemoryRecording();
  is(TimelineView.markersOverview.backgroundColor, DARK_BG,
    "correct theme on load for markers.");
  is(TimelineView.memoryOverview.backgroundColor, DARK_BG,
    "correct theme on load for memory.");

  yield TimelineController.toggleRecording();
  ok(true, "Recording has started.");

  yield TimelineController.toggleRecording();
  ok(true, "Recording has ended.");

  let refreshed = Promise.all([
    once(TimelineView.markersOverview, "refresh"),
    once(TimelineView.memoryOverview, "refresh"),
  ]);

  setTheme("light");
  yield refreshed;

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

  refreshed = Promise.all([
    once(TimelineView.markersOverview, "refresh"),
    once(TimelineView.memoryOverview, "refresh"),
  ]);

  setTheme("dark");
  yield refreshed;

  ok(true, "Both memory and markers were rerendered after theme change.");
  is(TimelineView.markersOverview.backgroundColor, DARK_BG,
    "correct theme on after toggle for markers once more.");
  is(TimelineView.memoryOverview.backgroundColor, DARK_BG,
    "correct theme on after toggle for memory once more.");

  refreshed = Promise.all([
    once(TimelineView.markersOverview, "refresh"),
    once(TimelineView.memoryOverview, "refresh"),
  ]);

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

/**
 * Mimics selecting the theme selector in the toolbox;
 * sets the preference and emits an event on gDevTools to trigger
 * the themeing.
 */
function setTheme (newTheme) {
  let oldTheme = Services.prefs.getCharPref("devtools.theme");
  info("Setting `devtools.theme` to \"" + newTheme + "\"");
  Services.prefs.setCharPref("devtools.theme", newTheme);
  gDevTools.emit("pref-changed", {
    pref: "devtools.theme",
    newValue: newTheme,
    oldValue: oldTheme
  });
}