[Pkg-mozext-commits] [requestpolicy] 36/65: [tst][ref] xpcshell tests: objectsAreEqual -> deepEqual

David Prévot taffit at moszumanska.debian.org
Fri Mar 25 22:59:49 UTC 2016


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit c7a06fc94d1095513504c0e85921de8efaa046b0
Author: Martin Kimmerle <dev at 256k.de>
Date:   Sun Jan 17 11:29:46 2016 +0100

    [tst][ref] xpcshell tests: objectsAreEqual -> deepEqual
---
 tests/xpcshell/head_utils.js         | 72 ------------------------------------
 tests/xpcshell/test_policystorage.js |  2 +-
 tests/xpcshell/test_subscription.js  |  2 +-
 3 files changed, 2 insertions(+), 74 deletions(-)

diff --git a/tests/xpcshell/head_utils.js b/tests/xpcshell/head_utils.js
index 8fae236..7104c36 100644
--- a/tests/xpcshell/head_utils.js
+++ b/tests/xpcshell/head_utils.js
@@ -1,8 +1,4 @@
 Components.utils.import("chrome://rpcontinued/content/lib/utils/files.jsm");
-//// TODO: Maybe the script loader needs to be used instead?
-//var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
-//    .getService(Components.interfaces.mozIJSSubScriptLoader);
-//loader.loadSubScript("chrome://rpcontinued/content/modules/FileUtil.jsm");
 
 function copyRulesetFileToProfile(filename, destFilename) {
   if (!destFilename) {
@@ -28,71 +24,3 @@ function deleteFileFromProfile(filename) {
   file.append(filename);
   file.remove(false);
 }
-
-/**
- * Compares to objects recursively to see if they have the same keys
- * and values.
- */
-function objectsAreEqual(objA, objB) {
-  print("%%%%%%%%%%%%%%%%%%%%%%%%%%");
-  print(objToStr(objA));
-  print("//////////////");
-  print(objToStr(objB));
-  print("%%%%%%%%%%%%%%%%%%%%%%%%%%");
-
-  // We compare two objects converted to strings because the first approach
-  // I tried, adding an "equals" method to Object.prototype, has unexpected
-  // results I believe because the Object object used by modules is
-  // different than our Object, and thus objects created in modules and
-  // passed back to the test didn't have the equals method. I'm sure a
-  // JavaScript master could have sorted it out, but for our purposes
-  // comparing "canonical" string representations works fine.
-  var result = objToStr(objA) == objToStr(objB);
-  return result;
-}
-
-// Returns the object represented as a string. If we had a library to
-// generate canonical JSON, we'd use that, instead.
-function objToStr(object, depth, max){
-  depth = depth || 1;
-  max = max || 20;
-
-  if (depth > max) {
-    return false;
-  }
-
-  var indent = "";
-  for (var i = 0; i < depth; i++) {
-    indent += "  ";
-  }
-
-  var output = "{";
-
-  var keys = Object.keys(object);
-  keys.sort();
-
-  for (var i in keys) {
-    var key = keys[i];
-    output += "\n" + indent + '"' + key + '" : ';
-    switch (typeof object[key]) {
-      case "object":
-        output += objToStr(object[key], depth + 1, max);
-        break;
-      case "function": output += "function";
-        break;
-      default: output += object[key];
-        break;
-    }
-    if (i < keys.length - 1) {
-      output += ",";
-    }
-  }
-
-  var indent = "";
-  for (var i = 0; i < depth - 1; i++) {
-    indent += "  ";
-  }
-
-  output +="\n" + indent + "}";
-  return output;
-}
diff --git a/tests/xpcshell/test_policystorage.js b/tests/xpcshell/test_policystorage.js
index d2d6824..9761cdf 100644
--- a/tests/xpcshell/test_policystorage.js
+++ b/tests/xpcshell/test_policystorage.js
@@ -48,7 +48,7 @@ function test_1() {
   jsonData = JSON.stringify(readRuleset);
   var readJsonObj = JSON.parse(jsonData);
 
-  do_check_true(objectsAreEqual(readJsonObj, exampleJsonObj));
+  deepEqual(readJsonObj, exampleJsonObj);
 
   deleteFileFromProfile(filename);
 }
diff --git a/tests/xpcshell/test_subscription.js b/tests/xpcshell/test_subscription.js
index 81a1a76..e5a7fc7 100644
--- a/tests/xpcshell/test_subscription.js
+++ b/tests/xpcshell/test_subscription.js
@@ -33,5 +33,5 @@ function test_1_completed(updateResults) {
   do_check_true(updateResults['official']['embedded']);
   do_check_true(false);
   do_test_finished();
-  //do_check_true(objectsAreEqual(readJsonObj, exampleJsonObj));
+  //deepEqual(readJsonObj, exampleJsonObj);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list