Bug 1482950 - Improve tracking annotation test. r=Ehsan!
authorFrancois Marier <francois@mozilla.com>
Mon, 20 Aug 2018 14:08:15 +0000
changeset 487561 0e95533b40e12ec879aa6fcfd0c1c735c42f443a
parent 487560 fe91a0b8bb4c6fd0a73bde4c95754d82a1c1fb97
child 487562 dc5cbee865e4286a767dd69749314c909e2f7343
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1482950
milestone63.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 1482950 - Improve tracking annotation test. r=Ehsan! A new parameter is introduced to makeConnection in order to specify the topWindowURI. This will be useful in future tests, but it also highlights the fact that we do set this in all of the existing tests. Finally, I also added a number of comments and explicit parameter setting in order to make the test more readily understandable. Depends on D3720 Differential Revision: https://phabricator.services.mozilla.com/D3721
netwerk/test/unit/test_trackingProtection_annotateChannels.js
--- a/netwerk/test/unit/test_trackingProtection_annotateChannels.js
+++ b/netwerk/test/unit/test_trackingProtection_annotateChannels.js
@@ -19,34 +19,34 @@ ChromeUtils.import("resource://testing-c
 // Below where we need to take different actions based on the process type we're
 // in, we use runtime.processType to take the correct actions.
 
 const runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
 if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
   do_get_profile();
 }
 
-const topWindowURI = NetUtil.newURI("http://www.example.com/");
+const defaultTopWindowURI = NetUtil.newURI("http://www.example.com/");
 
 function listener(tracking, priority, throttleable, nextTest) {
   this._tracking = tracking;
   this._priority = priority;
   this._throttleable = throttleable;
   this._nextTest = nextTest;
 }
 listener.prototype = {
   onStartRequest: function(request, context) {
     Assert.equal(request.QueryInterface(Ci.nsIHttpChannel).isTrackingResource,
-                 this._tracking);
+                 this._tracking, "tracking flag");
     Assert.equal(request.QueryInterface(Ci.nsISupportsPriority).priority,
-                 this._priority);
+                 this._priority, "channel priority");
     if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT && this._tracking) {
       Assert.equal(!!(request.QueryInterface(Ci.nsIClassOfService).classFlags &
                        Ci.nsIClassOfService.Throttleable),
-                   this._throttleable);
+                   this._throttleable, "throttleable flag");
     }
     request.cancel(Cr.NS_ERROR_ABORT);
     this._nextTest();
   },
   onDataAvailable: function(request, context, stream, offset, count) {
   },
   onStopRequest: function(request, context, status) {
   }
