Bug 1350646: Part 13 - Remove several SDK test modules. r?Mossop draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 05 Aug 2017 22:33:46 -0700
changeset 641194 8d5643d2245a8fa995cac57379c48b4e2f80c788
parent 641193 02b4ad623d5c6f9912f534d58781996c44ad954a
child 641195 6821c6c906615cd21c8b201da0047c19936eff7f
push id72469
push usermaglione.k@gmail.com
push dateSun, 06 Aug 2017 07:23:41 +0000
reviewersMossop
bugs1350646
milestone57.0a1
Bug 1350646: Part 13 - Remove several SDK test modules. r?Mossop MozReview-Commit-ID: F5AULX9DC5B
addon-sdk/moz.build
addon-sdk/source/lib/method/test/browser.js
addon-sdk/source/lib/method/test/common.js
addon-sdk/source/lib/sdk/test/harness.js
addon-sdk/source/lib/sdk/test/httpd.js
addon-sdk/source/lib/sdk/test/memory.js
addon-sdk/source/lib/sdk/test/runner.js
--- a/addon-sdk/moz.build
+++ b/addon-sdk/moz.build
@@ -19,18 +19,16 @@ EXTRA_JS_MODULES.sdk += [
 EXTRA_JS_MODULES.sdk.system += [
     'source/modules/system/Startup.js',
 ]
 
 modules = [
     'index.js',
     'jetpack-id/index.js',
     'method/core.js',
-    'method/test/browser.js',
-    'method/test/common.js',
     'mozilla-toolkit-versioning/index.js',
     'mozilla-toolkit-versioning/lib/utils.js',
     'node/os.js',
     'sdk/addon/installer.js',
     'sdk/addon/window.js',
     'sdk/base64.js',
     'sdk/browser/events.js',
     'sdk/clipboard.js',
@@ -91,21 +89,18 @@ modules = [
     'sdk/system/process.js',
     'sdk/system/runtime.js',
     'sdk/system/unload.js',
     'sdk/system/xul-app.js',
     'sdk/system/xul-app.jsm',
     'sdk/test.js',
     'sdk/test/assert.js',
     'sdk/test/harness.js',
-    'sdk/test/httpd.js',
     'sdk/test/loader.js',
-    'sdk/test/memory.js',
     'sdk/test/options.js',
-    'sdk/test/runner.js',
     'sdk/test/utils.js',
     'sdk/timers.js',
     'sdk/uri/resource.js',
     'sdk/url.js',
     'sdk/url/utils.js',
     'sdk/util/array.js',
     'sdk/util/collection.js',
     'sdk/util/contract.js',
deleted file mode 100644
--- a/addon-sdk/source/lib/method/test/browser.js
+++ /dev/null
@@ -1,20 +0,0 @@
-"use strict";
-
-exports["test common"] = require("./common")
-
-var Method = require("../core")
-
-exports["test host objects"] = function(assert) {
-  var isElement = Method("is-element")
-  isElement.define(function() { return false })
-
-  isElement.define(Element, function() { return true })
-
-  assert.notDeepEqual(typeof(Element.prototype[isElement]), "number",
-                     "Host object's prototype is extended with a number value")
-
-  assert.ok(!isElement({}), "object is not an Element")
-  assert.ok(document.createElement("div"), "Element is an element")
-}
-
-require("test").run(exports)
deleted file mode 100644
--- a/addon-sdk/source/lib/method/test/common.js
+++ /dev/null
@@ -1,272 +0,0 @@
-"use strict";
-
-var Method = require("../core")
-
-function type(value) {
-  return Object.prototype.toString.call(value).
-    split(" ").
-    pop().
-    split("]").
-    shift().
-    toLowerCase()
-}
-
-var values = [
-  null,                   // 0
-  undefined,              // 1
-  Infinity,               // 2
-  NaN,                    // 3
-  5,                      // 4
-  {},                     // 5
-  Object.create({}),      // 6
-  Object.create(null),    // 7
-  [],                     // 8
-  /foo/,                  // 9
-  new Date(),             // 10
-  Function,               // 11
-  function() {},          // 12
-  true,                   // 13
-  false,                  // 14
-  "string"                // 15
-]
-
-function True() { return true }
-function False() { return false }
-
-var trues = values.map(True)
-var falses = values.map(False)
-
-exports["test throws if not implemented"] = function(assert) {
-  var method = Method("nope")
-
-  assert.throws(function() {
-    method({})
-  }, /not implement/i, "method throws if not implemented")
-
-  assert.throws(function() {
-    method(null)
-  }, /not implement/i, "method throws on null")
-}
-
-exports["test all types inherit from default"] = function(assert) {
-  var isImplemented = Method("isImplemented")
-  isImplemented.define(function() { return true })
-
-  values.forEach(function(value) {
-    assert.ok(isImplemented(value),
-              type(value) + " inherits deafult implementation")
-  })
-}
-
-exports["test default can be implemented later"] = function(assert) {
-  var isImplemented = Method("isImplemented")
-  isImplemented.define(function() {
-    return true
-  })
-
-  values.forEach(function(value) {
-    assert.ok(isImplemented(value),
-              type(value) + " inherits deafult implementation")
-  })
-}
-
-exports["test dispatch not-implemented"] = function(assert) {
-  var isDefault = Method("isDefault")
-  values.forEach(function(value) {
-    assert.throws(function() {
-      isDefault(value)
-    }, /not implement/, type(value) + " throws if not implemented")
-  })
-}
-
-exports["test dispatch default"] = function(assert) {
-  var isDefault = Method("isDefault")
-
-  // Implement default
-  isDefault.define(True)
-  assert.deepEqual(values.map(isDefault), trues,
-                   "all implementation inherit from default")
-
-}
-
-exports["test dispatch null"] = function(assert) {
-  var isNull = Method("isNull")
-
-  // Implement default
-  isNull.define(False)
-  isNull.define(null, True)
-  assert.deepEqual(values.map(isNull),
-                   [ true ].
-                   concat(falses.slice(1)),
-                   "only null gets methods defined for null")
-}
-
-exports["test dispatch undefined"] = function(assert) {
-  var isUndefined = Method("isUndefined")
-
-  // Implement default
-  isUndefined.define(False)
-  isUndefined.define(undefined, True)
-  assert.deepEqual(values.map(isUndefined),
-                   [ false, true ].
-                   concat(falses.slice(2)),
-                   "only undefined gets methods defined for undefined")
-}
-
-exports["test dispatch object"] = function(assert) {
-  var isObject = Method("isObject")
-
-  // Implement default
-  isObject.define(False)
-  isObject.define(Object, True)
-  assert.deepEqual(values.map(isObject),
-                   [ false, false, false, false, false ].
-                   concat(trues.slice(5, 13)).
-                   concat([false, false, false]),
-                   "all values except primitives inherit Object methods")
-
-}
-
-exports["test dispatch number"] = function(assert) {
-  var isNumber = Method("isNumber")
-  isNumber.define(False)
-  isNumber.define(Number, True)
-
-  assert.deepEqual(values.map(isNumber),
-                  falses.slice(0, 2).
-                  concat(true, true, true).
-                  concat(falses.slice(5)),
-                  "all numbers inherit from Number method")
-}
-
-exports["test dispatch string"] = function(assert) {
-  var isString = Method("isString")
-  isString.define(False)
-  isString.define(String, True)
-
-  assert.deepEqual(values.map(isString),
-                  falses.slice(0, 15).
-                  concat(true),
-                  "all strings inherit from String method")
-}
-
-exports["test dispatch function"] = function(assert) {
-  var isFunction = Method("isFunction")
-  isFunction.define(False)
-  isFunction.define(Function, True)
-
-  assert.deepEqual(values.map(isFunction),
-                  falses.slice(0, 11).
-                  concat(true, true).
-                  concat(falses.slice(13)),
-                  "all functions inherit from Function method")
-}
-
-exports["test dispatch date"] = function(assert) {
-  var isDate = Method("isDate")
-  isDate.define(False)
-  isDate.define(Date, True)
-
-  assert.deepEqual(values.map(isDate),
-                  falses.slice(0, 10).
-                  concat(true).
-                  concat(falses.slice(11)),
-                  "all dates inherit from Date method")
-}
-
-exports["test dispatch RegExp"] = function(assert) {
-  var isRegExp = Method("isRegExp")
-  isRegExp.define(False)
-  isRegExp.define(RegExp, True)
-
-  assert.deepEqual(values.map(isRegExp),
-                  falses.slice(0, 9).
-                  concat(true).
-                  concat(falses.slice(10)),
-                  "all regexps inherit from RegExp method")
-}
-
-exports["test redefine for descendant"] = function(assert) {
-  var isFoo = Method("isFoo")
-  var ancestor = {}
-  isFoo.implement(ancestor, function() { return true })
-  var descendant = Object.create(ancestor)
-  isFoo.implement(descendant, function() { return false })
-
-  assert.ok(isFoo(ancestor), "defined on ancestor")
-  assert.ok(!isFoo(descendant), "overrided for descendant")
-}
-
-exports["test on custom types"] = function(assert) {
-  function Bar() {}
-  var isBar = Method("isBar")
-
-  isBar.define(function() { return false })
-  isBar.define(Bar, function() { return true })
-
-  assert.ok(!isBar({}), "object is get's default implementation")
-  assert.ok(isBar(new Bar()), "Foo type objects get own implementation")
-
-  var isObject = Method("isObject")
-  isObject.define(function() { return false })
-  isObject.define(Object, function() { return true })
-
-  assert.ok(isObject(new Bar()), "foo inherits implementation from object")
-
-
-  isObject.define(Bar, function() { return false })
-
-  assert.ok(!isObject(new Bar()),
-            "implementation inherited form object can be overrided")
-}
-
-
-exports["test error types"] = function(assert) {
-  var isError = Method("isError")
-  isError.define(function() { return false })
-  isError.define(Error, function() { return true })
-
-  assert.ok(isError(Error("boom")), "error is error")
-  assert.ok(isError(TypeError("boom")), "type error is an error")
-  assert.ok(isError(EvalError("boom")), "eval error is an error")
-  assert.ok(isError(RangeError("boom")), "range error is an error")
-  assert.ok(isError(ReferenceError("boom")), "reference error is an error")
-  assert.ok(isError(SyntaxError("boom")), "syntax error is an error")
-  assert.ok(isError(URIError("boom")), "URI error is an error")
-}
-
-exports["test override define polymorphic method"] = function(assert) {
-  var define = Method.define
-  var implement = Method.implement
-
-  var fn = Method("fn")
-  var methods = {}
-  implement(define, fn, function(method, label, implementation) {
-    methods[label] = implementation
-  })
-
-  function foo() {}
-
-  define(fn, "foo-case", foo)
-
-  assert.equal(methods["foo-case"], foo, "define set property")
-}
-
-exports["test override define via method API"] = function(assert) {
-  var define = Method.define
-  var implement = Method.implement
-
-  var fn = Method("fn")
-  var methods = {}
-  define.implement(fn, function(method, label, implementation) {
-    methods[label] = implementation
-  })
-
-  function foo() {}
-
-  define(fn, "foo-case", foo)
-
-  assert.equal(methods["foo-case"], foo, "define set property")
-}
-
-require("test").run(exports)
--- a/addon-sdk/source/lib/sdk/test/harness.js
+++ b/addon-sdk/source/lib/sdk/test/harness.js
@@ -10,17 +10,16 @@ module.metadata = {
 const { Cc, Ci, Cu } = require("chrome");
 const { Loader } = require('./loader');
 const { serializeStack, parseStack  } = require("toolkit/loader");
 const { setTimeout } = require('../timers');
 const { PlainTextConsole } = require("../console/plain-text");
 const { when: unload } = require("../system/unload");
 lazyRequire(this, "../console/traceback", "format", "fromException");
 const system = require("../system");
-const { gc: gcPromise } = require('./memory');
 const { defer } = require('../core/promise');
 const { extend } = require('../core/heritage');
 
 // Trick manifest builder to make it think we need these modules ?
 const unit = require("../deprecated/unit-test");
 const test = require("../../test");
 const url = require("../url");
 
@@ -139,54 +138,18 @@ function dictDiff(last, curr) {
   for (let name in curr) {
     var result = curr[name] - (last[name] || 0);
     if (result)
       diff[name] = (result > 0 ? "+" : "") + result;
   }
   return diff;
 }
 
-function reportMemoryUsage() {
-  if (!profileMemory) {
-    return emptyPromise();
-  }
-
-  return gcPromise().then((() => {
-    var mgr = Cc["@mozilla.org/memory-reporter-manager;1"]
-              .getService(Ci.nsIMemoryReporterManager);
-    let count = 0;
-    function logReporter(process, path, kind, units, amount, description) {
-      print(((++count == 1) ? "\n" : "") + description + ": " + amount + "\n");
-    }
-    mgr.getReportsForThisProcess(logReporter, null, /* anonymize = */ false);
-  }));
-}
-
 var gWeakrefInfo;
 
-function checkMemory() {
-  return gcPromise().then(_ => {
-    let leaks = getPotentialLeaks();
-
-    let compartmentURLs = Object.keys(leaks.compartments).filter(function(url) {
-      return !(url in startLeaks.compartments);
-    });
-
-    let windowURLs = Object.keys(leaks.windows).filter(function(url) {
-      return !(url in startLeaks.windows);
-    });
-
-    for (let url of compartmentURLs)
-      console.warn("LEAKED", leaks.compartments[url]);
-
-    for (let url of windowURLs)
-      console.warn("LEAKED", leaks.windows[url]);
-  }).then(showResults);
-}
-
 function showResults() {
   let { promise, resolve } = defer();
 
   if (gWeakrefInfo) {
     gWeakrefInfo.forEach(
       function(info) {
         var ref = info.weakref.get();
         if (ref !== null) {
@@ -238,17 +201,17 @@ function cleanup() {
     Cu.forceGC();
   }
   catch (e) {
     results.failed++;
     console.error("unload.send() threw an exception.");
     console.exception(e);
   };
 
-  setTimeout(require("./options").checkMemory ? checkMemory : showResults, 1);
+  setTimeout(showResults, 1);
 
   // dump the coverobject
   if (Object.keys(coverObject).length){
     const self = require('sdk/self');
     const {pathFor} = require("sdk/system");
     let file = require('sdk/io/file');
     const {env} = require('sdk/system/environment');
     console.log("CWD:", env.PWD);
@@ -372,31 +335,29 @@ function getPotentialLeaks() {
   return { compartments: compartments, windows: windows };
 }
 
 function nextIteration(tests) {
   if (tests) {
     results.passed += tests.passed;
     results.failed += tests.failed;
 
-    reportMemoryUsage().then(_ => {
-      let testRun = [];
-      for (let test of tests.testRunSummary) {
-        let testCopy = {};
-        for (let info in test) {
-          testCopy[info] = test[info];
-        }
-        testRun.push(testCopy);
+    let testRun = [];
+    for (let test of tests.testRunSummary) {
+      let testCopy = {};
+      for (let info in test) {
+        testCopy[info] = test[info];
       }
+      testRun.push(testCopy);
+    }
 
-      results.testRuns.push(testRun);
-      iterationsLeft--;
+    results.testRuns.push(testRun);
+    iterationsLeft--;
 
-      checkForEnd();
-    })
+    checkForEnd();
   }
   else {
     checkForEnd();
   }
 }
 
 function checkForEnd() {
   if (iterationsLeft && (!stopOnError || results.failed == 0)) {
deleted file mode 100644
--- a/addon-sdk/source/lib/sdk/test/httpd.js
+++ /dev/null
@@ -1,6 +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/. */
-
-throw new Error(`This file was removed. A copy can be obtained from:
-  https://github.com/mozilla/addon-sdk/blob/master/test/lib/httpd.js`);
deleted file mode 100644
--- a/addon-sdk/source/lib/sdk/test/memory.js
+++ /dev/null
@@ -1,11 +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';
-
-const { Cu } = require("chrome");
-
-function gc() {
-  return new Promise(resolve => Cu.schedulePreciseGC(resolve));
-}
-exports.gc = gc;
deleted file mode 100644
--- a/addon-sdk/source/lib/sdk/test/runner.js
+++ /dev/null
@@ -1,131 +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"
-};
-
-var { exit, stdout } = require("../system");
-var cfxArgs = require("../test/options");
-var events = require("../system/events");
-const { resolve } = require("../core/promise");
-
-function runTests(findAndRunTests) {
-  var harness = require("./harness");
-
-  function onDone(tests) {
-    stdout.write("\n");
-    var total = tests.passed + tests.failed;
-    stdout.write(tests.passed + " of " + total + " tests passed.\n");
-
-    events.emit("sdk:test:results", { data: JSON.stringify(tests) });
-
-    if (tests.failed == 0) {
-      if (tests.passed === 0)
-        stdout.write("No tests were run\n");
-      if (!cfxArgs.keepOpen)
-        exit(0);
-    } else {
-      if (cfxArgs.verbose || cfxArgs.parseable)
-        printFailedTests(tests, stdout.write);
-      if (!cfxArgs.keepOpen)
-        exit(1);
-    }
-  };
-
-  // We may have to run test on next cycle, otherwise XPCOM components
-  // are not correctly updated.
-  // For ex: nsIFocusManager.getFocusedElementForWindow may throw
-  // NS_ERROR_ILLEGAL_VALUE exception.
-  require("../timers").setTimeout(_ => harness.runTests({
-    findAndRunTests: findAndRunTests,
-    iterations: cfxArgs.iterations || 1,
-    filter: cfxArgs.filter,
-    profileMemory: cfxArgs.profileMemory,
-    stopOnError: cfxArgs.stopOnError,
-    verbose: cfxArgs.verbose,
-    parseable: cfxArgs.parseable,
-    print: stdout.write,
-    onDone: onDone
-  }));
-}
-
-function printFailedTests(tests, print) {
-  let iterationNumber = 0;
-  let singleIteration = (tests.testRuns || []).length == 1;
-  let padding = singleIteration ? "" : "  ";
-
-  print("\nThe following tests failed:\n");
-
-  for (let testRun of tests.testRuns) {
-    iterationNumber++;
-
-    if (!singleIteration)
-      print("  Iteration " + iterationNumber + ":\n");
-
-    for (let test of testRun) {
-      if (test.failed > 0) {
-        print(padding + "  " + test.name + ": " + test.errors +"\n");
-      }
-    }
-    print("\n");
-  }
-}
-
-function main() {
-  var testsStarted = false;
-
-  if (!testsStarted) {
-    testsStarted = true;
-    runTests(function findAndRunTests(loader, nextIteration) {
-      loader.require("../deprecated/unit-test").findAndRunTests({
-        testOutOfProcess: false,
-        testInProcess: true,
-        stopOnError: cfxArgs.stopOnError,
-        filter: cfxArgs.filter,
-        onDone: nextIteration
-      });
-    });
-  }
-};
-
-if (require.main === module)
-  main();
-
-exports.runTestsFromModule = function runTestsFromModule(module) {
-  let id = module.id;
-  // Make a copy of exports as it may already be frozen by module loader
-  let exports = {};
-  Object.keys(module.exports).forEach(key => {
-    exports[key] = module.exports[key];
-  });
-
-  runTests(function findAndRunTests(loader, nextIteration) {
-    // Consider that all these tests are CommonJS ones
-    loader.require('../../test').run(exports);
-
-    // Reproduce what is done in sdk/deprecated/unit-test-finder.findTests()
-    let tests = [];
-    for (let name of Object.keys(exports).sort()) {
-      tests.push({
-        setup: exports.setup,
-        teardown: exports.teardown,
-        testFunction: exports[name],
-        name: id + "." + name
-      });
-    }
-
-    // Reproduce what is done by unit-test.findAndRunTests()
-    var { TestRunner } = loader.require("../deprecated/unit-test");
-    var runner = new TestRunner();
-    runner.startMany({
-      tests: {
-        getNext: () => resolve(tests.shift())
-      },
-      stopOnError: cfxArgs.stopOnError,
-      onDone: nextIteration
-    });
-  });
-}