Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: components/test/data/password_manager/automated_tests/tests.py

Issue 1026833003: [Password manager Python tests] Re-arrange tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Automated tests for many websites""" 6 """Automated tests for many websites"""
7 7
8 import argparse 8 import argparse
9 9
10 from environment import Environment 10 from environment import Environment
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 "vube": Vube("vube"), # http://crbug.com/368690 468 "vube": Vube("vube"), # http://crbug.com/368690
469 "wikia": Wikia("wikia"), 469 "wikia": Wikia("wikia"),
470 "wikipedia": Wikipedia("wikipedia", username_not_auto=True), 470 "wikipedia": Wikipedia("wikipedia", username_not_auto=True),
471 "wordpress": Wordpress("wordpress"), 471 "wordpress": Wordpress("wordpress"),
472 "yahoo": Yahoo("yahoo", username_not_auto=True), 472 "yahoo": Yahoo("yahoo", username_not_auto=True),
473 "yandex": Yandex("yandex"), 473 "yandex": Yandex("yandex"),
474 "ziddu": Ziddu("ziddu"), # Password not saved. 474 "ziddu": Ziddu("ziddu"), # Password not saved.
475 } 475 }
476 476
477 477
478 def saveResults(environment_tests_results, environment_save_path): 478 def SaveResults(environment_tests_results, environment_save_path):
479 """Save the test results in an xml file. 479 """Save the test results in an xml file.
480 480
481 Args: 481 Args:
482 environment_tests_results: A list of the TestResults that are going to be 482 environment_tests_results: A list of the TestResults that are going to be
483 saved. 483 saved.
484 environment_save_path: The file where the results are going to be saved. 484 environment_save_path: The file where the results are going to be saved.
485 If it's None, the results are not going to be stored. 485 If it's None, the results are not going to be stored.
486 Raises: 486 Raises:
487 Exception: An exception is raised if the file is not found. 487 Exception: An exception is raised if the file is not found.
488 """ 488 """
489 if environment_save_path: 489 if environment_save_path:
490 xml = "<result>" 490 xml = "<result>"
491 for test_result in environment_tests_results: 491 for (name, test_type, success, failure_log) in environment_tests_results:
492 xml += ("<test name='%s' successful='%s' type='%s'>%s</test>" 492 xml += (
493 % (test_result.name, str(test_result.successful), 493 "<test name='{0}' successful='{1}' type='{2}'>{3}</test>".format(
494 test_result.test_type, test_result.message)) 494 name, success, test_type, failure_log))
495 xml += "</result>" 495 xml += "</result>"
496 with open(environment_save_path, "w") as save_file: 496 with open(environment_save_path, "w") as save_file:
497 save_file.write(xml) 497 save_file.write(xml)
498 498
499 def RunTest(chrome_path, chromedriver_path, profile_path, 499 def RunTest(chrome_path, chromedriver_path, profile_path,
500 environment_passwords_path, enable_automatic_password_saving, 500 environment_passwords_path, website_test_name, test_type):
501 website_test_name):
502 """Runs the test for the specified website. 501 """Runs the test for the specified website.
503 502
504 Args: 503 Args:
505 chrome_path: The chrome binary file. 504 chrome_path: The chrome binary file.
506 chromedriver_path: The chromedriver binary file. 505 chromedriver_path: The chromedriver binary file.
507 profile_path: The chrome testing profile folder. 506 profile_path: The chrome testing profile folder.
508 environment_passwords_path: The usernames and passwords file. 507 environment_passwords_path: The usernames and passwords file.
509 enable_automatic_password_saving: If True, the passwords are going to be
510 saved without showing the prompt.
511 website_test_name: Name of the website to test (refer to keys in 508 website_test_name: Name of the website to test (refer to keys in
512 all_tests above). 509 all_tests above).
513 510
514 Returns: 511 Returns:
515 The results of the test as list of TestResults. 512 The results of the test as list of TestResults.
516 513
517 Raises: 514 Raises:
518 Exception: An exception is raised if one of the tests for the website 515 Exception: An exception is raised if one of the tests for the website
519 fails, or if the website name is not known. 516 fails, or if the website name is not known.
520 """ 517 """
521 518
519 enable_automatic_password_saving = (
520 test_type == WebsiteTest.TEST_TYPE_SAVE_AND_AUTOFILL)
522 environment = Environment(chrome_path, chromedriver_path, profile_path, 521 environment = Environment(chrome_path, chromedriver_path, profile_path,
523 environment_passwords_path, 522 environment_passwords_path,
524 enable_automatic_password_saving) 523 enable_automatic_password_saving)
525 524
526 # Test which care about the save-password prompt need the prompt
527 # to be shown. Automatic password saving results in no prompt.
528 run_prompt_tests = not enable_automatic_password_saving
529
530 if website_test_name in all_tests: 525 if website_test_name in all_tests:
531 environment.AddWebsiteTest(all_tests[website_test_name]) 526 environment.AddWebsiteTest(all_tests[website_test_name])
532 else: 527 else:
533 raise Exception("Test name {} is unknown.".format(website_test_name)) 528 raise Exception("Test name {} is unknown.".format(website_test_name))
534 529
535 environment.AllTests(run_prompt_tests) 530 environment.RunTestsOnSites(test_type)
536
537 environment.Quit() 531 environment.Quit()
538 return environment.tests_results 532 return environment.tests_results
539 533
540 # Tests setup. 534 def main():
541 if __name__ == "__main__":
542 parser = argparse.ArgumentParser( 535 parser = argparse.ArgumentParser(
543 description="Password Manager automated tests help.") 536 description="Password Manager automated tests help.")
544 537
545 parser.add_argument( 538 parser.add_argument(
546 "--chrome-path", action="store", dest="chrome_path", 539 "--chrome-path", action="store", dest="chrome_path",
547 help="Set the chrome path (required).", required=True) 540 help="Set the chrome path (required).", required=True)
548 parser.add_argument( 541 parser.add_argument(
549 "--chromedriver-path", action="store", dest="chromedriver_path", 542 "--chromedriver-path", action="store", dest="chromedriver_path",
550 help="Set the chromedriver path (required).", required=True) 543 help="Set the chromedriver path (required).", required=True)
551 parser.add_argument( 544 parser.add_argument(
552 "--profile-path", action="store", dest="profile_path", 545 "--profile-path", action="store", dest="profile_path",
553 help="Set the profile path (required). You just need to choose a " 546 help="Set the profile path (required). You just need to choose a "
554 "temporary empty folder. If the folder is not empty all its content " 547 "temporary empty folder. If the folder is not empty all its content "
555 "is going to be removed.", 548 "is going to be removed.",
556 required=True) 549 required=True)
557 550
558 parser.add_argument( 551 parser.add_argument(
559 "--passwords-path", action="store", dest="passwords_path", 552 "--passwords-path", action="store", dest="passwords_path",
560 help="Set the usernames/passwords path (required).", required=True) 553 help="Set the usernames/passwords path (required).", required=True)
561 parser.add_argument("--save-path", action="store", dest="save_path", 554 parser.add_argument("--save-path", action="store", dest="save_path",
562 help="Write the results in a file.") 555 help="Write the results in a file.")
563 parser.add_argument("test", help="Test to be run.") 556 parser.add_argument("test", help="Test to be run.")
564 557
565 args = parser.parse_args() 558 args = parser.parse_args()
566 559
567 save_path = None 560 save_path = None
568 if args.save_path: 561 if args.save_path:
569 save_path = args.save_path 562 save_path = args.save_path
570 563
571 # Run the test without enable-automatic-password-saving to check whether or 564 tests_results = RunTest(
572 # not the prompt is shown in the way we expected. 565 args.chrome_path, args.chromedriver_path, args.profile_path,
573 tests_results = RunTest(args.chrome_path, 566 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_PROMPT_FAIL)
574 args.chromedriver_path,
575 args.profile_path,
576 args.passwords_path,
577 False,
578 args.test)
579 567
580 # Run the test with enable-automatic-password-saving to check whether or not 568 tests_results += RunTest(
581 # the passwords is stored in the the way we expected. 569 args.chrome_path, args.chromedriver_path, args.profile_path,
582 tests_results += RunTest(args.chrome_path, 570 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_PROMPT_SUCCESS)
583 args.chromedriver_path,
584 args.profile_path,
585 args.passwords_path,
586 True,
587 args.test)
588 571
589 saveResults(tests_results, save_path) 572 tests_results += RunTest(
573 args.chrome_path, args.chromedriver_path, args.profile_path,
574 args.passwords_path, args.test, WebsiteTest.TEST_TYPE_SAVE_AND_AUTOFILL)
575
576 SaveResults(tests_results, save_path)
577
578 if __name__ == "__main__":
579 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698