Bug 1630947 - Update Reporting API - part 2 - tests for Workers, r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D71318
This commit is contained in:
Andrea Marchesini 2020-04-17 19:57:09 +00:00
Родитель aaa72f6ebb
Коммит c1ceb8cfc9
4 изменённых файлов: 235 добавлений и 117 удалений

Просмотреть файл

@ -0,0 +1,182 @@
let testingInterface;
// eslint-disable-next-line no-unused-vars
function test_deprecatedInterface() {
info("Testing DeprecatedTestingInterface 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 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
.replace("test_deprecated.html", "common_deprecated.js")
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 47, "We have a lineNumber");
is(report.body.columnNumber, 23, "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");
});
}
// eslint-disable-next-line no-unused-vars
function test_deprecatedMethod() {
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 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
.replace("test_deprecated.html", "common_deprecated.js")
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 98, "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.deprecatedMethod();
ok(true, "Run a deprecated method.");
});
}
// eslint-disable-next-line no-unused-vars
function test_deprecatedAttribute() {
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 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
.replace("test_deprecated.html", "common_deprecated.js")
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 149, "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");
});
}
// eslint-disable-next-line no-unused-vars
function test_takeRecords() {
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");
});
}

Просмотреть файл

@ -5,6 +5,7 @@ prefs =
dom.reporting.testing.enabled=true
[test_deprecated.html]
support-files = common_deprecated.js worker_deprecated.js
[test_memoryPressure.html]
[test_delivering.html]
support-files = delivering.sjs iframe_delivering.html worker_delivering.js

Просмотреть файл

@ -3,134 +3,41 @@
<head>
<title>Test for Deprecated reports</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="common_deprecated.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");
}))
test_deprecatedInterface()
.then(() => test_deprecatedMethod())
.then(() => test_deprecatedAttribute())
.then(() => test_takeRecords())
.then(() => {
info("Testing DeprecatedTestingMethod report");
info("Workers!");
return new Promise(resolve => {
let obs = new ReportingObserver((reports, o) => {
is(obs, o, "Same observer!");
ok(reports.length == 1, "We have 1 report");
const w = new Worker("worker_deprecated.js");
w.onmessage = e => {
switch (e.data.type) {
case "info":
info(e.data.msg);
break;
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, 21, "We have a columnNumber");
case "check":
ok(e.data.check, e.data.msg);
break;
obs.disconnect();
resolve();
});
ok(!!obs, "ReportingObserver is a thing");
case "finish":
resolve();
break;
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");
default:
ok(false, "Invalid message");
break;
}
}
});
})

Просмотреть файл

@ -0,0 +1,28 @@
/* eslint-disable no-undef */
// eslint-disable-next-line no-unused-vars
function ok(a, msg) {
postMessage({ type: "check", check: !!a, msg });
}
// eslint-disable-next-line no-unused-vars
function is(a, b, msg) {
ok(a === b, msg);
}
// eslint-disable-next-line no-unused-vars
function info(msg) {
postMessage({ type: "info", msg });
}
function finish() {
postMessage({ type: "finish" });
}
importScripts("common_deprecated.js");
test_deprecatedInterface()
.then(() => test_deprecatedMethod())
.then(() => test_deprecatedAttribute())
.then(() => test_takeRecords())
.then(() => finish());