initial import
[vuplus_webkit] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / TestFailures / scripts / checkout_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("checkout");
29
30 test("subversionURLForTest", 1, function() {
31     equals(checkout.subversionURLForTest("path/to/test.html"), "http://svn.webkit.org/repository/webkit/trunk/LayoutTests/path/to/test.html");
32 });
33
34 test("updateExpectations", 4, function() {
35     var simulator = new NetworkSimulator();
36
37     // FIXME: This leaks state into g_haveSeenCheckoutAvailable, which is global.
38     simulator.ajax = function(options) { options.success.call(); },
39
40     simulator.post = function(url, data, callback)
41     {
42         equals(url, 'http://127.0.0.1:8127/updateexpectations');
43         equals(data, '[{"builderName":"WebKit Linux","testName":"another/test.svg"}]');
44         simulator.scheduleCallback(callback);
45     };
46
47     simulator.runTest(function() {
48         checkout.updateExpectations([{
49             'builderName': 'WebKit Linux',
50             'testName': 'another/test.svg',
51         }], function() {
52             ok(true);
53         }, function() {
54             ok(false);
55         });
56     });
57 });
58
59 test("optimizeBaselines", 3, function() {
60     var simulator = new NetworkSimulator();
61     simulator.post = function(url, callback)
62     {
63         equals(url, 'http://127.0.0.1:8127/optimizebaselines?test=another%2Ftest.svg');
64         simulator.scheduleCallback(callback);
65     };
66
67     simulator.runTest(function() {
68         checkout.optimizeBaselines('another/test.svg', function() {
69             ok(true);
70         });
71     });
72 });
73
74 test("rebaseline", 7, function() {
75     var simulator = new NetworkSimulator();
76
77     var requestedURLs = [];
78     simulator.post = function(url, callback)
79     {
80         requestedURLs.push(url);
81         simulator.scheduleCallback(callback);
82     };
83     simulator.ajax = function(options)
84     {
85         ok(options.url.indexOf('/ping') != -1);
86         simulator.scheduleCallback(options.success);
87     };
88
89     var kExpectedTestNameProgressStack = [
90         'fast/test.html',
91         'another/test.svg',
92         'another/test.svg', // This is the first one.
93     ];
94
95     simulator.runTest(function() {
96         checkout.rebaseline([{
97             'builderName': 'WebKit Linux',
98             'testName': 'another/test.svg',
99         }, {
100             'builderName': 'WebKit Mac10.6',
101             'testName': 'another/test.svg',
102         }, {
103             'builderName': 'Webkit Vista',
104             'testName': 'fast/test.html',
105         }], function() {
106             ok(true);
107         }, function(failureInfo) {
108             equals(failureInfo.testName, kExpectedTestNameProgressStack.pop());
109         }, function() {
110             ok(false, 'Checkout should be available.');
111         });
112     });
113
114     deepEqual(requestedURLs, [
115         "http://127.0.0.1:8127/rebaseline?builder=WebKit+Linux&test=another%2Ftest.svg",
116         "http://127.0.0.1:8127/rebaseline?builder=WebKit+Mac10.6&test=another%2Ftest.svg",
117         "http://127.0.0.1:8127/rebaseline?builder=Webkit+Vista&test=fast%2Ftest.html",
118         "http://127.0.0.1:8127/optimizebaselines?test=another%2Ftest.svg",
119         "http://127.0.0.1:8127/optimizebaselines?test=fast%2Ftest.html"
120     ]);
121 });
122
123 })();