Files
brave-core/app/command_utils_unittest.cc
T
cdesouza-chromium cfaf4c8d49 [CodeHealth][cr146] base::Contains() to be deleted (#33668)
[CodeHealth] `base::Contains()` to be deleted

The remaining cases of `base::Contains` in the codebase can be just
`std::ranges::contains`.

This change was done mechanically, with the following script

```bash
files_using_header="$(git grep -l base::Contains | tr '\n' ' ')"
sed -i 's/base::Contains/std::ranges::contains/g' \
  ${files_using_header}
../tools/add_header.py --header '<algorithm>' ${files_using_header}
files_including_header="$(git grep -l base/containers/contains.h | tr '\n' ' ')"
../tools/add_header.py --header '"base/containers/contains.h"' \
  --remove ${files_including_header}
git cl format
```

This CL also cherry-picks the contents of https://crrev.com/c/7380987 to
permit the use of certain range operations.

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/4e6249c911b515cc237707ba751290c6dbe9970f

commit 4e6249c911b515cc237707ba751290c6dbe9970f
Author: Victor Hugo Vianna Silva <victorvianna@google.com>
Date:   Sun Jan 18 11:32:26 2026 -0800

    Reland "Delete unused base::Contains()"

    This is a reland of commit 15af921783afac76cfc7d5beb04e4816ac0ffac7

    Original change's description:
    > Delete unused base::Contains()
    >
    > All callers were migrated.
    >
    > Fixed: 470391351
    > Change-Id: I404da9186a45c2c47669592242fac972ef70dfa3
    > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7459699
    > Auto-Submit: Victor Vianna <victorvianna@google.com>
    > Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
    > Reviewed-by: Francois Pierre Doray <fdoray@chromium.org>
    > Cr-Commit-Position: refs/heads/main@{#1570540}

    Bug: 470391351
    Change-Id: I858f7880bf8cb1857085eb44836dee4a0becf7ae
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7490440
    Owners-Override: Matthew Denton <mpdenton@chromium.org>
    Commit-Queue: Victor Vianna <victorvianna@google.com>
    Reviewed-by: Victor Vianna <victorvianna@google.com>
    Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
    Cr-Commit-Position: refs/heads/main@{#1570926}
2026-02-05 13:09:25 -03:00

48 lines
2.0 KiB
C++

// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#include "brave/app/command_utils.h"
#include <algorithm>
#include "base/containers/flat_set.h"
#include "base/test/scoped_feature_list.h"
#include "brave/components/commands/common/features.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/accelerator_table.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
// Note: If this test fails because an accelerated command isn't present just
// add the missing command to //brave/app/generate_command_metadata.py
TEST(CommandUtilsUnitTest, AllAcceleratedCommandsShouldBeAvailable) {
base::test::ScopedFeatureList features;
features.InitAndEnableFeature(commands::features::kBraveCommands);
auto accelerators = GetAcceleratorList();
const auto& commands = commands::GetCommands();
for (const auto& accelerator : accelerators) {
EXPECT_TRUE(std::ranges::contains(commands, accelerator.command_id))
<< "Accelerated command '" << accelerator.command_id
<< "' was not present in the list of commands.";
}
}
TEST(CommandUtilsUnitTest, NoTranslationsIncludeAmpersand) {
base::test::ScopedFeatureList features;
features.InitAndEnableFeature(commands::features::kBraveCommands);
for (const auto& command : commands::GetCommands()) {
auto translation = commands::GetCommandName(command);
EXPECT_THAT(translation, testing::Not(testing::HasSubstr("&")))
<< translation
<< " contains an '&' character. If this '&' is meant to be in the "
"translation then this might be a false positive, in which case the "
"test should be updated. The test is to ensure keyboard shortcuts "
"from menus are not included in the name of commands.";
}
}