|
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 |
|
6 const { create } = require('sdk/frame/utils'); |
|
7 const { open, close } = require('sdk/window/helpers'); |
|
8 |
|
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); |
|
12 |
|
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 }; |
|
25 |
|
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'); |
|
36 |
|
37 close(window).then(done); |
|
38 }, false); |
|
39 }); |
|
40 }; |
|
41 |
|
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'); |
|
53 |
|
54 close(window).then(done); |
|
55 }, false); |
|
56 }); |
|
57 }; |
|
58 |
|
59 require('test').run(exports); |