Bug 1102518 - Test for disabling tracking protection. r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 21 Nov 2014 08:03:20 -0800
changeset 241206 f4e09c6be90174c6a36061e88c26b8644676001a
parent 241205 ded64417fabe99e1b4c781ca87be640a2226f4c5
child 241207 1c41bf100a3d01d4987561cfe1d489f33956783f
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1102518
milestone36.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 1102518 - Test for disabling tracking protection. r=mfinkle
mobile/android/base/tests/testTrackingProtection.js
--- a/mobile/android/base/tests/testTrackingProtection.js
+++ b/mobile/android/base/tests/testTrackingProtection.js
@@ -10,32 +10,36 @@ const { classes: Cc, interfaces: Ci, uti
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Messaging.jsm");
 
 function ok(passed, text) {
   do_report_result(passed, text, Components.stack.caller, false);
 }
 
-function promiseLoadEvent(browser, url, eventType="load") {
+function promiseLoadEvent(browser, url, eventType="load", runBeforeLoad) {
   return new Promise((resolve, reject) => {
     do_print("Wait browser event: " + eventType);
 
     function handle(event) {
       if (event.target != browser.contentDocument || event.target.location.href == "about:blank" || (url && event.target.location.href != url)) {
         do_print("Skipping spurious '" + eventType + "' event" + " for " + event.target.location.href);
         return;
       }
 
       browser.removeEventListener(eventType, handle, true);
       do_print("Browser event received: " + eventType);
       resolve(event);
     }
 
-    browser.addEventListener(eventType, handle, true, true);
+    browser.addEventListener(eventType, handle, true);
+
+    if (runBeforeLoad) {
+      runBeforeLoad();
+    }
     if (url) {
       browser.loadURI(url);
     }
   });
 }
 
 // Test that the Tracking Protection is active and has the correct state when
 // tracking content is blocked (Bug 1063831)
@@ -117,16 +121,29 @@ add_task(function* () {
   // 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" });
 
+  // Simulate a click on the "Disable protection" button in the site identity popup.
+  // We need to wait for a "load" event because "Session:Reload" will cause a full page reload.
+  yield promiseLoadEvent(browser, undefined, undefined, () => {
+    Services.obs.notifyObservers(null, "Session:Reload", "{\"allowContent\":true,\"contentType\":\"tracking\"}");
+  });
+  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);
 
   // 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