Bug 1374731 - Don't use hardcoded test entries for the Flash classification tables. r=bytesized draft
authorFelipe Gomes <felipc@gmail.com>
Tue, 20 Jun 2017 18:15:44 -0300
changeset 597730 a4c77e4b09a78f515d1485c6ef95cf81f27ee783
parent 597455 464b2a3c25aa1065760d9ecbb0870bca4a66c62e
child 634297 dd1b51b5bc905966cfcaaae65a3b5a66692b2c0e
push id65004
push userfelipc@gmail.com
push dateTue, 20 Jun 2017 21:16:45 +0000
reviewersbytesized
bugs1374731
milestone56.0a1
Bug 1374731 - Don't use hardcoded test entries for the Flash classification tables. r=bytesized MozReview-Commit-ID: 1pG11W7PX4R
modules/libpref/init/all.js
toolkit/components/url-classifier/SafeBrowsing.jsm
toolkit/components/url-classifier/tests/browser/classifierTester.js
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5213,17 +5213,17 @@ pref("urlclassifier.phishTable", "goog-p
 #else
 pref("urlclassifier.phishTable", "googpub-phish-shavar,test-phish-simple");
 #endif
 
 // Tables for application reputation.
 pref("urlclassifier.downloadAllowTable", "goog-downloadwhite-proto");
 pref("urlclassifier.downloadBlockTable", "goog-badbinurl-proto");
 
-pref("urlclassifier.disallow_completions", "test-malware-simple,test-phish-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple,test-flashallow-simple,testexcept-flashallow-simple,test-flash-simple,testexcept-flash-simple,test-flashsubdoc-simple,testexcept-flashsubdoc-simple,goog-downloadwhite-digest256,base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256");
+pref("urlclassifier.disallow_completions", "test-malware-simple,test-phish-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple,goog-downloadwhite-digest256,base-track-digest256,mozstd-trackwhite-digest256,content-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256,block-flash-digest256,except-flash-digest256,allow-flashallow-digest256,except-flashallow-digest256,block-flashsubdoc-digest256,except-flashsubdoc-digest256,except-flashinfobar-digest256");
 
 // The table and update/gethash URLs for Safebrowsing phishing and malware
 // checks.
 pref("urlclassifier.trackingTable", "test-track-simple,base-track-digest256");
 pref("urlclassifier.trackingWhitelistTable", "test-trackwhite-simple,mozstd-trackwhite-digest256");
 
 // The number of random entries to send with a gethash request.
 pref("urlclassifier.gethashnoise", 4);
@@ -5289,22 +5289,22 @@ pref("browser.safebrowsing.provider.mozi
 pref("browser.safebrowsing.provider.mozilla.nextupdatetime", "1");
 // Block lists for tracking protection. The name values will be used as the keys
 // to lookup the localized name in preferences.properties.
 pref("browser.safebrowsing.provider.mozilla.lists.base.name", "mozstdName");
 pref("browser.safebrowsing.provider.mozilla.lists.base.description", "mozstdDesc");
 pref("browser.safebrowsing.provider.mozilla.lists.content.name", "mozfullName");
 pref("browser.safebrowsing.provider.mozilla.lists.content.description", "mozfullDesc");
 
-pref("urlclassifier.flashAllowTable", "test-flashallow-simple,allow-flashallow-digest256");
-pref("urlclassifier.flashAllowExceptTable", "testexcept-flashallow-simple,except-flashallow-digest256");
-pref("urlclassifier.flashTable", "test-flash-simple,block-flash-digest256");
-pref("urlclassifier.flashExceptTable", "testexcept-flash-simple,except-flash-digest256");
-pref("urlclassifier.flashSubDocTable", "test-flashsubdoc-simple,block-flashsubdoc-digest256");
-pref("urlclassifier.flashSubDocExceptTable", "testexcept-flashsubdoc-simple,except-flashsubdoc-digest256");
+pref("urlclassifier.flashAllowTable", "allow-flashallow-digest256");
+pref("urlclassifier.flashAllowExceptTable", "except-flashallow-digest256");
+pref("urlclassifier.flashTable", "block-flash-digest256");
+pref("urlclassifier.flashExceptTable", "except-flash-digest256");
+pref("urlclassifier.flashSubDocTable", "block-flashsubdoc-digest256");
+pref("urlclassifier.flashSubDocExceptTable", "except-flashsubdoc-digest256");
 pref("urlclassifier.flashInfobarTable", "except-flashinfobar-digest256");
 
 pref("plugins.http_https_only", true);
 pref("plugins.flashBlock.enabled", false);
 
 // Allow users to ignore Safe Browsing warnings.
 pref("browser.safebrowsing.allowOverride", true);
 
--- a/toolkit/components/url-classifier/SafeBrowsing.jsm
+++ b/toolkit/components/url-classifier/SafeBrowsing.jsm
@@ -395,23 +395,16 @@ this.SafeBrowsing = {
     const unwantedURL = "itisatrap.org/firefox/unwanted.html";
     const trackerURLs = [
       "trackertest.org/",
       "itisatracker.org/",
     ];
     const whitelistURL  = "itisatrap.org/?resource=itisatracker.org";
     const blockedURL    = "itisatrap.org/firefox/blocked.html";
 
-    const flashDenyURL = "flashblock.itisatrap.org/";
-    const flashDenyExceptURL = "except.flashblock.itisatrap.org/";
-    const flashAllowURL = "flashallow.itisatrap.org/";
-    const flashAllowExceptURL = "except.flashallow.itisatrap.org/";
-    const flashSubDocURL = "flashsubdoc.itisatrap.org/";
-    const flashSubDocExceptURL = "except.flashsubdoc.itisatrap.org/";
-
     let update = "n:1000\ni:test-malware-simple\nad:1\n" +
                  "a:1:32:" + malwareURL.length + "\n" +
                  malwareURL + "\n";
     update += "n:1000\ni:test-phish-simple\nad:1\n" +
               "a:1:32:" + phishURL.length + "\n" +
               phishURL  + "\n";
     update += "n:1000\ni:test-unwanted-simple\nad:1\n" +
               "a:1:32:" + unwantedURL.length + "\n" +
@@ -423,34 +416,16 @@ this.SafeBrowsing = {
                 trackerURL + "\n";
     });
     update += "n:1000\ni:test-trackwhite-simple\nad:1\n" +
               "a:1:32:" + whitelistURL.length + "\n" +
               whitelistURL;
     update += "n:1000\ni:test-block-simple\nad:1\n" +
               "a:1:32:" + blockedURL.length + "\n" +
               blockedURL;
-    update += "n:1000\ni:test-flash-simple\nad:1\n" +
-              "a:1:32:" + flashDenyURL.length + "\n" +
-              flashDenyURL;
-    update += "n:1000\ni:testexcept-flash-simple\nad:1\n" +
-              "a:1:32:" + flashDenyExceptURL.length + "\n" +
-              flashDenyExceptURL;
-    update += "n:1000\ni:test-flashallow-simple\nad:1\n" +
-              "a:1:32:" + flashAllowURL.length + "\n" +
-              flashAllowURL;
-    update += "n:1000\ni:testexcept-flashallow-simple\nad:1\n" +
-              "a:1:32:" + flashAllowExceptURL.length + "\n" +
-              flashAllowExceptURL;
-    update += "n:1000\ni:test-flashsubdoc-simple\nad:1\n" +
-              "a:1:32:" + flashSubDocURL.length + "\n" +
-              flashSubDocURL;
-    update += "n:1000\ni:testexcept-flashsubdoc-simple\nad:1\n" +
-              "a:1:32:" + flashSubDocExceptURL.length + "\n" +
-              flashSubDocExceptURL;
     log("addMozEntries:", update);
 
     let db = Cc["@mozilla.org/url-classifier/dbservice;1"].
              getService(Ci.nsIUrlClassifierDBService);
 
     // nsIUrlClassifierUpdateObserver
     let dummyListener = {
       updateUrlRequested: function() { },
@@ -461,17 +436,17 @@ this.SafeBrowsing = {
         Services.obs.notifyObservers(db, "mozentries-update-finished", "error");
       },
       updateSuccess:      function() {
         Services.obs.notifyObservers(db, "mozentries-update-finished", "success");
       }
     };
 
     try {
-      let tables = "test-malware-simple,test-phish-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple,test-flash-simple,testexcept-flash-simple,test-flashallow-simple,testexcept-flashallow-simple,test-flashsubdoc-simple,testexcept-flashsubdoc-simple";
+      let tables = "test-malware-simple,test-phish-simple,test-unwanted-simple,test-track-simple,test-trackwhite-simple,test-block-simple";
       db.beginUpdate(dummyListener, tables, "");
       db.beginStream("", "");
       db.updateStream(update);
       db.finishStream();
       db.finishUpdate();
     } catch(ex) {
       // beginUpdate will throw harmlessly if there's an existing update in progress, ignore failures.
       log("addMozEntries failed!", ex);
--- a/toolkit/components/url-classifier/tests/browser/classifierTester.js
+++ b/toolkit/components/url-classifier/tests/browser/classifierTester.js
@@ -4,16 +4,17 @@
 
 
 var classifierTester = {
   URL_PATH: "/browser/toolkit/components/url-classifier/tests/browser/flash_block_frame.html",
   OBJECT_ID: "testObject",
   IFRAME_ID: "testFrame",
   FLASHBLOCK_ENABLE_PREF: "plugins.flashBlock.enabled",
   FLASH_PLUGIN_USER_SETTING_PREF: "plugin.state.flash",
+  URLCLASSIFIER_DISALLOW_COMPLETIONS_PREF: "urlclassifier.disallow_completions",
   NEVER_ACTIVATE_PREF_VALUE: 0,
   ASK_TO_ACTIVATE_PREF_VALUE: 1,
   ALWAYS_ACTIVATE_PREF_VALUE: 2,
   ALLOW_CTA_PREF: "plugins.click_to_play",
 
   dbUrls: [
     {
       url: "flashallow.example.com/",
@@ -33,42 +34,52 @@ var classifierTester = {
     {
       url: "exception.flashblock.example.com/",
       db: "testexcept-flash-simple",
       pref: "urlclassifier.flashExceptTable"
     },
     {
       url: "subdocument.example.com/",
       db: "test-flashsubdoc-simple",
-      pref: "urlclassifier.flashThirdPartyTable"
+      pref: "urlclassifier.flashSubDocTable"
     },
     {
       url: "exception.subdocument.example.com/",
       db: "testexcept-flashsubdoc-simple",
-      pref: "urlclassifier.flashThirdPartyExceptTable"
+      pref: "urlclassifier.flashSubDocExceptTable"
     }
   ],
 
   setPrefs: function ({setDBs = true, flashBlockEnable = true, flashSetting = classifierTester.ALWAYS_ACTIVATE_PREF_VALUE} = {}) {
     if (setDBs) {
+      let DBs = [];
+
       for (let dbData of classifierTester.dbUrls) {
         Services.prefs.setCharPref(dbData.pref, dbData.db);
+        DBs.push(dbData.db);
       }
+
+      let completions = Services.prefs.getCharPref(classifierTester.URLCLASSIFIER_DISALLOW_COMPLETIONS_PREF);
+      completions += "," + DBs.join(",");
+      Services.prefs.setCharPref(classifierTester.URLCLASSIFIER_DISALLOW_COMPLETIONS_PREF, completions);
     }
+
     Services.prefs.setBoolPref(classifierTester.FLASHBLOCK_ENABLE_PREF,
                                flashBlockEnable);
     Services.prefs.setIntPref(classifierTester.FLASH_PLUGIN_USER_SETTING_PREF,
                               flashSetting);
     Services.prefs.setBoolPref(classifierTester.ALLOW_CTA_PREF, true);
   },
 
   unsetPrefs: function () {
     for (let dbData of classifierTester.dbUrls) {
       Services.prefs.clearUserPref(dbData.pref);
     }
+
+    Services.prefs.clearUserPref(classifierTester.URLCLASSIFIER_DISALLOW_COMPLETIONS_PREF);
     Services.prefs.clearUserPref(classifierTester.FLASHBLOCK_ENABLE_PREF);
     Services.prefs.clearUserPref(classifierTester.FLASH_PLUGIN_USER_SETTING_PREF);
     Services.prefs.clearUserPref(classifierTester.ALLOW_CTA_PREF);
   },
 
   // The |domains| property describes the domains of the nested documents making
   // up the page. |domains[0]| represents the domain in the URL bar. The last
   // domain in the list is the domain of the most deeply nested iframe.