| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 negation = "" | 182 negation = "" |
| 183 if clear_passwords: | 183 if clear_passwords: |
| 184 negation = "!" | 184 negation = "!" |
| 185 script += ( | 185 script += ( |
| 186 "if (%sdocument.querySelector('#delete-passwords-checkbox').checked)" | 186 "if (%sdocument.querySelector('#delete-passwords-checkbox').checked)" |
| 187 " document.querySelector('#delete-passwords-checkbox').click();" | 187 " document.querySelector('#delete-passwords-checkbox').click();" |
| 188 % negation) | 188 % negation) |
| 189 script += "document.querySelector('#clear-browser-data-commit').click();" | 189 script += "document.querySelector('#clear-browser-data-commit').click();" |
| 190 self.driver.execute_script(script) | 190 self.driver.execute_script(script) |
| 191 time.sleep(2) | 191 time.sleep(2) |
| 192 # Every time we do something to the cache let's enable password saving. |
| 193 # TODO(melandory): We should check why it's off in a first place. |
| 194 # TODO(melandory): Investigate, maybe there is no need to enable it that |
| 195 # often. |
| 196 self.EnablePasswordsSaving() |
| 197 |
| 198 def EnablePasswordsSaving(self): |
| 199 logging.info("\nEnablePasswordSaving\n") |
| 200 self.driver.get("chrome://settings") |
| 201 self.driver.switch_to_frame("settings") |
| 202 script = "document.getElementById('advanced-settings-expander').click();" |
| 203 self.driver.execute_script(script) |
| 204 time.sleep(2) |
| 205 script = ( |
| 206 "if (!document.querySelector('#password-manager-enabled').checked)" |
| 207 "{ document.querySelector('#password-manager-enabled').click();}") |
| 208 self.driver.execute_script(script) |
| 209 time.sleep(2) |
| 192 | 210 |
| 193 def OpenTabAndGoToInternals(self, url): | 211 def OpenTabAndGoToInternals(self, url): |
| 194 """If there is no |self.website_window|, opens a new tab and navigates to | 212 """If there is no |self.website_window|, opens a new tab and navigates to |
| 195 |url| in the new tab. Navigates to the passwords internals page in the | 213 |url| in the new tab. Navigates to the passwords internals page in the |
| 196 first tab. Raises an exception otherwise. | 214 first tab. Raises an exception otherwise. |
| 197 | 215 |
| 198 Args: | 216 Args: |
| 199 url: Url to go to in the new tab. | 217 url: Url to go to in the new tab. |
| 200 | 218 |
| 201 Raises: | 219 Raises: |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 websitetest.was_run = True | 386 websitetest.was_run = True |
| 369 websitetest.WrongLoginTest() | 387 websitetest.WrongLoginTest() |
| 370 websitetest.SuccessfulLoginTest() | 388 websitetest.SuccessfulLoginTest() |
| 371 self.ClearCache(False) | 389 self.ClearCache(False) |
| 372 websitetest.SuccessfulLoginWithAutofilledPasswordTest() | 390 websitetest.SuccessfulLoginWithAutofilledPasswordTest() |
| 373 self.ClearCache(True) | 391 self.ClearCache(True) |
| 374 websitetest.SuccessfulLoginTest() | 392 websitetest.SuccessfulLoginTest() |
| 375 self.ClearCache(True) | 393 self.ClearCache(True) |
| 376 except Exception as e: | 394 except Exception as e: |
| 377 successful = False | 395 successful = False |
| 396 error = e.message |
| 378 self.tests_results.append(TestResult(websitetest.name, "normal", | 397 self.tests_results.append(TestResult(websitetest.name, "normal", |
| 379 successful, e.message)) | 398 successful, error)) |
| 380 | 399 |
| 381 | 400 |
| 382 def PromptTestList(self, websitetests): | 401 def PromptTestList(self, websitetests): |
| 383 """Runs the prompt tests on the websites in |websitetests|. | 402 """Runs the prompt tests on the websites in |websitetests|. |
| 384 | 403 |
| 385 Args: | 404 Args: |
| 386 websitetests: A list of WebsiteTests that are going to be tested. | 405 websitetests: A list of WebsiteTests that are going to be tested. |
| 387 | 406 |
| 388 Raises: | 407 Raises: |
| 389 Exception: An exception is raised if the tests fail. | 408 Exception: An exception is raised if the tests fail. |
| 390 """ | 409 """ |
| 391 self.ClearCache(True) | 410 self.ClearCache(True) |
| 392 | 411 |
| 393 for websitetest in websitetests: | 412 for websitetest in websitetests: |
| 394 successful = True | 413 successful = True |
| 395 error = "" | 414 error = "" |
| 396 try: | 415 try: |
| 397 websitetest.was_run = True | 416 websitetest.was_run = True |
| 398 websitetest.PromptTest() | 417 websitetest.PromptTest() |
| 399 except Exception as e: | 418 except Exception as e: |
| 400 successful = False | 419 successful = False |
| 420 error = e.message |
| 401 self.tests_results.append(TestResult(websitetest.name, "prompt", | 421 self.tests_results.append(TestResult(websitetest.name, "prompt", |
| 402 successful, e.message)) | 422 successful, error)) |
| 403 | 423 |
| 404 def Quit(self): | 424 def Quit(self): |
| 405 """Closes the tests.""" | 425 """Closes the tests.""" |
| 406 # Close the webdriver. | 426 # Close the webdriver. |
| 407 self.driver.quit() | 427 self.driver.quit() |
| OLD | NEW |