Bug 1584479 - Part 4: Update TrackingDBService test. r=ewright
☠☠ backed out by 070d360bafef ☠ ☠
authorNihanth Subramanya <nhnt11@gmail.com>
Fri, 01 Nov 2019 20:07:00 +0000
changeset 500235 b0d9877bd8b07ad3b77196e35c1be702ba85ba93
parent 500234 d2c56bd61b08f11f9bcde957c12cb3ff45aa5148
child 500236 60244e31ea1d74b38eafe4ec3dcbf4e9a551fa0c
push id114164
push useraiakab@mozilla.com
push dateTue, 05 Nov 2019 10:06:15 +0000
treeherdermozilla-inbound@4d585c7edc76 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersewright
bugs1584479
milestone72.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 1584479 - Part 4: Update TrackingDBService test. r=ewright Differential Revision: https://phabricator.services.mozilla.com/D51409
toolkit/components/antitracking/test/xpcshell/test_tracking_db_service.js
--- a/toolkit/components/antitracking/test/xpcshell/test_tracking_db_service.js
+++ b/toolkit/components/antitracking/test/xpcshell/test_tracking_db_service.js
@@ -55,60 +55,75 @@ const LOG = {
   "https://6.example.com": [
     [
       Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_ALL |
         Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT,
       true,
       4,
     ],
   ],
+  "https://7.example.com": [
+    [Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_SOCIALTRACKER, true, 1],
+  ],
+  "https://8.example.com": [
+    [Ci.nsIWebProgressListener.STATE_BLOCKED_SOCIALTRACKING_CONTENT, true, 1],
+  ],
 
   // The contents below should not add to the database.
   // Cookie loaded but not blocked.
-  "https://7.example.com": [
+  "https://10.example.com": [
     [Ci.nsIWebProgressListener.STATE_COOKIES_LOADED, true, 1],
   ],
   // Tracker cookie loaded but not blocked.
-  "https://8.example.com": [
+  "https://11.unblocked.example.com": [
     [Ci.nsIWebProgressListener.STATE_COOKIES_LOADED_TRACKER, true, 1],
   ],
   // Social tracker cookie loaded but not blocked.
-  "https://9.example.com": [
+  "https://12.example.com": [
     [Ci.nsIWebProgressListener.STATE_COOKIES_LOADED_SOCIALTRACKER, true, 1],
   ],
   // Cookie blocked for other reason (not a tracker)
-  "https://10.example.com": [
+  "https://13.example.com": [
     [Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_BY_PERMISSION, true, 2],
   ],
   // Fingerprinters set to block, but this one has an exception
-  "https://11.example.com": [
+  "https://14.example.com": [
     [Ci.nsIWebProgressListener.STATE_BLOCKED_FINGERPRINTING_CONTENT, false, 1],
   ],
 };
 
 do_get_profile();
 
+Services.prefs.setBoolPref("browser.contentblocking.database.enabled", true);
+Services.prefs.setBoolPref(
+  "privacy.socialtracking.block_cookies.enabled",
+  true
+);
+registerCleanupFunction(() => {
+  Services.prefs.clearUserPref("browser.contentblocking.database.enabled");
+  Services.prefs.clearUserPref("privacy.socialtracking.block_cookies.enabled");
+});
+
 // This tests that data is added successfully, different types of events should get
 // their own entries, when the type is the same they should be aggregated. Events
 // that are not blocking events should not be recorded. Cookie blocking events
 // should only be recorded if we can identify the cookie as a tracking cookie.
 add_task(async function test_save_and_delete() {
-  Services.prefs.setBoolPref("browser.contentblocking.database.enabled", true);
   await TrackingDBService.saveEvents(JSON.stringify(LOG));
 
   // Peek in the DB to make sure we have the right data.
   let db = await Sqlite.openConnection({ path: DB_PATH });
   // Make sure the items table was created.
   ok(await db.tableExists("events"), "events table exists");
 
   // make sure we have the correct contents in the database
   let rows = await db.execute(SQL.selectAll);
   equal(
     rows.length,
-    4,
+    5,
     "Events that should not be saved have not been, length is 4"
   );
   rows = await db.execute(SQL.selectAllEntriesOfType, {
     type: TrackingDBService.TRACKERS_ID,
   });
   equal(rows.length, 1, "Only one day has had tracker entries, length is 1");
   let count = rows[0].getResultByName("count");
   equal(count, 1, "there is only one tracker entry");
@@ -137,29 +152,34 @@ add_task(async function test_save_and_de
   equal(
     rows.length,
     1,
     "Only one day has had fingerprinters entries, length is 1"
   );
   count = rows[0].getResultByName("count");
   equal(count, 1, "there is only one fingerprinter entry");
 
+  rows = await db.execute(SQL.selectAllEntriesOfType, {
+    type: TrackingDBService.SOCIAL_ID,
+  });
+  equal(rows.length, 1, "Only one day has had social entries, length is 1");
+  count = rows[0].getResultByName("count");
+  equal(count, 2, "there are two social entries");
+
   // Use the TrackingDBService API to delete the data.
   await TrackingDBService.clearAll();
   // Make sure the data was deleted.
   rows = await db.execute(SQL.selectAll);
   equal(rows.length, 0, "length is 0");
   await db.close();
-  Services.prefs.clearUserPref("browser.contentblocking.database.enabled");
 });
 
 // This tests that content blocking events encountered on the same day get aggregated,
 // and those on different days get seperate entries
 add_task(async function test_timestamp_aggragation() {
-  Services.prefs.setBoolPref("browser.contentblocking.database.enabled", true);
   // This creates the schema.
   await TrackingDBService.saveEvents(JSON.stringify({}));
   let db = await Sqlite.openConnection({ path: DB_PATH });
 
   let yesterday = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString();
   let today = new Date().toISOString();
   await db.execute(SQL.insertCustomTimeEvent, {
     type: TrackingDBService.TRACKERS_ID,
@@ -273,17 +293,16 @@ add_task(async function test_timestamp_a
   }
 
   // Use the TrackingDBService API to delete the data.
   await TrackingDBService.clearAll();
   // Make sure the data was deleted.
   rows = await db.execute(SQL.selectAll);
   equal(rows.length, 0, "length is 0");
   await db.close();
-  Services.prefs.clearUserPref("browser.contentblocking.database.enabled");
 });
 
 let addEventsToDB = async db => {
   let d = new Date(1521009000000);
   let date = d.toISOString();
   await db.execute(SQL.insertCustomTimeEvent, {
     type: TrackingDBService.CRYPTOMINERS_ID,
     count: 3,
@@ -317,17 +336,16 @@ let addEventsToDB = async db => {
     count: 2,
     timestamp: date,
   });
 };
 
 // This tests that TrackingDBService.getEventsByDateRange can accept two timestamps in unix epoch time
 // and return entries that occur within the timestamps, rounded to the nearest day and inclusive.
 add_task(async function test_getEventsByDateRange() {
-  Services.prefs.setBoolPref("browser.contentblocking.database.enabled", true);
   // This creates the schema.
   await TrackingDBService.saveEvents(JSON.stringify({}));
   let db = await Sqlite.openConnection({ path: DB_PATH });
   await addEventsToDB(db);
 
   let d = new Date(1521009000000);
   let daysBefore1 = new Date(d - 24 * 60 * 60 * 1000);
   let daysBefore4 = new Date(d - 4 * 24 * 60 * 60 * 1000);
@@ -354,45 +372,41 @@ add_task(async function test_getEventsBy
   equal(
     events.length,
     2,
     "There is 2 event entries between nine and four days before, inclusive"
   );
 
   await TrackingDBService.clearAll();
   await db.close();
-  Services.prefs.clearUserPref("browser.contentblocking.database.enabled");
 });
 
 // This tests that TrackingDBService.sumAllEvents returns the number of
 // tracking events in the database, and can handle 0 entries.
 add_task(async function test_sumAllEvents() {
-  Services.prefs.setBoolPref("browser.contentblocking.database.enabled", true);
   // This creates the schema.
   await TrackingDBService.saveEvents(JSON.stringify({}));
   let db = await Sqlite.openConnection({ path: DB_PATH });
 
   let sum = await TrackingDBService.sumAllEvents();
   equal(sum, 0, "There have been 0 events recorded");
 
   // populate the database
   await addEventsToDB(db);
 
   sum = await TrackingDBService.sumAllEvents();
   equal(sum, 11, "There have been 11 events recorded");
 
   await TrackingDBService.clearAll();
   await db.close();
-  Services.prefs.clearUserPref("browser.contentblocking.database.enabled");
 });
 
 // This tests that TrackingDBService.getEarliestRecordedDate returns the
 // earliest date recorded and can handle 0 entries.
 add_task(async function test_getEarliestRecordedDate() {
-  Services.prefs.setBoolPref("browser.contentblocking.database.enabled", true);
   // This creates the schema.
   await TrackingDBService.saveEvents(JSON.stringify({}));
   let db = await Sqlite.openConnection({ path: DB_PATH });
 
   let timestamp = await TrackingDBService.getEarliestRecordedDate();
   equal(timestamp, null, "There is no earliest recorded date");
 
   // populate the database
@@ -403,10 +417,9 @@ add_task(async function test_getEarliest
     .split("T")[0];
 
   timestamp = await TrackingDBService.getEarliestRecordedDate();
   let date = new Date(timestamp).toISOString().split("T")[0];
   equal(date, daysBefore9, "The earliest recorded event is nine days before.");
 
   await TrackingDBService.clearAll();
   await db.close();
-  Services.prefs.clearUserPref("browser.contentblocking.database.enabled");
 });