Refactor logic for parsing Trac revisions into its own function and add logic for...
[WebKit-https.git] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / dashboard / Scripts / tests / tests.js
1 /*
2  * Copyright (C) 2016 Apple, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 module("Trac", {
27     setup: function() {
28         this.trac = new MockTrac();
29     }
30 });
31
32 test("_loaded", function()
33 {
34     var client = new XMLHttpRequest();
35     client.open('GET', 'test-fixture-trac-rss.xml', false);
36     client.onreadystatechange = function () {
37         if (client.readyState === client.DONE)
38             this.trac._loaded(client.responseXML);
39     }.bind(this);
40     client.send();
41     var commits = this.trac.recordedCommits;
42     strictEqual(commits.length, 8, "should have 8 commits");
43     for (var i = 1; i < commits.length; i++) {
44         var firstRevision = commits[i - 1].revisionNumber;
45         var secondRevision = commits[i].revisionNumber;
46         strictEqual(secondRevision - firstRevision, 1, "commits should be in order " + firstRevision + ", " + secondRevision);
47     }
48 });
49
50 test("_parseRevisionFromURL", function()
51 {
52     strictEqual(this.trac._parseRevisionFromURL("https://trac.webkit.org/changeset/190497"), "190497", "Subversion");
53     strictEqual(this.trac._parseRevisionFromURL("http://trac.foobar.com/repository/changeset/75388/project"), "75388", "Subversion with suffix");
54     strictEqual(this.trac._parseRevisionFromURL("https://git.foobar.com/trac/Whatever.git/changeset/0e498db5d8e5b5a342631"), "0e498db5d8e5b5a342631", "Git");
55 });
56
57 module("BuildBotQueueView");
58
59 var settings = new Settings;
60 test("_appendPendingRevisionCount", function()
61 {
62     trac = new MockTrac();
63     var queue = new MockBuildbotQueue();
64     queue.branches = [{
65         name: "trunk",
66         repository: {
67             name: "openSource",
68             trac: trac
69         }
70     }]
71     var view = new MockBuildbotQueueView([queue]);
72     view._appendPendingRevisionCount(queue);
73     var revisionsBehind = view.element.getElementsByClassName("message")[0].innerHTML.match(/.*(\d+) revision(|s) behind/)[1];
74     equal(revisionsBehind, "1", "assert revisions behind");
75 });
76
77 module("BuildBotQueue", {
78     setup: function() {
79         this.queue = new MockBuildbotQueue();
80         this.queue.branches = [{
81             name: "trunk",
82             repository: {
83                 name: "openSource",
84             }
85         }];
86     }
87 });
88
89 test("compareIterations by revisions", function()
90 {
91     var finished = false;
92     var iteration1 = new BuildbotIteration(this.queue, 1, finished);
93     var iteration2 = new BuildbotIteration(this.queue, 2, finished);
94     iteration1.revision = { "openSource": 33018 };
95     iteration2.revision = { "openSource": 33019 };
96     iteration1.loaded = true;
97     iteration2.loaded = true;
98     ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
99     ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
100     strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal");
101 });
102
103 test("compareIterations by loaded (one revision missing)", function()
104 {
105     var finished = false;
106     var iteration1 = new BuildbotIteration(this.queue, 1, finished);
107     var iteration2 = new BuildbotIteration(this.queue, 2, finished);
108     iteration1.revision = {};
109     iteration2.revision = { "openSource": 33019 };
110     iteration1.loaded = false;
111     iteration2.loaded = true;
112     ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
113     ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
114 });
115
116 test("compareIterations by loaded (same revision)", function()
117 {
118     var finished = false;
119     var iteration1 = new BuildbotIteration(this.queue, 1, finished);
120     var iteration2 = new BuildbotIteration(this.queue, 2, finished);
121     iteration1.revision = { "openSource": 33019 };
122     iteration2.revision = { "openSource": 33019 };
123     iteration1.loaded = false;
124     iteration2.loaded = true;
125     ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
126     ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
127 });
128
129 test("compareIterations by id (revisions not specified)", function()
130 {
131     var finished = false;
132     var iteration1 = new BuildbotIteration(this.queue, 1, finished);
133     var iteration2 = new BuildbotIteration(this.queue, 2, finished);
134     iteration1.revision = {};
135     iteration2.revision = {};
136     iteration1.loaded = false;
137     iteration2.loaded = false;
138     ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
139     ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
140     strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal");
141 });
142
143 test("compareIterations by id (same revision)", function()
144 {
145     var finished = false;
146     var iteration1 = new BuildbotIteration(this.queue, 1, finished);
147     var iteration2 = new BuildbotIteration(this.queue, 2, finished);
148     iteration1.revision = { "openSource": 33019 };
149     iteration2.revision = { "openSource": 33019 };
150     iteration1.loaded = false;
151     iteration2.loaded = false;
152     ok(this.queue.compareIterations(iteration2, iteration1) < 0, "compareIterations: less than");
153     ok(this.queue.compareIterations(iteration1, iteration2) > 0, "compareIterations: greater than");
154     strictEqual(this.queue.compareIterations(iteration2, iteration2), 0, "compareIterations: equal");
155 });
156
157 test("compareIterationsByRevisions", function()
158 {
159     var finished = false;
160     var iteration1 = new BuildbotIteration(this.queue, 1, finished);
161     var iteration2 = new BuildbotIteration(this.queue, 2, finished);
162     iteration1.revision = { "openSource": 33018 };
163     iteration2.revision = { "openSource": 33019 };
164     iteration1.loaded = true;
165     iteration2.loaded = false;
166     ok(this.queue.compareIterationsByRevisions(iteration2, iteration1) < 0, "compareIterationsByRevisions: less than");
167     ok(this.queue.compareIterationsByRevisions(iteration1, iteration2) > 0, "compareIterationsByRevisions: greater than");
168     strictEqual(this.queue.compareIterationsByRevisions(iteration2, iteration2), 0, "compareIterationsByRevisions: equal");
169 });