| OLD | NEW |
| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 ).then(sections => sections.filter( | 88 ).then(sections => sections.filter( |
| 89 ([title, demo, filters]) => title && demo && filters.length > 0 | 89 ([title, demo, filters]) => title && demo && filters.length > 0 |
| 90 )); | 90 )); |
| 91 } | 91 } |
| 92 | 92 |
| 93 it("test pages", function() | 93 it("test pages", function() |
| 94 { | 94 { |
| 95 return this.driver.navigate().to(TEST_PAGES_URL).then(() => | 95 return this.driver.navigate().to(TEST_PAGES_URL).then(() => |
| 96 this.driver.findElements(By.css(".site-pagelist a")) | 96 this.driver.findElements(By.css(".site-pagelist a")) |
| 97 ).then(elements => | 97 ).then(elements => |
| 98 Promise.all(elements.map(elem => elem.getAttribute("href"))) | 98 Promise.all(elements.map(elem => Promise.all([elem.getAttribute("href"), |
| 99 elem.getText()]))) |
| 99 ).then(urls => | 100 ).then(urls => |
| 100 { | 101 { |
| 101 let p1 = Promise.resolve(); | 102 let p1 = Promise.resolve(); |
| 102 for (let url of urls) | 103 for (let [url, pageTitle] of urls) |
| 104 { |
| 105 let browser = this.test.parent.title.replace(/\s.*$/, ""); |
| 106 if (// https://issues.adblockplus.org/ticket/6917 |
| 107 pageTitle == "$subdocument" && browser == "Firefox" || |
| 108 // Chromium doesn't support Flash |
| 109 pageTitle.startsWith("$object") && browser == "Chromium" || |
| 110 // Chromium 63 doesn't have user stylesheets (required to |
| 111 // overrule inline styles) and doesn't run content scripts |
| 112 // in dynamically written documents. |
| 113 this.test.parent.title == "Chromium (oldest)" && |
| 114 (pageTitle == "Inline style !important" || |
| 115 pageTitle == "Anonymous iframe document.write()")) |
| 116 continue; |
| 117 |
| 103 p1 = p1.then(() => | 118 p1 = p1.then(() => |
| 104 this.driver.navigate().to(url) | 119 this.driver.navigate().to(url) |
| 105 ).then(() => | 120 ).then(() => |
| 106 Promise.all([ | 121 Promise.all([ |
| 107 getSections(this.driver), | 122 getSections(this.driver), |
| 108 this.driver.findElement(By.css("h2")).getAttribute("textContent"), | |
| 109 this.driver.executeScript("document.body.classList.add('expected');") | 123 this.driver.executeScript("document.body.classList.add('expected');") |
| 110 ]) | 124 ]) |
| 111 ).then(([sections, pageTitle]) => | 125 ).then(([sections]) => |
| 112 Promise.all(sections.map(([title, demo, filters]) => | 126 Promise.all(sections.map(([title, demo, filters]) => |
| 113 Promise.all([ | 127 Promise.all([ |
| 114 title.getAttribute("textContent").then(testTitle => | 128 title.getAttribute("textContent").then(testTitle => |
| 115 `${pageTitle.trim()} - ${testTitle.trim()}` | 129 `${pageTitle.trim()} - ${testTitle.trim()}` |
| 116 ), | 130 ), |
| 117 takeScreenshot(demo), | 131 takeScreenshot(demo), |
| 118 Promise.all(filters.map(elem => elem.getAttribute("textContent"))) | 132 Promise.all(filters.map(elem => elem.getAttribute("textContent"))) |
| 119 ]) | 133 ]) |
| 120 )) | 134 )) |
| 121 ).then(testCases => | 135 ).then(testCases => |
| 122 { | 136 { |
| 123 let p2 = Promise.resolve(); | 137 let p2 = Promise.resolve(); |
| 124 for (let i = 0; i < testCases.length; i++) | 138 for (let i = 0; i < testCases.length; i++) |
| 125 { | 139 { |
| 126 let [title, expectedScreenshot, filters] = testCases[i]; | 140 let [title, expectedScreenshot, filters] = testCases[i]; |
| 127 let browser = this.test.parent.title.replace(/\s.*$/, ""); | |
| 128 | |
| 129 if (// https://issues.adblockplus.org/ticket/6917 | |
| 130 title == "$subdocument - Test case" && browser == "Firefox" || | |
| 131 // Chromium doesn't support Flash | |
| 132 /^\$object(-subrequest)? /.test(title) && browser == "Chromium") | |
| 133 continue; | |
| 134 | 141 |
| 135 p2 = p2.then(() => | 142 p2 = p2.then(() => |
| 136 this.driver.navigate().to(this.origin + "/options.html") | 143 this.driver.navigate().to(this.origin + "/options.html") |
| 137 ).then(() => | 144 ).then(() => |
| 138 this.driver.executeAsyncScript(` | 145 this.driver.executeAsyncScript(` |
| 139 let filters = arguments[0]; | 146 let filters = arguments[0]; |
| 140 let callback = arguments[arguments.length - 1]; | 147 let callback = arguments[arguments.length - 1]; |
| 141 browser.runtime.sendMessage({type: "subscriptions.get", | 148 browser.runtime.sendMessage({type: "subscriptions.get", |
| 142 downloadable: true, | 149 downloadable: true, |
| 143 special: true}).then(subs => | 150 special: true}).then(subs => |
| 144 { | 151 { |
| 145 for (let subscription of subs) | 152 for (let subscription of subs) |
| 146 browser.runtime.sendMessage({type: "subscriptions.remove", | 153 browser.runtime.sendMessage({type: "subscriptions.remove", |
| 147 url: subscription.url}); | 154 url: subscription.url}); |
| 148 return browser.runtime.sendMessage({type: "filters.importRaw", | 155 return browser.runtime.sendMessage({type: "filters.importRaw", |
| 149 text: filters}); | 156 text: filters}); |
| 150 }).then(() => callback(), callback); | 157 }).then(() => callback(), callback); |
| 151 `, filters.join("\n")) | 158 `, filters.join("\n")) |
| 152 ).then(error => | 159 ).then(error => |
| 153 { | 160 { |
| 154 if (error) | 161 if (error) |
| 155 throw error; | 162 throw error; |
| 156 return this.driver.navigate().to(url); | 163 return this.driver.navigate().to(url); |
| 157 }).then(() => | 164 }).then(() => |
| 158 { | 165 { |
| 159 if (title.startsWith("$popup ")) | 166 if (pageTitle.startsWith("$popup")) |
| 160 { | 167 { |
| 161 return getSections(this.driver).then(sections => | 168 return getSections(this.driver).then(sections => |
| 162 sections[i][1].findElement(By.css("a[href],button")).click() | 169 sections[i][1].findElement(By.css("a[href],button")).click() |
| 163 ).then(() => | 170 ).then(() => |
| 164 this.driver.sleep(100) | 171 this.driver.sleep(100) |
| 165 ).then(() => | 172 ).then(() => |
| 166 this.driver.getAllWindowHandles() | 173 this.driver.getAllWindowHandles() |
| 167 ).then(handles => | 174 ).then(handles => |
| 168 { | 175 { |
| 169 if (title.startsWith("$popup Exception -")) | 176 if (pageTitle == "$popup - Exception") |
| 170 { | 177 { |
| 171 assert.equal(handles.length, 3, title); | 178 assert.equal(handles.length, 3, title); |
| 172 return closeWindow(this.driver, handles[2], handles[1]); | 179 return closeWindow(this.driver, handles[2], handles[1]); |
| 173 } | 180 } |
| 174 | 181 |
| 175 assert.equal(handles.length, 2, title); | 182 assert.equal(handles.length, 2, title); |
| 176 }); | 183 }); |
| 177 } | 184 } |
| 178 | 185 |
| 179 let checkTestCase = () => | 186 let checkTestCase = () => |
| (...skipping 10 matching lines...) Expand all Loading... |
| 190 // Sometimes on Firefox there is a delay until the added | 197 // Sometimes on Firefox there is a delay until the added |
| 191 // filters become effective. So if the test case fails once, | 198 // filters become effective. So if the test case fails once, |
| 192 // we reload the page and try once again. | 199 // we reload the page and try once again. |
| 193 return checkTestCase().catch(() => | 200 return checkTestCase().catch(() => |
| 194 this.driver.navigate().refresh().then(checkTestCase) | 201 this.driver.navigate().refresh().then(checkTestCase) |
| 195 ); | 202 ); |
| 196 }); | 203 }); |
| 197 } | 204 } |
| 198 return p2; | 205 return p2; |
| 199 }); | 206 }); |
| 207 } |
| 200 return p1; | 208 return p1; |
| 201 }); | 209 }); |
| 202 }); | 210 }); |
| 203 | 211 |
| 204 it("subscribe link", function() | 212 it("subscribe link", function() |
| 205 { | 213 { |
| 206 return this.driver.navigate().to(TEST_PAGES_URL).then(() => | 214 return this.driver.navigate().to(TEST_PAGES_URL).then(() => |
| 207 this.driver.findElement(By.id("subscribe-button")).click() | 215 this.driver.findElement(By.id("subscribe-button")).click() |
| 208 ).then(() => | 216 ).then(() => |
| 209 this.driver.wait(() => | 217 this.driver.wait(() => |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 `) | 252 `) |
| 245 ).then(([added, err]) => | 253 ).then(([added, err]) => |
| 246 { | 254 { |
| 247 if (err) | 255 if (err) |
| 248 throw err; | 256 throw err; |
| 249 assert.ok(added, "subscription added"); | 257 assert.ok(added, "subscription added"); |
| 250 }) | 258 }) |
| 251 ) | 259 ) |
| 252 ); | 260 ); |
| 253 }); | 261 }); |
| OLD | NEW |