2
* Copyright (C) 2011 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
26
function LayoutTestResultsLoader(builder) {
27
this._builder = builder;
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) {
38
errorCallback(cachedData.tests, cachedData.tooManyFailures);
40
callback(cachedData.tests, cachedData.tooManyFailures);
45
var result = { tests: {}, tooManyFailures: false, error: false, version: currentCachedDataVersion };
47
function cacheParseResultsAndCallCallback(parseResult) {
48
result.tests = parseResult.tests;
49
result.tooManyFailures = parseResult.tooManyFailures;
51
PersistentCache.set(cacheKey, result);
52
callback(result.tests, result.tooManyFailures);
56
self._fetchAndParseNRWTResults(buildName, cacheParseResultsAndCallCallback, function() {
57
self._fetchAndParseORWTResults(buildName, cacheParseResultsAndCallCallback, function() {
58
// We couldn't fetch results for this build.
60
PersistentCache.set(cacheKey, result);
61
errorCallback(result.tests, result.tooManyFailures);
66
_fetchAndParseNRWTResults: function(buildName, successCallback, errorCallback) {
67
getResource(this._builder.resultsDirectoryURL(buildName) + 'full_results.json', function(xhr) {
68
successCallback((new NRWTResultsParser()).parse(xhr.responseText));
75
_fetchAndParseORWTResults: function(buildName, successCallback, errorCallback) {
76
var parsedBuildName = this._builder.buildbot.parseBuildName(buildName);
78
// http://webkit.org/b/62380 was fixed in r89610.
79
var resultsHTMLSupportsTooManyFailuresInfo = parsedBuildName.revision >= 89610;
81
var result = { tests: {}, tooManyFailures: false };
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;
94
// We failed to fetch results.html.
99
function fetchNumberOfFailingTests(successCallback, errorCallback) {
100
self._builder.getNumberOfFailingTests(parsedBuildName.buildNumber, function(failingTestCount, tooManyFailures) {
101
result.tooManyFailures = tooManyFailures;
103
if (failingTestCount < 0) {
104
// The number of failing tests couldn't be determined.
109
successCallback(failingTestCount);
113
if (resultsHTMLSupportsTooManyFailuresInfo) {
114
fetchAndParseResultsHTML(function() {
115
successCallback(result);
118
fetchNumberOfFailingTests(function(failingTestCount) {
119
if (!failingTestCount) {
120
// All tests passed, so no results.html was generated.
121
successCallback(result);
125
// Something went wrong with fetching results.
132
fetchNumberOfFailingTests(function(failingTestCount) {
133
if (!failingTestCount) {
135
successCallback(result);
139
// Find out which tests failed.
140
fetchAndParseResultsHTML(function() {
141
successCallback(result);