| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright 2009, Google Inc. | 2 # Copyright 2009, Google Inc. |
| 3 # All rights reserved. | 3 # All rights reserved. |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 if not os.path.exists(pdiff_path): | 776 if not os.path.exists(pdiff_path): |
| 777 # Perceptualdiff.exe does not exist, fail. | 777 # Perceptualdiff.exe does not exist, fail. |
| 778 results.AddFailure( | 778 results.AddFailure( |
| 779 test_name, browser, | 779 test_name, browser, |
| 780 "Perceptual diff %s does not exist." % pdiff_path) | 780 "Perceptual diff %s does not exist." % pdiff_path) |
| 781 continue | 781 continue |
| 782 | 782 |
| 783 pixel_threshold = "10" | 783 pixel_threshold = "10" |
| 784 use_colorfactor = False | 784 use_colorfactor = False |
| 785 use_downsample = False | 785 use_downsample = False |
| 786 | 786 use_edge = True |
| 787 edge_threshold = "5" |
| 788 |
| 787 # Find out if the test specified any options relating to perceptual diff | 789 # Find out if the test specified any options relating to perceptual diff |
| 788 # that will override the defaults. | 790 # that will override the defaults. |
| 789 for opt in test_options: | 791 for opt in test_options: |
| 790 if opt.startswith("pdiff_threshold"): | 792 if opt.startswith("pdiff_threshold"): |
| 791 pixel_threshold = selenium_utilities.GetArgument(opt) | 793 pixel_threshold = selenium_utilities.GetArgument(opt) |
| 792 elif (opt.startswith("pdiff_threshold_mac") and | 794 elif (opt.startswith("pdiff_threshold_mac") and |
| 793 platform.system() == "Darwin"): | 795 platform.system() == "Darwin"): |
| 794 pixel_threshold = selenium_utilities.GetArgument(opt) | 796 pixel_threshold = selenium_utilities.GetArgument(opt) |
| 795 elif (opt.startswith("pdiff_threshold_win") and | 797 elif (opt.startswith("pdiff_threshold_win") and |
| 796 platform.system() == "Microsoft"): | 798 platform.system() == "Microsoft"): |
| 797 pixel_threshold = selenium_utilities.GetArgument(opt) | 799 pixel_threshold = selenium_utilities.GetArgument(opt) |
| 798 elif (opt.startswith("pdiff_threshold_linux") and | 800 elif (opt.startswith("pdiff_threshold_linux") and |
| 799 platform.system() == "Linux"): | 801 platform.system() == "Linux"): |
| 800 pixel_threshold = selenium_utilities.GetArgument(opt) | 802 pixel_threshold = selenium_utilities.GetArgument(opt) |
| 801 elif (opt.startswith("colorfactor")): | 803 elif (opt.startswith("colorfactor")): |
| 802 colorfactor = selenium_utilities.GetArgument(opt) | 804 colorfactor = selenium_utilities.GetArgument(opt) |
| 803 use_colorfactor = True | 805 use_colorfactor = True |
| 804 elif (opt.startswith("downsample")): | 806 elif (opt.startswith("downsample")): |
| 805 downsample_factor = selenium_utilities.GetArgument(opt) | 807 downsample_factor = selenium_utilities.GetArgument(opt) |
| 806 use_downsample = True | 808 use_downsample = True |
| 809 elif (opt.startswith("pdiff_edge_ignore_off")): |
| 810 use_edge = False |
| 811 elif (opt.startswith("pdiff_edge_threshold")): |
| 812 edge_threshold = selenium_utilities.GetArgument(opt) |
| 807 | 813 |
| 808 # Check if file exists | 814 # Check if file exists |
| 809 if os.path.exists(generated_file): | 815 if os.path.exists(generated_file): |
| 810 diff_file = os.path.join(base_path, screenshotsdir, | 816 diff_file = os.path.join(base_path, screenshotsdir, |
| 811 "compare_%s.png" % actual_name) | 817 "compare_%s.png" % actual_name) |
| 812 | 818 |
| 813 # Run perceptual diff | 819 # Run perceptual diff |
| 814 arguments = [pdiff_path, | 820 arguments = [pdiff_path, |
| 815 reference_file, | 821 reference_file, |
| 816 generated_file, | 822 generated_file, |
| 817 "-output", diff_file, | 823 "-output", diff_file, |
| 818 "-fov", "45", | 824 "-fov", "45", |
| 819 # Turn on verbose output for the percetual diff so we | 825 # Turn on verbose output for the percetual diff so we |
| 820 # can see how far off we are on the threshold. | 826 # can see how far off we are on the threshold. |
| 821 "-verbose", | 827 "-verbose", |
| 822 # Set the threshold to zero so we can get a count | 828 # Set the threshold to zero so we can get a count |
| 823 # of the different pixels. This causes the program | 829 # of the different pixels. This causes the program |
| 824 # to return failure for most images, but we can compare | 830 # to return failure for most images, but we can compare |
| 825 # the values ourselves below. | 831 # the values ourselves below. |
| 826 "-threshold", "0"] | 832 "-threshold", "0"] |
| 827 if use_colorfactor: | 833 if use_colorfactor: |
| 828 arguments += ["-colorfactor", colorfactor] | 834 arguments += ["-colorfactor", colorfactor] |
| 829 if use_downsample: | 835 if use_downsample: |
| 830 arguments += ["-downsample", downsample_factor] | 836 arguments += ["-downsample", downsample_factor] |
| 831 | 837 if use_edge: |
| 838 arguments += ["-ignoreEdges", edge_threshold] |
| 839 |
| 832 # Print the perceptual diff command line so we can debug easier. | 840 # Print the perceptual diff command line so we can debug easier. |
| 833 if verbose: | 841 if verbose: |
| 834 print " ".join(arguments) | 842 print " ".join(arguments) |
| 835 | 843 |
| 836 # diff tool should return 0 on success | 844 # diff tool should return 0 on success |
| 837 expected_result = 0 | 845 expected_result = 0 |
| 838 | 846 |
| 839 pdiff_pipe = subprocess.Popen(arguments, | 847 pdiff_pipe = subprocess.Popen(arguments, |
| 840 stdout=subprocess.PIPE, | 848 stdout=subprocess.PIPE, |
| 841 stderr=subprocess.PIPE) | 849 stderr=subprocess.PIPE) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 if all_tests_passed: | 953 if all_tests_passed: |
| 946 # All tests successful. | 954 # All tests successful. |
| 947 return 0 | 955 return 0 |
| 948 else: | 956 else: |
| 949 # Return error code 1. | 957 # Return error code 1. |
| 950 return 1 | 958 return 1 |
| 951 | 959 |
| 952 if __name__ == "__main__": | 960 if __name__ == "__main__": |
| 953 remaining_argv = FLAGS(sys.argv) | 961 remaining_argv = FLAGS(sys.argv) |
| 954 main(remaining_argv) | 962 main(remaining_argv) |
| OLD | NEW |