Bug 1055180: cleanup functions in test_classified_annotations and test_allowlisted_annotations. Making sure the nsChannelClassifier::ShouldEnableTrackingProtection does not abort on chrome URIs. (r=mmc)
authorGeorgios Kontaxis <gkontaxis@mozilla.com>
Mon, 18 Aug 2014 14:58:33 -0700
changeset 200212 a62e4d356ef3a818f6fa4d8f113792256d87f25b
parent 200211 24f9ec66094d3ca3f84d4204cd9f86ef31369246
child 200213 ea9d82ca538711559556f0a5422654f29b6e3b17
push id47836
push usermchew@mozilla.com
push dateMon, 18 Aug 2014 22:44:05 +0000
treeherdermozilla-inbound@a62e4d356ef3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmmc
bugs1055180
milestone34.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 1055180: cleanup functions in test_classified_annotations and test_allowlisted_annotations. Making sure the nsChannelClassifier::ShouldEnableTrackingProtection does not abort on chrome URIs. (r=mmc)
toolkit/components/url-classifier/tests/mochitest/classifiedAnnotatedFrame.html
toolkit/components/url-classifier/tests/mochitest/test_allowlisted_annotations.html
toolkit/components/url-classifier/tests/mochitest/test_classified_annotations.html
--- a/toolkit/components/url-classifier/tests/mochitest/classifiedAnnotatedFrame.html
+++ b/toolkit/components/url-classifier/tests/mochitest/classifiedAnnotatedFrame.html
@@ -76,16 +76,18 @@ function checkLoads() {
         (blockedTrackingNodes[i] == document.getElementById(badids[j]));
     }
 
     allNodeMatch &= nodeMatch;
   }
   window.parent.is(allNodeMatch, true,
     "All tracking nodes are expected to be annotated as such");
 
+  // Unset prefs, etc.
+  window.parent.cleanup();
   // End (parent) test.
   window.parent.SimpleTest.finish();
 }
 
 </script>
 
 <!-- Try loading from a tracking CSS URI -->
 <link id="badcss" rel="stylesheet" type="text/css" href="http://tracking.example.com/tests/toolkit/components/url-classifier/tests/mochitest/evil.css"></link>
--- a/toolkit/components/url-classifier/tests/mochitest/test_allowlisted_annotations.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_allowlisted_annotations.html
@@ -35,16 +35,18 @@ var dbService = Cc["@mozilla.org/url-cla
                 .getService(Ci.nsIUrlClassifierDBService);
 
 function clearPermissions() {
   SpecialPowers.removePermission("trackingprotection",
                                  { url: "https://allowlisted.example.com" });
   ok(!SpecialPowers.testPermission("trackingprotection",
                                    Ci.nsIPermissionManager.ALLOW_ACTION,
                                    { url: "https://allowlisted.example.com" }));
+  SpecialPowers.clearUserPref("privacy.trackingprotection.enabled");
+  SpecialPowers.clearUserPref("channelclassifier.allowlist_example");
 }
 
 function doUpdate(update) {
   var listener = {
     QueryInterface: function(iid)
     {
       if (iid.equals(Ci.nsISupports) ||
           iid.equals(Ci.nsIUrlClassifierUpdateObserver))
@@ -55,23 +57,18 @@ function doUpdate(update) {
     updateUrlRequested: function(url) { },
     streamFinished: function(status) { },
     updateError: function(errorCode) {
       ok(false, "Couldn't update classifier.");
       // Abort test.
       SimpleTest.finish();
     },
     updateSuccess: function(requestedTimeout) {
-      SpecialPowers.pushPrefEnv(
-        {"set" : [["privacy.trackingprotection.enabled", true]]},
-        function loadTestFrame() {
-          document.getElementById("testFrame").src =
-            "allowlistAnnotatedFrame.html";
-        }
-      );
+      SpecialPowers.setBoolPref("privacy.trackingprotection.enabled", true);
+      document.getElementById("testFrame").src = "allowlistAnnotatedFrame.html";
     }
   };
 
   dbService.beginUpdate(listener, "test-track-simple", "");
   dbService.beginStream("", "");
   dbService.updateStream(update);
   dbService.finishStream();
   dbService.finishUpdate();
--- a/toolkit/components/url-classifier/tests/mochitest/test_classified_annotations.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classified_annotations.html
@@ -19,16 +19,21 @@ var Ci = SpecialPowers.Ci;
 
 // Add some URLs to the tracking database
 var testData = "tracking.example.com/";
 var testUpdate =
   "n:1000\ni:test-track-simple\nad:1\n" +
   "a:524:32:" + testData.length + "\n" +
   testData;
 
+function cleanup() {
+  SpecialPowers.clearUserPref("privacy.trackingprotection.enabled");
+  SpecialPowers.clearUserPref("channelclassifier.allowlist_example");
+}
+
 var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
                 .getService(Ci.nsIUrlClassifierDBService);
 
 function doUpdate(update) {
   var listener = {
     QueryInterface: function(iid)
     {
       if (iid.equals(Ci.nsISupports) ||
@@ -40,23 +45,22 @@ function doUpdate(update) {
     updateUrlRequested: function(url) { },
     streamFinished: function(status) { },
     updateError: function(errorCode) {
       ok(false, "Couldn't update classifier.");
       // Abort test.
       SimpleTest.finish();
     },
     updateSuccess: function(requestedTimeout) {
-      SpecialPowers.pushPrefEnv(
-        {"set" : [["privacy.trackingprotection.enabled", true]]},
-        function loadTestFrame() {
-          document.getElementById("testFrame").src =
-            "classifiedAnnotatedFrame.html";
-        }
-      );
+      SpecialPowers.setBoolPref("privacy.trackingprotection.enabled", true);
+      // Make sure chrome:// URIs are processed. This does not white-list
+      // any URIs unless 'https://allowlisted.example.com' is added in the
+      // permission manager (see test_allowlisted_annotations.html)
+      SpecialPowers.setBoolPref("channelclassifier.allowlist_example", true);
+      document.getElementById("testFrame").src = "classifiedAnnotatedFrame.html";
     }
   };
 
   dbService.beginUpdate(listener, "test-track-simple", "");
   dbService.beginStream("", "");
   dbService.updateStream(update);
   dbService.finishStream();
   dbService.finishUpdate();