summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/browser/browser_perf-recording-actor-01.js
blob: 683493121af5761ba2e247659880dee56d70799d (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests the state of a recording rec from start to finish for recording,
 * completed, and rec data.
 */

const { PerformanceFront } = require("devtools/shared/fronts/performance");

add_task(function* () {
  let browser = yield addTab(MAIN_DOMAIN + "doc_perf.html");
  let doc = browser.contentDocument;

  initDebuggerServer();
  let client = new DebuggerClient(DebuggerServer.connectPipe());
  let form = yield connectDebuggerClient(client);
  let front = PerformanceFront(client, form);
  yield front.connect();

  let rec = yield front.startRecording({ withMarkers: true, withTicks: true, withMemory: true });
  ok(rec.isRecording(), "RecordingModel is recording when created");
  yield busyWait(100);
  yield waitUntil(() => rec.getMemory().length);
  ok(true, "RecordingModel populates memory while recording");
  yield waitUntil(() => rec.getTicks().length);
  ok(true, "RecordingModel populates ticks while recording");
  yield waitUntil(() => rec.getMarkers().length);
  ok(true, "RecordingModel populates markers while recording");

  ok(!rec.isCompleted(), "RecordingModel is not completed when still recording");

  let stopping = once(front, "recording-stopping");
  let stopped = once(front, "recording-stopped");
  front.stopRecording(rec);

  yield stopping;
  ok(!rec.isRecording(), "on 'recording-stopping', model is no longer recording");
  // This handler should be called BEFORE "recording-stopped" is called, as
  // there is some delay, but in the event where "recording-stopped" finishes
  // before we check here, ensure that we're atleast in the right state
  if (rec.getProfile()) {
    ok(rec.isCompleted(), "recording is completed once it has profile data");
  } else {
    ok(!rec.isCompleted(), "recording is not yet completed on 'recording-stopping'");
    ok(rec.isFinalizing(), "recording is considered finalizing between 'recording-stopping' and 'recording-stopped'");
  }

  yield stopped;
  ok(!rec.isRecording(), "on 'recording-stopped', model is still no longer recording");
  ok(rec.isCompleted(), "on 'recording-stopped', model is considered 'complete'");

  checkSystemInfo(rec, "Host");
  checkSystemInfo(rec, "Client");

  // Export and import a rec, and ensure it has the correct state.
  let file = FileUtils.getFile("TmpD", ["tmpprofile.json"]);
  file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("666", 8));
  yield rec.exportRecording(file);

  let importedModel = yield front.importRecording(file);

  ok(importedModel.isCompleted(), "All imported recordings should be completed");
  ok(!importedModel.isRecording(), "All imported recordings should not be recording");
  ok(importedModel.isImported(), "All imported recordings should be considerd imported");

  checkSystemInfo(importedModel, "Host");
  checkSystemInfo(importedModel, "Client");

  yield front.destroy();
  yield client.close();
  gBrowser.removeCurrentTab();
});

function checkSystemInfo(recording, type) {
  let data = recording[`get${type}SystemInfo`]();
  for (let field of ["appid", "apptype", "vendor", "name", "version"]) {
    ok(data[field], `get${type}SystemInfo() has ${field} property`);
  }
}