1 // Copyright (C) Zan Dobersek <zandobersek@gmail.com>
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
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
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.
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.
31 test('loading steps', 1, function() {
34 g_history._handleLocationChange = function() {
35 deepEqual(loadedSteps, ['step 1', 'step 2']);
37 var resourceLoader = new loader.Loader();
38 function loadingStep1() {
39 loadedSteps.push('step 1');
40 resourceLoader.load();
42 function loadingStep2() {
43 loadedSteps.push('step 2');
44 resourceLoader.load();
47 resourceLoader._loadingSteps = [loadingStep1, loadingStep2];
48 resourceLoader.load();
51 // Total number of assertions is 1 for the deepEqual of the builder lists
52 // and then 2 per builder (one for ok, one for deepEqual of tests).
53 test('results files loading', 11, function() {
55 var expectedLoadedBuilders = ['WebKit Linux', 'WebKit Linux (dbg)', 'WebKit Mac10.7', 'WebKit Win', 'WebKit Win (dbg)'];
56 var loadedBuilders = [];
57 var resourceLoader = new loader.Loader();
58 resourceLoader._loadNext = function() {
59 deepEqual(loadedBuilders.sort(), expectedLoadedBuilders);
60 loadedBuilders.forEach(function(builderName) {
61 ok('secondsSinceEpoch' in g_resultsByBuilder[builderName]);
62 deepEqual(g_resultsByBuilder[builderName].tests, {});
66 var requestFunction = loader.request;
67 loader.request = function(url, successCallback, errorCallback) {
68 var builderName = /builder=([\w ().]+)&/.exec(url)[1];
69 loadedBuilders.push(builderName);
70 successCallback({responseText: '{"version":4,"' + builderName + '":{"failure_map":{"A":"AUDIO","C":"CRASH","F":"TEXT"},"secondsSinceEpoch":[' + Date.now() + '],"tests":{}}}'});
73 builders.loadBuildersList('@ToT Blink', 'layout-tests');
76 resourceLoader._loadResultsFiles();
78 loader.request = requestFunction;
82 test('results file failing to load', 2, function() {
84 builders.loadBuildersList('@ToT Blink', 'layout-tests');
86 var resourceLoader = new loader.Loader();
87 var resourceLoadCount = 0;
88 resourceLoader._handleResourceLoad = function() {
92 var builder1 = 'builder1';
93 currentBuilders()[builder1] = true;
94 resourceLoader._handleResultsFileLoadError(builder1);
96 var builder2 = 'builder2';
97 currentBuilders()[builder2] = true;
98 resourceLoader._handleResultsFileLoadError(builder2);
100 deepEqual(resourceLoader._buildersThatFailedToLoad, [builder1, builder2]);
101 equal(resourceLoadCount, 2);
105 test('Default builder gets set.', 3, function() {
107 builders.loadBuildersList('@ToT Blink', 'layout-tests');
109 var defaultBuilder = currentBuilderGroup().defaultBuilder();
110 ok(defaultBuilder, "Default builder should exist.");
112 // Simulate error loading the default builder data, then make sure
113 // a new defaultBuilder is set, and isn't the now invalid one.
114 var resourceLoader = new loader.Loader();
115 resourceLoader._handleResultsFileLoadError(defaultBuilder);
116 var newDefaultBuilder = currentBuilderGroup().defaultBuilder();
117 ok(newDefaultBuilder, "There should still be a default builder.");
118 notEqual(newDefaultBuilder, defaultBuilder, "Default builder should not be the old default builder");
121 test('addBuilderLoadErrors', 1, function() {
122 var resourceLoader = new loader.Loader();
123 resourceLoader._buildersThatFailedToLoad = ['builder1', 'builder2'];
124 resourceLoader._staleBuilders = ['staleBuilder1'];
125 resourceLoader._addErrors();
126 equal(resourceLoader._errors._messages, 'ERROR: Failed to get data from builder1,builder2.<br>ERROR: Data from staleBuilder1 is more than 1 day stale.<br>');
130 test('flattenTrie', 1, function() {
133 'bar.html': {'results': [[100, 'F']], 'times': [[100, 0]]},
136 'baz.html': {'results': [[100, 'F']], 'times': [[100, 0]]},
140 var expectedFlattenedTests = {
141 'bar.html': {'results': [[100, 'F']], 'times': [[100, 0]]},
142 'foo/bar/baz.html': {'results': [[100, 'F']], 'times': [[100, 0]]},
144 equal(JSON.stringify(loader.Loader._flattenTrie(tests)), JSON.stringify(expectedFlattenedTests))