LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 result, | 73 result, |
74 `The property "${property}" ${result ? "should" : "shouldn't"} trigger an
exception.` | 74 `The property "${property}" ${result ? "should" : "shouldn't"} trigger an
exception.` |
75 ); | 75 ); |
76 assert.equal( | 76 assert.equal( |
77 value, | 77 value, |
78 result ? 1 : undefined, | 78 result ? 1 : undefined, |
79 `The value for "${property}" ${result ? "shouldn't" : "should"} have been
read.` | 79 `The value for "${property}" ${result ? "shouldn't" : "should"} have been
read.` |
80 ); | 80 ); |
81 } | 81 } |
82 | 82 |
83 it("Test abort property read", async() => | 83 it("abort-property-read", async() => |
84 { | 84 { |
85 window.abpTest = "fortytwo"; | 85 window.abpTest = "fortytwo"; |
86 await runSnippet("abort-on-property-read", "abpTest"); | 86 await runSnippet("abort-on-property-read", "abpTest"); |
87 testProperty("abpTest"); | 87 testProperty("abpTest"); |
88 | 88 |
89 window.abpTest2 = {prop1: "fortytwo"}; | 89 window.abpTest2 = {prop1: "fortytwo"}; |
90 await runSnippet("abort-on-property-read", "abpTest2.prop1"); | 90 await runSnippet("abort-on-property-read", "abpTest2.prop1"); |
91 testProperty("abpTest2.prop1"); | 91 testProperty("abpTest2.prop1"); |
92 | 92 |
93 // Test that we try to catch a property that doesn't exist yet. | 93 // Test that we try to catch a property that doesn't exist yet. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 await runSnippet("abort-on-property-read", "abpTest11.prototype.prop1"); | 157 await runSnippet("abort-on-property-read", "abpTest11.prototype.prop1"); |
158 testProperty("abpTest11.prototype.prop1"); | 158 testProperty("abpTest11.prototype.prop1"); |
159 | 159 |
160 // Class function properties with prototype function properties, with | 160 // Class function properties with prototype function properties, with |
161 // prototype property set afterwards. | 161 // prototype property set afterwards. |
162 window.abpTest12 = class {}; | 162 window.abpTest12 = class {}; |
163 await runSnippet("abort-on-property-read", "abpTest12.prototype.prop1"); | 163 await runSnippet("abort-on-property-read", "abpTest12.prototype.prop1"); |
164 window.abpTest12.prototype.prop1 = function() {}; | 164 window.abpTest12.prototype.prop1 = function() {}; |
165 testProperty("abpTest12.prototype.prop1"); | 165 testProperty("abpTest12.prototype.prop1"); |
166 }); | 166 }); |
| 167 |
| 168 it("abort-curent-inline-script", async() => |
| 169 { |
| 170 function injectInlineScript(doc, script) |
| 171 { |
| 172 let scriptElement = doc.createElement("script"); |
| 173 scriptElement.type = "application/javascript"; |
| 174 scriptElement.async = false; |
| 175 scriptElement.textContent = script; |
| 176 doc.body.appendChild(scriptElement); |
| 177 } |
| 178 |
| 179 await runSnippet( |
| 180 "abort-current-inline-script", "document.write", "atob" |
| 181 ); |
| 182 await runSnippet( |
| 183 "abort-current-inline-script", "document.write", "btoa" |
| 184 ); |
| 185 |
| 186 document.body.innerHTML = "<p id=\"result1\"></p><p id=\"message1\"></p><p i
d=\"result2\"></p><p id=\"message2\"></p>"; |
| 187 |
| 188 let script = ` |
| 189 try |
| 190 { |
| 191 let element = document.getElementById("result1"); |
| 192 document.write("<p>atob: " + atob("dGhpcyBpcyBhIGJ1Zw==") + "</p>"); |
| 193 element.textContent = atob("dGhpcyBpcyBhIGJ1Zw=="); |
| 194 } |
| 195 catch (e) |
| 196 { |
| 197 let msg = document.getElementById("message1"); |
| 198 msg.textContent = e.name; |
| 199 }`; |
| 200 |
| 201 injectInlineScript(document, script); |
| 202 |
| 203 let element = document.getElementById("result1"); |
| 204 assert.ok(element, "Element 'result1' was not found"); |
| 205 |
| 206 let msg = document.getElementById("message1"); |
| 207 assert.ok(msg, "Element 'message1' was not found"); |
| 208 |
| 209 if (element && msg) |
| 210 { |
| 211 assert.equals(element.textContent, "", "Result element should be empty"); |
| 212 assert.equals(msg.textContent, "ReferenceError", |
| 213 "There should have been an error"); |
| 214 } |
| 215 |
| 216 script = ` |
| 217 try |
| 218 { |
| 219 let element = document.getElementById("result2"); |
| 220 document.write("<p>btoa: " + btoa("this is a bug") + "</p>"); |
| 221 element.textContent = btoa("this is a bug"); |
| 222 } |
| 223 catch (e) |
| 224 { |
| 225 let msg = document.getElementById("message2"); |
| 226 msg.textContent = e.name; |
| 227 }`; |
| 228 |
| 229 injectInlineScript(document, script); |
| 230 |
| 231 element = document.getElementById("result2"); |
| 232 assert.ok(element, "Element 'result2' was not found"); |
| 233 |
| 234 msg = document.getElementById("message2"); |
| 235 assert.ok(msg, "Element 'message2' was not found"); |
| 236 |
| 237 if (element && msg) |
| 238 { |
| 239 assert.equals(element.textContent, "", "Result element should be empty"); |
| 240 assert.equals(msg.textContent, "ReferenceError", |
| 241 "There should have been an error"); |
| 242 } |
| 243 }); |
167 }); | 244 }); |
LEFT | RIGHT |