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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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';
     6 const { create } = require('sdk/frame/utils');
     7 const { open, close } = require('sdk/window/helpers');
     9 exports['test frame creation'] = function(assert, done) {
    10   open('data:text/html;charset=utf-8,Window').then(function (window) {
    11     let frame = create(window.document);
    13     assert.equal(frame.getAttribute('type'), 'content',
    14                  'frame type is content');
    15     assert.ok(frame.contentWindow, 'frame has contentWindow');
    16     assert.equal(frame.contentWindow.location.href, 'about:blank',
    17                  'by default "about:blank" is loaded');
    18     assert.equal(frame.docShell.allowAuth, false, 'auth disabled by default');
    19     assert.equal(frame.docShell.allowJavascript, false, 'js disabled by default');
    20     assert.equal(frame.docShell.allowPlugins, false,
    21                  'plugins disabled by default');
    22     close(window).then(done);
    23   });
    24 };
    26 exports['test fram has js disabled by default'] = function(assert, done) {
    27   open('data:text/html;charset=utf-8,window').then(function (window) {
    28     let frame = create(window.document, {
    29       uri: 'data:text/html;charset=utf-8,<script>document.documentElement.innerHTML' +
    30            '= "J" + "S"</script>',
    31     });
    32     frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
    33       frame.contentWindow.removeEventListener('DOMContentLoaded', ready, false);
    34       assert.ok(!~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
    35                 'JS was executed');
    37       close(window).then(done);
    38     }, false);
    39   });
    40 };
    42 exports['test frame with js enabled'] = function(assert, done) {
    43   open('data:text/html;charset=utf-8,window').then(function (window) {
    44     let frame = create(window.document, {
    45       uri: 'data:text/html;charset=utf-8,<script>document.documentElement.innerHTML' +
    46            '= "J" + "S"</script>',
    47       allowJavascript: true
    48     });
    49     frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
    50       frame.contentWindow.removeEventListener('DOMContentLoaded', ready, false);
    51       assert.ok(~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
    52                 'JS was executed');
    54       close(window).then(done);
    55     }, false);
    56   });
    57 };
    59 require('test').run(exports);

mercurial