├── .github └── dependabot.yml ├── .gitignore ├── .isort.cfg ├── .taskcluster.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── coverage_crawler ├── __init__.py ├── crawler.py ├── diff.py ├── filterpaths.py ├── generatehtml.py └── latest_cov_build.py ├── download_artifacts.py ├── requirements.txt ├── run_crawler.py ├── setup.cfg ├── setup.py ├── style.css ├── test-requirements.txt ├── tests ├── __init__.py ├── crawler │ ├── __init__.py │ └── test_crawler_unittest.py ├── example_website │ ├── __init__.py │ ├── templates │ │ └── index.html │ └── website_app.py ├── test_coverage_crawler.py └── test_diff.py └── websites.txt /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: pip 4 | directory: "/" 5 | schedule: 6 | interval: monthly 7 | open-pull-requests-limit: 99 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | 103 | data/ 104 | tools/ 105 | ccov-artifacts/ 106 | .pytest_cache/ 107 | lcov/ 108 | lcov-bin/ 109 | mozilla-central/ 110 | report/ 111 | output.json 112 | tests_report.json 113 | output.info 114 | *.zip 115 | -------------------------------------------------------------------------------- /.isort.cfg: -------------------------------------------------------------------------------- 1 | [settings] 2 | force_single_line=True 3 | -------------------------------------------------------------------------------- /.taskcluster.yml: -------------------------------------------------------------------------------- 1 | version: 1 2 | policy: 3 | pullRequests: public 4 | tasks: 5 | $let: 6 | user: ${event.sender.login} 7 | 8 | head_branch: 9 | $if: 'tasks_for == "github-pull-request"' 10 | then: ${event.pull_request.head.ref} 11 | else: 12 | $if: 'tasks_for == "github-push"' 13 | then: ${event.ref} 14 | else: ${event.release.target_commitish} 15 | 16 | head_rev: 17 | $if: 'tasks_for == "github-pull-request"' 18 | then: ${event.pull_request.head.sha} 19 | else: 20 | $if: 'tasks_for == "github-push"' 21 | then: ${event.after} 22 | else: ${event.release.tag_name} 23 | 24 | repository: 25 | $if: 'tasks_for == "github-pull-request"' 26 | then: ${event.pull_request.head.repo.html_url} 27 | else: ${event.repository.html_url} 28 | in: 29 | - taskId: {$eval: as_slugid("tests_task")} 30 | created: {$fromNow: ''} 31 | deadline: {$fromNow: '1 hour'} 32 | provisionerId: proj-relman 33 | workerType: ci 34 | payload: 35 | maxRunTime: 3600 36 | image: python:3.7 37 | command: 38 | - "/bin/bash" 39 | - "-lcx" 40 | - "git clone --quiet ${repository} && 41 | cd coverage-crawler && 42 | git -c advice.detachedHead=false checkout ${head_rev} && 43 | pip install --quiet -r requirements.txt && 44 | pip install --quiet -r test-requirements.txt && 45 | flake8 . && 46 | python -m pytest tests/test_*.py && 47 | python setup.py sdist bdist_wheel && 48 | pip install dist/coverage_crawler-1.0.0.tar.gz" 49 | metadata: 50 | name: coverage-crawler tests 51 | description: coverage-crawler tests 52 | owner: mcastelluccio@mozilla.com 53 | source: ${repository}/raw/${head_rev}/.taskcluster.yml 54 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Participation Guidelines 2 | 3 | This repository is governed by Mozilla's code of conduct and etiquette guidelines. 4 | For more details, please read the 5 | [Mozilla Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/). 6 | 7 | ## How to Report 8 | For more information on how to report violations of the Community Participation Guidelines, please read our '[How to Report](https://www.mozilla.org/about/governance/policies/participation/reporting/)' page. 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include requirements.txt 2 | include style.css 3 | include websites.txt 4 | 5 | recursive-exclude * __pycache__ 6 | recursive-exclude * *.py[co] 7 | recursive-exclude tests * 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # coverage-crawler 2 | [![Task Status](https://community-tc.services.mozilla.com/api/github/v1/repository/mozilla/coverage-crawler/master/badge.svg)](https://community-tc.services.mozilla.com/api/github/v1/repository/mozilla/coverage-crawler/master/latest) 3 | 4 | A crawler to find websites that exercise code in Firefox that is not covered by unit tests 5 | 6 | ## Software requirements 7 | - Python 3.6+ 8 | - [Mercurial](https://www.mercurial-scm.org/) 9 | 10 | ## Usage as a script 11 | 12 | - Install requirements with `pip install -r requirements.txt`; 13 | - Install development requirements with `pip install -r test-requirements.txt`; 14 | - Run the `download_artifacts.py` script with the desired revision passed as argument to download the latest Firefox coverage build; 15 | - Run the `run_crawler.py` script. 16 | 17 | ## Usage as a module 18 | 19 | - Add this project's repository to your requirements file as a Git dependency; 20 | - Import `coverage_crawler`; 21 | - Use function `download_artifacts` from `latest_cov_build.py` with the desired revision passed as argument to download the latest Firefox coverage build and other artifacts; 22 | - Run function `run` from `crawler.py` with the desired website passed as an argument. 23 | -------------------------------------------------------------------------------- /coverage_crawler/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /coverage_crawler/crawler.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import json 4 | import os 5 | import random 6 | import subprocess 7 | import sys 8 | import tempfile 9 | import time 10 | import traceback 11 | import uuid 12 | 13 | from selenium import webdriver 14 | from selenium.common.exceptions import ElementNotInteractableException 15 | from selenium.common.exceptions import InvalidSelectorException 16 | from selenium.common.exceptions import NoAlertPresentException 17 | from selenium.common.exceptions import NoSuchWindowException 18 | from selenium.common.exceptions import StaleElementReferenceException 19 | from selenium.common.exceptions import TimeoutException 20 | from selenium.common.exceptions import WebDriverException 21 | from selenium.webdriver.common.by import By 22 | from selenium.webdriver.common.keys import Keys 23 | 24 | from coverage_crawler import diff 25 | from coverage_crawler import filterpaths 26 | from coverage_crawler import generatehtml 27 | 28 | already_clicked_elems = set() 29 | 30 | 31 | def set_timeouts(driver): 32 | driver.set_script_timeout(30) 33 | driver.set_page_load_timeout(30) 34 | driver.implicitly_wait(30) 35 | 36 | 37 | def wait_loaded(driver): 38 | try: 39 | driver.execute_async_script(""" 40 | let done = arguments[0]; 41 | 42 | window.onload = done; 43 | if (document.readyState === "complete") { 44 | done(); 45 | } 46 | """) 47 | except: # noqa: E722 48 | traceback.print_exc(file=sys.stderr) 49 | print('Continuing...') 50 | 51 | # We hope the page is fully loaded in 7 seconds. 52 | time.sleep(7) 53 | 54 | try: 55 | driver.execute_async_script(""" 56 | window.requestIdleCallback(arguments[0], { 57 | timeout: 60000 58 | }); 59 | """) 60 | except: # noqa: E722 61 | traceback.print_exc(file=sys.stderr) 62 | print('Continuing...') 63 | 64 | 65 | def close_all_windows_except_first(driver): 66 | windows = driver.window_handles 67 | 68 | for window in windows[1:]: 69 | driver.switch_to.window(window) 70 | driver.close() 71 | 72 | while True: 73 | try: 74 | alert = driver.switch_to.alert() 75 | alert.dismiss() 76 | except (NoAlertPresentException, NoSuchWindowException): 77 | break 78 | 79 | driver.switch_to.window(windows[0]) 80 | 81 | 82 | def find_children(driver): 83 | body = driver.find_elements(By.TAG_NAME, 'body') 84 | assert len(body) == 1 85 | body = body[0] 86 | 87 | body.send_keys(Keys.CONTROL, 0) 88 | 89 | buttons = body.find_elements(By.TAG_NAME, 'button') 90 | links = body.find_elements(By.TAG_NAME, 'a') 91 | inputs = body.find_elements(By.TAG_NAME, 'input') 92 | selects = body.find_elements(By.TAG_NAME, 'select') 93 | children = buttons + links + inputs + selects 94 | 95 | random.shuffle(children) 96 | 97 | return children 98 | 99 | 100 | def do_something(driver): 101 | not_clickable_elems = set() 102 | 103 | children = find_children(driver) 104 | 105 | while True: 106 | elem = None 107 | 108 | try: 109 | # If we have clickable elements on which we haven't clicked yet, use them; otherwise, use all elements 110 | if set(children) - already_clicked_elems > not_clickable_elems: 111 | children = list(set(children) - already_clicked_elems) 112 | 113 | for child in children: 114 | # If the element is not displayed or is disabled, the user can't interact with it. Skip 115 | # non-displayed/disabled elements, since we're trying to mimic a real user. 116 | if not child.is_displayed() or not child.is_enabled() or child in not_clickable_elems: 117 | continue 118 | 119 | elem = child 120 | break 121 | 122 | if elem is None: 123 | return None 124 | 125 | driver.execute_script('return arguments[0].scrollIntoView();', elem) 126 | time.sleep(1) 127 | 128 | if elem.tag_name in ['button', 'a']: 129 | elem.click() 130 | elif elem.tag_name == 'input': 131 | input_type = elem.get_attribute('type') 132 | if input_type == 'url': 133 | elem.send_keys('http://www.mozilla.org/') 134 | elif input_type == 'text': 135 | elem.send_keys('marco') 136 | elif input_type == 'email': 137 | elem.send_keys('prova@email.it') 138 | elif input_type == 'password': 139 | elem.send_keys('aMildlyComplexPasswordIn2017') 140 | elif input_type == 'checkbox': 141 | elem.click() 142 | elif input_type == 'number': 143 | elem.send_keys('3') 144 | elif input_type in ['submit', 'reset', 'button']: 145 | elem.click() 146 | elif input_type == 'color': 147 | driver.execute_script("arguments[0].value = '#ff0000'", elem) 148 | elif input_type == 'search': 149 | elem.clear() 150 | elem.send_keys('quick search') 151 | elif input_type == 'radio': 152 | elem.click() 153 | elif input_type == 'tel': 154 | elem.send_keys('1234567890') 155 | elif input_type == 'date': 156 | elem.send_keys('20000101') 157 | else: 158 | raise Exception('Unsupported input type: %s' % input_type) 159 | elif elem.tag_name == 'select': 160 | for option in elem.find_elements(By.TAG_NAME, 'option'): 161 | if option.text != '': 162 | option.click() 163 | break 164 | 165 | already_clicked_elems.add(elem) 166 | 167 | close_all_windows_except_first(driver) 168 | 169 | # Get all the attributes of the child. 170 | return get_all_attributes(driver, child) 171 | 172 | except StaleElementReferenceException: 173 | traceback.print_exc(file=sys.stderr) 174 | close_all_windows_except_first(driver) 175 | children = find_children(driver) 176 | 177 | except (ElementNotInteractableException, InvalidSelectorException, WebDriverException): 178 | # Ignore frequent exceptions. 179 | traceback.print_exc(file=sys.stderr) 180 | close_all_windows_except_first(driver) 181 | not_clickable_elems.add(elem) 182 | 183 | 184 | def get_all_attributes(driver, child): 185 | child_attributes = driver.execute_script(""" 186 | let elem_attribute = {}; 187 | 188 | for (let i = 0; i < arguments[0].attributes.length; i++) { 189 | elem_attribute[arguments[0].attributes[i].name] = arguments[0].attributes[i].value; 190 | } 191 | return elem_attribute; 192 | """, child) 193 | 194 | return child_attributes 195 | 196 | 197 | def run_in_driver(website, driver): 198 | print('Running {}'.format(website)) 199 | 200 | try: 201 | driver.get(website) 202 | except TimeoutException: 203 | # Ignore timeouts, as they are too frequent. 204 | traceback.print_exc(file=sys.stderr) 205 | print('Continuing...') 206 | 207 | saved_sequence = [] 208 | for i in range(0, 20): 209 | print('Iteration {}'.format(i)) 210 | try: 211 | elem_attributes = do_something(driver) 212 | if elem_attributes is None: 213 | print('Cannot find any element to interact with on {}'.format(website)) 214 | break 215 | saved_sequence.append(elem_attributes) 216 | 217 | print(' - Using {}'.format(elem_attributes)) 218 | except TimeoutException: 219 | # Ignore frequent Timeout exceptions. 220 | traceback.print_exc(file=sys.stderr) 221 | print('Continuing...') 222 | 223 | return saved_sequence 224 | 225 | 226 | def run(websites): 227 | # Environmental vars set to overwrite default location of .gcda files 228 | if sys.platform.startswith('linux') or sys.platform.startswith('darwin'): 229 | prefix = '/builds/worker/workspace/build/src/' 230 | strip_count = prefix.count('/') 231 | elif sys.platform.startswith('cygwin') or sys.platform.startswith('win32'): 232 | prefix = 'z:/build/build/src/' 233 | strip_count = prefix.count('/') + 1 234 | 235 | # Remove a prefix from the path where .gcda files are stored 236 | os.environ['GCOV_PREFIX_STRIP'] = str(strip_count) 237 | os.environ['PATH'] += os.pathsep + os.path.abspath('tools') 238 | os.environ['MOZ_HEADLESS'] = '1' 239 | already_clicked_elems.clear() 240 | # Create temporary directories with context manager 241 | with tempfile.TemporaryDirectory() as gcov_dir, tempfile.TemporaryDirectory() as jsvm_dir: 242 | os.environ['GCOV_PREFIX'] = gcov_dir 243 | os.environ['JS_CODE_COVERAGE_OUTPUT_DIR'] = jsvm_dir 244 | 245 | # Webdriver uses Firefox Binaries from downloaded cov build 246 | driver = webdriver.Firefox(firefox_binary='tools/firefox/firefox-bin') 247 | 248 | set_timeouts(driver) 249 | 250 | for website in websites: 251 | # All steps are stored in new folder 252 | data_folder = str(uuid.uuid4()) 253 | os.makedirs(data_folder, exist_ok=True) 254 | try: 255 | sequence = run_in_driver(website, driver) 256 | with open('{}/steps.txt'.format(data_folder), 'w') as f: 257 | f.write('Website name: ' + website + '\n') 258 | for element in sequence: 259 | f.write(json.dumps(element) + '\n') 260 | except: # noqa: E722 261 | traceback.print_exc(file=sys.stderr) 262 | close_all_windows_except_first(driver) 263 | 264 | # Add paths to Mozilla-central modules 265 | sys.path.insert(0, 'tools/mozbuild/codecoverage') 266 | sys.path.insert(0, 'tools') 267 | 268 | from lcov_rewriter import LcovFileRewriter 269 | jsvm_files = [os.path.join(jsvm_dir, e) for e in os.listdir(jsvm_dir)] 270 | rewriter = LcovFileRewriter(os.path.join('tools', 'chrome-map.json')) 271 | jsvm_output_dir = os.path.join(jsvm_dir, 'jsvm_output') 272 | os.makedirs(jsvm_output_dir, exist_ok=True) 273 | jsvm_output_file = os.path.join(jsvm_output_dir, 'jsvm_lcov_output.info') 274 | rewriter.rewrite_files(jsvm_files, jsvm_output_file, '') 275 | 276 | grcov_command = [ 277 | os.path.join('tools', 'grcov'), 278 | '-t', 'coveralls+', 279 | '-p', prefix, 280 | 'tools', gcov_dir, 281 | jsvm_output_dir, 282 | '--filter', 'covered', 283 | '--token', 'UNUSED', 284 | '--commit-sha', 'UNUSED' 285 | ] 286 | 287 | with open('output.json', 'w+') as outfile: 288 | subprocess.check_call(grcov_command, stdout=outfile) 289 | 290 | with open('tests_report.json') as baseline_rep, open('output.json') as rep: 291 | baseline_report = json.load(baseline_rep) 292 | report = json.load(rep) 293 | 294 | filterpaths.ignore_third_party_filter(report) 295 | 296 | # Create diff report 297 | diff_report = diff.compare_reports(baseline_report, report, True) 298 | 299 | with open('{}/diff.json'.format(data_folder), 'w') as outfile: 300 | json.dump(diff_report, outfile) 301 | 302 | generatehtml.generate_html(data_folder) 303 | 304 | driver.quit() 305 | 306 | return os.path.abspath(os.path.join(os.getcwd(), '{}/report'.format(data_folder))) 307 | -------------------------------------------------------------------------------- /coverage_crawler/diff.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | def diff_line(i, j, ignore_hits): 5 | if j is None: 6 | return None 7 | elif i is None: 8 | return j 9 | elif j > 0 and j > i: 10 | if ignore_hits and i == 0: 11 | return 1 12 | elif ignore_hits is False: 13 | return j - i 14 | else: 15 | return 0 16 | else: 17 | return 0 18 | 19 | 20 | def compare_source_files_objects(obj1, obj2, ignore_hits): 21 | diff_funcs = [] 22 | diff_cov = [] 23 | if obj1['name'] == obj2['name']: 24 | 25 | if obj1['coverage'] != obj2['coverage']: 26 | diff_cov = [diff_line(k, m, ignore_hits) for k, m in zip(obj1['coverage'], obj2['coverage'])] 27 | 28 | if obj1['functions'] != obj2['functions']: 29 | for func1 in obj1['functions']: 30 | for func2 in obj2['functions']: 31 | if func1['name'] == func2['name']: 32 | if func1['exec'] is False and func2['exec'] is True: 33 | diff_funcs.append(func2) 34 | 35 | if len(diff_funcs) == 0 and all(cov == 0 or cov is None for cov in diff_cov): 36 | return None 37 | else: 38 | obj1['coverage'] = diff_cov 39 | obj1['functions'] = diff_funcs 40 | return obj1 41 | 42 | 43 | def compare_reports(baseline_report, report, ignore_hits): 44 | baseline_coverage = baseline_report['source_files'] 45 | coverage = report['source_files'] 46 | source_files = [] 47 | diff_report = {} 48 | for i in baseline_coverage: 49 | for j in coverage: 50 | comp_result = compare_source_files_objects(i, j, ignore_hits) 51 | if comp_result is not None: 52 | source_files.append(comp_result) 53 | diff_report['source_files'] = source_files 54 | for name in ['git', 'repo_token', 'service_job_number', 'service_name', 'service_number']: 55 | diff_report[name] = baseline_report[name] 56 | 57 | return diff_report 58 | -------------------------------------------------------------------------------- /coverage_crawler/filterpaths.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | def ignore_third_party_filter(report): 5 | with open('mozilla-central/tools/rewriting/ThirdPartyPaths.txt') as f: 6 | third_party_paths = [path.strip('\n') for path in f] 7 | report['source_files'] = [sf for sf in report['source_files'] if not any(sf['name'].startswith(path) for path in third_party_paths)] 8 | -------------------------------------------------------------------------------- /coverage_crawler/generatehtml.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import json 4 | import os 5 | 6 | from firefox_code_coverage import codecoverage 7 | 8 | 9 | def generate_html(data_folder): 10 | with open('{}/diff.json'.format(data_folder), 'r') as report: 11 | parsed_json = json.load(report) 12 | 13 | file_obj = open('{}/output.info'.format(data_folder), 'w') 14 | 15 | source_files = parsed_json['source_files'] 16 | file_obj.write('TN\n') 17 | for source_file in source_files: 18 | file_obj.write('SF:{}\n'.format(source_file['name'])) 19 | executed = 0 20 | 21 | # Functions 22 | if len(source_file['functions']) != 0: 23 | for function in source_file['functions']: 24 | file_obj.write('FN:{},{}\n'.format(function['start'], function['name'])) 25 | for function in source_file['functions']: 26 | if function['exec'] is True: 27 | file_obj.write('FNDA:{},{}\n'.format(1, function['name'])) 28 | executed += 1 29 | else: 30 | file_obj.write('FNDA:{},{}\n'.format(0, function['name'])) 31 | file_obj.write('FNF:{}\n'.format(len(source_file['functions']))) 32 | file_obj.write('FNH:{}\n'.format(executed)) 33 | 34 | # Branches 35 | branch_hits = 0 36 | if len(source_file['branches']) != 0: 37 | for branch in source_file['branches']: 38 | if branch['taken'] is True: 39 | file_obj.write('BRDA:{},0,{},{}\n'.format(branch['line'], branch['number'], 1)) 40 | branch_hits += 1 41 | else: 42 | file_obj.write('BRDA:{},0,{},{}\n'.format(branch['line'], branch['number'], '-')) 43 | file_obj.write('BRF:{}\n'.format(len(source_file['branches']))) 44 | file_obj.write('BRH:{}\n'.format(branch_hits)) 45 | 46 | # Lines 47 | line_number = 0 48 | cov_line_count = 0 49 | if len(source_file['coverage']) != 0: 50 | for line_number, line in enumerate(source_file['coverage'], 1): 51 | if line is not None: 52 | file_obj.write('DA:{},{}\n'.format(line_number, line)) 53 | if line > 0: 54 | cov_line_count += 1 55 | file_obj.write('LF:{}\n'.format(len(source_file['coverage']))) 56 | file_obj.write('LH:{}\n'.format(cov_line_count)) 57 | file_obj.write('end_of_record\n') 58 | file_obj.close() 59 | 60 | codecoverage.generate_html_report('mozilla-central', os.path.join(os.getcwd(), '{}/output.info'.format(data_folder)), os.path.join(os.getcwd(), '{}/report'.format(data_folder)), style_file=os.path.join(os.getcwd(), 'style.css')) 61 | -------------------------------------------------------------------------------- /coverage_crawler/latest_cov_build.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import os 4 | import platform 5 | import subprocess 6 | import sys 7 | import tarfile 8 | import zipfile 9 | 10 | import requests 11 | import taskcluster 12 | from firefox_code_coverage import codecoverage 13 | 14 | try: 15 | from urllib.request import urlretrieve 16 | except ImportError: 17 | from urllib import urlretrieve 18 | 19 | 20 | def get_github_release_url(repo_slug): 21 | repos_url = 'https://api.github.com/repos/{}/releases/latest'.format(repo_slug) 22 | download_url = 'https://github.com/{}/releases/download/'.format(repo_slug) 23 | latest_version = requests.get(repos_url) 24 | data = latest_version.json() 25 | tag_name = data['tag_name'] 26 | return download_url, tag_name 27 | 28 | 29 | def get_taskcluster_options(): 30 | return dict( 31 | rootUrl=os.environ.get('TASKCLUSTER_ROOT_URL', 'https://taskcluster.net') 32 | ) 33 | 34 | 35 | def download_artifacts(revision=None): 36 | # Create 'tools/' directory if doesn't exist 37 | if not os.path.exists('tools'): 38 | os.makedirs('tools') 39 | 40 | options = get_taskcluster_options() 41 | index = taskcluster.Index(options) 42 | queue = taskcluster.Queue(options) 43 | 44 | if revision is None: 45 | taskId = index.findTask('gecko.v2.mozilla-central.' + 'latest.firefox.linux64-ccov-debug')['taskId'] 46 | r = requests.get('https://queue.taskcluster.net/v1/task/{}'.format(taskId)) 47 | task_data = r.json() 48 | revision = task_data['payload']['env']['GECKO_HEAD_REV'] 49 | else: 50 | r = requests.get('https://index.taskcluster.net/v1/task/gecko.v2.mozilla-central.revision.{}.firefox.linux64-debug'.format(revision)) 51 | task_data = r.json() 52 | taskId = task_data['taskId'] 53 | 54 | # Download artifacts 55 | for name in ['target.tar.bz2', 'target.code-coverage-gcno.zip', 'chrome-map.json', 'target.common.tests.tar.gz']: 56 | url = queue.buildUrl('getLatestArtifact', taskId, 'public/build/{}'.format(name)) 57 | print('Downloading {}...'.format(url)) 58 | urlretrieve(url, os.path.join('tools', name)) 59 | 60 | # Geckodriver base url fot the latest version 61 | download_url, tag_name = get_github_release_url('mozilla/geckodriver') 62 | geckodriver_url = download_url + tag_name + '/geckodriver-' + tag_name + '-' 63 | 64 | # Grcov latest version base url 65 | download_url, tag_name = get_github_release_url('marco-c/grcov') 66 | grcov_url = download_url + tag_name 67 | 68 | # OS information for correct geckodriver version 69 | bitness = platform.architecture()[0] 70 | 71 | # Complete urls according to platforms 72 | if sys.platform.startswith('linux'): 73 | grcov_url += '/grcov-linux-x86_64.tar.bz2' 74 | if bitness == '64bit': 75 | version = 'linux64.tar.gz' 76 | else: 77 | version = 'linux32.tar.gz' 78 | elif sys.platform.startswith('darwin'): 79 | grcov_url += '/grcov-osx-x86_64.tar.bz2' 80 | version = 'macos.tar.gz' 81 | elif sys.platform.startswith('cygwin') or sys.platform.startswith('win32'): 82 | grcov_url += '/grcov-win-x86_64.tar.bz2' 83 | if bitness == '64bit': 84 | version = 'win64.zip' 85 | else: 86 | version = 'win32.zip' 87 | 88 | # Download geckodriver 89 | geckodriver_archive = os.path.join('tools', version) 90 | geckodriver_url += version 91 | print('Downloading {}...'.format(geckodriver_url)) 92 | urlretrieve(geckodriver_url, geckodriver_archive) 93 | 94 | # Download grcov 95 | grcov_archive = os.path.join('tools', 'grcov.tar.bz2') 96 | print('Downloading {}...'.format(grcov_url)) 97 | urlretrieve(grcov_url, grcov_archive) 98 | 99 | # Extract and delete archives for artifacts 100 | for filename in ['tools/target.code-coverage-gcno.zip', 'tools/target.tar.bz2', geckodriver_archive, grcov_archive, 'tools/target.common.tests.tar.gz']: 101 | if filename.endswith('zip'): 102 | with zipfile.ZipFile(filename, 'r') as zip_ref: 103 | zip_ref.extractall(path='tools') 104 | elif filename.endswith('tar.gz') or filename.endswith('tar.bz2'): 105 | if filename.endswith('tar.gz'): 106 | mode = 'r:gz' 107 | else: 108 | mode = 'r:bz2' 109 | with tarfile.open(filename, mode) as tar: 110 | tar.extractall(path='tools') 111 | os.remove(filename) 112 | 113 | # Download Firefox coverage report 114 | print('Downloading coverage artifacts...') 115 | codecoverage.download_coverage_artifacts(taskId, None, None, 'ccov-artifacts') 116 | print('Generating report...') 117 | codecoverage.generate_report('tools/grcov', 'coveralls+', 'tests_report.json', 'ccov-artifacts') 118 | 119 | # Download genhtml 120 | print('Downloading genhtml...') 121 | codecoverage.download_genhtml() 122 | 123 | # Clone if the repository doesn't exist yet. Otherwise, update. 124 | print('Cloning/Updating mozilla-central repository...') 125 | if os.path.isdir('mozilla-central'): 126 | os.chdir('mozilla-central') 127 | subprocess.call(['hg', 'pull', '--rev', revision, 'https://hg.mozilla.org/mozilla-central/']) 128 | subprocess.call(['hg', 'update', '--rev', revision]) 129 | else: 130 | subprocess.call(['hg', 'clone', 'https://hg.mozilla.org/mozilla-central/', '--rev', revision]) 131 | -------------------------------------------------------------------------------- /download_artifacts.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import argparse 4 | 5 | from coverage_crawler import latest_cov_build 6 | 7 | parser = argparse.ArgumentParser() 8 | parser.add_argument('--revision', action='store', nargs='?', help='Optional revision of the build') 9 | args = parser.parse_args() 10 | latest_cov_build.download_artifacts(args.revision) 11 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | selenium==4.5.0 2 | six==1.16.0 3 | taskcluster==44.22.1 4 | firefox_code_coverage==1.1.6 5 | -------------------------------------------------------------------------------- /run_crawler.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from coverage_crawler import crawler 4 | 5 | with open('websites.txt') as f: 6 | for website in f: 7 | report = crawler.run(website) 8 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | # no need to traverse these directories 3 | exclude = .git,__pycache__,data,tools 4 | 5 | # ignore line limit error 6 | ignore = E501 7 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import absolute_import 4 | 5 | import os 6 | 7 | from setuptools import find_packages 8 | from setuptools import setup 9 | 10 | here = os.path.dirname(__file__) 11 | 12 | 13 | def read_requirements(file_): 14 | requires = [] 15 | links = [] 16 | with open(os.path.join(here, file_)) as f: 17 | for line in f.readlines(): 18 | line = line.strip() 19 | 20 | if line.startswith('https://'): 21 | links.append(line + '-1.0.0') 22 | extras = '' 23 | if '[' in line: 24 | extras = '[' + line.split('[')[1].split(']')[0] + ']' 25 | line = line.split('#')[1].split('egg=')[1] + extras 26 | elif line == '' or line.startswith('#') or line.startswith('-'): 27 | continue 28 | line = line.split('#')[0].strip() 29 | requires.append(line) 30 | 31 | return sorted(list(set(requires))), links 32 | 33 | 34 | install_requires, dependency_links = read_requirements('requirements.txt') 35 | 36 | setup( 37 | name='coverage_crawler', 38 | version='1.0.0', 39 | description='A crawler to find websites that exercise code in Firefox that is not covered by unit tests', 40 | install_requires=install_requires, 41 | dependency_links=dependency_links, 42 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 43 | include_package_data=True, 44 | zip_safe=False, 45 | license='MPL2', 46 | ) 47 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | /* All views: initial background and text color */ 2 | body 3 | { 4 | color: #000000; 5 | background-color: #FFFFFF; 6 | } 7 | 8 | /* All views: standard link format*/ 9 | a:link 10 | { 11 | color: #284FA8; 12 | text-decoration: underline; 13 | } 14 | 15 | /* All views: standard link - visited format */ 16 | a:visited 17 | { 18 | color: #00CB40; 19 | text-decoration: underline; 20 | } 21 | 22 | /* All views: standard link - activated format */ 23 | a:active 24 | { 25 | color: #FF0040; 26 | text-decoration: underline; 27 | } 28 | 29 | /* All views: main title format */ 30 | td.title 31 | { 32 | text-align: center; 33 | padding-bottom: 10px; 34 | font-family: sans-serif; 35 | font-size: 20pt; 36 | font-style: italic; 37 | font-weight: bold; 38 | } 39 | 40 | /* All views: header item format */ 41 | td.headerItem 42 | { 43 | text-align: right; 44 | padding-right: 6px; 45 | font-family: sans-serif; 46 | font-weight: bold; 47 | vertical-align: top; 48 | white-space: nowrap; 49 | } 50 | 51 | /* All views: header item value format */ 52 | td.headerValue 53 | { 54 | text-align: left; 55 | color: #284FA8; 56 | font-family: sans-serif; 57 | font-weight: bold; 58 | white-space: nowrap; 59 | } 60 | 61 | /* All views: header item coverage table heading */ 62 | td.headerCovTableHead 63 | { 64 | text-align: center; 65 | padding-right: 6px; 66 | padding-left: 6px; 67 | padding-bottom: 0px; 68 | font-family: sans-serif; 69 | font-size: 80%; 70 | white-space: nowrap; 71 | } 72 | 73 | /* All views: header item coverage table entry */ 74 | td.headerCovTableEntry 75 | { 76 | text-align: right; 77 | color: #284FA8; 78 | font-family: sans-serif; 79 | font-weight: bold; 80 | white-space: nowrap; 81 | padding-left: 12px; 82 | padding-right: 4px; 83 | background-color: #DAE7FE; 84 | } 85 | 86 | /* All views: header item coverage table entry for high coverage rate */ 87 | td.headerCovTableEntryHi 88 | { 89 | text-align: right; 90 | color: #000000; 91 | font-family: sans-serif; 92 | font-weight: bold; 93 | white-space: nowrap; 94 | padding-left: 12px; 95 | padding-right: 4px; 96 | background-color: #A7FC9D; 97 | } 98 | 99 | /* All views: header item coverage table entry for medium coverage rate */ 100 | td.headerCovTableEntryMed 101 | { 102 | text-align: right; 103 | color: #000000; 104 | font-family: sans-serif; 105 | font-weight: bold; 106 | white-space: nowrap; 107 | padding-left: 12px; 108 | padding-right: 4px; 109 | background-color: #FFEA20; 110 | } 111 | 112 | /* All views: header item coverage table entry for ow coverage rate */ 113 | td.headerCovTableEntryLo 114 | { 115 | text-align: right; 116 | color: #000000; 117 | font-family: sans-serif; 118 | font-weight: bold; 119 | white-space: nowrap; 120 | padding-left: 12px; 121 | padding-right: 4px; 122 | background-color: #FF0000; 123 | } 124 | 125 | /* All views: header legend value for legend entry */ 126 | td.headerValueLeg 127 | { 128 | text-align: left; 129 | color: #000000; 130 | font-family: sans-serif; 131 | font-size: 80%; 132 | white-space: nowrap; 133 | padding-top: 4px; 134 | } 135 | 136 | /* All views: color of horizontal ruler */ 137 | td.ruler 138 | { 139 | background-color: #6688D4; 140 | } 141 | 142 | /* All views: version string format */ 143 | td.versionInfo 144 | { 145 | text-align: center; 146 | padding-top: 2px; 147 | font-family: sans-serif; 148 | font-style: italic; 149 | } 150 | 151 | /* Directory view/File view (all)/Test case descriptions: 152 | table headline format */ 153 | td.tableHead 154 | { 155 | text-align: center; 156 | color: #FFFFFF; 157 | background-color: #6688D4; 158 | font-family: sans-serif; 159 | font-size: 120%; 160 | font-weight: bold; 161 | white-space: nowrap; 162 | padding-left: 4px; 163 | padding-right: 4px; 164 | } 165 | 166 | span.tableHeadSort 167 | { 168 | padding-right: 4px; 169 | } 170 | 171 | /* Directory view/File view (all): filename entry format */ 172 | td.coverFile 173 | { 174 | text-align: left; 175 | padding-left: 10px; 176 | padding-right: 20px; 177 | color: #284FA8; 178 | background-color: #DAE7FE; 179 | font-family: monospace; 180 | } 181 | 182 | /* Directory view/File view (all): bar-graph entry format*/ 183 | td.coverBar 184 | { 185 | padding-left: 10px; 186 | padding-right: 10px; 187 | background-color: #DAE7FE; 188 | } 189 | 190 | /* Directory view/File view (all): bar-graph outline color */ 191 | td.coverBarOutline 192 | { 193 | background-color: #000000; 194 | } 195 | 196 | /* Directory view/File view (all): percentage entry for files with 197 | high coverage rate */ 198 | td.coverPerHi 199 | { 200 | text-align: right; 201 | padding-left: 10px; 202 | padding-right: 10px; 203 | background-color: #A7FC9D; 204 | font-weight: bold; 205 | font-family: sans-serif; 206 | } 207 | 208 | /* Directory view/File view (all): line count entry for files with 209 | high coverage rate */ 210 | td.coverNumHi 211 | { 212 | text-align: right; 213 | padding-left: 10px; 214 | padding-right: 10px; 215 | background-color: #A7FC9D; 216 | white-space: nowrap; 217 | font-family: sans-serif; 218 | } 219 | 220 | /* Directory view/File view (all): percentage entry for files with 221 | medium coverage rate */ 222 | td.coverPerMed 223 | { 224 | text-align: right; 225 | padding-left: 10px; 226 | padding-right: 10px; 227 | background-color: #FFEA20; 228 | font-weight: bold; 229 | font-family: sans-serif; 230 | } 231 | 232 | /* Directory view/File view (all): line count entry for files with 233 | medium coverage rate */ 234 | td.coverNumMed 235 | { 236 | text-align: right; 237 | padding-left: 10px; 238 | padding-right: 10px; 239 | background-color: #FFEA20; 240 | white-space: nowrap; 241 | font-family: sans-serif; 242 | } 243 | 244 | /* Directory view/File view (all): percentage entry for files with 245 | low coverage rate */ 246 | td.coverPerLo 247 | { 248 | text-align: right; 249 | padding-left: 10px; 250 | padding-right: 10px; 251 | background-color: #FF0000; 252 | font-weight: bold; 253 | font-family: sans-serif; 254 | } 255 | 256 | /* Directory view/File view (all): line count entry for files with 257 | low coverage rate */ 258 | td.coverNumLo 259 | { 260 | text-align: right; 261 | padding-left: 10px; 262 | padding-right: 10px; 263 | background-color: #FF0000; 264 | white-space: nowrap; 265 | font-family: sans-serif; 266 | } 267 | 268 | /* File view (all): "show/hide details" link format */ 269 | a.detail:link 270 | { 271 | color: #B8D0FF; 272 | font-size:80%; 273 | } 274 | 275 | /* File view (all): "show/hide details" link - visited format */ 276 | a.detail:visited 277 | { 278 | color: #B8D0FF; 279 | font-size:80%; 280 | } 281 | 282 | /* File view (all): "show/hide details" link - activated format */ 283 | a.detail:active 284 | { 285 | color: #FFFFFF; 286 | font-size:80%; 287 | } 288 | 289 | /* File view (detail): test name entry */ 290 | td.testName 291 | { 292 | text-align: right; 293 | padding-right: 10px; 294 | background-color: #DAE7FE; 295 | font-family: sans-serif; 296 | } 297 | 298 | /* File view (detail): test percentage entry */ 299 | td.testPer 300 | { 301 | text-align: right; 302 | padding-left: 10px; 303 | padding-right: 10px; 304 | background-color: #DAE7FE; 305 | font-family: sans-serif; 306 | } 307 | 308 | /* File view (detail): test lines count entry */ 309 | td.testNum 310 | { 311 | text-align: right; 312 | padding-left: 10px; 313 | padding-right: 10px; 314 | background-color: #DAE7FE; 315 | font-family: sans-serif; 316 | } 317 | 318 | /* Test case descriptions: test name format*/ 319 | dt 320 | { 321 | font-family: sans-serif; 322 | font-weight: bold; 323 | } 324 | 325 | /* Test case descriptions: description table body */ 326 | td.testDescription 327 | { 328 | padding-top: 10px; 329 | padding-left: 30px; 330 | padding-bottom: 10px; 331 | padding-right: 30px; 332 | background-color: #DAE7FE; 333 | } 334 | 335 | /* Source code view: function entry */ 336 | td.coverFn 337 | { 338 | text-align: left; 339 | padding-left: 10px; 340 | padding-right: 20px; 341 | color: #284FA8; 342 | background-color: #DAE7FE; 343 | font-family: monospace; 344 | } 345 | 346 | /* Source code view: function entry zero count*/ 347 | td.coverFnLo 348 | { 349 | text-align: right; 350 | padding-left: 10px; 351 | padding-right: 10px; 352 | background-color: #FF0000; 353 | font-weight: bold; 354 | font-family: sans-serif; 355 | } 356 | 357 | /* Source code view: function entry nonzero count*/ 358 | td.coverFnHi 359 | { 360 | text-align: right; 361 | padding-left: 10px; 362 | padding-right: 10px; 363 | background-color: #DAE7FE; 364 | font-weight: bold; 365 | font-family: sans-serif; 366 | } 367 | 368 | /* Source code view: source code format */ 369 | pre.source 370 | { 371 | font-family: monospace; 372 | white-space: pre; 373 | margin-top: 2px; 374 | } 375 | 376 | /* Source code view: line number format */ 377 | span.lineNum 378 | { 379 | background-color: #EFE383; 380 | } 381 | 382 | /* Source code view: format for lines which were executed */ 383 | td.lineCov, 384 | span.lineCov 385 | { 386 | background-color: #CAD7FE; 387 | } 388 | 389 | /* Source code view: format for Cov legend */ 390 | span.coverLegendCov 391 | { 392 | padding-left: 10px; 393 | padding-right: 10px; 394 | padding-bottom: 2px; 395 | background-color: #CAD7FE; 396 | } 397 | 398 | /* Source code view: format for lines which were not executed */ 399 | td.lineNoCov, 400 | span.lineNoCov 401 | { 402 | background-color: #FFFFFF; 403 | } 404 | 405 | /* Source code view: format for NoCov legend */ 406 | span.coverLegendNoCov 407 | { 408 | padding-left: 10px; 409 | padding-right: 10px; 410 | padding-bottom: 2px; 411 | background-color: #FF6230; 412 | } 413 | 414 | /* Source code view (function table): standard link - visited format */ 415 | td.lineNoCov > a:visited, 416 | td.lineCov > a:visited 417 | { 418 | color: black; 419 | text-decoration: underline; 420 | } 421 | 422 | /* Source code view: format for lines which were executed only in a 423 | previous version */ 424 | span.lineDiffCov 425 | { 426 | background-color: #B5F7AF; 427 | } 428 | 429 | /* Source code view: format for branches which were executed 430 | * and taken */ 431 | span.branchCov 432 | { 433 | background-color: #CAD7FE; 434 | } 435 | 436 | /* Source code view: format for branches which were executed 437 | * but not taken */ 438 | span.branchNoCov 439 | { 440 | background-color: #FF6230; 441 | } 442 | 443 | /* Source code view: format for branches which were not executed */ 444 | span.branchNoExec 445 | { 446 | background-color: #FF6230; 447 | } 448 | 449 | /* Source code view: format for the source code heading line */ 450 | pre.sourceHeading 451 | { 452 | white-space: pre; 453 | font-family: monospace; 454 | font-weight: bold; 455 | margin: 0px; 456 | } 457 | 458 | /* All views: header legend value for low rate */ 459 | td.headerValueLegL 460 | { 461 | font-family: sans-serif; 462 | text-align: center; 463 | white-space: nowrap; 464 | padding-left: 4px; 465 | padding-right: 2px; 466 | background-color: #FF0000; 467 | font-size: 80%; 468 | } 469 | 470 | /* All views: header legend value for med rate */ 471 | td.headerValueLegM 472 | { 473 | font-family: sans-serif; 474 | text-align: center; 475 | white-space: nowrap; 476 | padding-left: 2px; 477 | padding-right: 2px; 478 | background-color: #FFEA20; 479 | font-size: 80%; 480 | } 481 | 482 | /* All views: header legend value for hi rate */ 483 | td.headerValueLegH 484 | { 485 | font-family: sans-serif; 486 | text-align: center; 487 | white-space: nowrap; 488 | padding-left: 2px; 489 | padding-right: 4px; 490 | background-color: #A7FC9D; 491 | font-size: 80%; 492 | } 493 | 494 | /* All views except source code view: legend format for low coverage */ 495 | span.coverLegendCovLo 496 | { 497 | padding-left: 10px; 498 | padding-right: 10px; 499 | padding-top: 2px; 500 | background-color: #FF0000; 501 | } 502 | 503 | /* All views except source code view: legend format for med coverage */ 504 | span.coverLegendCovMed 505 | { 506 | padding-left: 10px; 507 | padding-right: 10px; 508 | padding-top: 2px; 509 | background-color: #FFEA20; 510 | } 511 | 512 | /* All views except source code view: legend format for hi coverage */ 513 | span.coverLegendCovHi 514 | { 515 | padding-left: 10px; 516 | padding-right: 10px; 517 | padding-top: 2px; 518 | background-color: #A7FC9D; 519 | } 520 | -------------------------------------------------------------------------------- /test-requirements.txt: -------------------------------------------------------------------------------- 1 | flake8==5.0.4 2 | flake8-isort==5.0.0 3 | flake8-quotes==3.3.1 4 | flake8-coding==1.3.2 5 | flake8-copyright==0.2.3 6 | flake8-debugger==4.1.2 7 | flake8-mypy==17.8.0 8 | pytest==7.1.3 9 | setuptools==65.5.0 10 | wheel==0.37.1 11 | webdriver-manager==3.8.4 12 | flask==2.2.2 -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/coverage-crawler/0e9132451834a60147853bc9dec220cd262b1e35/tests/__init__.py -------------------------------------------------------------------------------- /tests/crawler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/coverage-crawler/0e9132451834a60147853bc9dec220cd262b1e35/tests/crawler/__init__.py -------------------------------------------------------------------------------- /tests/crawler/test_crawler_unittest.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | import multiprocessing 3 | import unittest 4 | 5 | from selenium import webdriver 6 | from selenium.common.exceptions import WebDriverException 7 | from webdriver_manager.firefox import GeckoDriverManager 8 | 9 | from coverage_crawler import crawler 10 | from tests.example_website import website_app 11 | from tests.example_website.website_app import WEBSITE_TITLE 12 | from tests.example_website.website_app import run_server 13 | 14 | 15 | class TestCrawler(unittest.TestCase): 16 | driver: webdriver.Firefox 17 | 18 | def setUp(self): 19 | self.driver = webdriver.Firefox(executable_path=GeckoDriverManager().install()) 20 | 21 | def tearDown(self): 22 | self.driver.quit() 23 | 24 | def test_close_all_windows_except_first(self): 25 | """ 26 | when multiple windows are open, 27 | verify that calling `close_all_windows_except_first` closes all except the first. 28 | """ 29 | _open_tab_script = 'window.open("", "new window")' 30 | self.driver.execute_script(_open_tab_script) 31 | assert (len(self.driver.window_handles) == 2), 'some windows were not opened properly.' 32 | 33 | crawler.close_all_windows_except_first(self.driver) 34 | 35 | assert (len(self.driver.window_handles) == 1), 'some windows were not closed properly.' 36 | 37 | 38 | class TestCrawlerLive(unittest.TestCase): 39 | SERVER_SETUP_TRIES = 10 40 | 41 | @classmethod 42 | def setUpClass(cls): 43 | cls.server = multiprocessing.Process(target=run_server) 44 | cls.server.start() 45 | 46 | try: 47 | test_driver = webdriver.Firefox(executable_path=GeckoDriverManager().install()) 48 | for try_id in range(cls.SERVER_SETUP_TRIES): 49 | print(f'class setup tries: {try_id}/{cls.SERVER_SETUP_TRIES}') 50 | test_driver.get(website_app.WEBSITE_URL) 51 | assert test_driver.title == WEBSITE_TITLE 52 | test_driver.quit() 53 | return 54 | except WebDriverException as e: 55 | print('got exception:', e) 56 | 57 | cls.server.terminate() 58 | cls.server.join() 59 | cls.fail(cls, 'website did not start up correctly.') 60 | 61 | @classmethod 62 | def tearDownClass(cls): 63 | cls.server.terminate() 64 | cls.server.join() 65 | 66 | def setUp(self): 67 | self.driver = webdriver.Firefox(executable_path=GeckoDriverManager().install()) 68 | 69 | def tearDown(self): 70 | self.driver.quit() 71 | 72 | def test_find_children(self): 73 | """ 74 | when example server is open, 75 | verify that `find_children` returns the expected children. 76 | """ 77 | expected_link_text = 'i am the first link in the first div' 78 | 79 | self.driver.get(website_app.WEBSITE_URL) 80 | assert (self.driver.title == WEBSITE_TITLE), f'incorrect driver title: {self.driver.title}' 81 | 82 | children = crawler.find_children(self.driver) 83 | num_children = len(children) 84 | assert (num_children == 1), f'incorrect number of children found: {num_children}' 85 | assert (children[0].text == expected_link_text) 86 | 87 | def test_get_all_attributes(self): 88 | """ 89 | when example server is open, 90 | verify that `get_all_attributes` returns the expected attributes. 91 | """ 92 | expected_attribute = 'href' 93 | 94 | self.driver.get(website_app.WEBSITE_URL) 95 | assert (self.driver.title == WEBSITE_TITLE), f'incorrect driver title: {self.driver.title}' 96 | 97 | child = crawler.find_children(self.driver)[0] 98 | attributes = crawler.get_all_attributes(self.driver, child) 99 | num_attributes = len(attributes) 100 | assert (num_attributes == 1), f'incorrect number of attributes found: {num_attributes}' 101 | assert (expected_attribute in attributes), f'expected attribute is missing: {expected_attribute}' 102 | -------------------------------------------------------------------------------- /tests/example_website/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozilla/coverage-crawler/0e9132451834a60147853bc9dec220cd262b1e35/tests/example_website/__init__.py -------------------------------------------------------------------------------- /tests/example_website/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | coverage-crawler example website 6 | 7 | 8 | i am a body 9 |
i am the first div 10 |

i am the first paragraph of the first div 11 |

12 | i am the first link in the first div 13 |
14 | 15 |
i am the second div
16 | 17 | -------------------------------------------------------------------------------- /tests/example_website/website_app.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | import flask 3 | from flask import render_template 4 | 5 | WEBSITE_DOMAIN = 'localhost' 6 | WEBSITE_PORT = 8000 7 | WEBSITE_URL = f'{WEBSITE_DOMAIN}:{WEBSITE_PORT}' 8 | WEBSITE_TITLE = 'coverage-crawler example website' 9 | app = flask.Flask(__name__) 10 | 11 | 12 | @app.route('/') 13 | def index(): 14 | return render_template('index.html') 15 | 16 | 17 | def run_server(debug=False): 18 | app.run(host=WEBSITE_DOMAIN, port=WEBSITE_PORT, debug=debug) 19 | 20 | 21 | if __name__ == '__main__': 22 | run_server(debug=True) 23 | -------------------------------------------------------------------------------- /tests/test_coverage_crawler.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from coverage_crawler import crawler # NOQA 4 | 5 | 6 | def test(): 7 | pass 8 | -------------------------------------------------------------------------------- /tests/test_diff.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from coverage_crawler import diff 4 | 5 | 6 | # diff.compare_objects(obj1, obj2) returns true if equal and false if different coverage 7 | def test_compare_objects_same_coverage_same_functions(): 8 | obj1 = { 9 | 'functions': [ 10 | { 11 | 'name': 'func1', 12 | 'start': 36, 13 | 'exec': True 14 | }, 15 | { 16 | 'name': 'func2', 17 | 'start': 64, 18 | 'exec': False 19 | } 20 | ], 21 | 'branches': [], 22 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 23 | 'coverage': [ 24 | None, 25 | 2, 26 | None, 27 | None, 28 | 5 29 | ], 30 | 'source_digest': 'another_generated_number_with_literals' 31 | } 32 | obj2 = { 33 | 'functions': [ 34 | { 35 | 'name': 'func1', 36 | 'start': 36, 37 | 'exec': True 38 | }, 39 | { 40 | 'name': 'func2', 41 | 'start': 64, 42 | 'exec': False 43 | } 44 | ], 45 | 'branches': [], 46 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 47 | 'coverage': [ 48 | None, 49 | 2, 50 | None, 51 | None, 52 | 5 53 | ], 54 | 'source_digest': 'another_generated_number_with_literals' 55 | } 56 | assert diff.compare_source_files_objects(obj1, obj2, False) is None 57 | 58 | 59 | def test_compare_objects_same_coverage_diff_functions(): 60 | obj1 = { 61 | 'functions': [ 62 | { 63 | 'name': 'func1', 64 | 'start': 36, 65 | 'exec': True 66 | }, 67 | { 68 | 'name': 'func2', 69 | 'start': 64, 70 | 'exec': True 71 | } 72 | ], 73 | 'branches': [], 74 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 75 | 'coverage': [ 76 | None, 77 | 2, 78 | None, 79 | None, 80 | 5 81 | ], 82 | 'source_digest': 'another_generated_number_with_literals' 83 | } 84 | obj2 = { 85 | 'functions': [ 86 | { 87 | 'name': 'func1', 88 | 'start': 36, 89 | 'exec': True 90 | }, 91 | { 92 | 'name': 'func2', 93 | 'start': 64, 94 | 'exec': False 95 | } 96 | ], 97 | 'branches': [], 98 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 99 | 'coverage': [ 100 | None, 101 | 2, 102 | None, 103 | None, 104 | 5 105 | ], 106 | 'source_digest': 'another_generated_number_with_literals2' 107 | } 108 | 109 | assert diff.compare_source_files_objects(obj1, obj2, False) is None 110 | 111 | 112 | def test_compare_objects_diff_coverage_same_func(): 113 | obj1 = { 114 | 'functions': [ 115 | { 116 | 'name': 'func1', 117 | 'start': 36, 118 | 'exec': True 119 | }, 120 | { 121 | 'name': 'func2', 122 | 'start': 64, 123 | 'exec': False 124 | } 125 | ], 126 | 'branches': [], 127 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 128 | 'coverage': [ 129 | None, 130 | 2, 131 | None, 132 | None, 133 | 5 134 | ], 135 | 'source_digest': 'another_generated_number_with_literals' 136 | } 137 | obj2 = { 138 | 'functions': [ 139 | { 140 | 'name': 'func1', 141 | 'start': 36, 142 | 'exec': True 143 | }, 144 | { 145 | 'name': 'func2', 146 | 'start': 64, 147 | 'exec': False 148 | } 149 | ], 150 | 'branches': [], 151 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 152 | 'coverage': [ 153 | None, 154 | 2, 155 | None, 156 | None, 157 | 6 158 | ], 159 | 'source_digest': 'another_generated_number_with_literals2' 160 | } 161 | 162 | assert diff.compare_source_files_objects(obj1, obj2, False) == { 163 | 'functions': [], 164 | 'branches': [], 165 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 166 | 'coverage': [ 167 | None, 168 | 0, 169 | None, 170 | None, 171 | 1 172 | ], 173 | 'source_digest': 'another_generated_number_with_literals' 174 | } 175 | 176 | 177 | def test_compare_objects_diff_coverage_same_func_2(): 178 | obj1 = { 179 | 'functions': [ 180 | { 181 | 'name': 'func1', 182 | 'start': 36, 183 | 'exec': True 184 | }, 185 | { 186 | 'name': 'func2', 187 | 'start': 64, 188 | 'exec': False 189 | } 190 | ], 191 | 'branches': [], 192 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 193 | 'coverage': [ 194 | None, 195 | 2, 196 | None, 197 | 1, 198 | 5 199 | ], 200 | 'source_digest': 'another_generated_number_with_literals' 201 | } 202 | 203 | obj2 = { 204 | 'functions': [ 205 | { 206 | 'name': 'func1', 207 | 'start': 36, 208 | 'exec': True 209 | }, 210 | { 211 | 'name': 'func2', 212 | 'start': 64, 213 | 'exec': False 214 | } 215 | ], 216 | 'branches': [], 217 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 218 | 'coverage': [ 219 | None, 220 | 0, 221 | None, 222 | 0, 223 | 6 224 | ], 225 | 'source_digest': 'another_generated_number_with_literals2' 226 | } 227 | 228 | assert diff.compare_source_files_objects(obj1, obj2, False) == { 229 | 'functions': [], 230 | 'branches': [], 231 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 232 | 'coverage': [ 233 | None, 234 | 0, 235 | None, 236 | 0, 237 | 1 238 | ], 239 | 'source_digest': 'another_generated_number_with_literals' 240 | } 241 | 242 | 243 | def test_compare_objects_diff_coverage_diff_functions(): 244 | obj1 = { 245 | 'functions': [ 246 | { 247 | 'name': 'func1', 248 | 'start': 36, 249 | 'exec': True 250 | }, 251 | { 252 | 'name': 'func2', 253 | 'start': 64, 254 | 'exec': False 255 | } 256 | ], 257 | 'branches': [], 258 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 259 | 'coverage': [ 260 | None, 261 | 2, 262 | 0, 263 | None, 264 | 5 265 | ], 266 | 'source_digest': 'another_generated_number_with_literals' 267 | } 268 | obj2 = { 269 | 'functions': [ 270 | { 271 | 'name': 'func1', 272 | 'start': 36, 273 | 'exec': True 274 | }, 275 | { 276 | 'name': 'func2', 277 | 'start': 64, 278 | 'exec': True 279 | } 280 | ], 281 | 'branches': [], 282 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 283 | 'coverage': [ 284 | None, 285 | 2, 286 | 3, 287 | None, 288 | 5 289 | ], 290 | 'source_digest': 'another_generated_number_with_literals2' 291 | } 292 | 293 | assert diff.compare_source_files_objects(obj1, obj2, False) == { 294 | 'functions': [ 295 | { 296 | 'name': 'func2', 297 | 'start': 64, 298 | 'exec': True 299 | } 300 | ], 301 | 'branches': [], 302 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 303 | 'coverage': [ 304 | None, 305 | 0, 306 | 3, 307 | None, 308 | 0 309 | ], 310 | 'source_digest': 'another_generated_number_with_literals' 311 | } 312 | 313 | 314 | def test_compare_reports(): 315 | baseline_report = { 316 | 'git': { 317 | 'branch': 'master', 318 | 'head': { 319 | 'id': 'UNUSED' 320 | } 321 | }, 322 | 'repo_token': 'UNUSED', 323 | 'service_job_number': '', 324 | 'service_name': '', 325 | 'service_number': '', 326 | 'source_files': [ 327 | { 328 | 'functions': [ 329 | { 330 | 'name': 'func1', 331 | 'start': 36, 332 | 'exec': True 333 | }, 334 | { 335 | 'name': 'func2', 336 | 'start': 64, 337 | 'exec': False 338 | } 339 | ], 340 | 'branches': [], 341 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 342 | 'coverage': [ 343 | None, 344 | 2, 345 | None, 346 | 1, 347 | 5 348 | ], 349 | 'source_digest': 'another_generated_number_with_literals' 350 | } 351 | ] 352 | } 353 | report = { 354 | 'git': { 355 | 'branch': 'master', 356 | 'head': { 357 | 'id': 'UNUSED' 358 | } 359 | }, 360 | 'repo_token': 'UNUSED', 361 | 'service_job_number': '', 362 | 'service_name': '', 363 | 'service_number': '', 364 | 'source_files': [ 365 | { 366 | 'functions': [ 367 | { 368 | 'name': 'func1', 369 | 'start': 36, 370 | 'exec': True 371 | }, 372 | { 373 | 'name': 'func2', 374 | 'start': 64, 375 | 'exec': True 376 | } 377 | ], 378 | 'branches': [], 379 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 380 | 'coverage': [ 381 | None, 382 | 0, 383 | None, 384 | 0, 385 | 6 386 | ], 387 | 'source_digest': 'another_generated_number_with_literals2' 388 | } 389 | ] 390 | } 391 | assert diff.compare_reports(baseline_report, report, False) == { 392 | 'git': { 393 | 'branch': 'master', 394 | 'head': { 395 | 'id': 'UNUSED' 396 | } 397 | }, 398 | 'repo_token': 'UNUSED', 399 | 'service_job_number': '', 400 | 'service_name': '', 401 | 'service_number': '', 402 | 'source_files': [ 403 | { 404 | 'functions': [ 405 | { 406 | 'name': 'func2', 407 | 'start': 64, 408 | 'exec': True 409 | } 410 | ], 411 | 'branches': [], 412 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 413 | 'coverage': [ 414 | None, 415 | 0, 416 | None, 417 | 0, 418 | 1 419 | ], 420 | 'source_digest': 'another_generated_number_with_literals' 421 | } 422 | ] 423 | } 424 | 425 | 426 | def test_compare_reports_coverage_no_problems(): 427 | baseline_report = { 428 | 'git': { 429 | 'branch': 'master', 430 | 'head': { 431 | 'id': 'UNUSED' 432 | } 433 | }, 434 | 'repo_token': 'UNUSED', 435 | 'service_job_number': '', 436 | 'service_name': '', 437 | 'service_number': '', 438 | 'source_files': [ 439 | { 440 | 'functions': [ 441 | { 442 | 'name': 'func1', 443 | 'start': 36, 444 | 'exec': True 445 | } 446 | ], 447 | 'branches': [], 448 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 449 | 'coverage': [ 450 | None, 451 | 2, 452 | None, 453 | 1, 454 | 5 455 | ], 456 | 'source_digest': 'another_generated_number_with_literals' 457 | } 458 | ] 459 | } 460 | report = { 461 | 'git': { 462 | 'branch': 'master', 463 | 'head': { 464 | 'id': 'UNUSED' 465 | } 466 | }, 467 | 'repo_token': 'UNUSED', 468 | 'service_job_number': '', 469 | 'service_name': '', 470 | 'service_number': '', 471 | 'source_files': [ 472 | { 473 | 'functions': [ 474 | { 475 | 'name': 'func1', 476 | 'start': 36, 477 | 'exec': True 478 | } 479 | ], 480 | 'branches': [], 481 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 482 | 'coverage': [ 483 | None, 484 | 0, 485 | None, 486 | 0, 487 | 5 488 | ], 489 | 'source_digest': 'another_generated_number_with_literals2' 490 | } 491 | ] 492 | } 493 | assert diff.compare_reports(baseline_report, report, False) == { 494 | 'git': { 495 | 'branch': 'master', 496 | 'head': { 497 | 'id': 'UNUSED' 498 | } 499 | }, 500 | 'repo_token': 'UNUSED', 501 | 'service_job_number': '', 502 | 'service_name': '', 503 | 'service_number': '', 504 | 'source_files': [] 505 | } 506 | 507 | 508 | def test_compare_reports_2_files(): 509 | baseline_report = { 510 | 'git': { 511 | 'branch': 'master', 512 | 'head': { 513 | 'id': 'UNUSED' 514 | } 515 | }, 516 | 'repo_token': 'UNUSED', 517 | 'service_job_number': '', 518 | 'service_name': '', 519 | 'service_number': '', 520 | 'source_files': [ 521 | { 522 | 'functions': [ 523 | { 524 | 'name': 'function1', 525 | 'start': 36, 526 | 'exec': True 527 | }, 528 | { 529 | 'name': 'function2', 530 | 'start': 64, 531 | 'exec': False 532 | } 533 | ], 534 | 'branches': [], 535 | 'name': 'name1', 536 | 'coverage': [ 537 | None, 538 | 2, 539 | None, 540 | 1, 541 | 5 542 | ], 543 | 'source_digest': 'another_generated_number_with_literals' 544 | }, 545 | { 546 | 'functions': [ 547 | { 548 | 'name': 'func1', 549 | 'start': 36, 550 | 'exec': True 551 | }, 552 | { 553 | 'name': 'func2', 554 | 'start': 64, 555 | 'exec': False 556 | } 557 | ], 558 | 'branches': [], 559 | 'name': 'name2', 560 | 'coverage': [ 561 | None, 562 | 2, 563 | None, 564 | None, 565 | 5 566 | ], 567 | 'source_digest': 'another_generated_number_with_literals' 568 | } 569 | ] 570 | } 571 | report = { 572 | 'git': { 573 | 'branch': 'master', 574 | 'head': { 575 | 'id': 'UNUSED' 576 | } 577 | }, 578 | 'repo_token': 'UNUSED', 579 | 'service_job_number': '', 580 | 'service_name': '', 581 | 'service_number': '', 582 | 'source_files': [ 583 | { 584 | 'functions': [ 585 | { 586 | 'name': 'function1', 587 | 'start': 36, 588 | 'exec': True 589 | }, 590 | { 591 | 'name': 'function2', 592 | 'start': 64, 593 | 'exec': True 594 | } 595 | ], 596 | 'branches': [], 597 | 'name': 'name1', 598 | 'coverage': [ 599 | None, 600 | 0, 601 | None, 602 | 0, 603 | 6 604 | ], 605 | 'source_digest': 'another_generated_number_with_literals2' 606 | }, 607 | { 608 | 'functions': [ 609 | { 610 | 'name': 'func1', 611 | 'start': 36, 612 | 'exec': True 613 | }, 614 | { 615 | 'name': 'func2', 616 | 'start': 64, 617 | 'exec': False 618 | } 619 | ], 620 | 'branches': [], 621 | 'name': 'name2', 622 | 'coverage': [ 623 | None, 624 | 0, 625 | None, 626 | None, 627 | 6 628 | ], 629 | 'source_digest': 'another_generated_number_with_literals2' 630 | } 631 | ] 632 | } 633 | 634 | assert diff.compare_reports(baseline_report, report, False) == { 635 | 'git': { 636 | 'branch': 'master', 637 | 'head': { 638 | 'id': 'UNUSED' 639 | } 640 | }, 641 | 'repo_token': 'UNUSED', 642 | 'service_job_number': '', 643 | 'service_name': '', 644 | 'service_number': '', 645 | 'source_files': [ 646 | { 647 | 'functions': [ 648 | { 649 | 'name': 'function2', 650 | 'start': 64, 651 | 'exec': True 652 | } 653 | ], 654 | 'branches': [], 655 | 'name': 'name1', 656 | 'coverage': [ 657 | None, 658 | 0, 659 | None, 660 | 0, 661 | 1 662 | ], 663 | 'source_digest': 'another_generated_number_with_literals' 664 | }, 665 | { 666 | 'functions': [], 667 | 'branches': [], 668 | 'name': 'name2', 669 | 'coverage': [ 670 | None, 671 | 0, 672 | None, 673 | None, 674 | 1 675 | ], 676 | 'source_digest': 'another_generated_number_with_literals' 677 | } 678 | ] 679 | } 680 | 681 | 682 | def test_compare_reports_no_diff(): 683 | baseline_report = { 684 | 'git': { 685 | 'branch': 'master', 686 | 'head': { 687 | 'id': 'UNUSED' 688 | } 689 | }, 690 | 'repo_token': 'UNUSED', 691 | 'service_job_number': '', 692 | 'service_name': '', 693 | 'service_number': '', 694 | 'source_files': [ 695 | { 696 | 'functions': [ 697 | { 698 | 'name': 'func1', 699 | 'start': 36, 700 | 'exec': True 701 | }, 702 | { 703 | 'name': 'func2', 704 | 'start': 64, 705 | 'exec': False 706 | } 707 | ], 708 | 'branches': [], 709 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 710 | 'coverage': [ 711 | None, 712 | 2, 713 | None, 714 | None, 715 | 5 716 | ], 717 | 'source_digest': 'another_generated_number_with_literals' 718 | } 719 | ] 720 | } 721 | report = { 722 | 'git': { 723 | 'branch': 'master', 724 | 'head': { 725 | 'id': 'UNUSED' 726 | } 727 | }, 728 | 'repo_token': 'UNUSED', 729 | 'service_job_number': '', 730 | 'service_name': '', 731 | 'service_number': '', 732 | 'source_files': [ 733 | { 734 | 'functions': [ 735 | { 736 | 'name': 'func1', 737 | 'start': 36, 738 | 'exec': True 739 | }, 740 | { 741 | 'name': 'func2', 742 | 'start': 64, 743 | 'exec': False 744 | } 745 | ], 746 | 'branches': [], 747 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 748 | 'coverage': [ 749 | None, 750 | 2, 751 | None, 752 | None, 753 | 5 754 | ], 755 | 'source_digest': 'another_generated_number_with_literals2' 756 | } 757 | ] 758 | } 759 | 760 | assert diff.compare_reports(baseline_report, report, False) == { 761 | 'git': { 762 | 'branch': 'master', 763 | 'head': { 764 | 'id': 'UNUSED' 765 | } 766 | }, 767 | 'repo_token': 'UNUSED', 768 | 'service_job_number': '', 769 | 'service_name': '', 770 | 'service_number': '', 771 | 'source_files': [] 772 | } 773 | 774 | 775 | def test_compare_reports_ignore_hits(): 776 | baseline_report = { 777 | 'git': { 778 | 'branch': 'master', 779 | 'head': { 780 | 'id': 'UNUSED' 781 | } 782 | }, 783 | 'repo_token': 'UNUSED', 784 | 'service_job_number': '', 785 | 'service_name': '', 786 | 'service_number': '', 787 | 'source_files': [ 788 | { 789 | 'functions': [ 790 | { 791 | 'name': 'func1', 792 | 'start': 36, 793 | 'exec': True 794 | }, 795 | { 796 | 'name': 'func2', 797 | 'start': 64, 798 | 'exec': False 799 | } 800 | ], 801 | 'branches': [], 802 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 803 | 'coverage': [ 804 | None, 805 | 2, 806 | None, 807 | 1, 808 | 5 809 | ], 810 | 'source_digest': 'another_generated_number_with_literals' 811 | } 812 | ] 813 | } 814 | report = { 815 | 'git': { 816 | 'branch': 'master', 817 | 'head': { 818 | 'id': 'UNUSED' 819 | } 820 | }, 821 | 'repo_token': 'UNUSED', 822 | 'service_job_number': '', 823 | 'service_name': '', 824 | 'service_number': '', 825 | 'source_files': [ 826 | { 827 | 'functions': [ 828 | { 829 | 'name': 'func1', 830 | 'start': 36, 831 | 'exec': True 832 | }, 833 | { 834 | 'name': 'func2', 835 | 'start': 64, 836 | 'exec': True 837 | } 838 | ], 839 | 'branches': [], 840 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 841 | 'coverage': [ 842 | None, 843 | 2, 844 | None, 845 | 5, 846 | 6 847 | ], 848 | 'source_digest': 'another_generated_number_with_literals2' 849 | } 850 | ] 851 | } 852 | assert diff.compare_reports(baseline_report, report, True) == { 853 | 'git': { 854 | 'branch': 'master', 855 | 'head': { 856 | 'id': 'UNUSED' 857 | } 858 | }, 859 | 'repo_token': 'UNUSED', 860 | 'service_job_number': '', 861 | 'service_name': '', 862 | 'service_number': '', 863 | 'source_files': [ 864 | { 865 | 'functions': [ 866 | { 867 | 'name': 'func2', 868 | 'start': 64, 869 | 'exec': True 870 | } 871 | ], 872 | 'branches': [], 873 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 874 | 'coverage': [ 875 | None, 876 | 0, 877 | None, 878 | 0, 879 | 0 880 | ], 881 | 'source_digest': 'another_generated_number_with_literals' 882 | } 883 | ] 884 | } 885 | 886 | 887 | def test_compare_reports_ignore_hits_2(): 888 | baseline_report = { 889 | 'git': { 890 | 'branch': 'master', 891 | 'head': { 892 | 'id': 'UNUSED' 893 | } 894 | }, 895 | 'repo_token': 'UNUSED', 896 | 'service_job_number': '', 897 | 'service_name': '', 898 | 'service_number': '', 899 | 'source_files': [ 900 | { 901 | 'functions': [ 902 | { 903 | 'name': 'func1', 904 | 'start': 36, 905 | 'exec': True 906 | }, 907 | { 908 | 'name': 'func2', 909 | 'start': 64, 910 | 'exec': False 911 | } 912 | ], 913 | 'branches': [], 914 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 915 | 'coverage': [ 916 | None, 917 | 2, 918 | None, 919 | 1, 920 | 0 921 | ], 922 | 'source_digest': 'another_generated_number_with_literals' 923 | } 924 | ] 925 | } 926 | report = { 927 | 'git': { 928 | 'branch': 'master', 929 | 'head': { 930 | 'id': 'UNUSED' 931 | } 932 | }, 933 | 'repo_token': 'UNUSED', 934 | 'service_job_number': '', 935 | 'service_name': '', 936 | 'service_number': '', 937 | 'source_files': [ 938 | { 939 | 'functions': [ 940 | { 941 | 'name': 'func1', 942 | 'start': 36, 943 | 'exec': True 944 | }, 945 | { 946 | 'name': 'func2', 947 | 'start': 64, 948 | 'exec': True 949 | } 950 | ], 951 | 'branches': [], 952 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 953 | 'coverage': [ 954 | None, 955 | 2, 956 | None, 957 | 5, 958 | 6 959 | ], 960 | 'source_digest': 'another_generated_number_with_literals2' 961 | } 962 | ] 963 | } 964 | assert diff.compare_reports(baseline_report, report, True) == { 965 | 'git': { 966 | 'branch': 'master', 967 | 'head': { 968 | 'id': 'UNUSED' 969 | } 970 | }, 971 | 'repo_token': 'UNUSED', 972 | 'service_job_number': '', 973 | 'service_name': '', 974 | 'service_number': '', 975 | 'source_files': [ 976 | { 977 | 'functions': [ 978 | { 979 | 'name': 'func2', 980 | 'start': 64, 981 | 'exec': True 982 | } 983 | ], 984 | 'branches': [], 985 | 'name': 'obj-firefox/dist/include/mozilla/dom/DOMRectListBinding.h', 986 | 'coverage': [ 987 | None, 988 | 0, 989 | None, 990 | 0, 991 | 1 992 | ], 993 | 'source_digest': 'another_generated_number_with_literals' 994 | } 995 | ] 996 | } 997 | -------------------------------------------------------------------------------- /websites.txt: -------------------------------------------------------------------------------- 1 | https://stackoverflow.com/ 2 | https://www.mozilla.org/ 3 | https://www.python.org/ 4 | https://www.rust-lang.org/ 5 | https://www.wikipedia.org/ 6 | https://www.google.com/ 7 | https://www.youtube.com/ 8 | https://www.facebook.com/ 9 | https://www.yahoo.com/ 10 | https://www.amazon.com/ 11 | https://twitter.com/ 12 | https://www.instagram.com/ 13 | https://www.linkedin.com/ 14 | http://www.baidu.com/ 15 | https://www.microsoft.com/ru-kz/ 16 | https://ru.aliexpress.com/ 17 | https://yandex.kz/ 18 | http://twitter.com/ 19 | https://www.alexa.com/ 20 | https://www.kinopoisk.ru/ 21 | https://www.zakon.kz/ 22 | https://linux.die.net/ 23 | https://en.tengrinews.kz/ 24 | https://ok.ru/ 25 | https://www.gismeteo.ru/ 26 | https://krisha.kz/ 27 | https://www.netflix.com/kz/ 28 | https://github.com/ 29 | https://www.walmart.com/ 30 | https://www.quora.com 31 | https://www.salesforce.com/ 32 | https://www.livejournal.com/ 33 | https://pikabu.ru/ 34 | https://www.booking.com/ 35 | https://2gis.ru/ 36 | http://www.qq.com/ 37 | https://world.taobao.com/ 38 | https://www.tmall.com/ 39 | http://www.sohu.com/ 40 | https://www.tutorialspoint.com/ 41 | https://www.geeksforgeeks.org/ 42 | http://www.vesti.ru/ 43 | https://www.javascript.com/ 44 | https://www.w3schools.com/ 45 | https://www.mysql.com/ 46 | https://www.udacity.com/ 47 | https://www.coursera.org/ 48 | https://www.khanacademy.org/ 49 | http://web.mit.edu/ 50 | https://nu.edu.kz/ 51 | https://www.harvard.edu/ 52 | https://www.stanford.edu/ 53 | https://www.berkeley.edu/ 54 | https://www.cam.ac.uk/ 55 | https://www.ucl.ac.uk/ 56 | --------------------------------------------------------------------------------