jasmine-boot.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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(['pdfjs/display/global', 'pdfjs-test/unit/annotation_spec', 'pdfjs-test/unit/api_spec', 'pdfjs-test/unit/bidi_spec', 'pdfjs-test/unit/cff_parser_spec', 'pdfjs-test/unit/cmap_spec', 'pdfjs-test/unit/crypto_spec', 'pdfjs-test/unit/document_spec', 'pdfjs-test/unit/dom_utils_spec', 'pdfjs-test/unit/evaluator_spec', 'pdfjs-test/unit/fonts_spec', 'pdfjs-test/unit/function_spec', 'pdfjs-test/unit/metadata_spec', 'pdfjs-test/unit/murmurhash3_spec', 'pdfjs-test/unit/network_spec', 'pdfjs-test/unit/parser_spec', 'pdfjs-test/unit/primitives_spec', 'pdfjs-test/unit/stream_spec', 'pdfjs-test/unit/type1_parser_spec', 'pdfjs-test/unit/ui_utils_spec', 'pdfjs-test/unit/unicode_spec', 'pdfjs-test/unit/util_spec'].map(function (moduleName) {
  18. return SystemJS.import(moduleName);
  19. })).then(function (modules) {
  20. var displayGlobal = modules[0];
  21. displayGlobal.PDFJS.workerSrc = '../../src/worker_loader.js';
  22. callback();
  23. });
  24. }
  25. (function () {
  26. window.jasmine = jasmineRequire.core(jasmineRequire);
  27. jasmineRequire.html(jasmine);
  28. var env = jasmine.getEnv();
  29. var jasmineInterface = jasmineRequire.interface(jasmine, env);
  30. extend(window, jasmineInterface);
  31. var queryString = new jasmine.QueryString({
  32. getWindowLocation: function () {
  33. return window.location;
  34. }
  35. });
  36. var catchingExceptions = queryString.getParam('catch');
  37. env.catchExceptions(typeof catchingExceptions === 'undefined' ? true : catchingExceptions);
  38. var throwingExpectationFailures = queryString.getParam('throwFailures');
  39. env.throwOnExpectationFailure(throwingExpectationFailures);
  40. var random = queryString.getParam('random');
  41. env.randomizeTests(random);
  42. var seed = queryString.getParam('seed');
  43. if (seed) {
  44. env.seed(seed);
  45. }
  46. var htmlReporter = new jasmine.HtmlReporter({
  47. env: env,
  48. onRaiseExceptionsClick: function () {
  49. queryString.navigateWithNewParam('catch', !env.catchingExceptions());
  50. },
  51. onThrowExpectationsClick: function () {
  52. queryString.navigateWithNewParam('throwFailures', !env.throwingExpectationFailures());
  53. },
  54. onRandomClick: function () {
  55. queryString.navigateWithNewParam('random', !env.randomTests());
  56. },
  57. addToExistingQueryString: function (key, value) {
  58. return queryString.fullStringWithNewParam(key, value);
  59. },
  60. getContainer: function () {
  61. return document.body;
  62. },
  63. createElement: function () {
  64. return document.createElement.apply(document, arguments);
  65. },
  66. createTextNode: function () {
  67. return document.createTextNode.apply(document, arguments);
  68. },
  69. timer: new jasmine.Timer()
  70. });
  71. env.addReporter(htmlReporter);
  72. if (queryString.getParam('browser')) {
  73. var testReporter = new TestReporter(queryString.getParam('browser'), queryString.getParam('path'));
  74. env.addReporter(testReporter);
  75. }
  76. var specFilter = new jasmine.HtmlSpecFilter({
  77. filterString: function () {
  78. return queryString.getParam('spec');
  79. }
  80. });
  81. env.specFilter = function (spec) {
  82. return specFilter.matches(spec.getFullName());
  83. };
  84. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  85. var currentWindowOnload = window.onload;
  86. window.onload = function () {
  87. if (currentWindowOnload) {
  88. currentWindowOnload();
  89. }
  90. initializePDFJS(function () {
  91. htmlReporter.initialize();
  92. env.execute();
  93. });
  94. };
  95. function extend(destination, source) {
  96. for (var property in source) {
  97. destination[property] = source[property];
  98. }
  99. return destination;
  100. }
  101. })();