File: test_TelemetryLockCount.js

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (63 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download | duplicates (4)
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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
*/
/* A testcase to make sure reading the failed profile lock count works.  */

const LOCK_FILE_NAME = "Telemetry.FailedProfileLocks.txt";
const N_FAILED_LOCKS = 10;

// Constants from prio.h for nsIFileOutputStream.init
const PR_WRONLY = 0x2;
const PR_CREATE_FILE = 0x8;
const PR_TRUNCATE = 0x20;
const RW_OWNER = parseInt("0600", 8);

function write_string_to_file(file, contents) {
  let ostream = Cc[
    "@mozilla.org/network/safe-file-output-stream;1"
  ].createInstance(Ci.nsIFileOutputStream);
  ostream.init(
    file,
    PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
    RW_OWNER,
    ostream.DEFER_OPEN
  );
  ostream.write(contents, contents.length);
  ostream.QueryInterface(Ci.nsISafeOutputStream).finish();
  ostream.close();
}

function construct_file() {
  let profileDirectory = Services.dirsvc.get("ProfD", Ci.nsIFile);
  let file = profileDirectory.clone();
  file.append(LOCK_FILE_NAME);
  return file;
}

function run_test() {
  do_get_profile();
  Services.fog.initializeFOG();

  Assert.equal(Services.telemetry.failedProfileLockCount, 0);
  Assert.equal(Glean.profileLock.failedLockCount.testGetValue(), null);

  write_string_to_file(construct_file(), N_FAILED_LOCKS.toString());

  // Make sure that we're not eagerly reading the count now that the
  // file exists.
  Assert.equal(Services.telemetry.failedProfileLockCount, 0);
  Assert.equal(Glean.profileLock.failedLockCount.testGetValue(), null);

  do_test_pending();
  Services.telemetry.asyncFetchTelemetryData(actual_test);
}

function actual_test() {
  Assert.equal(Services.telemetry.failedProfileLockCount, N_FAILED_LOCKS);
  Assert.equal(
    Glean.profileLock.failedLockCount.testGetValue(),
    N_FAILED_LOCKS
  );
  Assert.ok(!construct_file().exists());
  do_test_finished();
}