Bug 1400394 - Remove `TestingUtils.deepCopy`. r=markh
MozReview-Commit-ID: 3ZZpA3inWSF
deleted file mode 100644
--- a/services/common/modules-testing/utils.js
+++ /dev/null
@@ -1,42 +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";
-
-this.EXPORTED_SYMBOLS = [
- "TestingUtils",
-];
-
-this.TestingUtils = {
- /**
- * Perform a deep copy of an Array or Object.
- */
- deepCopy: function deepCopy(thing, noSort) {
- if (typeof(thing) != "object" || thing == null) {
- return thing;
- }
-
- if (Array.isArray(thing)) {
- let ret = [];
- for (let element of thing) {
- ret.push(this.deepCopy(element, noSort));
- }
-
- return ret;
- }
-
- let ret = {};
- let props = Object.keys(thing);
-
- if (!noSort) {
- props = props.sort();
- }
-
- for (let prop of props) {
- ret[prop] = this.deepCopy(thing[prop], noSort);
- }
-
- return ret;
- },
-};
--- a/services/common/moz.build
+++ b/services/common/moz.build
@@ -35,15 +35,14 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'andr
]
TESTING_JS_MODULES.services.common += [
'modules-testing/storageserver.js',
]
TESTING_JS_MODULES.services.common += [
'modules-testing/logging.js',
- 'modules-testing/utils.js',
]
JS_PREFERENCE_FILES += [
'services-common.js',
]
deleted file mode 100644
--- a/services/common/tests/unit/test_utils_deepCopy.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ */
-
-Cu.import("resource://testing-common/services/common/utils.js");
-
-function run_test() {
- let thing = {o: {foo: "foo", bar: ["bar"]}, a: ["foo", {bar: "bar"}]};
- let ret = TestingUtils.deepCopy(thing);
- do_check_neq(ret, thing)
- do_check_neq(ret.o, thing.o);
- do_check_neq(ret.o.bar, thing.o.bar);
- do_check_neq(ret.a, thing.a);
- do_check_neq(ret.a[1], thing.a[1]);
- do_check_eq(ret.o.foo, thing.o.foo);
- do_check_eq(ret.o.bar[0], thing.o.bar[0]);
- do_check_eq(ret.a[0], thing.a[0]);
- do_check_eq(ret.a[1].bar, thing.a[1].bar);
-}
--- a/services/common/tests/unit/xpcshell.ini
+++ b/services/common/tests/unit/xpcshell.ini
@@ -26,17 +26,16 @@ tags = blocklist
[test_storage_adapter.js]
tags = blocklist
[test_storage_adapter_shutdown.js]
tags = blocklist
[test_utils_atob.js]
[test_utils_convert_string.js]
[test_utils_dateprefs.js]
-[test_utils_deepCopy.js]
[test_utils_encodeBase32.js]
[test_utils_encodeBase64URL.js]
[test_utils_ensureMillisecondsTimestamp.js]
[test_utils_json.js]
[test_utils_makeURI.js]
[test_utils_namedTimer.js]
[test_utils_sets.js]
[test_utils_utf8.js]
--- a/services/sync/tests/unit/head_helpers.js
+++ b/services/sync/tests/unit/head_helpers.js
@@ -7,17 +7,16 @@
/* import-globals-from head_http_server.js */
// This file expects Service to be defined in the global scope when EHTestsCommon
// is used (from service.js).
/* global Service */
Cu.import("resource://services-common/async.js");
Cu.import("resource://services-common/utils.js");
-Cu.import("resource://testing-common/services/common/utils.js");
Cu.import("resource://testing-common/PlacesTestUtils.jsm");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/ObjectUtils.jsm");
add_task(async function head_setup() {
// If a test imports Service, make sure it is initialized first.
@@ -234,24 +233,24 @@ function mockGetWindowEnumerator(url, nu
mockIsPrivate: false,
gBrowser: {
tabs,
},
};
elements.push(win);
for (let t = 0; t < numTabs; ++t) {
- tabs.push(TestingUtils.deepCopy({
+ tabs.push(Cu.cloneInto({
index: indexes ? indexes() : 1,
entries: (moreURLs ? [url].concat(moreURLs()) : [url]).map(url2entry),
attributes: {
image: "image"
},
lastAccessed: 1499
- }));
+ }, {}));
}
}
// Always include a closed window and a private window.
elements.push({
closed: true,
mockIsPrivate: false,
gBrowser: {
--- a/services/sync/tests/unit/test_bookmark_livemarks.js
+++ b/services/sync/tests/unit/test_bookmark_livemarks.js
@@ -2,17 +2,16 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/record.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/engines/bookmarks.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/service.js");
-Cu.import("resource://testing-common/services/common/utils.js");
const DESCRIPTION_ANNO = "bookmarkProperties/description";
let engine;
let store;
// Record borrowed from Bug 631361.
const record631361 = {
@@ -50,17 +49,17 @@ const record631361 = {
"mNTdpgoRZMbW", "-L8Vci6CbkJY", "bVzudKSQERc1", "Gxl9lb4DXsmL",
"3Qr13GucOtEh"]},
collection: "bookmarks"
};
function makeLivemark(p, mintGUID) {
let b = new Livemark("bookmarks", p.id);
// Copy here, because tests mutate the contents.
- b.cleartext = TestingUtils.deepCopy(p);
+ b.cleartext = Cu.cloneInto(p, {});
if (mintGUID)
b.id = Utils.makeGUID();
return b;
}
add_task(async function setup() {
--- a/services/sync/tests/unit/test_tab_store.js
+++ b/services/sync/tests/unit/test_tab_store.js
@@ -1,15 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://services-sync/engines/tabs.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/util.js");
-Cu.import("resource://testing-common/services/common/utils.js");
async function getMockStore() {
let engine = new TabEngine(Service);
await engine.initialize();
let store = engine._store;
store.getTabState = mockGetTabState;
store.shouldSkipWindow = mockShouldSkipWindow;
return store;