From a184de4560179f88771da4b3cb2e12e30780963c Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Tue, 30 Jun 2015 15:10:35 -0700 Subject: [PATCH] Bug 1179013: Uplift Add-on SDK. a=me https://github.com/mozilla/addon-sdk/compare/d8ba32821ef1a53963f4b8015b61f97d624018b0...96ae8d914fab9baad903cac07bf9f37da98fc0bc --HG-- extra : commitid : a69qoBWTUP extra : rebase_source : 7d0464d7fa1af660b5971bda97786112b0c76053 --- addon-sdk/moz.build | 7 +- addon-sdk/source/.travis.yml | 2 +- addon-sdk/source/bin/jpm-test.js | 9 +- .../bin/node-scripts/test.firefox-bin.js | 37 + addon-sdk/source/bin/node-scripts/test.ini.js | 33 +- .../source/bin/node-scripts/update-ini.js | 85 ++- addon-sdk/source/bin/node-scripts/utils.js | 3 + addon-sdk/source/gulpfile.js | 10 +- addon-sdk/source/lib/sdk/console/traceback.js | 5 +- addon-sdk/source/lib/sdk/content/sandbox.js | 11 +- .../sdk/content/sandbox/events.js} | 9 +- addon-sdk/source/lib/sdk/deprecated/memory.js | 129 ---- .../source/lib/sdk/deprecated/sync-worker.js | 9 - .../lib/sdk/deprecated/unit-test-finder.js | 2 - .../source/lib/sdk/deprecated/unit-test.js | 44 +- addon-sdk/source/lib/sdk/io/data.js | 90 --- addon-sdk/source/lib/sdk/io/text-streams.js | 31 +- .../source/lib/sdk/places/host/host-query.js | 67 +- addon-sdk/source/lib/sdk/places/utils.js | 12 +- addon-sdk/source/lib/sdk/self.js | 5 +- addon-sdk/source/lib/sdk/tabs/helpers.js | 10 - addon-sdk/source/lib/sdk/tabs/tab-fennec.js | 20 - addon-sdk/source/lib/sdk/tabs/tab-firefox.js | 10 - addon-sdk/source/lib/sdk/test/harness.js | 22 +- addon-sdk/source/lib/sdk/test/memory.js | 11 +- addon-sdk/source/lib/sdk/util/bond.js | 36 - addon-sdk/source/lib/sdk/util/rules.js | 5 +- addon-sdk/source/lib/sdk/zip/utils.js | 22 +- addon-sdk/source/lib/toolkit/loader.js | 3 +- addon-sdk/source/mapping.json | 1 - addon-sdk/source/package.json | 1 + .../source/python-lib/cuddlefish/__init__.py | 8 - .../tests/addons/simplest-test/main.js | 17 - .../simplest-test/manifest-overload.json | 3 - .../tests/addons/simplest-test/package.json | 6 - .../python-lib/cuddlefish/tests/test_init.py | 31 +- .../source/test/addons/chrome/data/panel.js | 2 + addon-sdk/source/test/addons/chrome/main.js | 30 +- .../test/addons/e10s-tabs/lib/test-tab.js | 106 --- .../lib/test-cuddlefish-loader.js | 10 - .../test/addons/places/lib/places-helper.js | 7 - .../places/lib/test-places-bookmarks.js | 129 ++-- .../addons/places/lib/test-places-events.js | 2 +- .../addons/places/lib/test-places-history.js | 195 +++-- .../addons/places/lib/test-places-host.js | 14 +- .../addons/require/{memory.js => list.js} | 1 + addon-sdk/source/test/addons/require/main.js | 6 +- addon-sdk/source/test/fixtures/index.html | 5 + .../test/fixtures/loader/globals/main.js | 1 + .../fixtures/test-addon-extras-window.html | 21 + .../test/fixtures/test-addon-extras.html | 31 + addon-sdk/source/test/fixtures/test.html | 12 + addon-sdk/source/test/jetpack-package.ini | 19 +- addon-sdk/source/test/loader/user-global.js | 11 + .../helpers.js} | 8 +- .../source/test/private-browsing/windows.js | 20 +- .../source/test/tabs/test-fennec-tabs.js | 11 - .../source/test/tabs/test-firefox-tabs.js | 215 +++--- addon-sdk/source/test/test-addon-extras.js | 171 +++++ addon-sdk/source/test/test-bond.js | 169 ----- addon-sdk/source/test/test-file.js | 1 - addon-sdk/source/test/test-hotkeys.js | 56 +- addon-sdk/source/test/test-indexed-db.js | 11 - addon-sdk/source/test/test-loader.js | 28 + addon-sdk/source/test/test-memory.js | 22 - .../source/test/test-mpl2-license-header.js | 24 +- addon-sdk/source/test/test-page-mod-debug.js | 66 ++ addon-sdk/source/test/test-page-mod.js | 689 +++++++++++------- addon-sdk/source/test/test-panel.js | 66 +- addon-sdk/source/test/test-tab.js | 103 --- addon-sdk/source/test/test-test-utils.js | 47 +- .../source/test/test-ui-action-button.js | 13 +- addon-sdk/source/test/test-unit-test.js | 15 +- addon-sdk/source/test/test-weak-set.js | 150 ++-- addon-sdk/source/test/test-windows-common.js | 26 +- addon-sdk/source/test/test-xul-app.js | 23 +- .../test/windows/test-firefox-windows.js | 3 +- 77 files changed, 1593 insertions(+), 1752 deletions(-) create mode 100644 addon-sdk/source/bin/node-scripts/test.firefox-bin.js rename addon-sdk/source/{python-lib/cuddlefish/tests/addons/simplest-test/tests/test-minimal.js => lib/sdk/content/sandbox/events.js} (65%) delete mode 100644 addon-sdk/source/lib/sdk/deprecated/memory.js delete mode 100644 addon-sdk/source/lib/sdk/io/data.js delete mode 100644 addon-sdk/source/lib/sdk/util/bond.js delete mode 100644 addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/main.js delete mode 100644 addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/manifest-overload.json delete mode 100644 addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/package.json rename addon-sdk/source/test/addons/require/{memory.js => list.js} (94%) create mode 100644 addon-sdk/source/test/fixtures/test-addon-extras-window.html create mode 100644 addon-sdk/source/test/fixtures/test-addon-extras.html create mode 100644 addon-sdk/source/test/loader/user-global.js rename addon-sdk/source/test/{pagemod-test-helpers.js => page-mod/helpers.js} (93%) create mode 100644 addon-sdk/source/test/test-addon-extras.js delete mode 100644 addon-sdk/source/test/test-bond.js delete mode 100644 addon-sdk/source/test/test-memory.js create mode 100644 addon-sdk/source/test/test-page-mod-debug.js diff --git a/addon-sdk/moz.build b/addon-sdk/moz.build index 2186e00d25877..d83cb209c4ff0 100644 --- a/addon-sdk/moz.build +++ b/addon-sdk/moz.build @@ -29,7 +29,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != "gonk": EXTRA_JS_MODULES.commonjs.sdk.deprecated += [ 'source/lib/sdk/deprecated/api-utils.js', - 'source/lib/sdk/deprecated/memory.js', 'source/lib/sdk/deprecated/sync-worker.js', 'source/lib/sdk/deprecated/unit-test-finder.js', 'source/lib/sdk/deprecated/unit-test.js', @@ -258,6 +257,10 @@ EXTRA_JS_MODULES.commonjs.sdk.content += [ 'source/lib/sdk/content/worker.js', ] +EXTRA_JS_MODULES.commonjs.sdk.content.sandbox += [ + 'source/lib/sdk/content/sandbox/events.js', +] + EXTRA_JS_MODULES.commonjs.sdk['context-menu'] += [ 'source/lib/sdk/context-menu/context.js', 'source/lib/sdk/context-menu/core.js', @@ -307,7 +310,6 @@ EXTRA_JS_MODULES.commonjs.sdk.input += [ EXTRA_JS_MODULES.commonjs.sdk.io += [ 'source/lib/sdk/io/buffer.js', 'source/lib/sdk/io/byte-streams.js', - 'source/lib/sdk/io/data.js', 'source/lib/sdk/io/file.js', 'source/lib/sdk/io/fs.js', 'source/lib/sdk/io/stream.js', @@ -453,7 +455,6 @@ EXTRA_JS_MODULES.commonjs.sdk.url += [ EXTRA_JS_MODULES.commonjs.sdk.util += [ 'source/lib/sdk/util/array.js', - 'source/lib/sdk/util/bond.js', 'source/lib/sdk/util/collection.js', 'source/lib/sdk/util/contract.js', 'source/lib/sdk/util/deprecate.js', diff --git a/addon-sdk/source/.travis.yml b/addon-sdk/source/.travis.yml index d74bec240146b..287b62a4f8b63 100644 --- a/addon-sdk/source/.travis.yml +++ b/addon-sdk/source/.travis.yml @@ -1,7 +1,7 @@ sudo: false language: node_js node_js: - - "0.10" + - "0.12" env: - JPM_FX_DEBUG=0 diff --git a/addon-sdk/source/bin/jpm-test.js b/addon-sdk/source/bin/jpm-test.js index cc06e8c321727..f22a552ea7ba5 100644 --- a/addon-sdk/source/bin/jpm-test.js +++ b/addon-sdk/source/bin/jpm-test.js @@ -17,12 +17,13 @@ exports.run = function(type) { return new Promise(function(resolve) { type = type || ""; [ - (!isDebug && /^(modules)?$/.test(type)) && require.resolve("../bin/node-scripts/test.modules"), - (!isDebug && /^(addons)?$/.test(type)) && require.resolve("../bin/node-scripts/test.addons"), - (/^(examples)?$/.test(type)) && require.resolve("../bin/node-scripts/test.examples"), + (!isDebug && /^(firefox-bin)?$/.test(type)) && require.resolve("../bin/node-scripts/test.firefox-bin"), (!isDebug && /^(docs)?$/.test(type)) && require.resolve("../bin/node-scripts/test.docs"), (!isDebug && /^(ini)?$/.test(type)) && require.resolve("../bin/node-scripts/test.ini"), - ].sort().forEach(function(filepath) { + (/^(examples)?$/.test(type)) && require.resolve("../bin/node-scripts/test.examples"), + (!isDebug && /^(addons)?$/.test(type)) && require.resolve("../bin/node-scripts/test.addons"), + (!isDebug && /^(modules)?$/.test(type)) && require.resolve("../bin/node-scripts/test.modules"), + ].forEach(function(filepath) { filepath && mocha.addFile(filepath); }) diff --git a/addon-sdk/source/bin/node-scripts/test.firefox-bin.js b/addon-sdk/source/bin/node-scripts/test.firefox-bin.js new file mode 100644 index 0000000000000..2570dae20f89e --- /dev/null +++ b/addon-sdk/source/bin/node-scripts/test.firefox-bin.js @@ -0,0 +1,37 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +var fs = require("fs"); +var Promise = require("promise"); +var chai = require("chai"); +var expect = chai.expect; +var normalizeBinary = require("fx-runner/lib/utils").normalizeBinary; + +//var firefox_binary = process.env["JPM_FIREFOX_BINARY"] || normalizeBinary("nightly"); + +describe("Checking Firefox binary", function () { + + it("using matching fx-runner version with jpm", function () { + var sdkPackageJSON = require("../../package.json"); + var jpmPackageINI = require("jpm/package.json"); + expect(sdkPackageJSON.devDependencies["fx-runner"]).to.be.equal(jpmPackageINI.dependencies["fx-runner"]); + }); + + it("exists", function (done) { + var useEnvVar = new Promise(function(resolve) { + resolve(process.env["JPM_FIREFOX_BINARY"]); + }); + + var firefox_binary = process.env["JPM_FIREFOX_BINARY"] ? useEnvVar : normalizeBinary("nightly"); + firefox_binary.then(function(path) { + expect(path).to.be.ok; + fs.exists(path, function (exists) { + expect(exists).to.be.ok; + done(); + }); + }) + }); + +}); diff --git a/addon-sdk/source/bin/node-scripts/test.ini.js b/addon-sdk/source/bin/node-scripts/test.ini.js index 5b8f76e7af882..07bd15d1fde50 100644 --- a/addon-sdk/source/bin/node-scripts/test.ini.js +++ b/addon-sdk/source/bin/node-scripts/test.ini.js @@ -11,6 +11,7 @@ var expect = chai.expect; var ini = require("./update-ini"); var addonINI = path.resolve("./test/addons/jetpack-addon.ini"); +var packageINI = path.resolve("./test/jetpack-package.ini"); describe("Checking ini files", function () { @@ -20,7 +21,10 @@ describe("Checking ini files", function () { if (err) { throw err; } - var text = data.toString(); + // filter comments + var text = data.toString().split("\n").filter(function(line) { + return !/^\s*#/.test(line); + }).join("\n"); var expected = ""; ini.makeAddonIniContent() @@ -28,7 +32,32 @@ describe("Checking ini files", function () { expected = contents; setTimeout(function end() { - expect(expected.trim()).to.be.equal(text.trim()); + expect(text.trim()).to.be.equal(expected.trim()); + done(); + }); + }); + }); + + }); + + it("Check test/jetpack-package.ini", function (done) { + + fs.readFile(packageINI, function (err, data) { + if (err) { + throw err; + } + // filter comments + var text = data.toString().split("\n").filter(function(line) { + return !/^\s*#/.test(line); + }).join("\n"); + var expected = ""; + + ini.makePackageIniContent() + .then(function(contents) { + expected = contents; + + setTimeout(function end() { + expect(text.trim()).to.be.equal(expected.trim()); done(); }); }); diff --git a/addon-sdk/source/bin/node-scripts/update-ini.js b/addon-sdk/source/bin/node-scripts/update-ini.js index 250d7da01ddfd..634cbc1de721c 100644 --- a/addon-sdk/source/bin/node-scripts/update-ini.js +++ b/addon-sdk/source/bin/node-scripts/update-ini.js @@ -11,6 +11,14 @@ var parser = require("ini-parser"); var addonINI = path.resolve("./test/addons/jetpack-addon.ini"); var addonsDir = path.resolve("./test/addons/"); +var packageINI = path.resolve("./test/jetpack-package.ini"); +var packageDir = path.resolve("./test/"); +var packageIgnorables = [ "addons", "preferences" ]; +var packageSupportFiles = [ + "fixtures.js", + "test-context-menu.html", + "util.js" +] function updateAddonINI() { return new Promise(function(resolve) { @@ -32,16 +40,18 @@ function makeAddonIniContent() { var result = {}; fs.readdir(addonsDir, function(err, files) { + // get a list of folders var folders = files.filter(function(file) { return fs.statSync(path.resolve(addonsDir, file)).isDirectory(); }).sort(); + // copy any related data from the existing ini folders.forEach(function(folder) { var oldData = data[folder + ".xpi"]; result[folder] = oldData ? oldData : {}; }); - // build ini file + // build a new ini file var contents = []; Object.keys(result).sort().forEach(function(key) { contents.push("[" + key + ".xpi]"); @@ -56,3 +66,76 @@ function makeAddonIniContent() { }); } exports.makeAddonIniContent = makeAddonIniContent; + +function makePackageIniContent() { + return new Promise(function(resolve) { + var data = parser.parse(fs.readFileSync(packageINI, { encoding: "utf8" }).toString()); + var result = {}; + + fs.readdir(packageDir, function(err, files) { + // get a list of folders + var folders = files.filter(function(file) { + var ignore = (packageIgnorables.indexOf(file) >= 0); + var isDir = fs.statSync(path.resolve(packageDir, file)).isDirectory(); + return (isDir && !ignore); + }).sort(); + + // get a list of "test-"" files + var files = files.filter(function(file) { + var ignore = !/^test\-.*\.js$/i.test(file); + var isDir = fs.statSync(path.resolve(packageDir, file)).isDirectory(); + return (!isDir && !ignore); + }).sort(); + + // get a list of the support files + var support_files = packageSupportFiles.map(function(file) { + return " " + file; + }); + folders.forEach(function(folder) { + support_files.push(" " + folder + "/**"); + }); + support_files = support_files.sort(); + + // copy any related data from the existing ini + files.forEach(function(file) { + var oldData = data[file]; + result[file] = oldData ? oldData : {}; + }); + + // build a new ini file + var contents = [ + "[DEFAULT]", + "support-files =" + ]; + support_files.forEach(function(support_file) { + contents.push(support_file); + }); + contents.push(""); + + Object.keys(result).sort().forEach(function(key) { + contents.push("[" + key + "]"); + Object.keys(result[key]).forEach(function(dataKey) { + contents.push(dataKey + " = " + result[key][dataKey]); + }); + }); + contents = contents.join("\n") + "\n"; + + return resolve(contents); + }); + }); +} +exports.makePackageIniContent = makePackageIniContent; + +function updatePackageINI() { + return new Promise(function(resolve) { + console.log("Start updating " + packageINI); + + makeAddonIniContent(). + then(function(contents) { + fs.writeFileSync(packageINI, contents, { encoding: "utf8" }); + console.log("Done updating " + packageINI); + resolve(); + }); + }) +} +exports.updatePackageINI = updatePackageINI; diff --git a/addon-sdk/source/bin/node-scripts/utils.js b/addon-sdk/source/bin/node-scripts/utils.js index 9cb47d04e2358..1d7f94474cf94 100644 --- a/addon-sdk/source/bin/node-scripts/utils.js +++ b/addon-sdk/source/bin/node-scripts/utils.js @@ -65,6 +65,9 @@ function run (cmd, options, p) { if (p) { proc.stdout.pipe(p.stdout); } + else if (!isDebug) { + proc.stdout.pipe(DEFAULT_PROCESS.stdout); + } else { proc.stdout.on("data", function (data) { data = (data || "") + ""; diff --git a/addon-sdk/source/gulpfile.js b/addon-sdk/source/gulpfile.js index 362ef11c362f8..4020dd9d49eb4 100644 --- a/addon-sdk/source/gulpfile.js +++ b/addon-sdk/source/gulpfile.js @@ -28,7 +28,11 @@ gulp.task('test:modules', function(done) { }); gulp.task('test:ini', function(done) { - test("ini").catch(console.error).then(done); + require("./bin/jpm-test").run("ini").catch(console.error).then(done); +}); + +gulp.task('test:firefox-bin', function(done) { + require("./bin/jpm-test").run("firefox-bin").catch(console.error).then(done); }); gulp.task('patch:clean', function(done) { @@ -38,7 +42,3 @@ gulp.task('patch:clean', function(done) { gulp.task('patch:apply', function(done) { patch.apply().catch(console.error).then(done); }); - -gulp.task('update:ini', function(done) { - ini.updateAddonINI().catch(console.error).then(done); -}); diff --git a/addon-sdk/source/lib/sdk/console/traceback.js b/addon-sdk/source/lib/sdk/console/traceback.js index 93e387b2585a8..be0fb7b94ff69 100644 --- a/addon-sdk/source/lib/sdk/console/traceback.js +++ b/addon-sdk/source/lib/sdk/console/traceback.js @@ -1,19 +1,16 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - "use strict"; module.metadata = { "stability": "experimental" }; -const { Cc, Ci, components } = require("chrome"); +const { Ci, components } = require("chrome"); const { parseStack, sourceURI } = require("toolkit/loader"); const { readURISync } = require("../net/url"); -exports.sourceURI = sourceURI - function safeGetFileLine(path, line) { try { var scheme = require("../url").URL(path).scheme; diff --git a/addon-sdk/source/lib/sdk/content/sandbox.js b/addon-sdk/source/lib/sdk/content/sandbox.js index 503c48c67c1b5..4a66eab53b9eb 100644 --- a/addon-sdk/source/lib/sdk/content/sandbox.js +++ b/addon-sdk/source/lib/sdk/content/sandbox.js @@ -10,6 +10,7 @@ module.metadata = { const { Class } = require('../core/heritage'); const { EventTarget } = require('../event/target'); const { on, off, emit } = require('../event/core'); +const { events } = require('./sandbox/events'); const { requiresAddonGlobal } = require('./utils'); const { delay: async } = require('../lang/functional'); const { Ci, Cu, Cc } = require('chrome'); @@ -20,8 +21,7 @@ const { merge } = require('../util/object'); const { getTabForContentWindow } = require('../tabs/utils'); const { getInnerId } = require('../window/utils'); const { PlainTextConsole } = require('../console/plain-text'); -const { data } = require('../self'); -const { isChildLoader } = require('../remote/core'); +const { data } = require('../self');const { isChildLoader } = require('../remote/core'); // WeakMap of sandboxes so we can access private values const sandboxes = new WeakMap(); @@ -166,6 +166,7 @@ const WorkerSandbox = Class({ get top() top, get parent() parent }); + // Use the Greasemonkey naming convention to provide access to the // unwrapped window object so the content script can access document // JavaScript values. @@ -261,6 +262,11 @@ const WorkerSandbox = Class({ win.console = con; }; + emit(events, "content-script-before-inserted", { + window: window, + worker: worker + }); + // The order of `contentScriptFile` and `contentScript` evaluation is // intentional, so programs can load libraries like jQuery from script URLs // and use them in scripts. @@ -273,6 +279,7 @@ const WorkerSandbox = Class({ if (contentScriptFile) importScripts.apply(null, [this].concat(contentScriptFile)); + if (contentScript) { evaluateIn( this, diff --git a/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/tests/test-minimal.js b/addon-sdk/source/lib/sdk/content/sandbox/events.js similarity index 65% rename from addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/tests/test-minimal.js rename to addon-sdk/source/lib/sdk/content/sandbox/events.js index 533cd34e6fbad..d6f7eb0040635 100644 --- a/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/tests/test-minimal.js +++ b/addon-sdk/source/lib/sdk/content/sandbox/events.js @@ -2,6 +2,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -exports.minimalTest = function(test) { - test.assert(true); +"use strict"; + +module.metadata = { + "stability": "experimental" }; + +const events = {}; +exports.events = events; diff --git a/addon-sdk/source/lib/sdk/deprecated/memory.js b/addon-sdk/source/lib/sdk/deprecated/memory.js deleted file mode 100644 index b2aa48e888e46..0000000000000 --- a/addon-sdk/source/lib/sdk/deprecated/memory.js +++ /dev/null @@ -1,129 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -"use strict"; - -module.metadata = { - "stability": "deprecated" -}; - -const { Cc, Ci, Cu, components } = require("chrome"); -const { when: unload } = require("../system/unload") - -var trackedObjects = {}; -const Compacter = { - notify: function() { - var newTrackedObjects = {}; - - for (let name in trackedObjects) { - let oldBin = trackedObjects[name]; - let newBin = []; - let strongRefs = []; - - for (let i = 0, l = oldBin.length; i < l; i++) { - let strongRef = oldBin[i].weakref.get(); - - if (strongRef && strongRefs.indexOf(strongRef) == -1) { - strongRefs.push(strongRef); - newBin.push(oldBin[i]); - } - } - - if (newBin.length) - newTrackedObjects[name] = newBin; - } - - trackedObjects = newTrackedObjects; - } -}; - -var timer = Cc["@mozilla.org/timer;1"] - .createInstance(Ci.nsITimer); -timer.initWithCallback(Compacter, - 5000, - Ci.nsITimer.TYPE_REPEATING_SLACK); - -function track(object, bin, stackFrameNumber) { - var frame = components.stack.caller; - var weakref = Cu.getWeakReference(object); - - if (!bin && 'constructor' in object) - bin = object.constructor.name; - if (bin == "Object") - bin = frame.name; - if (!bin) - bin = "generic"; - if (!(bin in trackedObjects)) - trackedObjects[bin] = []; - - if (stackFrameNumber > 0) - for (var i = 0; i < stackFrameNumber; i++) - frame = frame.caller; - - trackedObjects[bin].push({weakref: weakref, - created: new Date(), - filename: frame.filename, - lineNo: frame.lineNumber, - bin: bin}); -} -exports.track = track; - -var getBins = exports.getBins = function getBins() { - var names = []; - for (let name in trackedObjects) - names.push(name); - return names; -}; - -function getObjects(bin) { - var results = []; - - function getLiveObjectsInBin(bin) { - for (let i = 0, l = bin.length; i < l; i++) { - let object = bin[i].weakref.get(); - - if (object) { - results.push(bin[i]); - } - } - } - - if (bin) { - if (bin in trackedObjects) - getLiveObjectsInBin(trackedObjects[bin]); - } - else { - for (let name in trackedObjects) - getLiveObjectsInBin(trackedObjects[name]); - } - - return results; -} -exports.getObjects = getObjects; - -function gc() { - // Components.utils.forceGC() doesn't currently perform - // cycle collection, which means that e.g. DOM elements - // won't be collected by it. Fortunately, there are - // other ways... - var test_utils = Cc["@mozilla.org/appshell/appShellService;1"] - .getService(Ci.nsIAppShellService) - .hiddenDOMWindow - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindowUtils); - test_utils.garbageCollect(); - // Clean metadata for dead objects - Compacter.notify(); - // Not sure why, but sometimes it appears that we don't get - // them all with just one CC, so let's do it again. - test_utils.garbageCollect(); -}; -exports.gc = gc; - -unload(_ => { - trackedObjects = {}; - if (timer) { - timer.cancel(); - timer = null; - } -}); diff --git a/addon-sdk/source/lib/sdk/deprecated/sync-worker.js b/addon-sdk/source/lib/sdk/deprecated/sync-worker.js index 225b16ca52429..051e25e3fa9e0 100644 --- a/addon-sdk/source/lib/sdk/deprecated/sync-worker.js +++ b/addon-sdk/source/lib/sdk/deprecated/sync-worker.js @@ -30,7 +30,6 @@ const unload = require('../system/unload'); const events = require('../system/events'); const { getInnerId } = require("../window/utils"); const { WorkerSandbox } = require('../content/sandbox'); -const { getTabForWindow } = require('../tabs/helpers'); const { isPrivate } = require('../private-browsing/utils'); // A weak map of workers to hold private attributes that @@ -118,14 +117,6 @@ const Worker = Class({ return model.window ? model.window.document.URL : null; }, - get tab () { - let model = modelFor(this); - // model.window will be null after detach - if (model.window) - return getTabForWindow(model.window); - return null; - }, - // Implemented to provide some of the previous features of exposing sandbox // so that Worker can be extended getSandbox: function () { diff --git a/addon-sdk/source/lib/sdk/deprecated/unit-test-finder.js b/addon-sdk/source/lib/sdk/deprecated/unit-test-finder.js index 2f062b5b35748..518d813df4dce 100644 --- a/addon-sdk/source/lib/sdk/deprecated/unit-test-finder.js +++ b/addon-sdk/source/lib/sdk/deprecated/unit-test-finder.js @@ -8,7 +8,6 @@ module.metadata = { }; const file = require("../io/file"); -const memory = require('./memory'); const { Loader } = require("../test/loader"); const { isNative } = require('@loader/options'); @@ -132,7 +131,6 @@ let loader = Loader(module); const NOT_TESTS = ['setup', 'teardown']; var TestFinder = exports.TestFinder = function TestFinder(options) { - memory.track(this); this.filter = options.filter; this.testInProcess = options.testInProcess === false ? false : true; this.testOutOfProcess = options.testOutOfProcess === true ? true : false; diff --git a/addon-sdk/source/lib/sdk/deprecated/unit-test.js b/addon-sdk/source/lib/sdk/deprecated/unit-test.js index 976472f5a8249..b93001971ced5 100644 --- a/addon-sdk/source/lib/sdk/deprecated/unit-test.js +++ b/addon-sdk/source/lib/sdk/deprecated/unit-test.js @@ -7,7 +7,6 @@ module.metadata = { "stability": "deprecated" }; -const memory = require("./memory"); const timer = require("../timers"); const cfxArgs = require("../test/options"); const { getTabs, closeTab, getURI, getTabId, getSelectedTab } = require("../tabs/utils"); @@ -47,7 +46,6 @@ const TestRunner = function TestRunner(options) { this.fs = options.fs; this.console = options.console || console; - memory.track(this); this.passed = 0; this.failed = 0; this.testRunSummary = []; @@ -283,40 +281,46 @@ TestRunner.prototype = { } this.isDone = true; + this.pass("This test is done."); + if (this.test.teardown) { this.test.teardown(this); } + if (this.waitTimeout !== null) { timer.clearTimeout(this.waitTimeout); this.waitTimeout = null; } + // Do not leave any callback set when calling to `waitUntil` this.waitUntilCallback = null; if (this.test.passed == 0 && this.test.failed == 0) { this._logTestFailed("empty test"); + if ("testMessage" in this.console) { this.console.testMessage(false, false, this.test.name, "Empty test"); } else { this.console.error("fail:", "Empty test") } + this.failed++; this.test.failed++; } let wins = windows(null, { includePrivate: true }); - let winPromises = wins.map(win => { - let { promise, resolve } = defer(); - if (["interactive", "complete"].indexOf(win.document.readyState) >= 0) { - resolve() - } - else { - win.addEventListener("DOMContentLoaded", function onLoad() { - win.removeEventListener("DOMContentLoaded", onLoad, false); - resolve(); - }, false); - } - return promise; + let winPromises = wins.map(win => { + return new Promise(resolve => { + if (["interactive", "complete"].indexOf(win.document.readyState) >= 0) { + resolve() + } + else { + win.addEventListener("DOMContentLoaded", function onLoad() { + win.removeEventListener("DOMContentLoaded", onLoad, false); + resolve(); + }, false); + } + }); }); PromiseDebugging.flushUncaughtErrors(); @@ -358,9 +362,17 @@ TestRunner.prototype = { } } - return null; + return failure; + }). + then(failure => { + if (!failure) { + this.pass("There was a clean UI."); + return null; + } + return cleanUI().then(() => { + this.pass("There is a clean UI."); + }); }). - then(cleanUI). then(() => { this.testRunSummary.push({ name: this.test.name, diff --git a/addon-sdk/source/lib/sdk/io/data.js b/addon-sdk/source/lib/sdk/io/data.js deleted file mode 100644 index 57e80f2ce77f0..0000000000000 --- a/addon-sdk/source/lib/sdk/io/data.js +++ /dev/null @@ -1,90 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -"use strict"; - -module.metadata = { - "stability": "unstable" -}; - -const { Cc, Ci, Cu } = require("chrome"); -const base64 = require("../base64"); -const IOService = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - -const { deprecateFunction } = require('../util/deprecate'); -const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm"); -const { Services } = Cu.import("resource://gre/modules/Services.jsm"); -const FaviconService = Cc["@mozilla.org/browser/favicon-service;1"]. - getService(Ci.nsIFaviconService); - -const PNG_B64 = "data:image/png;base64,"; -const DEF_FAVICON_URI = "chrome://mozapps/skin/places/defaultFavicon.png"; -let DEF_FAVICON = null; - -/** - * Takes URI of the page and returns associated favicon URI. - * If page under passed uri has no favicon then base64 encoded data URI of - * default faveicon is returned. - * @param {String} uri - * @returns {String} - */ -function getFaviconURIForLocation(uri) { - let pageURI = NetUtil.newURI(uri); - try { - return FaviconService.getFaviconDataAsDataURL( - FaviconService.getFaviconForPage(pageURI)); - } - catch(e) { - if (!DEF_FAVICON) { - DEF_FAVICON = PNG_B64 + - base64.encode(getChromeURIContent(DEF_FAVICON_URI)); - } - return DEF_FAVICON; - } -} -exports.getFaviconURIForLocation = getFaviconURIForLocation; - -/** - * Takes chrome URI and returns content under that URI. - * @param {String} chromeURI - * @returns {String} - */ -function getChromeURIContent(chromeURI) { - let channel = IOService.newChannel2(chromeURI, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_OTHER); - let input = channel.open(); - let stream = Cc["@mozilla.org/binaryinputstream;1"]. - createInstance(Ci.nsIBinaryInputStream); - stream.setInputStream(input); - let content = stream.readBytes(input.available()); - stream.close(); - input.close(); - return content; -} -exports.getChromeURIContent = deprecateFunction(getChromeURIContent, - 'getChromeURIContent is deprecated, ' + - 'please use require("sdk/net/url").readURI instead.' -); - -/** - * Creates a base-64 encoded ASCII string from a string of binary data. - */ -exports.base64Encode = deprecateFunction(base64.encode, - 'base64Encode is deprecated, ' + - 'please use require("sdk/base64").encode instead.' -); -/** - * Decodes a string of data which has been encoded using base-64 encoding. - */ -exports.base64Decode = deprecateFunction(base64.decode, - 'base64Dencode is deprecated, ' + - 'please use require("sdk/base64").decode instead.' -); diff --git a/addon-sdk/source/lib/sdk/io/text-streams.js b/addon-sdk/source/lib/sdk/io/text-streams.js index 7a385cf03c491..ed4ec4972b293 100644 --- a/addon-sdk/source/lib/sdk/io/text-streams.js +++ b/addon-sdk/source/lib/sdk/io/text-streams.js @@ -1,17 +1,15 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - "use strict"; module.metadata = { "stability": "experimental" }; -const {Cc,Ci,Cu,components} = require("chrome"); -var NetUtil = {}; -Cu.import("resource://gre/modules/NetUtil.jsm", NetUtil); -NetUtil = NetUtil.NetUtil; +const { Cc, Ci, Cu, components } = require("chrome"); +const { ensure } = require("../system/unload"); +const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm", {}); // NetUtil.asyncCopy() uses this buffer length, and since we call it, for best // performance we use it, too. @@ -19,8 +17,6 @@ const BUFFER_BYTE_LEN = 0x8000; const PR_UINT32_MAX = 0xffffffff; const DEFAULT_CHARSET = "UTF-8"; -exports.TextReader = TextReader; -exports.TextWriter = TextWriter; /** * An input stream that reads text from a backing stream using a given text @@ -35,7 +31,6 @@ exports.TextWriter = TextWriter; * documentation on how to determine other valid values for this. */ function TextReader(inputStream, charset) { - const self = this; charset = checkCharset(charset); let stream = Cc["@mozilla.org/intl/converter-input-stream;1"]. @@ -89,6 +84,7 @@ function TextReader(inputStream, charset) { return str; }; } +exports.TextReader = TextReader; /** * A buffered output stream that writes text to a backing stream using a given @@ -103,7 +99,6 @@ function TextReader(inputStream, charset) { * for documentation on how to determine other valid values for this. */ function TextWriter(outputStream, charset) { - const self = this; charset = checkCharset(charset); let stream = outputStream; @@ -169,7 +164,7 @@ function TextWriter(outputStream, charset) { this.writeAsync = function TextWriter_writeAsync(str, callback) { manager.ensureOpened(); let istream = uconv.convertToInputStream(str); - NetUtil.asyncCopy(istream, stream, function (result) { + NetUtil.asyncCopy(istream, stream, (result) => { let err = components.isSuccessCode(result) ? undefined : new Error("An error occured while writing to the stream: " + result); if (err) @@ -180,7 +175,7 @@ function TextWriter(outputStream, charset) { if (typeof(callback) === "function") { try { - callback.call(self, err); + callback.call(this, err); } catch (exc) { console.exception(exc); @@ -189,34 +184,32 @@ function TextWriter(outputStream, charset) { }); }; } +exports.TextWriter = TextWriter; // This manages the lifetime of stream, a TextReader or TextWriter. It defines // closed and close() on stream and registers an unload listener that closes // rawStream if it's still opened. It also provides ensureOpened(), which // throws an exception if the stream is closed. function StreamManager(stream, rawStream) { - const self = this; this.rawStream = rawStream; this.opened = true; /** * True iff the stream is closed. */ - stream.__defineGetter__("closed", function stream_closed() { - return !self.opened; - }); + stream.__defineGetter__("closed", () => !this.opened); /** * Closes both the stream and its backing stream. If the stream is already * closed, an exception is thrown. For TextWriters, this first flushes the * backing stream's buffer. */ - stream.close = function stream_close() { - self.ensureOpened(); - self.unload(); + stream.close = () => { + this.ensureOpened(); + this.unload(); }; - require("../system/unload").ensure(this); + ensure(this); } StreamManager.prototype = { diff --git a/addon-sdk/source/lib/sdk/places/host/host-query.js b/addon-sdk/source/lib/sdk/places/host/host-query.js index 12ba203afcd65..6ce12c231c95f 100644 --- a/addon-sdk/source/lib/sdk/places/host/host-query.js +++ b/addon-sdk/source/lib/sdk/places/host/host-query.js @@ -1,7 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - "use strict"; module.metadata = { @@ -13,7 +12,7 @@ module.metadata = { }; const { Cc, Ci } = require('chrome'); -const { defer, all, resolve } = require('../../core/promise'); +const { all } = require('../../core/promise'); const { safeMerge, omit } = require('../../util/object'); const historyService = Cc['@mozilla.org/browser/nav-history-service;1'] .getService(Ci.nsINavHistoryService); @@ -45,13 +44,11 @@ const PLACES_PROPERTIES = [ ]; function execute (queries, options) { - let deferred = defer(); - let root = historyService - .executeQueries(queries, queries.length, options).root; - - let items = collect([], root); - deferred.resolve(items); - return deferred.promise; + return new Promise(resolve => { + let root = historyService + .executeQueries(queries, queries.length, options).root; + resolve(collect([], root)); + }); } function collect (acc, node) { @@ -69,40 +66,35 @@ function collect (acc, node) { } function query (queries, options) { - queries = queries || []; - options = options || {}; - let deferred = defer(); - let optionsObj, queryObjs; + return new Promise((resolve, reject) => { + queries = queries || []; + options = options || {}; + let optionsObj, queryObjs; - try { optionsObj = historyService.getNewQueryOptions(); queryObjs = [].concat(queries).map(createQuery); if (!queryObjs.length) { queryObjs = [historyService.getNewQuery()]; } safeMerge(optionsObj, options); - } catch (e) { - deferred.reject(e); - return deferred.promise; - } - /* - * Currently `places:` queries are not supported - */ - optionsObj.excludeQueries = true; - - execute(queryObjs, optionsObj).then(function (results) { - if (optionsObj.queryType === 0) { - return results.map(normalize); - } else if (optionsObj.queryType === 1) { - // Formats query results into more standard - // data structures for returning - return all(results.map(({itemId}) => - send('sdk-places-bookmarks-get', { id: itemId }))); - } - }).then(deferred.resolve, deferred.reject); - - return deferred.promise; + /* + * Currently `places:` queries are not supported + */ + optionsObj.excludeQueries = true; + + execute(queryObjs, optionsObj).then((results) => { + if (optionsObj.queryType === 0) { + return results.map(normalize); + } + else if (optionsObj.queryType === 1) { + // Formats query results into more standard + // data structures for returning + return all(results.map(({itemId}) => + send('sdk-places-bookmarks-get', { id: itemId }))); + } + }).then(resolve, reject); + }); } exports.query = query; @@ -140,7 +132,7 @@ function queryReceiver (message) { /* * Converts a nsINavHistoryResultNode into a plain object - * + * * https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavHistoryResultNode */ function normalize (historyObj) { @@ -150,7 +142,8 @@ function normalize (historyObj) { else if (prop === 'time') { // Cast from microseconds to milliseconds obj.time = Math.floor(historyObj.time / 1000) - } else if (prop === 'accessCount') + } + else if (prop === 'accessCount') obj.visitCount = historyObj[prop]; else obj[prop] = historyObj[prop]; diff --git a/addon-sdk/source/lib/sdk/places/utils.js b/addon-sdk/source/lib/sdk/places/utils.js index e016a14525327..f03a8f6a75a54 100644 --- a/addon-sdk/source/lib/sdk/places/utils.js +++ b/addon-sdk/source/lib/sdk/places/utils.js @@ -51,14 +51,14 @@ exports.TreeNode = TreeNode; /* * Descends down from `node` applying `fn` to each in order. * `fn` can return values or promises -- if promise returned, - * children are not processed until resolved. `fn` is passed + * children are not processed until resolved. `fn` is passed * one argument, the current node, `curr`. */ function walk (curr, fn) { return promised(fn)(curr).then(val => { return all(curr.children.map(child => walk(child, fn))); }); -} +} /* * Descends from the TreeNode `node`, returning @@ -122,7 +122,7 @@ exports.isRootGroup = isRootGroup; /* * Merges appropriate options into query based off of url * 4 scenarios: - * + * * 'moz.com' // domain: moz.com, domainIsHost: true * --> 'http://moz.com', 'http://moz.com/thunderbird' * '*.moz.com' // domain: moz.com, domainIsHost: false @@ -177,9 +177,9 @@ function createQuery (type, query) { let qObj = { searchTerms: query.query }; - + urlQueryParser(qObj, query.url); - + // 0 === history if (type === 0) { // PRTime used by query is in microseconds, not milliseconds @@ -194,7 +194,7 @@ function createQuery (type, query) { else if (type === 1) { qObj.tags = query.tags; qObj.folder = query.group && query.group.id; - } + } // 2 === unified (not implemented on platform) else if (type === 2) { diff --git a/addon-sdk/source/lib/sdk/self.js b/addon-sdk/source/lib/sdk/self.js index af2a4a647561d..d825a41a394e2 100644 --- a/addon-sdk/source/lib/sdk/self.js +++ b/addon-sdk/source/lib/sdk/self.js @@ -27,6 +27,9 @@ const metadata = options.metadata || {}; const permissions = metadata.permissions || {}; const isPacked = rootURI && rootURI.indexOf("jar:") === 0; +const isPrivateBrowsingSupported = 'private-browsing' in permissions && + permissions['private-browsing'] === true; + const uri = (path="") => path.includes(":") ? path : addonDataURI + path.replace(/^\.\//, ""); @@ -55,4 +58,4 @@ exports.data = Object.freeze({ return readURISync(uri(path)); } }); -exports.isPrivateBrowsingSupported = permissions['private-browsing'] === true; +exports.isPrivateBrowsingSupported = isPrivateBrowsingSupported; diff --git a/addon-sdk/source/lib/sdk/tabs/helpers.js b/addon-sdk/source/lib/sdk/tabs/helpers.js index fab18cd4e11dc..43bea1ca5b008 100644 --- a/addon-sdk/source/lib/sdk/tabs/helpers.js +++ b/addon-sdk/source/lib/sdk/tabs/helpers.js @@ -14,16 +14,6 @@ module.metadata = { const { getTabForContentWindow, getTabForBrowser: getRawTabForBrowser } = require('./utils'); const { modelFor } = require('../model/core'); -function getTabForWindow(win) { - let tab = getTabForContentWindow(win); - // We were unable to find the related tab! - if (!tab) - return null; - - return modelFor(tab); -} -exports.getTabForWindow = getTabForWindow; - exports.getTabForRawTab = modelFor; function getTabForBrowser(browser) { diff --git a/addon-sdk/source/lib/sdk/tabs/tab-fennec.js b/addon-sdk/source/lib/sdk/tabs/tab-fennec.js index 515f6e102795f..6d32bc809031b 100644 --- a/addon-sdk/source/lib/sdk/tabs/tab-fennec.js +++ b/addon-sdk/source/lib/sdk/tabs/tab-fennec.js @@ -71,26 +71,6 @@ const Tab = Class({ }, set url(url) setTabURL(tabNS(this).tab, url), - /** - * URI of the favicon for the page currently loaded in this tab. - * @type {String} - */ - get favicon() { - /* - * Synchronous favicon services were never supported on Fennec, - * and as of FF22, are now deprecated. When/if favicon services - * are supported for Fennec, this getter should reference - * `require('sdk/places/favicon').getFavicon` - */ - console.error( - 'tab.favicon is deprecated, and currently ' + - 'favicon helpers are not yet supported by Fennec' - ); - - // return 16x16 blank default - return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAEklEQVQ4jWNgGAWjYBSMAggAAAQQAAF/TXiOAAAAAElFTkSuQmCC'; - }, - getThumbnail: function() { // TODO: implement! console.error(ERR_FENNEC_MSG); diff --git a/addon-sdk/source/lib/sdk/tabs/tab-firefox.js b/addon-sdk/source/lib/sdk/tabs/tab-firefox.js index db7ac11b069c8..5362d8cf6c2da 100644 --- a/addon-sdk/source/lib/sdk/tabs/tab-firefox.js +++ b/addon-sdk/source/lib/sdk/tabs/tab-firefox.js @@ -15,8 +15,6 @@ const { getBrowserForTab, setTabURL, getTabId, getTabURL, getTabForBrowser, getTabs, getTabTitle, setTabTitle, getIndex, closeTab, reload, move, activateTab, pin, unpin, isTab } = require('./utils'); const { isBrowser, getInnerId, isWindowPrivate } = require('../window/utils'); -const { getFaviconURIForLocation } = require("../io/data"); -const { deprecateUsage } = require('../util/deprecate'); const { getThumbnailURIForWindow, BLANK } = require("../content/thumbnail"); const { when } = require('../system/unload'); const { ignoreWindow, isPrivate } = require('../private-browsing/utils') @@ -96,14 +94,6 @@ const Tab = Class({ setTabURL(viewsFor.get(this), val); }, - get favicon() { - deprecateUsage( - 'tab.favicon is deprecated, ' + - 'please use require("sdk/places/favicon").getFavicon instead.' - ); - return isDestroyed(this) ? undefined : getFaviconURIForLocation(this.url); - }, - get contentType() { return isDestroyed(this) ? undefined : browser(this).documentContentType; }, diff --git a/addon-sdk/source/lib/sdk/test/harness.js b/addon-sdk/source/lib/sdk/test/harness.js index b32cf54f7ef16..c5e3f09d49306 100644 --- a/addon-sdk/source/lib/sdk/test/harness.js +++ b/addon-sdk/source/lib/sdk/test/harness.js @@ -15,7 +15,6 @@ const { PlainTextConsole } = require("../console/plain-text"); const { when: unload } = require("../system/unload"); const { format, fromException } = require("../console/traceback"); const system = require("../system"); -const memory = require('../deprecated/memory'); const { gc: gcPromise } = require('./memory'); const { defer } = require('../core/promise'); const { extend } = require('../core/heritage'); @@ -150,7 +149,7 @@ function reportMemoryUsage() { return emptyPromise(); } - return gcPromise().then((function () { + return gcPromise().then((() => { var mgr = Cc["@mozilla.org/memory-reporter-manager;1"] .getService(Ci.nsIMemoryReporterManager); let count = 0; @@ -158,11 +157,6 @@ function reportMemoryUsage() { print(((++count == 1) ? "\n" : "") + description + ": " + amount + "\n"); } mgr.getReportsForThisProcess(logReporter, null, /* anonymize = */ false); - - var weakrefs = [info.weakref.get() - for (info of memory.getObjects())]; - weakrefs = [weakref for (weakref of weakrefs) if (weakref)]; - print("Tracked memory objects in testing sandbox: " + weakrefs.length + "\n"); })); } @@ -216,16 +210,6 @@ function showResults() { function cleanup() { let coverObject = {}; try { - for (let name in loader.modules) - memory.track(loader.modules[name], - "module global scope: " + name); - memory.track(loader, "Cuddlefish Loader"); - - if (profileMemory) { - gWeakrefInfo = [{ weakref: info.weakref, bin: info.bin } - for (info of memory.getObjects())]; - } - loader.unload(); if (loader.globals.console.errorsLogged && !results.failed) { @@ -251,7 +235,7 @@ function cleanup() { consoleListener.unregister(); - memory.gc(); + Cu.forceGC(); } catch (e) { results.failed++; @@ -278,7 +262,7 @@ function cleanup() { } function getPotentialLeaks() { - memory.gc(); + Cu.forceGC(); // Things we can assume are part of the platform and so aren't leaks let GOOD_BASE_URLS = [ diff --git a/addon-sdk/source/lib/sdk/test/memory.js b/addon-sdk/source/lib/sdk/test/memory.js index 1c564331266f9..bd1198bfe52d4 100644 --- a/addon-sdk/source/lib/sdk/test/memory.js +++ b/addon-sdk/source/lib/sdk/test/memory.js @@ -4,17 +4,8 @@ 'use strict'; const { Cu } = require("chrome"); -const memory = require('../deprecated/memory'); -const { defer } = require('../core/promise'); function gc() { - let { promise, resolve } = defer(); - - Cu.forceGC(); - memory.gc(); - - Cu.schedulePreciseGC(_ => resolve()); - - return promise; + return new Promise(resolve => Cu.schedulePreciseGC(resolve)); } exports.gc = gc; diff --git a/addon-sdk/source/lib/sdk/util/bond.js b/addon-sdk/source/lib/sdk/util/bond.js deleted file mode 100644 index 422f57737e179..0000000000000 --- a/addon-sdk/source/lib/sdk/util/bond.js +++ /dev/null @@ -1,36 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -"use strict"; - -module.metadata = { - "stability": "experimental" -}; - -const makeDescriptor = (name, method) => ({ - get() { - if (!Object.hasOwnProperty.call(this, name)) { - Object.defineProperty(this, name, {value: method.bind(this)}); - return this[name]; - } else { - return method; - } - } -}); - -const Bond = function(methods) { - let descriptor = {}; - let members = [...Object.getOwnPropertyNames(methods), - ...Object.getOwnPropertySymbols(methods)]; - - for (let name of members) { - let method = methods[name]; - if (typeof(method) !== "function") { - throw new TypeError(`Property named "${name}" passed to Bond must be a function`); - } - descriptor[name] = makeDescriptor(name, method); - } - - return Object.create(Bond.prototype, descriptor); -} -exports.Bond = Bond; diff --git a/addon-sdk/source/lib/sdk/util/rules.js b/addon-sdk/source/lib/sdk/util/rules.js index 9ab791ae7f2d0..1abe36b8735bd 100644 --- a/addon-sdk/source/lib/sdk/util/rules.js +++ b/addon-sdk/source/lib/sdk/util/rules.js @@ -1,7 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - "use strict"; module.metadata = { @@ -10,9 +9,7 @@ module.metadata = { const { Class } = require('../core/heritage'); const { MatchPattern } = require('./match-pattern'); -const { on, off, emit } = require('../event/core'); -const { method } = require('../lang/functional'); -const objectUtil = require('./object'); +const { emit } = require('../event/core'); const { EventTarget } = require('../event/target'); const { List, addListItem, removeListItem } = require('./list'); diff --git a/addon-sdk/source/lib/sdk/zip/utils.js b/addon-sdk/source/lib/sdk/zip/utils.js index bc1e0b610b7ee..e600380cbea6a 100644 --- a/addon-sdk/source/lib/sdk/zip/utils.js +++ b/addon-sdk/source/lib/sdk/zip/utils.js @@ -1,22 +1,16 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -'use strict'; +"use strict"; -const { Cc, Ci, Cu } = require("chrome"); -const { defer } = require("../core/promise"); +const { Cc, Ci } = require("chrome"); -const getZipReader = function getZipReader(aFile) { - let { promise, resolve, reject } = defer(); - let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]. - createInstance(Ci.nsIZipReader); - try { +function getZipReader(aFile) { + return new Promise(resolve => { + let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]. + createInstance(Ci.nsIZipReader); zipReader.open(aFile); - } - catch(e){ - reject(e); - } - resolve(zipReader); - return promise; + resolve(zipReader); + }); }; exports.getZipReader = getZipReader; diff --git a/addon-sdk/source/lib/toolkit/loader.js b/addon-sdk/source/lib/toolkit/loader.js index 53f3968d32c7f..73e28237d0994 100644 --- a/addon-sdk/source/lib/toolkit/loader.js +++ b/addon-sdk/source/lib/toolkit/loader.js @@ -874,7 +874,8 @@ function Loader(options) { metadata: { addonID: options.id, URI: "Addon-SDK" - } + }, + prototype: options.sandboxPrototype || {} }); } diff --git a/addon-sdk/source/mapping.json b/addon-sdk/source/mapping.json index 18b78b979a1f9..d8f497a26fc74 100644 --- a/addon-sdk/source/mapping.json +++ b/addon-sdk/source/mapping.json @@ -13,7 +13,6 @@ "l10n/prefs": "sdk/l10n/prefs", "list": "sdk/util/list", "loader": "sdk/loader/loader", - "memory": "sdk/deprecated/memory", "namespace": "sdk/core/namespace", "preferences-service": "sdk/preferences/service", "promise": "sdk/core/promise", diff --git a/addon-sdk/source/package.json b/addon-sdk/source/package.json index 35a4e9c9034ea..5a9707afb8388 100644 --- a/addon-sdk/source/package.json +++ b/addon-sdk/source/package.json @@ -22,6 +22,7 @@ "async": "0.9.0", "chai": "2.1.1", "fs-extra": "0.18.2", + "fx-runner": "0.0.7", "glob": "4.4.2", "gulp": "3.8.11", "ini-parser": "0.0.2", diff --git a/addon-sdk/source/python-lib/cuddlefish/__init__.py b/addon-sdk/source/python-lib/cuddlefish/__init__.py index 7fafe14689b1a..365d96c5ef4d6 100644 --- a/addon-sdk/source/python-lib/cuddlefish/__init__.py +++ b/addon-sdk/source/python-lib/cuddlefish/__init__.py @@ -236,10 +236,6 @@ help="Where to put the finished .xpi", default=None, cmds=['xpi'])), - (("", "--manifest-overload",), dict(dest="manifest_overload", - help="JSON file to overload package.json properties", - default=None, - cmds=['xpi'])), (("", "--abort-on-missing-module",), dict(dest="abort_on_missing", help="Abort if required module is missing", action="store_true", @@ -661,10 +657,6 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None, target_cfg_json = os.path.join(options.pkgdir, 'package.json') target_cfg = packaging.get_config_in_dir(options.pkgdir) - if options.manifest_overload: - for k, v in packaging.load_json_file(options.manifest_overload).items(): - target_cfg[k] = v - # At this point, we're either building an XPI or running Jetpack code in # a Mozilla application (which includes running tests). diff --git a/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/main.js b/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/main.js deleted file mode 100644 index 22018c2a2eb04..0000000000000 --- a/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/main.js +++ /dev/null @@ -1,17 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const { Cc, Ci } = require("chrome"); - -exports.main = function(options, callbacks) { - // Close Firefox window. Firefox should quit. - require("sdk/deprecated/window-utils").activeBrowserWindow.close(); - - // But not on Mac where it stay alive! We have to request application quit. - if (require("sdk/system/runtime").OS == "Darwin") { - let appStartup = Cc['@mozilla.org/toolkit/app-startup;1']. - getService(Ci.nsIAppStartup); - appStartup.quit(appStartup.eAttemptQuit); - } -} diff --git a/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/manifest-overload.json b/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/manifest-overload.json deleted file mode 100644 index a446378b0cfbd..0000000000000 --- a/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/manifest-overload.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "version": "1.0-nightly" -} diff --git a/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/package.json b/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/package.json deleted file mode 100644 index afbc15803daa5..0000000000000 --- a/addon-sdk/source/python-lib/cuddlefish/tests/addons/simplest-test/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "id": "simplest-test", - "directories": { - "lib": "." - } -} diff --git a/addon-sdk/source/python-lib/cuddlefish/tests/test_init.py b/addon-sdk/source/python-lib/cuddlefish/tests/test_init.py index f331b09cbea9f..5ececfea60207 100644 --- a/addon-sdk/source/python-lib/cuddlefish/tests/test_init.py +++ b/addon-sdk/source/python-lib/cuddlefish/tests/test_init.py @@ -182,35 +182,6 @@ def assertIn(self, member, container): container) self.fail(standardMsg) - def test_cfx_run(self): - addon_path = os.path.join(tests_path, - "addons", "simplest-test") - rc, out, err = self.run_cfx(addon_path, ["run"]) - self.assertEqual(rc, 0) - self.assertIn("Program terminated successfully.", err) - - def test_cfx_test(self): - addon_path = os.path.join(tests_path, "addons", "simplest-test") - rc, out, err = self.run_cfx(addon_path, ["test"]) - self.assertEqual(rc, 0) - self.assertIn("1 of 1 tests passed.", err) - self.assertIn("Program terminated successfully.", err) - - def test_cfx_xpi(self): - addon_path = os.path.join(tests_path, - "addons", "simplest-test") - rc, out, err = self.run_cfx(addon_path, \ - ["xpi", "--manifest-overload", "manifest-overload.json"]) - self.assertEqual(rc, 0) - # Ensure that the addon version from our manifest overload is used - # in install.rdf - xpi_path = os.path.join(addon_path, "simplest-test.xpi") - xpi = zipfile.ZipFile(xpi_path, "r") - manifest = xpi.read("install.rdf") - self.assertIn("1.0-nightly", manifest) - xpi.close() - os.remove(xpi_path) - def test_cfx_init(self): # Create an empty test directory addon_path = os.path.abspath(os.path.join(".test_tmp", "test-cfx-init")) @@ -232,7 +203,7 @@ def test_cfx_init(self): # run cfx test rc, out, err = self.run_cfx(addon_path, ["test"]) self.assertEqual(rc, 0) - self.assertIn("2 of 2 tests passed.", err) + self.assertIn("6 of 6 tests passed.", err) self.assertIn("Program terminated successfully.", err) diff --git a/addon-sdk/source/test/addons/chrome/data/panel.js b/addon-sdk/source/test/addons/chrome/data/panel.js index ae728ed898b6b..c38eca85227d6 100644 --- a/addon-sdk/source/test/addons/chrome/data/panel.js +++ b/addon-sdk/source/test/addons/chrome/data/panel.js @@ -6,3 +6,5 @@ self.port.on('echo', _ => { self.port.emit('echo', ''); }); + +self.port.emit('start', ''); diff --git a/addon-sdk/source/test/addons/chrome/main.js b/addon-sdk/source/test/addons/chrome/main.js index 62e2d691056bc..84b82245842d3 100644 --- a/addon-sdk/source/test/addons/chrome/main.js +++ b/addon-sdk/source/test/addons/chrome/main.js @@ -67,23 +67,31 @@ exports.testChromeLocale = function(assert) { 'locales en-US folder was copied correctly'); } -exports.testChromeInPanel = function(assert, done) { +exports.testChromeInPanel = function*(assert) { let panel = Panel({ contentURL: 'chrome://test/content/panel.html', - contentScriptWhen: 'start', + contentScriptWhen: 'end', contentScriptFile: data.url('panel.js') }); - panel.once('show', _ => { - assert.pass('panel shown'); - panel.port.once('echo', _ => { - assert.pass('got echo'); - panel.destroy(); - assert.pass('panel is destroyed'); - done(); - }); + + yield new Promise(resolve => panel.port.once('start', resolve)); + assert.pass('start was emitted'); + + yield new Promise(resolve => { + panel.once('show', resolve); + panel.show(); + }); + assert.pass('panel shown'); + + yield new Promise(resolve => { + panel.port.once('echo', resolve); panel.port.emit('echo'); }); - panel.show(); + + assert.pass('got echo'); + + panel.destroy(); + assert.pass('panel is destroyed'); } require('sdk/test/runner').runTestsFromModule(module); diff --git a/addon-sdk/source/test/addons/e10s-tabs/lib/test-tab.js b/addon-sdk/source/test/addons/e10s-tabs/lib/test-tab.js index 1d79ee4620b67..0a94984a65160 100644 --- a/addon-sdk/source/test/addons/e10s-tabs/lib/test-tab.js +++ b/addon-sdk/source/test/addons/e10s-tabs/lib/test-tab.js @@ -1,122 +1,17 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - "use strict"; const tabs = require("sdk/tabs"); // From addon-kit const windowUtils = require("sdk/deprecated/window-utils"); -const { getTabForWindow } = require('sdk/tabs/helpers'); const app = require("sdk/system/xul-app"); const { viewFor } = require("sdk/view/core"); const { modelFor } = require("sdk/model/core"); const { getTabId, isTab } = require("sdk/tabs/utils"); const { defer } = require("sdk/lang/functional"); -// The primary test tab -var primaryTab; - -// We have an auxiliary tab to test background tabs. -var auxTab; - -// The window for the outer iframe in the primary test page -var iframeWin; - -exports["test GetTabForWindow"] = function(assert, done) { - - assert.equal(getTabForWindow(windowUtils.activeWindow), null, - "getTabForWindow return null on topwindow"); - assert.equal(getTabForWindow(windowUtils.activeBrowserWindow), null, - "getTabForWindow return null on topwindow"); - - let subSubDocument = encodeURIComponent( - 'Sub iframe
'+ - '