dom/reporting/tests/test_deprecated.html
author Andreea Pavel <apavel@mozilla.com>
Wed, 13 Feb 2019 04:27:22 +0200
changeset 458838 e32e036906b9573147bc59a533b4af0f4e3e6988
parent 458825 d381785b0c4c0acf1c733fb8ea77fdafb1d15f37
child 458849 82a6589f4b919e399f1af4ae4831b8cb3436e0c8
permissions -rw-r--r--
Backed out 3 changesets (bug 1518661) for failing test_promise_rejections_from_jsimplemented.html Backed out changeset d381785b0c4c (bug 1518661) Backed out changeset 4a8b38e5373b (bug 1518661) Backed out changeset 64ebb085a6b3 (bug 1518661)

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Deprecated reports</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>

<script type="application/javascript">

let testingInterface;

(new Promise(resolve => {
  info("Testing DeprecatedTestingInterface report");
  let obs = new ReportingObserver((reports, o) => {
    is(obs, o, "Same observer!");
    ok(reports.length == 1, "We have 1 report");

    let report = reports[0];
    is(report.type, "deprecation", "Deprecation report received");
    is(report.url, location.href, "URL is window.location");
    ok(!!report.body, "The report has a body");
    ok(report.body instanceof DeprecationReportBody, "Correct type for the body");
    is(report.body.id, "DeprecatedTestingInterface", "report.body.id matches DeprecatedTestingMethod");
    ok(!report.body.anticipatedRemoval, "We don't have a anticipatedRemoval");
    ok(report.body.message.includes("TestingDeprecatedInterface"), "We have a message");
    is(report.body.sourceFile, location.href, "We have a sourceFile");
    is(report.body.lineNumber, 40, "We have a lineNumber");
    is(report.body.columnNumber, 21, "We have a columnNumber");

    obs.disconnect();
    resolve();
  });
  ok(!!obs, "ReportingObserver is a thing");

  obs.observe();
  ok(true, "ReportingObserver.observe() is callable");

  testingInterface = new TestingDeprecatedInterface();
  ok(true, "Created a deprecated interface");
}))

.then(() => {
  info("Testing DeprecatedTestingMethod report");
  return new Promise(resolve => {
    let obs = new ReportingObserver((reports, o) => {
      is(obs, o, "Same observer!");
      ok(reports.length == 1, "We have 1 report");

      let report = reports[0];
      is(report.type, "deprecation", "Deprecation report received");
      is(report.url, location.href, "URL is window.location");
      ok(!!report.body, "The report has a body");
      ok(report.body instanceof DeprecationReportBody, "Correct type for the body");
      is(report.body.id, "DeprecatedTestingMethod", "report.body.id matches DeprecatedTestingMethod");
      ok(!report.body.anticipatedRemoval, "We don't have a anticipatedRemoval");
      ok(report.body.message.includes("TestingDeprecatedInterface.deprecatedMethod"), "We have a message");
      is(report.body.sourceFile, location.href, "We have a sourceFile");
      is(report.body.lineNumber, 71, "We have a lineNumber");
      is(report.body.columnNumber, 4, "We have a columnNumber");

      obs.disconnect();
      resolve();
    });
    ok(!!obs, "ReportingObserver is a thing");

    obs.observe();
    ok(true, "ReportingObserver.observe() is callable");

    testingInterface.deprecatedMethod();
    ok(true, "Run a deprecated method.");
  });
})

.then(() => {
  info("Testing DeprecatedTestingAttribute report");
  return new Promise(resolve => {
    let obs = new ReportingObserver((reports, o) => {
      is(obs, o, "Same observer!");
      ok(reports.length == 1, "We have 1 report");

      let report = reports[0];
      is(report.type, "deprecation", "Deprecation report received");
      is(report.url, location.href, "URL is window.location");
      ok(!!report.body, "The report has a body");
      ok(report.body instanceof DeprecationReportBody, "Correct type for the body");
      is(report.body.id, "DeprecatedTestingAttribute", "report.body.id matches DeprecatedTestingAttribute");
      ok(!report.body.anticipatedRemoval, "We don't have a anticipatedRemoval");
      ok(report.body.message.includes("TestingDeprecatedInterface.deprecatedAttribute"), "We have a message");
      is(report.body.sourceFile, location.href, "We have a sourceFile");
      is(report.body.lineNumber, 103, "We have a lineNumber");
      is(report.body.columnNumber, 4, "We have a columnNumber");

      obs.disconnect();
      resolve();
    });
    ok(!!obs, "ReportingObserver is a thing");

    obs.observe();
    ok(true, "ReportingObserver.observe() is callable");

    ok(testingInterface.deprecatedAttribute, "Attributed called");
  });
})

.then(() => {
  info("Testing ReportingObserver.takeRecords()");
  let p = new Promise(resolve => {
    let obs = new ReportingObserver((reports, o) => {
      is(obs, o, "Same observer!");
      resolve(obs);
    });
    ok(!!obs, "ReportingObserver is a thing");

    obs.observe();
    ok(true, "ReportingObserver.observe() is callable");

    testingInterface.deprecatedMethod();
    ok(true, "Run a deprecated method.");
  });

  return p.then(obs => {
    let reports = obs.takeRecords();
    is(reports.length, 0, "No reports after an callback");

    testingInterface.deprecatedAttribute + 1;

    reports = obs.takeRecords();
    ok(reports.length >= 1, "We have at least 1 report");

    reports = obs.takeRecords();
    is(reports.length, 0, "No more reports");
  });
})

.then(() => { SimpleTest.finish(); });

SimpleTest.waitForExplicitFinish();

</script>
</body>
</html>