jasmine-boot.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. function initializePDFJS(callback) {
  17. Promise.all([
  18. 'pdfjs/display/global',
  19. 'pdfjs-test/unit/annotation_spec',
  20. 'pdfjs-test/unit/api_spec',
  21. 'pdfjs-test/unit/bidi_spec',
  22. 'pdfjs-test/unit/cff_parser_spec',
  23. 'pdfjs-test/unit/cmap_spec',
  24. 'pdfjs-test/unit/crypto_spec',
  25. 'pdfjs-test/unit/document_spec',
  26. 'pdfjs-test/unit/dom_utils_spec',
  27. 'pdfjs-test/unit/evaluator_spec',
  28. 'pdfjs-test/unit/fonts_spec',
  29. 'pdfjs-test/unit/function_spec',
  30. 'pdfjs-test/unit/metadata_spec',
  31. 'pdfjs-test/unit/murmurhash3_spec',
  32. 'pdfjs-test/unit/network_spec',
  33. 'pdfjs-test/unit/parser_spec',
  34. 'pdfjs-test/unit/primitives_spec',
  35. 'pdfjs-test/unit/stream_spec',
  36. 'pdfjs-test/unit/type1_parser_spec',
  37. 'pdfjs-test/unit/ui_utils_spec',
  38. 'pdfjs-test/unit/unicode_spec',
  39. 'pdfjs-test/unit/util_spec'
  40. ].map(function (moduleName) {
  41. return SystemJS.import(moduleName);
  42. })).then(function (modules) {
  43. var displayGlobal = modules[0];
  44. displayGlobal.PDFJS.workerSrc = '../../src/worker_loader.js';
  45. callback();
  46. });
  47. }
  48. (function () {
  49. window.jasmine = jasmineRequire.core(jasmineRequire);
  50. jasmineRequire.html(jasmine);
  51. var env = jasmine.getEnv();
  52. var jasmineInterface = jasmineRequire.interface(jasmine, env);
  53. extend(window, jasmineInterface);
  54. var queryString = new jasmine.QueryString({
  55. getWindowLocation: function () {
  56. return window.location;
  57. }
  58. });
  59. var catchingExceptions = queryString.getParam('catch');
  60. env.catchExceptions(typeof catchingExceptions === 'undefined' ? true : catchingExceptions);
  61. var throwingExpectationFailures = queryString.getParam('throwFailures');
  62. env.throwOnExpectationFailure(throwingExpectationFailures);
  63. var random = queryString.getParam('random');
  64. env.randomizeTests(random);
  65. var seed = queryString.getParam('seed');
  66. if (seed) {
  67. env.seed(seed);
  68. }
  69. var htmlReporter = new jasmine.HtmlReporter({
  70. env: env,
  71. onRaiseExceptionsClick: function () {
  72. queryString.navigateWithNewParam('catch', !env.catchingExceptions());
  73. },
  74. onThrowExpectationsClick: function () {
  75. queryString.navigateWithNewParam('throwFailures', !env.throwingExpectationFailures());
  76. },
  77. onRandomClick: function () {
  78. queryString.navigateWithNewParam('random', !env.randomTests());
  79. },
  80. addToExistingQueryString: function (key, value) {
  81. return queryString.fullStringWithNewParam(key, value);
  82. },
  83. getContainer: function () {
  84. return document.body;
  85. },
  86. createElement: function () {
  87. return document.createElement.apply(document, arguments);
  88. },
  89. createTextNode: function () {
  90. return document.createTextNode.apply(document, arguments);
  91. },
  92. timer: new jasmine.Timer()
  93. });
  94. env.addReporter(htmlReporter);
  95. if (queryString.getParam('browser')) {
  96. var testReporter = new TestReporter(queryString.getParam('browser'), queryString.getParam('path'));
  97. env.addReporter(testReporter);
  98. }
  99. var specFilter = new jasmine.HtmlSpecFilter({
  100. filterString: function () {
  101. return queryString.getParam('spec');
  102. }
  103. });
  104. env.specFilter = function (spec) {
  105. return specFilter.matches(spec.getFullName());
  106. };
  107. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  108. var currentWindowOnload = window.onload;
  109. window.onload = function () {
  110. if (currentWindowOnload) {
  111. currentWindowOnload();
  112. }
  113. initializePDFJS(function () {
  114. htmlReporter.initialize();
  115. env.execute();
  116. });
  117. };
  118. function extend(destination, source) {
  119. for (var property in source) {
  120. destination[property] = source[property];
  121. }
  122. return destination;
  123. }
  124. }());