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