test-frame-utils.js 2.4 KB

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