1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/test/addons/unsafe-content-script/main.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 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: makeFrame } = require("sdk/frame/utils"); 1.10 +const { window } = require("sdk/addon/window"); 1.11 +const { Loader } = require('sdk/test/loader'); 1.12 +const loader = Loader(module); 1.13 +const Worker = loader.require("sdk/content/worker").Worker; 1.14 + 1.15 +exports.testMembranelessMode = function(assert, done) { 1.16 + 1.17 + let url = "data:text/html;charset=utf-8," + encodeURIComponent( 1.18 + '<script>' + 1.19 + 'function runTest() {' + 1.20 + ' assert(fuu.bar == 42, "Content-script objects should be accessible to content with' + 1.21 + ' the unsafe-content-script flag on.");' + 1.22 + '}' + 1.23 + '</script>' 1.24 + ); 1.25 + 1.26 + let element = makeFrame(window.document, { 1.27 + nodeName: "iframe", 1.28 + type: "content", 1.29 + allowJavascript: true, 1.30 + allowPlugins: true, 1.31 + allowAuth: true, 1.32 + uri: url 1.33 + }); 1.34 + 1.35 + element.addEventListener("DOMContentLoaded", onDOMReady, false); 1.36 + 1.37 + function onDOMReady() { 1.38 + let worker = Worker({ 1.39 + window: element.contentWindow, 1.40 + contentScript: 1.41 + 'new ' + function () { 1.42 + var assert = function assert(v, msg) { 1.43 + self.port.emit("assert", { assertion: v, msg: msg }); 1.44 + } 1.45 + var done = function done() { 1.46 + self.port.emit("done"); 1.47 + } 1.48 + window.wrappedJSObject.fuu = { bar: 42 }; 1.49 + window.wrappedJSObject.assert = assert; 1.50 + window.wrappedJSObject.runTest(); 1.51 + done(); 1.52 + } 1.53 + }); 1.54 + worker.port.on("done", function () { 1.55 + element.parentNode.removeChild(element); 1.56 + done(); 1.57 + }); 1.58 + worker.port.on("assert", function (data) { 1.59 + assert.ok(data.assertion, data.msg); 1.60 + }); 1.61 + } 1.62 +}; 1.63 + 1.64 +require("sdk/test/runner").runTestsFromModule(module);