REGRESSION(r230960): Browser tests under TimeSeriesChart fetchMeasurementSets all...
[WebKit-https.git] / Websites / perf.webkit.org / unit-tests / commit-log-tests.js
1 'use strict';
2
3 const assert = require('assert');
4
5 require('../tools/js/v3-models.js');
6 const BrowserPrivilegedAPI = require('../public/v3/privileged-api.js').PrivilegedAPI;
7 const MockModels = require('./resources/mock-v3-models.js').MockModels;
8 const MockRemoteAPI = require('../unit-tests/resources/mock-remote-api.js').MockRemoteAPI;
9
10 function webkitCommit()
11 {
12     return new CommitLog(1, {
13         repository: MockModels.webkit,
14         revision: '200805',
15         time: +(new Date('2016-05-13T00:55:57.841344Z')),
16     });
17 }
18
19 function oldWebKitCommit()
20 {
21     return new CommitLog(2, {
22         repository: MockModels.webkit,
23         revision: '200574',
24         time: +(new Date('2016-05-09T14:59:23.553767Z')),
25     });
26 }
27
28 function gitWebKitCommit()
29 {
30     return new CommitLog(3, {
31         repository: MockModels.webkit,
32         revision: '6f8b0dbbda95a440503b88db1dd03dad3a7b07fb',
33         time: +(new Date('2016-05-13T00:55:57.841344Z')),
34     });
35 }
36
37 function oldGitWebKitCommit()
38 {
39     return new CommitLog(4, {
40         repository: MockModels.webkit,
41         revision: 'ffda14e6db0746d10d0f050907e4a7325851e502',
42         time: +(new Date('2016-05-09T14:59:23.553767Z')),
43     });
44 }
45
46 function osxCommit()
47 {
48     return new CommitLog(5, {
49         repository: MockModels.osx,
50         revision: '10.11.4 15E65',
51         time: null,
52         order: 1504065
53     });
54 }
55
56 function oldOSXCommit()
57 {
58     return new CommitLog(6, {
59         repository: MockModels.osx,
60         revision: '10.11.3 15D21',
61         time: null,
62         order: 1503021
63     });
64 }
65
66 function commitWithoutOwnedCommits()
67 {
68     return new CommitLog(6, {
69         repository: MockModels.ownerRepository,
70         revision: '10.11.4 15E66',
71         ownsCommits: false,
72         time: null,
73         order: 1504065
74     });
75 }
76
77 function ownerCommit()
78 {
79     return new CommitLog(5, {
80         repository: MockModels.ownerRepository,
81         revision: '10.11.4 15E65',
82         ownsCommits: true,
83         time: null,
84         order: 1504065
85     });
86 }
87
88 function otherOwnerCommit()
89 {
90     return new CommitLog(5, {
91         repository: MockModels.ownerRepository,
92         revision: '10.11.4 15E66',
93         ownsCommits: true,
94         time: null,
95         order: 1504066
96     });
97 }
98
99 function ownedCommit()
100 {
101     return new CommitLog(11, {
102         repository: MockModels.ownedRepository,
103         revision: 'owned-commit-0',
104         ownsCommits: true,
105         time: null
106     });
107 }
108
109 function anotherOwnedCommit()
110 {
111     return new CommitLog(11, {
112         repository: MockModels.ownedRepository,
113         revision: 'owned-commit-1',
114         ownsCommits: true,
115         time: null
116     });
117 }
118
119 describe('CommitLog', function () {
120     MockModels.inject();
121
122     describe('label', function () {
123         it('should prefix SVN revision with "r"', function () {
124             assert.equal(webkitCommit().label(), 'r200805');
125         });
126
127         it('should truncate a Git hash at 8th character', function () {
128             assert.equal(gitWebKitCommit().label(), '6f8b0dbb');
129         });
130
131         it('should not modify OS X version', function () {
132             assert.equal(osxCommit().label(), '10.11.4 15E65');
133         });
134     });
135
136     describe('title', function () {
137         it('should prefix SVN revision with "r"', function () {
138             assert.equal(webkitCommit().title(), 'WebKit at r200805');
139         });
140
141         it('should truncate a Git hash at 8th character', function () {
142             assert.equal(gitWebKitCommit().title(), 'WebKit at 6f8b0dbb');
143         });
144
145         it('should not modify OS X version', function () {
146             assert.equal(osxCommit().title(), 'OS X at 10.11.4 15E65');
147         });
148     });
149
150     describe('order', () => {
151         it('should return null if no commit order', () => {
152             assert.equal(webkitCommit().order(), null);
153         });
154         it('should return commit order if order exists', () => {
155             assert.equal(osxCommit().order(), 1504065);
156         });
157     });
158
159     describe('diff', function () {
160         it('should use label() as the label the previous commit is missing', function () {
161             assert.deepEqual(webkitCommit().diff(), {
162                 label: 'r200805',
163                 url: 'http://trac.webkit.org/changeset/200805',
164                 repository: MockModels.webkit
165             });
166
167             assert.deepEqual(gitWebKitCommit().diff(), {
168                 label: '6f8b0dbb',
169                 url: 'http://trac.webkit.org/changeset/6f8b0dbbda95a440503b88db1dd03dad3a7b07fb',
170                 repository: MockModels.webkit,
171             });
172
173             assert.deepEqual(osxCommit().diff(), {
174                 label: '10.11.4 15E65',
175                 url: '',
176                 repository: MockModels.osx,
177             });
178         });
179
180         it('should use increment the old SVN revision by 1', function () {
181             assert.deepEqual(webkitCommit().diff(oldWebKitCommit()), {
182                 label: 'r200574-r200805',
183                 url: '',
184                 repository: MockModels.webkit
185             });
186         });
187
188         it('should truncate a Git hash at 8th character', function () {
189             assert.deepEqual(gitWebKitCommit().diff(oldGitWebKitCommit()), {
190                 label: 'ffda14e6..6f8b0dbb',
191                 url: '',
192                 repository: MockModels.webkit
193             });
194         });
195
196         it('should surround "-" with spaces', function () {
197             assert.deepEqual(osxCommit().diff(oldOSXCommit()), {
198                 label: '10.11.3 15D21 - 10.11.4 15E65',
199                 url: '',
200                 repository: MockModels.osx
201             });
202         });
203     });
204
205     describe('hasOrdering', () => {
206         it('should return "true" when both commits have commit orders', () => {
207             assert.ok(CommitLog.hasOrdering(osxCommit(), oldOSXCommit()));
208         });
209
210         it('should return "true" when both commits have commit time', () => {
211             assert.ok(CommitLog.hasOrdering(webkitCommit(), oldWebKitCommit()));
212         });
213
214         it('should return "false" when neither commit time nor commit order exists', () => {
215             assert.ok(!CommitLog.hasOrdering(ownedCommit(), anotherOwnedCommit()));
216         });
217
218         it('should return "false" when one commit only has commit time and another only has commit order', () => {
219             assert.ok(!CommitLog.hasOrdering(webkitCommit(), osxCommit()));
220         });
221     });
222
223     describe('hasCommitOrder', () => {
224         it('should return "true" when a commit has commit order', () => {
225             assert.ok(osxCommit().hasCommitOrder());
226         });
227
228         it('should return "false" when a commit only has commit time', () => {
229             assert.ok(!webkitCommit().hasCommitOrder());
230         });
231     });
232
233     describe('hasCommitTime', () => {
234         it('should return "true" when a commit has commit order', () => {
235             assert.ok(!osxCommit().hasCommitTime());
236         });
237
238         it('should return "false" when a commit only has commit time', () => {
239             assert.ok(webkitCommit().hasCommitTime());
240         });
241     });
242
243     describe('orderTowCommits', () => {
244         it('should order by time when both commits have time', () => {
245             const startCommit = oldWebKitCommit();
246             const endCommit = webkitCommit();
247             assert.deepEqual(CommitLog.orderTwoCommits(endCommit, startCommit), [startCommit, endCommit]);
248             assert.deepEqual(CommitLog.orderTwoCommits(startCommit, endCommit), [startCommit, endCommit]);
249         });
250
251         it('should order by commit order when both commits only have commit order', () => {
252             const startCommit = oldOSXCommit();
253             const endCommit = osxCommit();
254             assert.deepEqual(CommitLog.orderTwoCommits(endCommit, startCommit), [startCommit, endCommit]);
255             assert.deepEqual(CommitLog.orderTwoCommits(startCommit, endCommit), [startCommit, endCommit]);
256         });
257     });
258
259     describe('fetchOwnedCommits', () => {
260         beforeEach(() => {
261             MockRemoteAPI.inject(null, BrowserPrivilegedAPI);
262         });
263
264         it('should reject if repository of the commit does not own other repositories', () => {
265             const commit = osxCommit();
266             return commit.fetchOwnedCommits().then(() => {
267                assert(false, 'Should not execute this line.');
268             }, (error) => {
269                 assert.equal(error, undefined);
270             });
271         });
272
273         it('should reject if commit does not own other owned-commits', () => {
274             const commit = commitWithoutOwnedCommits();
275             return commit.fetchOwnedCommits().then(() => {
276                 assert(false, 'Should not execute this line.');
277             }, (error) => {
278                 assert.equal(error, undefined);
279             });
280         });
281
282         it('should return owned-commit for a valid commit revision', () => {
283             const commit = ownerCommit();
284             const fetchingPromise = commit.fetchOwnedCommits();
285             const requests = MockRemoteAPI.requests;
286             assert.equal(requests.length, 1);
287             assert.equal(requests[0].url, '../api/commits/111/owned-commits?owner-revision=10.11.4%2015E65');
288             assert.equal(requests[0].method, 'GET');
289
290             requests[0].resolve({commits: [{
291                 id: 233,
292                 repository: MockModels.ownedRepository.id(),
293                 revision: '6f8b0dbbda95a440503b88db1dd03dad3a7b07fb',
294                 time: +(new Date('2016-05-13T00:55:57.841344Z')),
295             }]});
296             return fetchingPromise.then((ownedCommits) => {
297                 assert.equal(ownedCommits.length, 1);
298                 assert.equal(ownedCommits[0].repository(), MockModels.ownedRepository);
299                 assert.equal(ownedCommits[0].revision(), '6f8b0dbbda95a440503b88db1dd03dad3a7b07fb');
300                 assert.equal(ownedCommits[0].id(), 233);
301                 assert.equal(ownedCommits[0].ownerCommit(), commit);
302             });
303         });
304
305         it('should only fetch owned-commits exactly once', () => {
306             const commit = ownerCommit();
307             const fetchingPromise = commit.fetchOwnedCommits();
308             const requests = MockRemoteAPI.requests;
309             let existingOwnedCommits = null;
310             assert.equal(requests.length, 1);
311             assert.equal(requests[0].url, '../api/commits/111/owned-commits?owner-revision=10.11.4%2015E65');
312             assert.equal(requests[0].method, 'GET');
313
314             MockRemoteAPI.requests[0].resolve({commits: [{
315                 id: 233,
316                 repository: MockModels.ownedRepository.id(),
317                 revision: '6f8b0dbbda95a440503b88db1dd03dad3a7b07fb',
318                 time: +(new Date('2016-05-13T00:55:57.841344Z')),
319             }]});
320
321             return fetchingPromise.then((ownedCommits) => {
322                 existingOwnedCommits = ownedCommits;
323                 assert.equal(ownedCommits.length, 1);
324                 assert.equal(ownedCommits[0].repository(), MockModels.ownedRepository);
325                 assert.equal(ownedCommits[0].revision(), '6f8b0dbbda95a440503b88db1dd03dad3a7b07fb');
326                 assert.equal(ownedCommits[0].id(), 233);
327                 assert.equal(ownedCommits[0].ownerCommit(), commit);
328                 return commit.fetchOwnedCommits();
329             }).then((ownedCommits) => {
330                 assert.equal(requests.length, 1);
331                 assert.equal(existingOwnedCommits, ownedCommits);
332             });
333         });
334     });
335
336     describe('ownedCommitDifferenceForOwnerCommits', () => {
337         beforeEach(() => {
338             MockRemoteAPI.reset();
339         });
340
341         it('should return difference between owned-commits of 2 owner commits', () => {
342             const oneCommit = ownerCommit();
343             const otherCommit = otherOwnerCommit();
344             const fetchingPromise = oneCommit.fetchOwnedCommits();
345             const requests = MockRemoteAPI.requests;
346             assert.equal(requests.length, 1);
347             assert.equal(requests[0].url, '../api/commits/111/owned-commits?owner-revision=10.11.4%2015E65');
348             assert.equal(requests[0].method, 'GET');
349
350             requests[0].resolve({commits: [{
351                 id: 233,
352                 repository: MockModels.ownedRepository.id(),
353                 revision: '6f8b0dbbda95a440503b88db1dd03dad3a7b07fb',
354                 time: +(new Date('2016-05-13T00:55:57.841344Z')),
355             }, {
356                 id: 299,
357                 repository: MockModels.webkitGit.id(),
358                 revision: '04a6c72038f0b771a19248ca2549e1258617b5fc',
359                 time: +(new Date('2016-05-13T00:55:57.841344Z')),
360             }]});
361
362             return fetchingPromise.then((ownedCommits) => {
363                 assert.equal(ownedCommits.length, 2);
364                 assert.equal(ownedCommits[0].repository(), MockModels.ownedRepository);
365                 assert.equal(ownedCommits[0].revision(), '6f8b0dbbda95a440503b88db1dd03dad3a7b07fb');
366                 assert.equal(ownedCommits[0].id(), 233);
367                 assert.equal(ownedCommits[0].ownerCommit(), oneCommit);
368                 assert.equal(ownedCommits[1].repository(), MockModels.webkitGit);
369                 assert.equal(ownedCommits[1].revision(), '04a6c72038f0b771a19248ca2549e1258617b5fc');
370                 assert.equal(ownedCommits[1].id(), 299);
371                 assert.equal(ownedCommits[1].ownerCommit(), oneCommit);
372
373                 const otherFetchingPromise = otherCommit.fetchOwnedCommits();
374                 assert.equal(requests.length, 2);
375                 assert.equal(requests[1].url, '../api/commits/111/owned-commits?owner-revision=10.11.4%2015E66');
376                 assert.equal(requests[1].method, 'GET');
377
378                 requests[1].resolve({commits: [{
379                     id: 234,
380                     repository: MockModels.ownedRepository.id(),
381                     revision: 'd5099e03b482abdd77f6c4dcb875afd05bda5ab8',
382                     time: +(new Date('2016-05-13T00:55:57.841344Z')),
383                 }, {
384                     id: 299,
385                     repository: MockModels.webkitGit.id(),
386                     revision: '04a6c72038f0b771a19248ca2549e1258617b5fc',
387                     time: +(new Date('2016-05-13T00:55:57.841344Z')),
388                 }]});
389
390                 return otherFetchingPromise;
391             }).then((ownedCommits) => {
392                 assert.equal(ownedCommits.length, 2);
393                 assert.equal(ownedCommits[0].repository(), MockModels.ownedRepository);
394                 assert.equal(ownedCommits[0].revision(), 'd5099e03b482abdd77f6c4dcb875afd05bda5ab8');
395                 assert.equal(ownedCommits[0].id(), 234);
396                 assert.equal(ownedCommits[0].ownerCommit(), otherCommit);
397                 assert.equal(ownedCommits[1].repository(), MockModels.webkitGit);
398                 assert.equal(ownedCommits[1].revision(), '04a6c72038f0b771a19248ca2549e1258617b5fc');
399                 assert.equal(ownedCommits[1].id(), 299);
400                 assert.equal(ownedCommits[1].ownerCommit(), otherCommit);
401                 const difference = CommitLog.ownedCommitDifferenceForOwnerCommits(oneCommit, otherCommit);
402                 assert.equal(difference.size, 1);
403                 assert.equal(difference.keys().next().value, MockModels.ownedRepository);
404             });
405
406         });
407     });
408 });