@@ -87,24 +87,29 @@ function setup_test() {
 
 function doPriorityTest() {
   if (!testPriorityMap.length) {
     runTests();
     return;
   }
 
   currentTest = testPriorityMap.shift();
-  var channel = makeChannel(currentTest.path, currentTest.loadingPrincipal);
+
+  // Let's be explicit about what we're testing!
+  Assert.ok("loadingPrincipal" in currentTest, "check for incomplete test case");
+  Assert.ok("topWindowURI" in currentTest, "check for incomplete test case");
+
+  var channel = makeChannel(currentTest.path, currentTest.loadingPrincipal, currentTest.topWindowURI);
   channel.asyncOpen2(new listener(currentTest.expectedTracking,
                                   currentTest.expectedPriority,
                                   currentTest.expectedThrottleable,
                                   doPriorityTest));
 }
 
-function makeChannel(path, loadingPrincipal) {
+function makeChannel(path, loadingPrincipal, topWindowURI) {
   var chan;
 
   if (loadingPrincipal) {
     chan = NetUtil.newChannel({
       uri: path,
       loadingPrincipal: loadingPrincipal,
       securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
       contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER,
@@ -113,17 +118,19 @@ function makeChannel(path, loadingPrinci
     chan = NetUtil.newChannel({
       uri: path,
       loadUsingSystemPrincipal: true,
     });
   }
   chan.QueryInterface(Ci.nsIHttpChannel);
   chan.requestMethod = "GET";
   chan.loadFlags |= Ci.nsIChannel.LOAD_CLASSIFY_URI;
-  chan.QueryInterface(Ci.nsIHttpChannelInternal).setTopWindowURIIfUnknown(topWindowURI);
+  if (topWindowURI) {
+    chan.QueryInterface(Ci.nsIHttpChannelInternal).setTopWindowURIIfUnknown(topWindowURI);
+  }
   return chan;
 }
 
 var tests =[
   // Create the HTTP server.
   setup_test,
 
   // Add the test table into tracking protection table.
@@ -132,137 +139,160 @@ var tests =[
       UrlClassifierTestUtils.addTestTrackers().then(() => {
         runTests();
       });
     } else {
       runTests();
     }
   },
 
-  // With the pref off, the priority of channel should be normal.
-  function setupNormalPriority() {
+  // Annotations OFF, normal loading principal, topWinURI of example.com
+  // => trackers should not be de-prioritized
+  function setupAnnotationsOff() {
     if (skipNormalPriority) {
       runTests();
       return;
     }
     if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
       Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", false);
       Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", false);
     }
+    var principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin(normalOrigin);
     testPriorityMap = [
       {
         path: normalOrigin + "/innocent.css",
+        loadingPrincipal: principal,
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: false,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
-        expectedThrottleable: false,
+        expectedThrottleable: false, // ignored since tracking==false
       },
       {
         path: normalOrigin + "/innocent.js",
+        loadingPrincipal: principal,
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: false,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
-        expectedThrottleable: false,
+        expectedThrottleable: false, // ignored since tracking==false
       },
       {
         path: trackingOrigin + "/evil.css",
+        loadingPrincipal: principal,
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: false,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
-        expectedThrottleable: false,
+        expectedThrottleable: false, // ignored since tracking==false
       },
       {
         path: trackingOrigin + "/evil.js",
+        loadingPrincipal: principal,
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: false,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
-        expectedThrottleable: false,
+        expectedThrottleable: false, // ignored since tracking==false
       },
     ];
     // We add the doPriorityTest test here so that it only gets injected in the
     // test list if we're not skipping over this test.
     tests.unshift(doPriorityTest);
     runTests();
   },
 
-  // With the pref on, the priority of channel should be lowest.
-  function setupLowestPriority() {
+  // Annotations ON, normal loading principal, topWinURI of example.com
+  // => trackers should be de-prioritized
+  function setupAnnotationsOn() {
     if (skipLowestPriority) {
       runTests();
       return;
     }
     if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
       Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", true);
       Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", true);
     }
     var principal = Services.scriptSecurityManager.createCodebasePrincipalFromOrigin(normalOrigin);
     testPriorityMap = [
       {
         path: normalOrigin + "/innocent.css",
         loadingPrincipal: principal,
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: false,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
-        expectedThrottleable: true,
+        expectedThrottleable: false, // ignored since tracking==false
       },
       {
         path: normalOrigin + "/innocent.js",
         loadingPrincipal: principal,
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: false,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
-        expectedThrottleable: true,
+        expectedThrottleable: false, // ignored since tracking==false
       },
       {
         path: trackingOrigin + "/evil.css",
         loadingPrincipal: principal,
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: true,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_LOWEST,
         expectedThrottleable: true,
       },
       {
         path: trackingOrigin + "/evil.js",
         loadingPrincipal: principal,
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: true,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_LOWEST,
         expectedThrottleable: true,
       },
     ];
     // We add the doPriorityTest test here so that it only gets injected in the
     // test list if we're not skipping over this test.
     tests.unshift(doPriorityTest);
     runTests();
   },
 
-  // With the pref on, but not top-level requests, the priority of channel
-  // should be normal.
-  function setupTopLevelNormalPriority() {
+  // Annotations ON, system loading principal, topWinURI of example.com
+  // => trackers should be de-prioritized
+  function setupAnnotationsOnSystemPrincipal() {
     if (skipLowestPriority) {
       runTests();
       return;
     }
     if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
       Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", true);
       Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", true);
     }
     testPriorityMap = [
       {
         path: normalOrigin + "/innocent.css",
+        loadingPrincipal: null, // system principal
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: false,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
-        expectedThrottleable: false,
+        expectedThrottleable: false, // ignored since tracking==false
       },
       {
         path: normalOrigin + "/innocent.js",
+        loadingPrincipal: null, // system principal
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: false,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
-        expectedThrottleable: false,
+        expectedThrottleable: false, // ignored since tracking==false
       },
       {
         path: trackingOrigin + "/evil.css",
+        loadingPrincipal: null, // system principal
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: true,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
         expectedThrottleable: false,
       },
       {
         path: trackingOrigin + "/evil.js",
+        loadingPrincipal: null, // system principal
+        topWindowURI: defaultTopWindowURI,
         expectedTracking: true,
         expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL,
         expectedThrottleable: false,
       },
     ];
     // We add the doPriorityTest test here so that it only gets injected in the
     // test list if we're not skipping over this test.
     tests.unshift(doPriorityTest);