123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // Copyright 2020 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "ui/base/test/skia_gold_matching_algorithm.h"
- #include "base/command_line.h"
- #include "base/notreached.h"
- #include "base/strings/string_number_conversions.h"
- #include "base/strings/string_util.h"
- namespace {
- constexpr char kMaxDifferentPixels[] = "fuzzy_max_different_pixels";
- constexpr char kPixelDeltaThreshold[] = "fuzzy_pixel_delta_threshold";
- constexpr char kEdgeThreshold[] = "sobel_edge_threshold";
- constexpr char kIgnoredBorderThickness[] = "fuzzy_ignored_border_thickness";
- } // namespace
- namespace ui {
- namespace test {
- SkiaGoldMatchingAlgorithm::SkiaGoldMatchingAlgorithm() = default;
- SkiaGoldMatchingAlgorithm::~SkiaGoldMatchingAlgorithm() = default;
- void SkiaGoldMatchingAlgorithm::AppendAlgorithmToCmdline(
- base::CommandLine& cmd) const {
- cmd.AppendSwitchASCII(
- "add-test-optional-key",
- base::JoinString({"image_matching_algorithm", GetCommandLineSwitchName()},
- ":"));
- }
- ExactSkiaGoldMatchingAlgorithm::ExactSkiaGoldMatchingAlgorithm() = default;
- ExactSkiaGoldMatchingAlgorithm::~ExactSkiaGoldMatchingAlgorithm() = default;
- std::string ExactSkiaGoldMatchingAlgorithm::GetCommandLineSwitchName() const {
- return "exact";
- }
- void ExactSkiaGoldMatchingAlgorithm::AppendAlgorithmToCmdline(
- base::CommandLine& cmd) const {
- // Do not call base class AppendAlgorithmToCmdline.
- // Nothing to append.
- }
- FuzzySkiaGoldMatchingAlgorithm::~FuzzySkiaGoldMatchingAlgorithm() = default;
- std::string FuzzySkiaGoldMatchingAlgorithm::GetCommandLineSwitchName() const {
- return "fuzzy";
- }
- FuzzySkiaGoldMatchingAlgorithm::FuzzySkiaGoldMatchingAlgorithm(
- int max_different_pixels,
- int pixel_delta_threshold,
- int ignored_border_thickness)
- : max_different_pixels_(max_different_pixels),
- pixel_delta_threshold_(pixel_delta_threshold),
- ignored_border_thickness_(ignored_border_thickness) {
- DCHECK_GT(max_different_pixels, 0);
- DCHECK_GT(pixel_delta_threshold, 0);
- DCHECK_LE(pixel_delta_threshold, 255 * 4);
- DCHECK_GE(ignored_border_thickness, 0);
- }
- void FuzzySkiaGoldMatchingAlgorithm::AppendAlgorithmToCmdline(
- base::CommandLine& cmd) const {
- SkiaGoldMatchingAlgorithm::AppendAlgorithmToCmdline(cmd);
- cmd.AppendSwitchASCII(
- "add-test-optional-key",
- base::JoinString(
- {kMaxDifferentPixels, base::NumberToString(max_different_pixels_)},
- ":"));
- cmd.AppendSwitchASCII(
- "add-test-optional-key",
- base::JoinString(
- {kPixelDeltaThreshold, base::NumberToString(pixel_delta_threshold_)},
- ":"));
- if (ignored_border_thickness_)
- cmd.AppendSwitchASCII(
- "add-test-optional-key",
- base::JoinString({kIgnoredBorderThickness,
- base::NumberToString(ignored_border_thickness_)},
- ":"));
- }
- SobelSkiaGoldMatchingAlgorithm::~SobelSkiaGoldMatchingAlgorithm() = default;
- std::string SobelSkiaGoldMatchingAlgorithm::GetCommandLineSwitchName() const {
- return "sobel";
- }
- SobelSkiaGoldMatchingAlgorithm::SobelSkiaGoldMatchingAlgorithm(
- int max_different_pixels,
- int pixel_delta_threshold,
- int edge_threshold,
- int ignored_border_thickness)
- : FuzzySkiaGoldMatchingAlgorithm(max_different_pixels,
- pixel_delta_threshold,
- ignored_border_thickness),
- edge_threshold_(edge_threshold) {
- DCHECK_GE(edge_threshold, 0);
- DCHECK_LE(edge_threshold, 255);
- }
- void SobelSkiaGoldMatchingAlgorithm::AppendAlgorithmToCmdline(
- base::CommandLine& cmd) const {
- FuzzySkiaGoldMatchingAlgorithm::AppendAlgorithmToCmdline(cmd);
- cmd.AppendSwitchASCII(
- "add-test-optional-key",
- base::JoinString({kEdgeThreshold, base::NumberToString(edge_threshold_)},
- ":"));
- }
- } // namespace test
- } // namespace ui
|