Bug 1638711 - Fix test_CSP to detect CSP events from the parent process. r=ckerschb
☠☠ backed out by 1caff03435d2 ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 27 May 2020 00:33:17 +0000
changeset 532333 254871b49de9aad85c89d1c6db3c2108e66eecd0
parent 532332 97d1d239058656066888cbdeefc3695b59a610ef
child 532334 75d97b8df5baba871fb0c00a79084c381faa647f
push id37454
push userccoroiu@mozilla.com
push dateWed, 27 May 2020 16:14:31 +0000
treeherdermozilla-central@a1dd9afbfdf5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1638711
milestone78.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 1638711 - Fix test_CSP to detect CSP events from the parent process. r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D75723
dom/security/test/csp/test_CSP.html
--- a/dom/security/test/csp/test_CSP.html
+++ b/dom/security/test/csp/test_CSP.html
@@ -32,20 +32,23 @@ window.tests = {
   media_good: -1,
   media_bad: -1,
   font_good: -1,
   font_bad: -1,
   object_good: -1,
   object_bad: -1,
 };
 
+SpecialPowers.registerObservers("csp-on-violate-policy");
+
 // This is used to watch the blocked data bounce off CSP and allowed data
 // get sent out to the wire.
 function examiner() {
   SpecialPowers.addObserver(this, "csp-on-violate-policy");
+  SpecialPowers.addObserver(this, "specialpowers-csp-on-violate-policy");
   SpecialPowers.addObserver(this, "specialpowers-http-notify-request");
 }
 examiner.prototype  = {
   observe(subject, topic, data) {
     var testpat = new RegExp("testid=([a-z0-9_]+)");
 
     //_good things better be allowed!
     //_bad things better be stopped!
@@ -58,31 +61,33 @@ examiner.prototype  = {
       if (!testpat.test(uri)) return;
       var testid = testpat.exec(uri)[1];
 
       window.testResult(testid,
                         /_good/.test(testid),
                         uri + " allowed by csp");
     }
 
-    if (topic === "csp-on-violate-policy") {
+    if (topic === "csp-on-violate-policy" ||
+        topic === "specialpowers-csp-on-violate-policy") {
       // these were blocked... record that they were blocked
       var asciiSpec = SpecialPowers.getPrivilegedProps(SpecialPowers.do_QueryInterface(subject, "nsIURI"), "asciiSpec");
       if (!testpat.test(asciiSpec)) return;
       var testid = testpat.exec(asciiSpec)[1];
       window.testResult(testid,
                         /_bad/.test(testid),
                         asciiSpec + " blocked by \"" + data + "\"");
     }
   },
 
   // must eventually call this to remove the listener,
   // or mochitests might get borked.
   remove() {
     SpecialPowers.removeObserver(this, "csp-on-violate-policy");
+    SpecialPowers.removeObserver(this, "specialpowers-csp-on-violate-policy");
     SpecialPowers.removeObserver(this, "specialpowers-http-notify-request");
   }
 }
 
 window.examiner = new examiner();
 
 window.testResult = function(testname, result, msg) {
   // test already complete.... forget it... remember the first result.