1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
let testingInterface;
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// 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
.split("?")[0]
.replace("test_deprecated.html", "common_deprecated.js")
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 50, "We have a lineNumber");
is(report.body.columnNumber, 24, "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
.split("?")[0]
.replace("test_deprecated.html", "common_deprecated.js")
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 102, "We have a lineNumber");
is(report.body.columnNumber, 22, "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_deprecatedMethodWithDataURI() {
info("Testing deprecatedMethodWithDataURI report");
const uri = `data:text/html,<script>
window.onload = () => {
let obs = new ReportingObserver((reports, o) => {
obs.disconnect();
let report = reports[0];
const message = (report.url == "data:...") ? "passed" : "failed";
window.opener.postMessage(message, "http://mochi.test:8888");
close();
});
obs.observe();
let testingInterface = new TestingDeprecatedInterface();
testingInterface.deprecatedMethod();
};
</script>`;
return new Promise(resolve => {
window.open(uri);
window.addEventListener("message", e => {
is(e.data, "passed", "The data URI is truncated");
resolve();
});
});
}
// 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
.split("?")[0]
.replace("test_deprecated.html", "common_deprecated.js")
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 183, "We have a lineNumber");
is(report.body.columnNumber, 8, "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");
});
}
|