addon-sdk/source/test/addons/unsafe-content-script/main.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.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 "use strict";
michael@0 5
michael@0 6 const { create: makeFrame } = require("sdk/frame/utils");
michael@0 7 const { window } = require("sdk/addon/window");
michael@0 8 const { Loader } = require('sdk/test/loader');
michael@0 9 const loader = Loader(module);
michael@0 10 const Worker = loader.require("sdk/content/worker").Worker;
michael@0 11
michael@0 12 exports.testMembranelessMode = function(assert, done) {
michael@0 13
michael@0 14 let url = "data:text/html;charset=utf-8," + encodeURIComponent(
michael@0 15 '<script>' +
michael@0 16 'function runTest() {' +
michael@0 17 ' assert(fuu.bar == 42, "Content-script objects should be accessible to content with' +
michael@0 18 ' the unsafe-content-script flag on.");' +
michael@0 19 '}' +
michael@0 20 '</script>'
michael@0 21 );
michael@0 22
michael@0 23 let element = makeFrame(window.document, {
michael@0 24 nodeName: "iframe",
michael@0 25 type: "content",
michael@0 26 allowJavascript: true,
michael@0 27 allowPlugins: true,
michael@0 28 allowAuth: true,
michael@0 29 uri: url
michael@0 30 });
michael@0 31
michael@0 32 element.addEventListener("DOMContentLoaded", onDOMReady, false);
michael@0 33
michael@0 34 function onDOMReady() {
michael@0 35 let worker = Worker({
michael@0 36 window: element.contentWindow,
michael@0 37 contentScript:
michael@0 38 'new ' + function () {
michael@0 39 var assert = function assert(v, msg) {
michael@0 40 self.port.emit("assert", { assertion: v, msg: msg });
michael@0 41 }
michael@0 42 var done = function done() {
michael@0 43 self.port.emit("done");
michael@0 44 }
michael@0 45 window.wrappedJSObject.fuu = { bar: 42 };
michael@0 46 window.wrappedJSObject.assert = assert;
michael@0 47 window.wrappedJSObject.runTest();
michael@0 48 done();
michael@0 49 }
michael@0 50 });
michael@0 51 worker.port.on("done", function () {
michael@0 52 element.parentNode.removeChild(element);
michael@0 53 done();
michael@0 54 });
michael@0 55 worker.port.on("assert", function (data) {
michael@0 56 assert.ok(data.assertion, data.msg);
michael@0 57 });
michael@0 58 }
michael@0 59 };
michael@0 60
michael@0 61 require("sdk/test/runner").runTestsFromModule(module);

mercurial