Bug 1877642 - Disable browser_fullscreen-tab-close-race.js on apple_silicon !debug...
[gecko.git] / testing / mochitest / manifestLibrary.js
blob8bc9f15648fb1ece8b9da4053a6a426080dea24a
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) {
8   let links = {};
9   let paths = [];
11   // Support --test-manifest format for mobile
12   if ("runtests" in testManifest || "excludetests" in testManifest) {
13     callback(testManifest);
14     return;
15   }
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) {
21     let 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       let name = params.baseurl + "/" + params.testRoot + "/" + path;
29       links[name] = {
30         test: {
31           url: name,
32           expected: obj.expected,
33           https_first_disabled: obj.https_first_disabled,
34           allow_xul_xbl: obj.allow_xul_xbl,
35         },
36       };
37     } else {
38       let name = params.testPrefix + path;
39       if (params.xOriginTests && obj.scheme == "https") {
40         name = params.httpsBaseUrl + path;
41       }
42       paths.push({
43         test: {
44           url: name,
45           expected: obj.expected,
46           https_first_disabled: obj.https_first_disabled,
47           allow_xul_xbl: obj.allow_xul_xbl,
48         },
49       });
50     }
51   }
52   if (paths.length) {
53     callback(paths);
54   } else {
55     callback(links);
56   }
59 function getTestManifest(url, params, callback) {
60   let req = new XMLHttpRequest();
61   req.open("GET", url);
62   req.onload = function () {
63     if (req.readyState == 4) {
64       if (req.status == 200) {
65         try {
66           parseTestManifest(JSON.parse(req.responseText), params, callback);
67         } catch (e) {
68           dump(
69             "TEST-UNEXPECTED-FAIL: manifestLibrary.js | error parsing " +
70               url +
71               " (" +
72               e +
73               ")\n"
74           );
75           throw e;
76         }
77       } else {
78         dump(
79           "TEST-UNEXPECTED-FAIL: manifestLibrary.js | error loading " +
80             url +
81             " (HTTP " +
82             req.status +
83             ")\n"
84         );
85         callback({});
86       }
87     }
88   };
89   req.send();
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
97  testList
98  parameters:
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
102  returns:
103    filtered version of testList
105 function filterTests(filter, testList, runOnly) {
106   let filteredTests = [];
107   let runtests = {};
108   let excludetests = {};
110   if (filter == null) {
111     return testList;
112   }
114   if ("runtests" in filter) {
115     runtests = filter.runtests;
116   }
117   if ("excludetests" in filter) {
118     excludetests = filter.excludetests;
119   }
120   if (!("runtests" in filter) && !("excludetests" in filter)) {
121     if (runOnly == "true") {
122       runtests = filter;
123     } else {
124       excludetests = filter;
125     }
126   }
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
131   // filteredTests.
132   if (Object.keys(runtests).length) {
133     for (let i = 0; i < testList.length; i++) {
134       let testpath;
135       if (testList[i] instanceof Object && "test" in testList[i]) {
136         testpath = testList[i].test.url;
137       } else {
138         testpath = testList[i];
139       }
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);
149           break;
150         }
151       }
152     }
153   } else {
154     filteredTests = testList.slice(0);
155   }
157   // Continue with filteredTests, and deselect everything that's in
158   // excludedtests.
159   if (!Object.keys(excludetests).length) {
160     return filteredTests;
161   }
163   let refilteredTests = [];
164   for (let i = 0; i < filteredTests.length; i++) {
165     let found = false;
166     let testpath;
167     if (filteredTests[i] instanceof Object && "test" in filteredTests[i]) {
168       testpath = filteredTests[i].test.url;
169     } else {
170       testpath = filteredTests[i];
171     }
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) {
180         found = true;
181         break;
182       }
183     }
184     if (!found) {
185       refilteredTests.push(testpath);
186     }
187   }
188   return refilteredTests;