test-hidden-frame.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const { Loader } = require("sdk/test/loader");
  6. const hiddenFrames = require("sdk/frame/hidden-frame");
  7. const { HiddenFrame } = hiddenFrames;
  8. exports["test Frame"] = function(assert, done) {
  9. let url = "data:text/html;charset=utf-8,<!DOCTYPE%20html>";
  10. let hiddenFrame = hiddenFrames.add(HiddenFrame({
  11. onReady: function () {
  12. assert.equal(this.element.contentWindow.location, "about:blank",
  13. "HiddenFrame loads about:blank by default.");
  14. function onDOMReady() {
  15. hiddenFrame.element.removeEventListener("DOMContentLoaded", onDOMReady,
  16. false);
  17. assert.equal(hiddenFrame.element.contentWindow.location, url,
  18. "HiddenFrame loads the specified content.");
  19. done();
  20. }
  21. this.element.addEventListener("DOMContentLoaded", onDOMReady, false);
  22. this.element.setAttribute("src", url);
  23. }
  24. }));
  25. };
  26. exports["test frame removed properly"] = function(assert, done) {
  27. let url = "data:text/html;charset=utf-8,<!DOCTYPE%20html>";
  28. let hiddenFrame = hiddenFrames.add(HiddenFrame({
  29. onReady: function () {
  30. let frame = this.element;
  31. assert.ok(frame.parentNode, "frame has a parent node");
  32. hiddenFrames.remove(hiddenFrame);
  33. assert.ok(!frame.parentNode, "frame no longer has a parent node");
  34. done();
  35. }
  36. }));
  37. };
  38. exports["test unload detaches panels"] = function(assert, done) {
  39. let loader = Loader(module);
  40. let { add, remove, HiddenFrame } = loader.require("sdk/frame/hidden-frame");
  41. let frames = []
  42. function ready() {
  43. frames.push(this.element);
  44. if (frames.length === 2) complete();
  45. }
  46. add(HiddenFrame({ onReady: ready }));
  47. add(HiddenFrame({ onReady: ready }));
  48. function complete() {
  49. frames.forEach(function(frame) {
  50. assert.ok(frame.parentNode, "frame is in the document");
  51. })
  52. loader.unload();
  53. frames.forEach(function(frame) {
  54. assert.ok(!frame.parentNode, "frame isn't in the document'");
  55. });
  56. done();
  57. }
  58. };
  59. require("test").run(exports);