module-worker.test.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Copyright 2018 Google Inc. All Rights Reserved.
  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. * http://www.apache.org/licenses/LICENSE-2.0
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. describe("Module Worker", function() {
  14. const blob = new Blob([""], { type: "text/javascript" });
  15. const url = URL.createObjectURL(blob);
  16. let supportsModuleWorker = false;
  17. const options = {
  18. get type() {
  19. supportsModuleWorker = true;
  20. }
  21. };
  22. new Worker(url, options).terminate();
  23. URL.revokeObjectURL(url);
  24. beforeEach(function() {
  25. if (!supportsModuleWorker) {
  26. return this.skip();
  27. }
  28. this.ifr = document.createElement("iframe");
  29. document.body.append(this.ifr);
  30. });
  31. afterEach(function() {
  32. this.ifr.remove();
  33. });
  34. it("work", function(done) {
  35. window.addEventListener("message", function l(ev) {
  36. if (ev.data === "a") {
  37. window.removeEventListener("message", l);
  38. done();
  39. }
  40. });
  41. this.ifr.src = "/base/tests/fixtures/module-worker/build/runner.html";
  42. });
  43. });