summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/remote-debugging/test/xpcshell/test_version_checker.js
blob: 92f7d54a1e8f3f5327766574d99b391d392d71ee (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* global equal */

"use strict";

const {
  _compareVersionCompatibility,
  checkVersionCompatibility,
  COMPATIBILITY_STATUS,
} = require("resource://devtools/client/shared/remote-debugging/version-checker.js");

const TEST_DATA = [
  {
    description: "same build date and same version number",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190131000000",
    runtimeVersion: "60.0",
    expected: COMPATIBILITY_STATUS.COMPATIBLE,
  },
  {
    description: "same build date and older version in range (-1)",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190131000000",
    runtimeVersion: "59.0",
    expected: COMPATIBILITY_STATUS.COMPATIBLE,
  },
  {
    description: "same build date and older version in range (-2)",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190131000000",
    runtimeVersion: "58.0",
    expected: COMPATIBILITY_STATUS.COMPATIBLE,
  },
  {
    description: "same build date and older version in range (-2 Nightly)",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190131000000",
    runtimeVersion: "58.0a1",
    expected: COMPATIBILITY_STATUS.COMPATIBLE,
  },
  {
    description: "same build date and older version out of range (-3)",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190131000000",
    runtimeVersion: "57.0",
    expected: COMPATIBILITY_STATUS.TOO_OLD,
  },
  {
    description: "same build date and newer version out of range (+1)",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190131000000",
    runtimeVersion: "61.0",
    expected: COMPATIBILITY_STATUS.TOO_RECENT,
  },
  {
    description: "same major version and build date in range (-10 days)",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190121000000",
    runtimeVersion: "60.0",
    expected: COMPATIBILITY_STATUS.COMPATIBLE,
  },
  {
    description: "same major version and build date in range (+2 days)",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190202000000",
    runtimeVersion: "60.0",
    expected: COMPATIBILITY_STATUS.COMPATIBLE,
  },
  {
    description: "same major version and build date out of range (+8 days)",
    localBuildId: "20190131000000",
    localVersion: "60.0",
    runtimeBuildId: "20190208000000",
    runtimeVersion: "60.0",
    expected: COMPATIBILITY_STATUS.TOO_RECENT,
  },
  {
    description:
      "fennec 68 compatibility error not raised for 68 -> 68 Android",
    localBuildId: "20190131000000",
    localVersion: "68.0",
    runtimeBuildId: "20190202000000",
    runtimeVersion: "68.0",
    runtimeOs: "Android",
    expected: COMPATIBILITY_STATUS.COMPATIBLE,
  },
  {
    description:
      "fennec 68 compatibility error not raised for 70 -> 68 Android",
    localBuildId: "20190131000000",
    localVersion: "70.0",
    runtimeBuildId: "20190202000000",
    runtimeVersion: "68.0",
    runtimeOs: "Android",
    expected: COMPATIBILITY_STATUS.COMPATIBLE,
  },
  {
    description: "fennec 68 compatibility error raised for 71 -> 68 Android",
    localBuildId: "20190131000000",
    localVersion: "71.0",
    runtimeBuildId: "20190202000000",
    runtimeVersion: "68.0",
    runtimeOs: "Android",
    expected: COMPATIBILITY_STATUS.TOO_OLD_FENNEC,
  },
  {
    description:
      "fennec 68 compatibility error not raised for 71 -> 68 non-Android",
    localBuildId: "20190131000000",
    localVersion: "71.0",
    runtimeBuildId: "20190202000000",
    runtimeVersion: "68.0",
    runtimeOs: "NotAndroid",
    expected: COMPATIBILITY_STATUS.TOO_OLD,
  },
];

add_task(async function testVersionChecker() {
  for (const testData of TEST_DATA) {
    const localDescription = {
      appbuildid: testData.localBuildId,
      platformversion: testData.localVersion,
    };

    const runtimeDescription = {
      appbuildid: testData.runtimeBuildId,
      platformversion: testData.runtimeVersion,
      os: testData.runtimeOs,
    };

    const report = _compareVersionCompatibility(
      localDescription,
      runtimeDescription
    );
    equal(
      report.status,
      testData.expected,
      "Expected status for test: " + testData.description
    );
  }
});

add_task(async function testVersionCheckWithVeryOldClient() {
  // Use an empty object as devtools client, calling any method on it will fail.
  const emptyClient = {};
  const report = await checkVersionCompatibility(emptyClient);
  equal(
    report.status,
    COMPATIBILITY_STATUS.TOO_OLD,
    "Report status too old if devtools client is not implementing expected interface"
  );
});