Commit bce6091b authored by sanketh's avatar sanketh Committed by Matthew Finkel
Browse files

(ESR68) Bug 1511941 - Don't expose PerformanceNavigationTiming in RFP mode

In RFP mode, we do not support PerformanceNavigationTiming, so don't expose it.
In particular, window.PerformanceNavigationTiming should return undefined.

Added a new method PerformanceNavigationTiming::Enabled which when used with the
WebIDL Func attribute allows us to toggle whether
window.PerformanceNavigationTiming is exposed.

Created
dom/tests/mochitest/general/test_toggling_performance_navigation_timing.html to
test whether the toggling works. Updated
browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js
to create a new window each time privacy.resistFingerprinting is flipped so this
behavior does not leak into other tests.
parent 08e44ea2
Loading
Loading
Loading
Loading
+21 −41
Original line number Diff line number Diff line
@@ -78,7 +78,6 @@ let isRounded = (x, expectedPrecision) => {
};

let setupTest = async function(
  tab,
  resistFingerprinting,
  reduceTimerPrecision,
  expectedPrecision,
@@ -95,6 +94,13 @@ let setupTest = async function(
      ],
    ],
  });

  let win = await BrowserTestUtils.openNewBrowserWindow();
  let tab = await BrowserTestUtils.openNewForegroundTab(
    win.gBrowser,
    TEST_PATH + "file_dummy.html"
  );

  // No matter what we set the precision to, if we're in ResistFingerprinting mode
  // we use the larger of the precision pref and the constant 100ms
  if (resistFingerprinting) {
@@ -110,15 +116,11 @@ let setupTest = async function(
    },
    runTests
  );
  await BrowserTestUtils.closeWindow(win);
};
// ================================================================================================
// ================================================================================================
add_task(async function runRPTests() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TEST_PATH + "file_dummy.html"
  );

  let runTests = async function(data) {
    let timerlist = data.list;
    let expectedPrecision = data.precision;
@@ -165,21 +167,14 @@ add_task(async function runRPTests() {
    );
  };

  await setupTest(tab, true, true, 100, runTests);
  await setupTest(tab, true, false, 13, runTests);
  await setupTest(tab, true, false, 0.13, runTests);

  BrowserTestUtils.removeTab(tab);
  await setupTest(true, true, 100, runTests);
  await setupTest(true, false, 13, runTests);
  await setupTest(true, false, 0.13, runTests);
});

// ================================================================================================
// ================================================================================================
add_task(async function runRTPTests() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TEST_PATH + "file_dummy.html"
  );

  let runTests = async function(data) {
    let timerlist = data.list;
    let expectedPrecision = data.precision;
@@ -215,6 +210,7 @@ add_task(async function runRTPTests() {
      content.performance.getEntries().length,
      4,
      "For reduceTimerPrecision, there should be 4 entries for performance.getEntries()"
      // PerformanceNavigationTiming, PerformanceMark, PerformanceMark, PerformanceMeasure
    );
    for (var i = 0; i < 4; i++) {
      let startTime = content.performance.getEntries()[i].startTime;
@@ -253,11 +249,9 @@ add_task(async function runRTPTests() {
    content.performance.clearResourceTimings();
  };

  await setupTest(tab, false, true, 100, runTests);
  await setupTest(tab, false, true, 13, runTests);
  await setupTest(tab, false, true, 0.13, runTests);

  BrowserTestUtils.removeTab(tab);
  await setupTest(false, true, 100, runTests);
  await setupTest(false, true, 13, runTests);
  await setupTest(false, true, 0.13, runTests);
});

// ================================================================================================
@@ -284,27 +278,13 @@ let runWorkerTest = async function(data) {
};

add_task(async function runRPTestsForWorker() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TEST_PATH + "file_dummy.html"
  );

  await setupTest(tab, true, true, 100, runWorkerTest, "runRPTests");
  await setupTest(tab, true, false, 13, runWorkerTest, "runRPTests");
  await setupTest(tab, true, true, 0.13, runWorkerTest, "runRPTests");

  BrowserTestUtils.removeTab(tab);
  await setupTest(true, true, 100, runWorkerTest, "runRPTests");
  await setupTest(true, false, 13, runWorkerTest, "runRPTests");
  await setupTest(true, true, 0.13, runWorkerTest, "runRPTests");
});

add_task(async function runRTPTestsForWorker() {
  let tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    TEST_PATH + "file_dummy.html"
  );

  await setupTest(tab, false, true, 100, runWorkerTest, "runRTPTests");
  await setupTest(tab, false, true, 13, runWorkerTest, "runRTPTests");
  await setupTest(tab, false, true, 0.13, runWorkerTest, "runRTPTests");

  BrowserTestUtils.removeTab(tab);
  await setupTest(false, true, 100, runWorkerTest, "runRTPTests");
  await setupTest(false, true, 13, runWorkerTest, "runRTPTests");
  await setupTest(false, true, 0.13, runWorkerTest, "runRTPTests");
});
+2 −1
Original line number Diff line number Diff line
@@ -305,7 +305,8 @@ DOMHighResTimeStamp PerformanceMainThread::CreationTime() const {
void PerformanceMainThread::CreateNavigationTimingEntry() {
  MOZ_ASSERT(!mDocEntry, "mDocEntry should be null.");

  if (!StaticPrefs::dom_enable_performance_navigation_timing()) {
  if (!StaticPrefs::dom_enable_performance_navigation_timing() ||
      StaticPrefs::privacy_resistFingerprinting()) {
    return;
  }

+6 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

#include "mozilla/dom/PerformanceNavigationTiming.h"
#include "mozilla/dom/PerformanceNavigationTimingBinding.h"
#include "mozilla/StaticPrefs.h"

using namespace mozilla::dom;

@@ -138,3 +139,8 @@ void PerformanceNavigationTiming::UpdatePropertiesFromHttpChannel(
    nsIHttpChannel* aHttpChannel, nsITimedChannel* aChannel) {
  mTimingData->SetPropertiesFromHttpChannel(aHttpChannel, aChannel);
}

bool PerformanceNavigationTiming::Enabled(JSContext* aCx, JSObject* aGlobal) {
  return (StaticPrefs::dom_enable_performance_navigation_timing() &&
          !StaticPrefs::privacy_resistFingerprinting());
}
+6 −0
Original line number Diff line number Diff line
@@ -65,6 +65,12 @@ class PerformanceNavigationTiming final : public PerformanceResourceTiming {
  void UpdatePropertiesFromHttpChannel(nsIHttpChannel* aHttpChannel,
                                       nsITimedChannel* aChannel);

  /*
   * For use with the WebIDL Func attribute to determine whether
   * window.PerformanceNavigationTiming is exposed.
   */
  static bool Enabled(JSContext* aCx, JSObject* aGlobal);

 private:
  ~PerformanceNavigationTiming() {}
};
+1 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ skip-if = toolkit == 'android' # bug 1230232 - Mouse doesn't select in the same
[test_storagePermissionsReject.html]
[test_storagePermissionsRejectForeign.html]
[test_stylesheetPI.html]
[test_toggling_performance_navigation_timing.html]
[test_vibrator.html]
[test_WebKitCSSMatrix.html]
[test_windowedhistoryframes.html]
Loading