Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / GardeningServer / scripts / model_unittests.js
1 /*
2  * Copyright (C) 2011 Google 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 (function () {
27
28 module("model");
29
30 var kExampleCommitDataXML =
31    "<feed xmlns='http://www.w3.org/2005/Atom'>\n" +
32    "<title>blink, branch master</title>\n" +
33    "<subtitle>Mirror of the Chromium Blink repository.</subtitle>\n" +
34    "<link rel='alternate' type='text/html' href='http://blink.lc/blink/'/>\n" +
35    "<entry>\n" +
36    "<title>Throw SecurityError when setting 'Replaceable' properties cross-origin.</title>\n" +
37    "<updated>2013-09-30T20:22:01Z</updated>\n" +
38    "<author>\n" +
39    "<name>mkwst@chromium.org</name>\n" +
40    "</author>\n" +
41    "<published>2013-09-30T20:22:01Z</published>\n" +
42    "<link rel='alternate' type='text/html' href='http://blink.lc/blink/commit/?id=723e62a4a4e093435b4772b4839aa3fd7cf6b991'/>\n" +
43    "<id>723e62a4a4e093435b4772b4839aa3fd7cf6b991</id>\n" +
44    "<content type='text'>\n" +
45    "This matches Gecko's behavior for these types of properties.\n" +
46    "\n" +
47    "BUG=13\n" +
48    "R=jochen@chromium.org\n" +
49    "CC=abarth@chromium.org\n" +
50    "\n" +
51    "Review URL: https://chromiumcodereview.appspot.com/25022002\n" +
52    "\n" +
53    "git-svn-id: svn://svn.chromium.org/blink/trunk@3 bbb929c8-8fbe-4397-9dbb-9b2b20218538\n" +
54    "</content>\n" +
55    "</entry>\n" +
56    "<entry>\n" +
57    "<title>Fix one more layering violation caught by check-blink-deps</title>\n" +
58    "<updated>2013-09-30T19:36:21Z</updated>\n" +
59    "<author>\n" +
60    "<name>eseidel@chromium.org</name>\n" +
61    "</author>\n" +
62    "<published>2013-09-30T19:36:21Z</published>\n" +
63    "<link rel='alternate' type='text/html' href='http://blink.lc/blink/commit/?id=51e5c70050dcb0980eb31f112d0cd948f3ece820'/>\n" +
64    "<id>51e5c70050dcb0980eb31f112d0cd948f3ece820</id>\n" +
65    "<content type='text'>\n" +
66    "core/platform may not depend on core/ even for testing.\n" +
67    "\n" +
68    "BUG=12\n" +
69    "R=abarth@chromium.org, abarth\n" +
70    "\n" +
71    "Review URL: https://codereview.chromium.org/25284004\n" +
72    "\n" +
73    "git-svn-id: svn://svn.chromium.org/blink/trunk@2 bbb929c8-8fbe-4397-9dbb-9b2b20218538\n" +
74    "</content>\n" +
75    "</entry>\n" +
76    "<entry>\n" +
77    "<title>Update DEPS include_rules after addition of root-level platform directory</title>\n" +
78    "<updated>2013-09-30T19:28:49Z</updated>\n" +
79    "<author>\n" +
80    "<name>eseidel@chromium.org</name>\n" +
81    "</author>\n" +
82    "<published>2013-09-30T19:28:49Z</published>\n" +
83    "<link rel='alternate' type='text/html' href='http://blink.lc/blink/commit/?id=227add0156e8ab272abcd3368dfc0b5a91f35749'/>\n" +
84    "<id>227add0156e8ab272abcd3368dfc0b5a91f35749</id>\n" +
85    "<content type='text'>\n" +
86    "These were all failures noticed when running check-blink-deps\n" +
87    "\n" +
88    "R=abarth@chromium.org, abarth\n" +
89    "BUG=11\n" +
90    "\n" +
91    "Review URL: https://codereview.chromium.org/25275005\n" +
92    "\n" +
93    "git-svn-id: svn://svn.chromium.org/blink/trunk@1 bbb929c8-8fbe-4397-9dbb-9b2b20218538\n" +
94    "</content>\n" +
95    "</entry>\n" +
96    "</feed>\n";
97
98 test("rebaselineQueue", 3, function() {
99     var queue = model.takeRebaselineQueue();
100     deepEqual(queue, []);
101     model.queueForRebaseline('failureInfo1');
102     model.queueForRebaseline('failureInfo2');
103     var queue = model.takeRebaselineQueue();
104     deepEqual(queue, ['failureInfo1', 'failureInfo2']);
105     var queue = model.takeRebaselineQueue();
106     deepEqual(queue, []);
107 });
108
109 test("rebaselineQueue", 3, function() {
110     var queue = model.takeExpectationUpdateQueue();
111     deepEqual(queue, []);
112     model.queueForExpectationUpdate('failureInfo1');
113     model.queueForExpectationUpdate('failureInfo2');
114     var queue = model.takeExpectationUpdateQueue();
115     deepEqual(queue, ['failureInfo1', 'failureInfo2']);
116     var queue = model.takeExpectationUpdateQueue();
117     deepEqual(queue, []);
118 });
119
120 asyncTest("updateRecentCommits", 2, function() {
121     var simulator = new NetworkSimulator();
122
123     simulator.xml = function(url)
124     {
125         var parser = new DOMParser();
126         var responseDOM = parser.parseFromString(kExampleCommitDataXML, "application/xml");
127         return Promise.resolve(responseDOM);
128     };
129
130     simulator.runTest(function() {
131         model.updateRecentCommits().then(function() {
132             var recentCommits = model.state.recentCommits;
133             delete model.state.recentCommits;
134             $.each(recentCommits, function(index, commitData) {
135                 delete commitData.message;
136             });
137             deepEqual(recentCommits, [{
138                 "revision": 3,
139                 "title": "Throw SecurityError when setting 'Replaceable' properties cross-origin.",
140                 "time": "2013-09-30T20:22:01Z",
141                 "summary": "This matches Gecko's behavior for these types of properties.",
142                 "author": "mkwst@chromium.org",
143                 "reviewer": "jochen@chromium.org",
144                 "bugID": [13],
145                 "revertedRevision": undefined,
146               },
147               {
148                 "revision": 2,
149                 "title": "Fix one more layering violation caught by check-blink-deps",
150                 "time": "2013-09-30T19:36:21Z",
151                 "summary": "core/platform may not depend on core/ even for testing.",
152                 "author": "eseidel@chromium.org",
153                 "reviewer": "abarth@chromium.org, abarth",
154                 "bugID": [12],
155                 "revertedRevision": undefined
156               },
157               {
158                 "revision": 1,
159                 "title": "Update DEPS include_rules after addition of root-level platform directory",
160                 "time": "2013-09-30T19:28:49Z",
161                 "summary": "These were all failures noticed when running check-blink-deps",
162                 "author": "eseidel@chromium.org",
163                 "reviewer": "abarth@chromium.org, abarth",
164                 "bugID": [11],
165                 "revertedRevision": undefined
166               }
167             ]);
168         });
169     }).then(start);
170 });
171
172 asyncTest("commitDataListForRevisionRange", 6, function() {
173     var simulator = new NetworkSimulator();
174
175     simulator.xml = function(url)
176     {
177         var parser = new DOMParser();
178         var responseDOM = parser.parseFromString(kExampleCommitDataXML, "application/xml");
179         return Promise.resolve(responseDOM);
180     };
181
182     simulator.runTest(function() {
183         model.updateRecentCommits().then(function() {
184             function extractBugIDs(commitData)
185             {
186                 return commitData.bugID;
187             }
188
189             deepEqual(model.commitDataListForRevisionRange(3, 3).map(extractBugIDs), [[13]]);
190             deepEqual(model.commitDataListForRevisionRange(1, 3).map(extractBugIDs), [[11], [12], [13]]);
191             deepEqual(model.commitDataListForRevisionRange(0, 1).map(extractBugIDs), [[11]]);
192             deepEqual(model.commitDataListForRevisionRange(0, 4).map(extractBugIDs), [[11], [12], [13]]);
193             deepEqual(model.commitDataListForRevisionRange(4, 0).map(extractBugIDs), []);
194             delete model.state.recentCommits;
195         });
196     }).then(start);
197 });
198
199 test("buildersInFlightForRevision", 3, function() {
200     var unmock = model.state.resultsByBuilder;
201     model.state.resultsByBuilder = {
202         'Mr. Beasley': {blink_revision: '5'},
203         'Mr Dixon': {blink_revision: '1'},
204         'Mr. Sabatini': {blink_revision: '4'},
205         'Bob': {blink_revision: '6'}
206     };
207     deepEqual(model.buildersInFlightForRevision(1), {});
208     deepEqual(model.buildersInFlightForRevision(3), {
209       "Mr Dixon": {
210         "actual": "BUILDING"
211       }
212     });
213     deepEqual(model.buildersInFlightForRevision(10), {
214       "Mr. Beasley": {
215         "actual": "BUILDING"
216       },
217       "Mr Dixon": {
218         "actual": "BUILDING"
219       },
220       "Mr. Sabatini": {
221         "actual": "BUILDING"
222       },
223       "Bob": {
224         "actual": "BUILDING"
225       }
226     });
227     model.state.resultsByBuilder = unmock;
228 });
229
230 test("latestRevisionWithNoBuildersInFlight", 1, function() {
231     var unmock = model.state.resultsByBuilder;
232     model.state.resultsByBuilder = {
233         'Mr. Beasley': { },
234         'Mr Dixon': {blink_revision: '2'},
235         'Mr. Sabatini': {blink_revision: '4'},
236         'Bob': {blink_revision: '6'}
237     };
238     equals(model.latestRevisionWithNoBuildersInFlight(), 2);
239     model.state.resultsByBuilder = unmock;
240 });
241
242 })();