tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generic-sensor-reporting.https.html (2184B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <script src='/resources/testharness.js'></script>
      5    <script src='/resources/testharnessreport.js'></script>
      6  </head>
      7  <body>
      8    <script>
      9 var sensor_features_verified = {
     10  "accelerometer": false,
     11  "ambient-light-sensor": false,
     12  "magnetometer": false,
     13  "gyroscope": false
     14 };
     15 
     16 var check_report_format = function(reports, observer) {
     17  // Check each report in this batch. This observer callback may be called
     18  // multiple times before all reports have been processed.
     19  for (const report of reports) {
     20 
     21    // Validate that the reported feature is one of the sensor features, and that
     22    // we have not seen a report for this feature before.
     23    assert_true(sensor_features_verified.hasOwnProperty(report.body.featureId));
     24    assert_false(sensor_features_verified[report.body.featureId]);
     25 
     26    // Validate the remainder of the report
     27    assert_equals(report.type, "permissions-policy-violation");
     28    assert_equals(report.url, document.location.href);
     29    assert_equals(report.body.sourceFile, document.location.href);
     30    assert_equals(typeof report.body.lineNumber, "number");
     31    assert_equals(typeof report.body.columnNumber, "number");
     32    assert_equals(report.body.disposition, "enforce");
     33 
     34    sensor_features_verified[report.body.featureId] = true;
     35  }
     36 
     37  // Test is only done when reports for all features have been seen
     38  for (let result of Object.values(sensor_features_verified)) {
     39    if (!result)
     40      return;
     41  }
     42  this.done();
     43 };
     44 
     45 async_test(t => {
     46  new ReportingObserver(t.step_func(check_report_format),
     47                        {types: ['permissions-policy-violation']}).observe();
     48  assert_throws_dom("SecurityError", () => new Accelerometer(), "Constructing sensors should be blocked by policy");
     49  assert_throws_dom("SecurityError", () => new AmbientLightSensor(), "Constructing sensors should be blocked by policy");
     50  assert_throws_dom("SecurityError", () => new Gyroscope(), "Constructing sensors should be blocked by policy");
     51  assert_throws_dom("SecurityError", () => new Magnetometer(), "Constructing sensors should be blocked by policy");
     52 }, "Generic Sensor Report Format");
     53    </script>
     54  </body>
     55 </html>