~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/scripts/LayoutTestResultsLoader.js

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 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
function LayoutTestResultsLoader(builder) {
 
27
    this._builder = builder;
 
28
}
 
29
 
 
30
LayoutTestResultsLoader.prototype = {
 
31
    start: function(buildName, callback, errorCallback) {
 
32
        var cacheKey = 'LayoutTestResultsLoader.' + this._builder.name + '.' + buildName;
 
33
        const currentCachedDataVersion = 8;
 
34
        if (PersistentCache.contains(cacheKey)) {
 
35
            var cachedData = PersistentCache.get(cacheKey);
 
36
            if (cachedData.version === currentCachedDataVersion) {
 
37
                if (cachedData.error)
 
38
                    errorCallback(cachedData.tests, cachedData.tooManyFailures);
 
39
                else
 
40
                    callback(cachedData.tests, cachedData.tooManyFailures);
 
41
                return;
 
42
            }
 
43
        }
 
44
 
 
45
        var result = { tests: {}, tooManyFailures: false, error: false, version: currentCachedDataVersion };
 
46
 
 
47
        function cacheParseResultsAndCallCallback(parseResult) {
 
48
            result.tests = parseResult.tests;
 
49
            result.tooManyFailures = parseResult.tooManyFailures;
 
50
 
 
51
            PersistentCache.set(cacheKey, result);
 
52
            callback(result.tests, result.tooManyFailures);
 
53
        }
 
54
 
 
55
        var self = this;
 
56
        self._fetchAndParseNRWTResults(buildName, cacheParseResultsAndCallCallback, function() {
 
57
            self._fetchAndParseORWTResults(buildName, cacheParseResultsAndCallCallback, function() {
 
58
                // We couldn't fetch results for this build.
 
59
                result.error = true;
 
60
                PersistentCache.set(cacheKey, result);
 
61
                errorCallback(result.tests, result.tooManyFailures);
 
62
            });
 
63
        });
 
64
    },
 
65
 
 
66
    _fetchAndParseNRWTResults: function(buildName, successCallback, errorCallback) {
 
67
        getResource(this._builder.resultsDirectoryURL(buildName) + 'full_results.json', function(xhr) {
 
68
            successCallback((new NRWTResultsParser()).parse(xhr.responseText));
 
69
        },
 
70
        function(xhr) {
 
71
            errorCallback();
 
72
        });
 
73
    },
 
74
 
 
75
    _fetchAndParseORWTResults: function(buildName, successCallback, errorCallback) {
 
76
        var parsedBuildName = this._builder.buildbot.parseBuildName(buildName);
 
77
 
 
78
        // http://webkit.org/b/62380 was fixed in r89610.
 
79
        var resultsHTMLSupportsTooManyFailuresInfo = parsedBuildName.revision >= 89610;
 
80
 
 
81
        var result = { tests: {}, tooManyFailures: false };
 
82
 
 
83
        var self = this;
 
84
 
 
85
        function fetchAndParseResultsHTML(successCallback, errorCallback) {
 
86
            getResource(self._builder.resultsPageURL(buildName), function(xhr) {
 
87
                var parseResult = (new ORWTResultsParser()).parse(xhr.responseText);
 
88
                result.tests = parseResult.tests;
 
89
                if (resultsHTMLSupportsTooManyFailuresInfo)
 
90
                    result.tooManyFailures = parseResult.tooManyFailures;
 
91
                successCallback();
 
92
            },
 
93
            function(xhr) {
 
94
                // We failed to fetch results.html.
 
95
                errorCallback();
 
96
            });
 
97
        }
 
98
 
 
99
        function fetchNumberOfFailingTests(successCallback, errorCallback) {
 
100
            self._builder.getNumberOfFailingTests(parsedBuildName.buildNumber, function(failingTestCount, tooManyFailures) {
 
101
                result.tooManyFailures = tooManyFailures;
 
102
 
 
103
                if (failingTestCount < 0) {
 
104
                    // The number of failing tests couldn't be determined.
 
105
                    errorCallback();
 
106
                    return;
 
107
                }
 
108
 
 
109
                successCallback(failingTestCount);
 
110
            });
 
111
        }
 
112
 
 
113
        if (resultsHTMLSupportsTooManyFailuresInfo) {
 
114
            fetchAndParseResultsHTML(function() {
 
115
                successCallback(result);
 
116
            },
 
117
            function() {
 
118
                fetchNumberOfFailingTests(function(failingTestCount) {
 
119
                    if (!failingTestCount) {
 
120
                        // All tests passed, so no results.html was generated.
 
121
                        successCallback(result);
 
122
                        return;
 
123
                    }
 
124
 
 
125
                    // Something went wrong with fetching results.
 
126
                    errorCallback();
 
127
                }, errorCallback);
 
128
            });
 
129
            return;
 
130
        }
 
131
 
 
132
        fetchNumberOfFailingTests(function(failingTestCount) {
 
133
            if (!failingTestCount) {
 
134
                // All tests passed.
 
135
                successCallback(result);
 
136
                return;
 
137
            }
 
138
 
 
139
            // Find out which tests failed.
 
140
            fetchAndParseResultsHTML(function() {
 
141
                successCallback(result);
 
142
            }, errorCallback);
 
143
        }, errorCallback);
 
144
    },
 
145
};