Skip to content

Commit

Permalink
DNR: Remove equals operator for RulesetManager::Action.
Browse files Browse the repository at this point in the history
This is only used in tests. Instead provide a test only function to test
equality.

BUG=696822

Change-Id: I97ec7787aaea8ac0c73c662baa7fea05109e1364
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1595424
Commit-Queue: Karan Bhatia <karandeepb@chromium.org>
Reviewed-by: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657548}
  • Loading branch information
Karan Bhatia authored and Commit Bot committed May 8, 2019
1 parent 4f1b5aa commit 9e4ac2e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@

namespace extensions {
namespace declarative_net_request {

// Note: This is not declared in the anonymous namespace so that we can use it
// with gtest.
bool operator==(const RulesetManager::Action& lhs,
const RulesetManager::Action& rhs) {
static_assert(flat::ActionIndex_count == 6,
"Modify this method to ensure it stays updated as new actions "
"are added.");

auto are_vectors_equal = [](std::vector<const char*> a,
std::vector<const char*> b) {
return std::set<base::StringPiece>(a.begin(), a.end()) ==
std::set<base::StringPiece>(b.begin(), b.end());
};

return lhs.type == rhs.type && lhs.redirect_url == rhs.redirect_url &&
are_vectors_equal(lhs.request_headers_to_remove,
rhs.request_headers_to_remove) &&
are_vectors_equal(lhs.response_headers_to_remove,
rhs.response_headers_to_remove);
}

namespace {

constexpr char kJSONRulesFilename[] = "rules_file.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@ RulesetManager::Action::~Action() = default;
RulesetManager::Action::Action(Action&&) = default;
RulesetManager::Action& RulesetManager::Action::operator=(Action&&) = default;

bool RulesetManager::Action::operator==(const Action& that) const {
return type == that.type && redirect_url == that.redirect_url;
}

RulesetManager::RulesetManager(const InfoMap* info_map) : info_map_(info_map) {
DCHECK(info_map_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class RulesetManager {
Action(Action&&);
Action& operator=(Action&&);

bool operator==(const Action&) const;

Type type = Type::NONE;

// Valid iff |type| is |REDIRECT|.
Expand Down

0 comments on commit 9e4ac2e

Please sign in to comment.