Bug 1180975 - UI for re-enabling tracking protection no longer shown (Private Browsing); r=liuche
authorMartyn Haigh <mhaigh@mozilla.org>
Tue, 14 Jul 2015 12:04:50 +0100
changeset 253799 d8ab8c7fe5ab55a852a6b7631166e7417ddc72d8
parent 253798 89ebfc11c1a273d2b487ab44d5a7df549a52f6e3
child 253800 e60d8e177e13e8c3ca4adc64b822266e2c726ea3
push id29080
push usercbook@mozilla.com
push dateTue, 21 Jul 2015 14:53:05 +0000
treeherdermozilla-central@b918ff317c7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1180975
milestone42.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 1180975 - UI for re-enabling tracking protection no longer shown (Private Browsing); r=liuche
mobile/android/chrome/content/browser.js
mobile/android/tests/browser/robocop/testTrackingProtection.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -7020,17 +7020,17 @@ var IdentityHandler = {
   MIXED_MODE_UNKNOWN: "unknown",
 
   // Blocked active mixed content. Shield icon is shown, with a popup option to load content.
   MIXED_MODE_CONTENT_BLOCKED: "mixed_content_blocked",
 
   // Loaded active mixed content. Yellow triangle icon is shown.
   MIXED_MODE_CONTENT_LOADED: "mixed_content_loaded",
 
-  // The following tracking content modes are only used if "privacy.trackingprotection.enabled"
+  // The following tracking content modes are only used if tracking protection
   // is enabled. Our Java frontend coalesces them into one indicator.
 
   // No tracking content information. No tracking content icon is shown.
   TRACKING_MODE_UNKNOWN: "unknown",
 
   // Blocked active tracking content. Shield icon is shown, with a popup option to load content.
   TRACKING_MODE_CONTENT_BLOCKED: "tracking_content_blocked",
 
@@ -7098,25 +7098,28 @@ var IdentityHandler = {
     if ((aState & Ci.nsIWebProgressListener.STATE_LOADED_MIXED_ACTIVE_CONTENT) &&
          Services.prefs.getBoolPref("security.mixed_content.block_active_content")) {
       return this.MIXED_MODE_CONTENT_LOADED;
     }
 
     return this.MIXED_MODE_UNKNOWN;
   },
 
-  getTrackingMode: function getTrackingMode(aState) {
+  getTrackingMode: function getTrackingMode(aState, aBrowser) {
     if (aState & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT) {
       Telemetry.addData("TRACKING_PROTECTION_SHIELD", 2);
       return this.TRACKING_MODE_CONTENT_BLOCKED;
     }
 
     // Only show an indicator for loaded tracking content if the pref to block it is enabled
-    if ((aState & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT) &&
-         Services.prefs.getBoolPref("privacy.trackingprotection.enabled")) {
+    let tpEnabled = Services.prefs.getBoolPref("privacy.trackingprotection.enabled") ||
+                    (Services.prefs.getBoolPref("privacy.trackingprotection.pbmode.enabled") &&
+                     PrivateBrowsingUtils.isBrowserPrivate(aBrowser));
+
+    if ((aState & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT) && tpEnabled) {
       Telemetry.addData("TRACKING_PROTECTION_SHIELD", 1);
       return this.TRACKING_MODE_CONTENT_LOADED;
     }
 
     Telemetry.addData("TRACKING_PROTECTION_SHIELD", 0);
     return this.TRACKING_MODE_UNKNOWN;
   },
 
@@ -7143,17 +7146,17 @@ var IdentityHandler = {
       // Can sometimes throw if the URL being visited has no host/hostname,
       // e.g. about:blank. The _state for these pages means we won't need these
       // properties anyways, though.
     }
     this._lastLocation = locationObj;
 
     let identityMode = this.getIdentityMode(aState);
     let mixedMode = this.getMixedMode(aState);
-    let trackingMode = this.getTrackingMode(aState);
+    let trackingMode = this.getTrackingMode(aState, aBrowser);
     let result = {
       origin: locationObj.origin,
       mode: {
         identity: identityMode,
         mixed: mixedMode,
         tracking: trackingMode
       }
     };
--- a/mobile/android/tests/browser/robocop/testTrackingProtection.js
+++ b/mobile/android/tests/browser/robocop/testTrackingProtection.js
@@ -38,17 +38,16 @@ function promiseLoadEvent(browser, url, 
 }
 
 // Test that the Tracking Protection is active and has the correct state when
 // tracking content is blocked (Bug 1063831)
 
 // Code is mostly stolen from:
 // http://mxr.mozilla.org/mozilla-central/source/browser/base/content/test/general/browser_trackingUI.js
 
-var PREF = "privacy.trackingprotection.enabled";
 var TABLE = "urlclassifier.trackingTable";
 
 // Update tracking database
 function doUpdate() {
   // Add some URLs to the tracking database (to be blocked)
   var testData = "tracking.example.com/";
   var testUpdate =
     "n:1000\ni:test-track-simple\nad:1\n" +
@@ -79,46 +78,34 @@ function doUpdate() {
     dbService.beginUpdate(listener, "test-track-simple", "");
     dbService.beginStream("", "");
     dbService.updateStream(testUpdate);
     dbService.finishStream();
     dbService.finishUpdate();
   });
 }
 
-// Track the <browser> where the tests are happening
-let browser;
+// Tests the tracking protection UI in private browsing. By default, tracking protection is
+// enabled in private browsing ("privacy.trackingprotection.pbmode.enabled").
+add_task(function* test_tracking_pb() {
+  let BrowserApp = Services.wm.getMostRecentWindow("navigator:browser").BrowserApp;
 
-add_test(function setup_browser() {
-  let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
-  let BrowserApp = chromeWin.BrowserApp;
-
-  do_register_cleanup(function cleanup() {
-    Services.prefs.clearUserPref(PREF);
-    Services.prefs.clearUserPref(TABLE);
-    BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+  // Load a blank page
+  let browser = BrowserApp.addTab("about:blank", { selected: true, parentId: BrowserApp.selectedTab.id, isPrivate: true }).browser;
+  yield new Promise((resolve, reject) => {
+    browser.addEventListener("load", function startTests(event) {
+      browser.removeEventListener("load", startTests, true);
+      Services.tm.mainThread.dispatch(resolve, Ci.nsIThread.DISPATCH_NORMAL);
+    }, true);
   });
 
-  // Load a blank page
-  let url = "about:blank";
-  browser = BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
-  browser.addEventListener("load", function startTests(event) {
-    browser.removeEventListener("load", startTests, true);
-    Services.tm.mainThread.dispatch(run_next_test, Ci.nsIThread.DISPATCH_NORMAL);
-  }, true);
-});
-
-add_task(function* () {
   // Populate and use 'test-track-simple' for tracking protection lookups
   Services.prefs.setCharPref(TABLE, "test-track-simple");
   yield doUpdate();
 
-  // Enable Tracking Protection
-  Services.prefs.setBoolPref(PREF, true);
-
   // Point tab to a test page NOT containing tracking elements
   yield promiseLoadEvent(browser, "http://tracking.example.org/tests/robocop/tracking_good.html");
   Messaging.sendRequest({ type: "Test:Expected", expected: "unknown" });
 
   // Point tab to a test page containing tracking elements
   yield promiseLoadEvent(browser, "http://tracking.example.org/tests/robocop/tracking_bad.html");
   Messaging.sendRequest({ type: "Test:Expected", expected: "tracking_content_blocked" });
 
@@ -130,18 +117,18 @@ add_task(function* () {
   Messaging.sendRequest({ type: "Test:Expected", expected: "tracking_content_loaded" });
 
   // Simulate a click on the "Enable protection" button in the site identity popup.
   yield promiseLoadEvent(browser, undefined, undefined, () => {
     Services.obs.notifyObservers(null, "Session:Reload", "{\"allowContent\":false,\"contentType\":\"tracking\"}");
   });
   Messaging.sendRequest({ type: "Test:Expected", expected: "tracking_content_blocked" });
 
-  // Disable Tracking Protection
-  Services.prefs.setBoolPref(PREF, false);
+  // Disable tracking protection to make sure we don't show the UI when the pref is disabled.
+  Services.prefs.setBoolPref("privacy.trackingprotection.pbmode.enabled", false);
 
   // Point tab to a test page containing tracking elements
   yield promiseLoadEvent(browser, "http://tracking.example.org/tests/robocop/tracking_bad.html");
   Messaging.sendRequest({ type: "Test:Expected", expected: "unknown" });
 
   // Point tab to a test page NOT containing tracking elements
   yield promiseLoadEvent(browser, "http://tracking.example.org/tests/robocop/tracking_good.html");
   Messaging.sendRequest({ type: "Test:Expected", expected: "unknown" });