manifestLibrary.js 4.6 KB

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