Add sanity check for source origin in WebLoaderStrategy::startPingLoad()
[WebKit-https.git] / Websites / perf.webkit.org / browser-tests / commit-log-viewer-tests.js
1 describe('CommitLogViewer', () => {
2
3     function importCommitLogViewer(context)
4     {
5         const scripts = [
6             '../shared/statistics.js',
7             'instrumentation.js',
8             'lazily-evaluated-function.js',
9             'models/data-model.js',
10             'models/repository.js',
11             'models/commit-set.js',
12             'models/commit-log.js',
13             'components/base.js',
14             'components/spinner-icon.js',
15             'components/commit-log-viewer.js'];
16         return context.importScripts(scripts, 'ComponentBase', 'CommitLogViewer', 'Repository', 'CommitLog', 'RemoteAPI').then(() => {
17             return context.symbols.CommitLogViewer;
18         });
19     }
20
21     const webkitCommit210949 = {
22         "id": "185334",
23         "revision": "210949",
24         "repository": 1,
25         "previousCommit": null,
26         "ownsSubCommits": false,
27         "time": +new Date("2017-01-20T03:23:50.645Z"),
28         "authorName": "Chris Dumez",
29         "authorEmail": "cdumez@apple.com",
30         "message": "some message",
31     };
32
33     const webkitCommit210950 = {
34         "id": "185338",
35         "revision": "210950",
36         "repository": 1,
37         "previousCommit": null,
38         "ownsSubCommits": false,
39         "time": +new Date("2017-01-20T03:49:37.887Z"),
40         "authorName": "Commit Queue",
41         "authorEmail": "commit-queue@webkit.org",
42         "message": "another message",
43     };
44
45     it('should initially be empty with no spinner', () => {
46         const context = new BrowsingContext();
47         return importCommitLogViewer(context).then((CommitLogViewer) => {
48             const viewer = new CommitLogViewer;
49             context.document.body.appendChild(viewer.element());
50             viewer.enqueueToRender();
51             return waitForComponentsToRender(context).then(() => {
52                 expect(viewer.content('spinner-container').offsetHeight).to.be(0);
53                 expect(viewer.content('commits-list').matches(':empty')).to.be(true);
54                 expect(viewer.content('repository-name').matches(':empty')).to.be(true);
55             });
56         });
57     });
58
59     it('should show the repository name and the spinner once it started fetching the list of commits ', () => {
60         const context = new BrowsingContext();
61         return importCommitLogViewer(context).then((CommitLogViewer) => {
62             const Repository = context.symbols.Repository;
63             const SpinnerIcon = context.symbols.SpinnerIcon;
64             const ComponentBase = context.symbols.ComponentBase;
65             const RemoteAPI = context.symbols.RemoteAPI;
66             const viewer = new CommitLogViewer;
67             const webkit = new Repository(1, {name: 'WebKit'});
68             context.document.body.appendChild(viewer.element());
69             viewer.enqueueToRender();
70             return waitForComponentsToRender(context).then(() => {
71                 expect(viewer.content('spinner-container').offsetHeight).to.be(0);
72                 expect(viewer.content('commits-list').matches(':empty')).to.be(true);
73                 expect(viewer.content('repository-name').matches(':empty')).to.be(true);
74                 expect(RemoteAPI.requests.length, 0);
75                 viewer.view(webkit, '210948', '210950');
76                 expect(RemoteAPI.requests.length, 1);
77                 return waitForComponentsToRender(context);
78             }).then(() => {
79                 expect(viewer.content('spinner-container').offsetHeight).to.not.be(0);
80                 expect(viewer.content('commits-list').matches(':empty')).to.be(true);
81                 expect(viewer.content('repository-name').matches(':empty')).to.be(false);
82                 expect(viewer.content('repository-name').textContent).to.contain('WebKit');
83             });
84         });
85     });
86
87     it('should show the repository name, the list of commits, and hide the spinner once the list of commits are fetched', () => {
88         const context = new BrowsingContext();
89         return importCommitLogViewer(context).then((CommitLogViewer) => {
90             const Repository = context.symbols.Repository;
91             const SpinnerIcon = context.symbols.SpinnerIcon;
92             const ComponentBase = context.symbols.ComponentBase;
93             const requests = context.symbols.RemoteAPI.requests;
94             const viewer = new CommitLogViewer;
95             const webkit = new Repository(1, {name: 'WebKit'});
96             context.document.body.appendChild(viewer.element());
97             viewer.enqueueToRender();
98             return waitForComponentsToRender(context).then(() => {
99                 viewer.view(webkit, '210948', '210950');
100                 return waitForComponentsToRender(context);
101             }).then(() => {
102                 expect(viewer.content('spinner-container').offsetHeight).to.not.be(0);
103                 expect(viewer.content('commits-list').matches(':empty')).to.be(true);
104                 expect(viewer.content('repository-name').matches(':empty')).to.be(false);
105                 expect(viewer.content('repository-name').textContent).to.contain('WebKit');
106                 expect(requests.length).to.be(1);
107                 expect(requests[0].url).to.be('/api/commits/1/?precedingRevision=210948&lastRevision=210950');
108                 requests[0].resolve({
109                     "status": "OK",
110                     "commits": [webkitCommit210949, webkitCommit210950],
111                 });
112                 return waitForComponentsToRender(context);
113             }).then(() => {
114                 expect(viewer.content('spinner-container').offsetHeight).to.be(0);
115                 expect(viewer.content('commits-list').matches(':empty')).to.be(false);
116                 expect(viewer.content('commits-list').textContent).to.contain('r210949');
117                 expect(viewer.content('commits-list').textContent).to.contain('Chris Dumez');
118                 expect(viewer.content('commits-list').textContent).to.contain('r210950');
119                 expect(viewer.content('commits-list').textContent).to.contain('Commit Queue');
120                 expect(viewer.content('repository-name').matches(':empty')).to.be(false);
121                 expect(viewer.content('repository-name').textContent).to.contain('WebKit');
122                 expect(viewer.content('commits-list').querySelector('a')).to.be(null);
123             });
124         });
125     });
126
127 });