addon-sdk/source/test/test-hidden-frame.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-hidden-frame.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +"use strict";
     1.8 +
     1.9 +const { Loader } = require("sdk/test/loader");
    1.10 +const hiddenFrames = require("sdk/frame/hidden-frame");
    1.11 +const { HiddenFrame } = hiddenFrames;
    1.12 +
    1.13 +exports["test Frame"] = function(assert, done) {
    1.14 +  let url = "data:text/html;charset=utf-8,<!DOCTYPE%20html>";
    1.15 +
    1.16 +  let hiddenFrame = hiddenFrames.add(HiddenFrame({
    1.17 +    onReady: function () {
    1.18 +      assert.equal(this.element.contentWindow.location, "about:blank",
    1.19 +                       "HiddenFrame loads about:blank by default.");
    1.20 +
    1.21 +      function onDOMReady() {
    1.22 +        hiddenFrame.element.removeEventListener("DOMContentLoaded", onDOMReady,
    1.23 +                                                false);
    1.24 +        assert.equal(hiddenFrame.element.contentWindow.location, url,
    1.25 +                         "HiddenFrame loads the specified content.");
    1.26 +        done();
    1.27 +      }
    1.28 +
    1.29 +      this.element.addEventListener("DOMContentLoaded", onDOMReady, false);
    1.30 +      this.element.setAttribute("src", url);
    1.31 +    }
    1.32 +  }));
    1.33 +};
    1.34 +
    1.35 +exports["test frame removed properly"] = function(assert, done) {
    1.36 +  let url = "data:text/html;charset=utf-8,<!DOCTYPE%20html>";
    1.37 +
    1.38 +  let hiddenFrame = hiddenFrames.add(HiddenFrame({
    1.39 +    onReady: function () {
    1.40 +      let frame = this.element;
    1.41 +      assert.ok(frame.parentNode, "frame has a parent node");
    1.42 +      hiddenFrames.remove(hiddenFrame);
    1.43 +      assert.ok(!frame.parentNode, "frame no longer has a parent node");
    1.44 +      done();
    1.45 +    }
    1.46 +  }));
    1.47 +};
    1.48 +
    1.49 +exports["test unload detaches panels"] = function(assert, done) {
    1.50 +  let loader = Loader(module);
    1.51 +  let { add, remove, HiddenFrame } = loader.require("sdk/frame/hidden-frame");
    1.52 +  let frames = []
    1.53 +
    1.54 +  function ready() {
    1.55 +    frames.push(this.element);
    1.56 +    if (frames.length === 2) complete();
    1.57 +  }
    1.58 +
    1.59 +  add(HiddenFrame({ onReady: ready }));
    1.60 +  add(HiddenFrame({ onReady: ready }));
    1.61 +
    1.62 +  function complete() {
    1.63 +    frames.forEach(function(frame) {
    1.64 +      assert.ok(frame.parentNode, "frame is in the document");
    1.65 +    })
    1.66 +    loader.unload();
    1.67 +    frames.forEach(function(frame) {
    1.68 +      assert.ok(!frame.parentNode, "frame isn't in the document'");
    1.69 +    });
    1.70 +    done();
    1.71 +  }
    1.72 +};
    1.73 +
    1.74 +require("test").run(exports);

mercurial