Bug 1503465 - Part 3: Add a <xul:browser> API for retrieving the top-level content blocking log r=johannh
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 31 Oct 2018 21:21:38 +0000
changeset 443848 79a9c9f0946ee1971a5dc9c4ed075adee2a4da15
parent 443847 f7fda20ef298e560e6905d97e25e25ee21a043a2
child 443849 9536fe8330a88f1ae48fca1c1c4ce7b1fa5ae4a1
push id72113
push usereakhgari@mozilla.com
push dateWed, 31 Oct 2018 22:27:57 +0000
treeherderautoland@79a9c9f0946e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1503465
milestone65.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 1503465 - Part 3: Add a <xul:browser> API for retrieving the top-level content blocking log r=johannh Depends on D10363 Differential Revision: https://phabricator.services.mozilla.com/D10364
toolkit/components/antitracking/test/browser/browser_subResources.js
toolkit/content/widgets/browser.xml
--- a/toolkit/components/antitracking/test/browser/browser_subResources.js
+++ b/toolkit/components/antitracking/test/browser/browser_subResources.js
@@ -151,16 +151,35 @@ add_task(async function() {
     });
 
   await fetch("https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=script")
     .then(r => r.text())
     .then(text => {
       is(text, 1, "One cookie received received for scripts.");
     });
 
+  let log = JSON.parse(await browser.getContentBlockingLog());
+  for (let trackerOrigin in log) {
+    is(trackerOrigin, TEST_3RD_PARTY_DOMAIN, "Correct tracker origin must be reported");
+    let originLog = log[trackerOrigin];
+    is(originLog.length, 2, "We should have two entries in the compressed log");
+    is(originLog[0][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
+       "Correct blocking type reported");
+    is(originLog[0][1], true,
+       "Correct blocking status reported");
+    is(originLog[0][2], 6, // 1 for each HTTP request which attempts to set a cookie
+       "Correct repeat count reported");
+    is(originLog[1][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
+       "Correct blocking type reported");
+    is(originLog[1][1], false,
+       "Correct blocking status reported");
+    is(originLog[1][2], 1, // Only got unblocked once
+       "Correct repeat count reported");
+  }
+
   info("Removing the tab");
   BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function() {
   info("Cleaning up.");
   await new Promise(resolve => {
     Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
--- a/toolkit/content/widgets/browser.xml
+++ b/toolkit/content/widgets/browser.xml
@@ -1937,16 +1937,27 @@
               name: aLinks[i + 1],
               type: aLinks[i + 2],
             });
           }
           this.droppedLinkHandler(null, links, aTriggeringPrincipal);
           return true;
         ]]></body>
       </method>
+
+      <method name="getContentBlockingLog">
+        <body><![CDATA[
+          if (this.isRemoteBrowser) {
+            return this.frameLoader.tabParent.getContentBlockingLog();
+          }
+          return this.docShell ?
+                   this.docShell.getContentBlockingLog() :
+                   Promise.reject("docshell isn't available");
+        ]]></body>
+      </method>
     </implementation>
 
     <handlers>
       <handler event="keypress" keycode="VK_F7" group="system">
         <![CDATA[
           if (event.defaultPrevented || !event.isTrusted)
             return;