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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-frame-utils.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     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 { create } = require('sdk/frame/utils');
    1.10 +const { open, close } = require('sdk/window/helpers');
    1.11 +
    1.12 +exports['test frame creation'] = function(assert, done) {
    1.13 +  open('data:text/html;charset=utf-8,Window').then(function (window) {
    1.14 +    let frame = create(window.document);
    1.15 +
    1.16 +    assert.equal(frame.getAttribute('type'), 'content',
    1.17 +                 'frame type is content');
    1.18 +    assert.ok(frame.contentWindow, 'frame has contentWindow');
    1.19 +    assert.equal(frame.contentWindow.location.href, 'about:blank',
    1.20 +                 'by default "about:blank" is loaded');
    1.21 +    assert.equal(frame.docShell.allowAuth, false, 'auth disabled by default');
    1.22 +    assert.equal(frame.docShell.allowJavascript, false, 'js disabled by default');
    1.23 +    assert.equal(frame.docShell.allowPlugins, false,
    1.24 +                 'plugins disabled by default');
    1.25 +    close(window).then(done);
    1.26 +  });
    1.27 +};
    1.28 +
    1.29 +exports['test fram has js disabled by default'] = function(assert, done) {
    1.30 +  open('data:text/html;charset=utf-8,window').then(function (window) {
    1.31 +    let frame = create(window.document, {
    1.32 +      uri: 'data:text/html;charset=utf-8,<script>document.documentElement.innerHTML' +
    1.33 +           '= "J" + "S"</script>',
    1.34 +    });
    1.35 +    frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
    1.36 +      frame.contentWindow.removeEventListener('DOMContentLoaded', ready, false);
    1.37 +      assert.ok(!~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
    1.38 +                'JS was executed');
    1.39 +
    1.40 +      close(window).then(done);
    1.41 +    }, false);
    1.42 +  });
    1.43 +};
    1.44 +
    1.45 +exports['test frame with js enabled'] = function(assert, done) {
    1.46 +  open('data:text/html;charset=utf-8,window').then(function (window) {
    1.47 +    let frame = create(window.document, {
    1.48 +      uri: 'data:text/html;charset=utf-8,<script>document.documentElement.innerHTML' +
    1.49 +           '= "J" + "S"</script>',
    1.50 +      allowJavascript: true
    1.51 +    });
    1.52 +    frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
    1.53 +      frame.contentWindow.removeEventListener('DOMContentLoaded', ready, false);
    1.54 +      assert.ok(~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
    1.55 +                'JS was executed');
    1.56 +
    1.57 +      close(window).then(done);
    1.58 +    }, false);
    1.59 +  });
    1.60 +};
    1.61 +
    1.62 +require('test').run(exports);

mercurial