jasmine-boot.js 5.2 KB

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