Bug 1302044 - Init tableArray with only enabled tables. r=francois.
authorHenry Chang <hchang@mozilla.com>
Mon, 12 Sep 2016 17:30:06 +0800
changeset 357375 e5cc560f4a47bdd0f30556356bd34f9f31915f5a
parent 357374 7c2dca45dd214a68f8bb0172592e5da794748c36
child 357376 501e27643a529ce2844924cd47f01ef3150fa0ba
child 357377 fc9963bf6d98d7cc010d8cb7463dec948c61e9e9
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1302044
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1302044 - Init tableArray with only enabled tables. r=francois. MozReview-Commit-ID: KMp8oLkBXwb
toolkit/components/url-classifier/content/listmanager.js
toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
toolkit/components/url-classifier/tests/unit/test_listmanager.js
toolkit/components/url-classifier/tests/unit/test_threat_type_conversion.js
--- a/toolkit/components/url-classifier/content/listmanager.js
+++ b/toolkit/components/url-classifier/content/listmanager.js
@@ -383,17 +383,22 @@ PROT_ListManager.prototype.makeUpdateReq
     if (!streamerMap.tableList) {
       streamerMap.tableList = tableName;
     } else {
       streamerMap.tableList += "," + tableName;
     }
   }
 
   if (useProtobuf) {
-    let tableArray = streamerMap.tableList.split(',');
+    let tableArray = [];
+    Object.keys(streamerMap.tableNames).forEach(aTableName => {
+      if (streamerMap.tableNames[aTableName]) {
+        tableArray.push(aTableName);
+      }
+    });
 
     // The state is a byte stream which server told us from the
     // last table update. The state would be used to do the partial
     // update and the empty string means the table has
     // never been downloaded. See Bug 1287058 for supporting
     // partial update.
     let stateArray = [];
     tableArray.forEach(listName => {
--- a/toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierUtils.cpp
@@ -213,16 +213,17 @@ static const struct {
 } THREAT_TYPE_CONV_TABLE[] = {
   { "goog-malware-proto",  MALWARE_THREAT},            // 1
   { "googpub-phish-proto", SOCIAL_ENGINEERING_PUBLIC}, // 2
   { "goog-unwanted-proto", UNWANTED_SOFTWARE},         // 3
   { "goog-phish-proto", SOCIAL_ENGINEERING},           // 5
 
   // For testing purpose.
   { "test-phish-proto",    SOCIAL_ENGINEERING_PUBLIC}, // 2
+  { "test-unwanted-proto", UNWANTED_SOFTWARE}, // 3
 };
 
 NS_IMETHODIMP
 nsUrlClassifierUtils::ConvertThreatTypeToListNames(uint32_t aThreatType,
                                                    nsACString& aListNames)
 {
   for (uint32_t i = 0; i < ArrayLength(THREAT_TYPE_CONV_TABLE); i++) {
     if (aThreatType == THREAT_TYPE_CONV_TABLE[i].mThreatType) {
--- a/toolkit/components/url-classifier/tests/unit/test_listmanager.js
+++ b/toolkit/components/url-classifier/tests/unit/test_listmanager.js
@@ -26,23 +26,29 @@ const TEST_TABLE_DATA_LIST = [
   {
     tableName: "test-listmanager2-digest256",
     providerName: "google",
     updateUrl: "http://localhost:4444/safebrowsing/update",
     gethashUrl: "http://localhost:4444/safebrowsing/gethash2",
   }
 ];
 
-// This table has a different update URL (for v4).
+// These tables have a different update URL (for v4).
 const TEST_TABLE_DATA_V4 = {
   tableName: "test-phish-proto",
   providerName: "google4",
   updateUrl: "http://localhost:5555/safebrowsing/update?",
   gethashUrl: "http://localhost:5555/safebrowsing/gethash-v4",
 };
+const TEST_TABLE_DATA_V4_DISABLED = {
+  tableName: "test-unwanted-proto",
+  providerName: "google4",
+  updateUrl: "http://localhost:5555/safebrowsing/update?",
+  gethashUrl: "http://localhost:5555/safebrowsing/gethash-v4",
+};
 
 const PREF_NEXTUPDATETIME = "browser.safebrowsing.provider.google.nextupdatetime";
 const PREF_NEXTUPDATETIME_V4 = "browser.safebrowsing.provider.google4.nextupdatetime";
 
 let gListManager = Cc["@mozilla.org/url-classifier/listmanager;1"]
                      .getService(Ci.nsIUrlListManager);
 
 let gUrlUtils = Cc["@mozilla.org/url-classifier/utils;1"]
@@ -74,16 +80,22 @@ TEST_TABLE_DATA_LIST.forEach(function(t)
                              t.gethashUrl);
 });
 
 gListManager.registerTable(TEST_TABLE_DATA_V4.tableName,
                            TEST_TABLE_DATA_V4.providerName,
                            TEST_TABLE_DATA_V4.updateUrl,
                            TEST_TABLE_DATA_V4.gethashUrl);
 
+// To test Bug 1302044.
+gListManager.registerTable(TEST_TABLE_DATA_V4_DISABLED.tableName,
+                           TEST_TABLE_DATA_V4_DISABLED.providerName,
+                           TEST_TABLE_DATA_V4_DISABLED.updateUrl,
+                           TEST_TABLE_DATA_V4_DISABLED.gethashUrl);
+
 const SERVER_INVOLVED_TEST_CASE_LIST = [
   // - Do table0 update.
   // - Server would respond "a:5:32:32\n[DATA]".
   function test_update_table0() {
     disableAllUpdates();
 
     gListManager.enableUpdate(TEST_TABLE_DATA_LIST[0].tableName);
     gExpectedUpdateRequest = TEST_TABLE_DATA_LIST[0].tableName + ";\n";
@@ -117,17 +129,22 @@ const SERVER_INVOLVED_TEST_CASE_LIST = [
   // two udpates for different URL.
   function test_update_all_tables() {
     disableAllUpdates();
 
     // Enable all tables including TEST_TABLE_DATA_V4!
     TEST_TABLE_DATA_LIST.forEach(function(t) {
       gListManager.enableUpdate(t.tableName);
     });
+
+    // We register two v4 tables but only enable one of them
+    // to verify that the disabled tables are not updated.
+    // See Bug 1302044.
     gListManager.enableUpdate(TEST_TABLE_DATA_V4.tableName);
+    gListManager.disableUpdate(TEST_TABLE_DATA_V4_DISABLED.tableName);
 
     // Expected results for v2.
     gExpectedUpdateRequest = TEST_TABLE_DATA_LIST[0].tableName + ";a:5:s:2-12\n" +
                              TEST_TABLE_DATA_LIST[1].tableName + ";\n" +
                              TEST_TABLE_DATA_LIST[2].tableName + ";\n";
     gUpdateResponse = "n:1000\n";
 
     // We test the request against the query string since v4 request
--- a/toolkit/components/url-classifier/tests/unit/test_threat_type_conversion.js
+++ b/toolkit/components/url-classifier/tests/unit/test_threat_type_conversion.js
@@ -17,17 +17,17 @@ function run_test() {
   try {
     urlUtils.convertListNameToThreatType("bad-list-name");
     ok(false, "Bad list name should lead to exception.");
   } catch (e) {}
 
   // Test threat type to list name conversion.
   equal(urlUtils.convertThreatTypeToListNames(1), "goog-malware-proto");
   equal(urlUtils.convertThreatTypeToListNames(2), "googpub-phish-proto,test-phish-proto");
-  equal(urlUtils.convertThreatTypeToListNames(3), "goog-unwanted-proto");
+  equal(urlUtils.convertThreatTypeToListNames(3), "goog-unwanted-proto,test-unwanted-proto");
   equal(urlUtils.convertThreatTypeToListNames(5), "goog-phish-proto");
 
   try {
     urlUtils.convertThreatTypeToListNames(0);
     ok(false, "Bad threat type should lead to exception.");
   } catch (e) {}
 
   try {