Bug 1264169 - P2. Refine classifierHelper chunk format. r?francois draft
authordimi <dlee@mozilla.com>
Mon, 25 Apr 2016 10:13:15 +0800
changeset 355729 0c26ce404b3e03d79ca4fc76451c208016db0689
parent 355279 2e589650680605dd1775503af1b52ad0599b8318
child 519266 dd0f2df4030ead14873c4cecb595b7610c953085
push id16366
push userdlee@mozilla.com
push dateMon, 25 Apr 2016 02:37:27 +0000
reviewersfrancois
bugs1264169
milestone48.0a1
Bug 1264169 - P2. Refine classifierHelper chunk format. r?francois MozReview-Commit-ID: WBexu4sO8R
toolkit/components/url-classifier/tests/mochitest/classifierHelper.js
--- a/toolkit/components/url-classifier/tests/mochitest/classifierHelper.js
+++ b/toolkit/components/url-classifier/tests/mochitest/classifierHelper.js
@@ -1,47 +1,62 @@
 if (typeof(classifierHelper) == "undefined") {
   var classifierHelper = {};
 }
 
 const CLASSIFIER_COMMON_URL = SimpleTest.getTestFileURL("classifierCommon.js");
 var classifierCommonScript = SpecialPowers.loadChromeScript(CLASSIFIER_COMMON_URL);
 
+const ADD_CHUNKNUM = 524;
+const SUB_CHUNKNUM = 523;
+const HASHLEN = 32;
+
 // addUrlToDB & removeUrlFromDB are asynchronous, queue the task to ensure
 // the callback follow correct order.
 classifierHelper._updates = [];
 
 // Keep urls added to database, those urls should be automatically
 // removed after test complete.
 classifierHelper._updatesToCleanup = [];
 
 // Pass { url: ..., db: ... } to add url to database,
 // onsuccess/onerror will be called when update complete.
 classifierHelper.addUrlToDB = function(updateData, onsuccess, onerror) {
   var testUpdate = "";
   for (var update of updateData) {
+    var LISTNAME = update.db;
+    var CHUNKDATA = update.url;
+    var CHUNKLEN = CHUNKDATA.length;
+
     classifierHelper._updatesToCleanup.push(update);
     testUpdate +=
-      "n:1000\ni:" + update.db + "\nad:1\n" +
-      "a:524:32:" + update.url.length + "\n" +
-      update.url;
+      "n:1000\n" +
+      "i:" + LISTNAME + "\n" +
+      "ad:1\n" +
+      "a:" + ADD_CHUNKNUM + ":" + HASHLEN + ":" + CHUNKLEN + "\n" +
+      CHUNKDATA;
   }
 
   classifierHelper._update(testUpdate, onsuccess, onerror);
 }
 
 // Pass { url: ..., db: ... } to remove url from database,
 // onsuccess/onerror will be called when update complete.
 classifierHelper.removeUrlFromDB = function(updateData, onsuccess, onerror) {
   var testUpdate = "";
   for (var update of updateData) {
+    var LISTNAME = update.db;
+    var CHUNKDATA = ADD_CHUNKNUM + ":" + update.url;
+    var CHUNKLEN = CHUNKDATA.length;
+
     testUpdate +=
-      "n:1000\ni:" + update.db + "\nsd:1\n" +
-      "s:524:32:" + (4 + update.url.length) + "\n" +
-      "524:" + update.url;
+      "n:1000\n" +
+      "i:" + LISTNAME + "\n" +
+      "s:" + SUB_CHUNKNUM + ":" + HASHLEN + ":" + CHUNKLEN + "\n" +
+      CHUNKDATA;
   }
 
   classifierHelper._updatesToCleanup =
     classifierHelper._updatesToCleanup.filter((v) => {
       return updateData.indexOf(v) == -1;
     });
 
   classifierHelper._update(testUpdate, onsuccess, onerror);