1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// Copyright 2020 The Chromium Authors
// 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 ui {
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 test {
// SkiaGoldMatchingAlgorithm ---------------------------------------------------
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::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::~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::~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_)},
":"));
}
// PositiveIfOnlyImageAlgorithm ------------------------------------------------
PositiveIfOnlyImageAlgorithm::PositiveIfOnlyImageAlgorithm() = default;
PositiveIfOnlyImageAlgorithm::~PositiveIfOnlyImageAlgorithm() = default;
void PositiveIfOnlyImageAlgorithm::AppendAlgorithmToCmdline(
base::CommandLine& cmd) const {
SkiaGoldMatchingAlgorithm::AppendAlgorithmToCmdline(cmd);
// Disallow the user from triaging images.
cmd.AppendSwitchASCII("add-test-optional-key", "disallow_triaging:true");
}
std::string PositiveIfOnlyImageAlgorithm::GetCommandLineSwitchName() const {
return "positive_if_only_image";
}
} // namespace test
} // namespace ui
|