| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """The testing Environment class.""" | 5 """The testing Environment class.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import shutil | 8 import shutil |
| 9 import sys | 9 import sys |
| 10 import time | 10 import time |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 self.passwords_tree.find( | 158 self.passwords_tree.find( |
| 159 ".//*[@name='%s']/password" % websitetest.name)) | 159 ".//*[@name='%s']/password" % websitetest.name)) |
| 160 if password_tag.text: | 160 if password_tag.text: |
| 161 websitetest.password = password_tag.text | 161 websitetest.password = password_tag.text |
| 162 self.websitetests.append(websitetest) | 162 self.websitetests.append(websitetest) |
| 163 if disabled: | 163 if disabled: |
| 164 self.disabled_tests.append(websitetest.name) | 164 self.disabled_tests.append(websitetest.name) |
| 165 else: | 165 else: |
| 166 self.working_tests.append(websitetest.name) | 166 self.working_tests.append(websitetest.name) |
| 167 | 167 |
| 168 def RemoveAllPasswords(self): | 168 def ClearCache(self, clear_passwords): |
| 169 """Removes all the stored passwords.""" | 169 """Clear the browser cookies. If |clear_passwords| is true, clear all the |
| 170 logging.info("\nRemoveAllPasswords\n") | 170 saved passwords too. |
| 171 self.driver.get("chrome://settings/passwords") | |
| 172 self.driver.switch_to_frame("settings") | |
| 173 while True: | |
| 174 try: | |
| 175 self.driver.execute_script( | |
| 176 "document.querySelector('#saved-passwords-list .row-delete-button')" | |
| 177 ".click()") | |
| 178 time.sleep(1) | |
| 179 except NoSuchElementException: | |
| 180 break | |
| 181 except WebDriverException: | |
| 182 break | |
| 183 | 171 |
| 184 def ClearAllCookies(self): | 172 Args: |
| 185 """Removes all the cookies.""" | 173 clear_passwords : Clear all the passwords if the bool value is true. |
| 186 logging.info("\nClearAllCookies\n") | 174 """ |
| 175 logging.info("\nClearCache\n") |
| 187 self.driver.get("chrome://settings/clearBrowserData") | 176 self.driver.get("chrome://settings/clearBrowserData") |
| 188 self.driver.switch_to_frame("settings") | 177 self.driver.switch_to_frame("settings") |
| 189 self.driver.execute_script( | 178 script = ( |
| 190 "var checkboxes = document.querySelectorAll(" | 179 "if (!document.querySelector('#delete-cookies-checkbox').checked)" |
| 191 " '#clear-data-checkboxes [type=\\\'checkbox\\\']');" | 180 " document.querySelector('#delete-cookies-checkbox').click();" |
| 192 "for (var i in checkboxes)" | 181 ) |
| 193 " checkboxes[i].checked = false;" | 182 negation = "" |
| 194 "document.querySelector('#delete-cookies-checkbox').checked = true;" | 183 if clear_passwords: |
| 195 "document.querySelector('#clear-browser-data-commit').click();") | 184 negation = "!" |
| 185 script += ( |
| 186 "if (%sdocument.querySelector('#delete-passwords-checkbox').checked)" |
| 187 " document.querySelector('#delete-passwords-checkbox').click();" |
| 188 % negation) |
| 189 script += "document.querySelector('#clear-browser-data-commit').click();" |
| 190 self.driver.execute_script(script) |
| 196 time.sleep(2) | 191 time.sleep(2) |
| 197 | 192 |
| 198 def OpenTabAndGoToInternals(self, url): | 193 def OpenTabAndGoToInternals(self, url): |
| 199 """If there is no |self.website_window|, opens a new tab and navigates to | 194 """If there is no |self.website_window|, opens a new tab and navigates to |
| 200 |url| in the new tab. Navigates to the passwords internals page in the | 195 |url| in the new tab. Navigates to the passwords internals page in the |
| 201 first tab. Raises an exception otherwise. | 196 first tab. Raises an exception otherwise. |
| 202 | 197 |
| 203 Args: | 198 Args: |
| 204 url: Url to go to in the new tab. | 199 url: Url to go to in the new tab. |
| 205 | 200 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 352 |
| 358 def TestList(self, websitetests): | 353 def TestList(self, websitetests): |
| 359 """Runs the tests on the websites in |websitetests|. | 354 """Runs the tests on the websites in |websitetests|. |
| 360 | 355 |
| 361 Args: | 356 Args: |
| 362 websitetests: A list of WebsiteTests that are going to be tested. | 357 websitetests: A list of WebsiteTests that are going to be tested. |
| 363 | 358 |
| 364 Raises: | 359 Raises: |
| 365 Exception: An exception is raised if the tests fail. | 360 Exception: An exception is raised if the tests fail. |
| 366 """ | 361 """ |
| 367 self.RemoveAllPasswords() | 362 self.ClearCache(True) |
| 368 | 363 |
| 369 for websitetest in websitetests: | 364 for websitetest in websitetests: |
| 370 successful = True | 365 successful = True |
| 371 error = "" | 366 error = "" |
| 372 try: | 367 try: |
| 373 websitetest.was_run = True | 368 websitetest.was_run = True |
| 374 websitetest.WrongLoginTest() | 369 websitetest.WrongLoginTest() |
| 375 websitetest.SuccessfulLoginTest() | 370 websitetest.SuccessfulLoginTest() |
| 371 self.ClearCache(False) |
| 376 websitetest.SuccessfulLoginWithAutofilledPasswordTest() | 372 websitetest.SuccessfulLoginWithAutofilledPasswordTest() |
| 377 self.RemoveAllPasswords() | 373 self.ClearCache(True) |
| 378 websitetest.SuccessfulLoginTest() | 374 websitetest.SuccessfulLoginTest() |
| 375 self.ClearCache(True) |
| 379 except Exception: | 376 except Exception: |
| 380 successful = False | 377 successful = False |
| 381 error = traceback.format_exc() | 378 error = traceback.format_exc() |
| 382 self.tests_results.append(TestResult(websitetest.name, "normal", | 379 self.tests_results.append(TestResult(websitetest.name, "normal", |
| 383 successful, escape(error))) | 380 successful, escape(error))) |
| 384 | 381 |
| 382 |
| 385 def PromptTestList(self, websitetests): | 383 def PromptTestList(self, websitetests): |
| 386 """Runs the prompt tests on the websites in |websitetests|. | 384 """Runs the prompt tests on the websites in |websitetests|. |
| 387 | 385 |
| 388 Args: | 386 Args: |
| 389 websitetests: A list of WebsiteTests that are going to be tested. | 387 websitetests: A list of WebsiteTests that are going to be tested. |
| 390 | 388 |
| 391 Raises: | 389 Raises: |
| 392 Exception: An exception is raised if the tests fail. | 390 Exception: An exception is raised if the tests fail. |
| 393 """ | 391 """ |
| 394 self.RemoveAllPasswords() | 392 self.ClearCache(True) |
| 395 | 393 |
| 396 for websitetest in websitetests: | 394 for websitetest in websitetests: |
| 397 successful = True | 395 successful = True |
| 398 error = "" | 396 error = "" |
| 399 try: | 397 try: |
| 400 websitetest.was_run = True | 398 websitetest.was_run = True |
| 401 websitetest.PromptTest() | 399 websitetest.PromptTest() |
| 402 except Exception: | 400 except Exception: |
| 403 successful = False | 401 successful = False |
| 404 error = traceback.format_exc() | 402 error = traceback.format_exc() |
| 405 self.tests_results.append(TestResult(websitetest.name, "prompt", | 403 self.tests_results.append(TestResult(websitetest.name, "prompt", |
| 406 successful, escape(error))) | 404 successful, escape(error))) |
| 407 | 405 |
| 408 def Quit(self): | 406 def Quit(self): |
| 409 """Closes the tests.""" | 407 """Closes the tests.""" |
| 410 # Close the webdriver. | 408 # Close the webdriver. |
| 411 self.driver.quit() | 409 self.driver.quit() |
| OLD | NEW |