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

« back to all changes in this revision

Viewing changes to Tools/TestResultServer/static-dashboards/loader_unittests.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
// Copyright (C) Zan Dobersek <zandobersek@gmail.com>
 
2
//
 
3
// Redistribution and use in source and binary forms, with or without
 
4
// modification, are permitted provided that the following conditions are
 
5
// met:
 
6
//
 
7
//         * Redistributions of source code must retain the above copyright
 
8
// notice, this list of conditions and the following disclaimer.
 
9
//         * Redistributions in binary form must reproduce the above
 
10
// copyright notice, this list of conditions and the following disclaimer
 
11
// in the documentation and/or other materials provided with the
 
12
// distribution.
 
13
//         * Neither the name of Google Inc. nor the names of its
 
14
// contributors may be used to endorse or promote products derived from
 
15
// this software without specific prior written permission.
 
16
//
 
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
18
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
19
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
20
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
21
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
22
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
23
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
24
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
25
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
27
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 
 
29
module('loader');
 
30
 
 
31
test('loading steps', 1, function() {
 
32
    var loadedSteps = [];
 
33
    var resourceLoader = new loader.Loader();
 
34
    function loadingStep1() {
 
35
        loadedSteps.push('step 1');
 
36
        resourceLoader.load();
 
37
    }
 
38
    function loadingStep2() {
 
39
        loadedSteps.push('step 2');
 
40
        resourceLoader.load();
 
41
    }
 
42
 
 
43
    var loadingCompleteCallback = resourceLoadingComplete;
 
44
    resourceLoadingComplete = function() {
 
45
        deepEqual(loadedSteps, ['step 1', 'step 2']);
 
46
    }
 
47
 
 
48
    try {
 
49
        resourceLoader._loadingSteps = [loadingStep1, loadingStep2];
 
50
        resourceLoader.load();
 
51
    } finally {
 
52
        resourceLoadingComplete = loadingCompleteCallback;
 
53
    }
 
54
});
 
55
 
 
56
test('results files loading', 5, function() {
 
57
    var expectedLoadedBuilders = ["WebKit Linux", "WebKit Win"];
 
58
    var loadedBuilders = [];
 
59
    var resourceLoader = new loader.Loader();
 
60
    resourceLoader._loadNext = function() {
 
61
        deepEqual(loadedBuilders.sort(), expectedLoadedBuilders);
 
62
        loadedBuilders.forEach(function(builderName) {
 
63
            ok('secondsSinceEpoch' in g_resultsByBuilder[builderName]);
 
64
            deepEqual(g_resultsByBuilder[builderName].tests, {});
 
65
        });
 
66
    }
 
67
 
 
68
    var requestFunction = loader.request;
 
69
    loader.request = function(url, successCallback, errorCallback) {
 
70
        var builderName = /builder=([\w ]+)&/.exec(url)[1];
 
71
        loadedBuilders.push(builderName);
 
72
        successCallback({responseText: '{"version": 4, "' + builderName + '": {"secondsSinceEpoch": [' + Date.now() + '], "tests": {}}}'});
 
73
    }
 
74
 
 
75
    g_builders = {"WebKit Linux": true, "WebKit Win": true};
 
76
 
 
77
    builders.masters['ChromiumWebkit'] = {'tests': {'layout-tests': {builders: ["WebKit Linux", "WebKit Win"]}}};
 
78
    loadBuildersList('@ToT - chromium.org', 'layout-tests');
 
79
 
 
80
    try {
 
81
        resourceLoader._loadResultsFiles();
 
82
    } finally {
 
83
        g_builders = undefined;
 
84
        g_resultsByBuilder = {};
 
85
        loader.request = requestFunction;
 
86
    }
 
87
});
 
88
 
 
89
test('expectations files loading', 1, function() {
 
90
    var expectedLoadedPlatforms = ["chromium", "chromium-android", "efl", "efl-wk1", "efl-wk2", "gtk",
 
91
                                   "gtk-wk2", "mac", "mac-lion", "mac-snowleopard", "qt", "win", "wk2"];
 
92
    var loadedPlatforms = [];
 
93
    var resourceLoader = new loader.Loader();
 
94
    resourceLoader._loadNext = function() {
 
95
        deepEqual(loadedPlatforms.sort(), expectedLoadedPlatforms);
 
96
    }
 
97
 
 
98
    var requestFunction = loader.request;
 
99
    loader.request = function(url, successCallback, errorCallback) {
 
100
        loadedPlatforms.push(/LayoutTests\/platform\/(.+)\/TestExpectations/.exec(url)[1]);
 
101
        successCallback({responseText: ''});
 
102
    }
 
103
 
 
104
    try {
 
105
        resourceLoader._loadExpectationsFiles();
 
106
    } finally {
 
107
        loader.request = requestFunction;
 
108
    }
 
109
});
 
110
 
 
111
test('results file failing to load', 2, function() {
 
112
    // FIXME: loader shouldn't depend on state defined in dashboard_base.js.
 
113
    g_buildersThatFailedToLoad = [];
 
114
    g_builders = {};
 
115
 
 
116
    var resourceLoader = new loader.Loader();
 
117
    var resourceLoadCount = 0;
 
118
    resourceLoader._handleResourceLoad = function() {
 
119
        resourceLoadCount++;
 
120
    }
 
121
 
 
122
    var builder1 = 'builder1';
 
123
    g_builders[builder1] = true;
 
124
    resourceLoader._handleResultsFileLoadError(builder1);
 
125
 
 
126
    var builder2 = 'builder2';
 
127
    g_builders[builder2] = true;
 
128
    resourceLoader._handleResultsFileLoadError(builder2);
 
129
 
 
130
    deepEqual(g_buildersThatFailedToLoad, [builder1, builder2]);
 
131
    equal(resourceLoadCount, 2);
 
132
 
 
133
})