|
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 function parseTestManifest(testManifest, params, callback) { |
|
8 var links = {}; |
|
9 var paths = []; |
|
10 |
|
11 // Support --test-manifest format for mobile/b2g |
|
12 if ("runtests" in testManifest || "excludetests" in testManifest) { |
|
13 callback(testManifest); |
|
14 return; |
|
15 } |
|
16 |
|
17 // For mochitest-chrome and mochitest-browser-chrome harnesses, we |
|
18 // define tests as links[testname] = true. |
|
19 // For mochitest-plain, we define lists as an array of testnames. |
|
20 for (var obj of testManifest['tests']) { |
|
21 var path = obj['path']; |
|
22 // Note that obj.disabled may be "". We still want to skip in that case. |
|
23 if ("disabled" in obj) { |
|
24 dump("TEST-SKIPPED | " + path + " | " + obj.disabled + "\n"); |
|
25 continue; |
|
26 } |
|
27 if (params.testRoot != 'tests' && params.testRoot !== undefined) { |
|
28 links[params.baseurl + '/' + params.testRoot + '/' + path] = true |
|
29 } else { |
|
30 paths.push(params.testPrefix + path); |
|
31 } |
|
32 } |
|
33 if (paths.length > 0) { |
|
34 callback(paths); |
|
35 } else { |
|
36 callback(links); |
|
37 } |
|
38 } |
|
39 |
|
40 function getTestManifest(url, params, callback) { |
|
41 var req = new XMLHttpRequest(); |
|
42 req.open("GET", url); |
|
43 req.onload = function() { |
|
44 if (req.readyState == 4) { |
|
45 if (req.status == 200) { |
|
46 try { |
|
47 parseTestManifest(JSON.parse(req.responseText), params, callback); |
|
48 } catch (e) { |
|
49 dump("TEST-UNEXPECTED-FAIL: setup.js | error parsing " + url + " (" + e + ")\n"); |
|
50 throw e; |
|
51 } |
|
52 } else { |
|
53 dump("TEST-UNEXPECTED-FAIL: setup.js | error loading " + url + "\n"); |
|
54 callback({}); |
|
55 } |
|
56 } |
|
57 } |
|
58 req.send(); |
|
59 } |
|
60 |
|
61 // Test Filtering Code |
|
62 |
|
63 /* |
|
64 Open the file referenced by runOnly|exclude and use that to compare against |
|
65 testList |
|
66 parameters: |
|
67 filter = json object of runtests | excludetests |
|
68 testList = array of test names to run |
|
69 runOnly = use runtests vs excludetests in case both are defined |
|
70 returns: |
|
71 filtered version of testList |
|
72 */ |
|
73 function filterTests(filter, testList, runOnly) { |
|
74 |
|
75 var filteredTests = []; |
|
76 var removedTests = []; |
|
77 var runtests = {}; |
|
78 var excludetests = {}; |
|
79 |
|
80 if (filter == null) { |
|
81 return testList; |
|
82 } |
|
83 |
|
84 if ('runtests' in filter) { |
|
85 runtests = filter.runtests; |
|
86 } |
|
87 if ('excludetests' in filter) { |
|
88 excludetests = filter.excludetests; |
|
89 } |
|
90 if (!('runtests' in filter) && !('excludetests' in filter)) { |
|
91 if (runOnly == 'true') { |
|
92 runtests = filter; |
|
93 } else { |
|
94 excludetests = filter; |
|
95 } |
|
96 } |
|
97 |
|
98 var testRoot = config.testRoot || "tests"; |
|
99 // Start with testList, and put everything that's in 'runtests' in |
|
100 // filteredTests. |
|
101 if (Object.keys(runtests).length) { |
|
102 for (var i = 0; i < testList.length; i++) { |
|
103 var testpath = testList[i]; |
|
104 var tmppath = testpath.replace(/^\//, ''); |
|
105 for (var f in runtests) { |
|
106 // Remove leading /tests/ if exists |
|
107 file = f.replace(/^\//, '') |
|
108 file = file.replace(/^tests\//, '') |
|
109 |
|
110 // Match directory or filename, testList has <testroot>/<path> |
|
111 if (tmppath.match(testRoot + "/" + file) != null) { |
|
112 filteredTests.push(testpath); |
|
113 break; |
|
114 } |
|
115 } |
|
116 } |
|
117 } else { |
|
118 filteredTests = testList.slice(0); |
|
119 } |
|
120 |
|
121 // Continue with filteredTests, and deselect everything that's in |
|
122 // excludedtests. |
|
123 if (!Object.keys(excludetests).length) { |
|
124 return filteredTests; |
|
125 } |
|
126 |
|
127 var refilteredTests = []; |
|
128 for (var i = 0; i < filteredTests.length; i++) { |
|
129 var found = false; |
|
130 var testpath = filteredTests[i]; |
|
131 var tmppath = testpath.replace(/^\//, ''); |
|
132 for (var f in excludetests) { |
|
133 // Remove leading /tests/ if exists |
|
134 file = f.replace(/^\//, '') |
|
135 file = file.replace(/^tests\//, '') |
|
136 |
|
137 // Match directory or filename, testList has <testroot>/<path> |
|
138 if (tmppath.match(testRoot + "/" + file) != null) { |
|
139 found = true; |
|
140 break; |
|
141 } |
|
142 } |
|
143 if (!found) { |
|
144 refilteredTests.push(testpath); |
|
145 } |
|
146 } |
|
147 return refilteredTests; |
|
148 } |