Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / TestResultServer / static-dashboards / loader_unittests.js
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     resetGlobals();
33     var loadedSteps = [];
34     g_history._handleLocationChange = function() {
35         deepEqual(loadedSteps, ['step 1', 'step 2']);
36     }
37     var resourceLoader = new loader.Loader();
38     function loadingStep1() {
39         loadedSteps.push('step 1');
40         resourceLoader.load();
41     }
42     function loadingStep2() {
43         loadedSteps.push('step 2');
44         resourceLoader.load();
45     }
46
47     resourceLoader._loadingSteps = [loadingStep1, loadingStep2];
48     resourceLoader.load();
49 });
50
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() {
54     resetGlobals();
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, {});
63         });
64     }
65
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":{}}}'});
71     }
72
73     builders.loadBuildersList('@ToT Blink', 'layout-tests');
74
75     try {
76         resourceLoader._loadResultsFiles();
77     } finally {
78         loader.request = requestFunction;
79     }
80 });
81
82 test('results file failing to load', 2, function() {
83     resetGlobals();
84     builders.loadBuildersList('@ToT Blink', 'layout-tests');
85
86     var resourceLoader = new loader.Loader();
87     var resourceLoadCount = 0;
88     resourceLoader._handleResourceLoad = function() {
89         resourceLoadCount++;
90     }
91
92     var builder1 = 'builder1';
93     currentBuilders()[builder1] = true;
94     resourceLoader._handleResultsFileLoadError(builder1);
95
96     var builder2 = 'builder2';
97     currentBuilders()[builder2] = true;
98     resourceLoader._handleResultsFileLoadError(builder2);
99
100     deepEqual(resourceLoader._buildersThatFailedToLoad, [builder1, builder2]);
101     equal(resourceLoadCount, 2);
102
103 });
104
105 test('Default builder gets set.', 3, function() {
106     resetGlobals();
107     builders.loadBuildersList('@ToT Blink', 'layout-tests');
108
109     var defaultBuilder = currentBuilderGroup().defaultBuilder();
110     ok(defaultBuilder, "Default builder should exist.");
111
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");
119 });
120
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>');
127 });
128
129
130 test('flattenTrie', 1, function() {
131     resetGlobals();
132     var tests = {
133         'bar.html': {'results': [[100, 'F']], 'times': [[100, 0]]},
134         'foo': {
135             'bar': {
136                 'baz.html': {'results': [[100, 'F']], 'times': [[100, 0]]},
137             }
138         }
139     };
140     var expectedFlattenedTests = {
141         'bar.html': {'results': [[100, 'F']], 'times': [[100, 0]]},
142         'foo/bar/baz.html': {'results': [[100, 'F']], 'times': [[100, 0]]},
143     };
144     equal(JSON.stringify(loader.Loader._flattenTrie(tests)), JSON.stringify(expectedFlattenedTests))
145 });