1 /* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
7 function parseTestManifest(testManifest, params, callback) {
11 // Support --test-manifest format for mobile
12 if ("runtests" in testManifest || "excludetests" in testManifest) {
13 callback(testManifest);
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 (let obj of testManifest.tests) {
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");
27 if (params.testRoot != "tests" && params.testRoot !== undefined) {
28 let name = params.baseurl + "/" + params.testRoot + "/" + path;
32 expected: obj.expected,
33 https_first_disabled: obj.https_first_disabled,
34 allow_xul_xbl: obj.allow_xul_xbl,
38 let name = params.testPrefix + path;
39 if (params.xOriginTests && obj.scheme == "https") {
40 name = params.httpsBaseUrl + path;
45 expected: obj.expected,
46 https_first_disabled: obj.https_first_disabled,
47 allow_xul_xbl: obj.allow_xul_xbl,
59 function getTestManifest(url, params, callback) {
60 let req = new XMLHttpRequest();
62 req.onload = function () {
63 if (req.readyState == 4) {
64 if (req.status == 200) {
66 parseTestManifest(JSON.parse(req.responseText), params, callback);
69 "TEST-UNEXPECTED-FAIL: manifestLibrary.js | error parsing " +
79 "TEST-UNEXPECTED-FAIL: manifestLibrary.js | error loading " +
92 // Test Filtering Code
93 // TODO Only used by ipc tests, remove once those are implemented sanely
96 Open the file referenced by runOnly|exclude and use that to compare against
99 filter = json object of runtests | excludetests
100 testList = array of test names to run
101 runOnly = use runtests vs excludetests in case both are defined
103 filtered version of testList
105 function filterTests(filter, testList, runOnly) {
106 let filteredTests = [];
108 let excludetests = {};
110 if (filter == null) {
114 if ("runtests" in filter) {
115 runtests = filter.runtests;
117 if ("excludetests" in filter) {
118 excludetests = filter.excludetests;
120 if (!("runtests" in filter) && !("excludetests" in filter)) {
121 if (runOnly == "true") {
124 excludetests = filter;
128 // eslint-disable-next-line no-undef
129 let testRoot = config.testRoot || "tests";
130 // Start with testList, and put everything that's in 'runtests' in
132 if (Object.keys(runtests).length) {
133 for (let i = 0; i < testList.length; i++) {
135 if (testList[i] instanceof Object && "test" in testList[i]) {
136 testpath = testList[i].test.url;
138 testpath = testList[i];
140 let tmppath = testpath.replace(/^\//, "");
141 for (let f in runtests) {
142 // Remove leading /tests/ if exists
143 let file = f.replace(/^\//, "");
144 file = file.replace(/^tests\//, "");
146 // Match directory or filename, testList has <testroot>/<path>
147 if (tmppath.match(testRoot + "/" + file) != null) {
148 filteredTests.push(testpath);
154 filteredTests = testList.slice(0);
157 // Continue with filteredTests, and deselect everything that's in
159 if (!Object.keys(excludetests).length) {
160 return filteredTests;
163 let refilteredTests = [];
164 for (let i = 0; i < filteredTests.length; i++) {
167 if (filteredTests[i] instanceof Object && "test" in filteredTests[i]) {
168 testpath = filteredTests[i].test.url;
170 testpath = filteredTests[i];
172 let tmppath = testpath.replace(/^\//, "");
173 for (let f in excludetests) {
174 // Remove leading /tests/ if exists
175 let file = f.replace(/^\//, "");
176 file = file.replace(/^tests\//, "");
178 // Match directory or filename, testList has <testroot>/<path>
179 if (tmppath.match(testRoot + "/" + file) != null) {
185 refilteredTests.push(testpath);
188 return refilteredTests;