Bug 1535638, Ensure ReportingObservers are notified even if a previous observer calls disconnect, r=baku
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 15 Mar 2019 17:01:39 +0200
changeset 522385 d3f3cada7e5886374b0c6f36093b6ae622e3dc24
parent 522378 124ee436c4214fbb5c770c87054a7484c31772f5
child 522386 2a96d8f9339f49e84789bbe3899699c5d7185406
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1535638
milestone67.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 1535638, Ensure ReportingObservers are notified even if a previous observer calls disconnect, r=baku Reusing an existing wpt test. That particular test happens to be enabled in Firefox, unlike most Feature Policy/Reporting API tests. Differential Revision: https://phabricator.services.mozilla.com/D23675
dom/base/nsGlobalWindowInner.cpp
testing/web-platform/tests/feature-policy/reporting/fullscreen-reporting.html
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -7004,17 +7004,18 @@ void nsPIDOMWindowInner::BroadcastReport
   }
 
   while (mReportRecords.Length() > MAX_REPORT_RECORDS) {
     mReportRecords.RemoveElementAt(0);
   }
 }
 
 void nsPIDOMWindowInner::NotifyReportingObservers() {
-  for (ReportingObserver* observer : mReportingObservers) {
+  nsTArray<RefPtr<ReportingObserver>> reportingObservers(mReportingObservers);
+  for (ReportingObserver* observer : reportingObservers) {
     observer->MaybeNotify();
   }
 }
 
 nsPIDOMWindowInner::~nsPIDOMWindowInner() {}
 
 #undef FORWARD_TO_OUTER
 #undef FORWARD_TO_OUTER_OR_THROW
--- a/testing/web-platform/tests/feature-policy/reporting/fullscreen-reporting.html
+++ b/testing/web-platform/tests/feature-policy/reporting/fullscreen-reporting.html
@@ -2,28 +2,44 @@
 <html>
   <head>
     <script src='/resources/testharness.js'></script>
     <script src='/resources/testharnessreport.js'></script>
   </head>
   <body>
     <div id='fs'></div>
     <script>
+var observer1;
+var observer2;
+
 var check_report_format = (reports, observer) => {
+  // Test that observer2 is notified, even if it is disconnected.
+  observer1.disconnect();
+  observer2.disconnect();
   let report = reports[0];
   assert_equals(report.type, "feature-policy-violation");
   assert_equals(report.url, document.location.href);
   assert_equals(report.body.featureId, "fullscreen");
   assert_equals(report.body.sourceFile, document.location.href);
   assert_equals(typeof report.body.lineNumber, "number");
   assert_equals(typeof report.body.columnNumber, "number");
   assert_equals(report.body.disposition, "enforce");
 };
 
+var check_second_observer = (reports, observer) => {
+  let report = reports[0];
+  assert_equals(report.type, "feature-policy-violation");
+  assert_equals(report.body.featureId, "fullscreen");
+};
+
 async_test(t => {
-  new ReportingObserver(t.step_func_done(check_report_format),
-                        {types: ['feature-policy-violation']}).observe();
+  observer1 = new ReportingObserver(t.step_func(check_report_format),
+                                    {types: ['feature-policy-violation']});
+  observer1.observe();
+  observer2 = new ReportingObserver(t.step_func_done(check_second_observer),
+                                    {types: ['feature-policy-violation']});
+  observer2.observe();
   document.getElementById('fs').requestFullscreen().then(t.unreached_func(
     "Fullscreen should not be allowed in this document.")).catch(()=>{});
 }, "Fullscreen Report Format");
     </script>
   </body>
 </html>