Chromium changes: https://chromium.googlesource.com/chromium/src/+/499cfaea23ab8386461cbfeec1c4a2dcbd8ca8f6 commit 499cfaea23ab8386461cbfeec1c4a2dcbd8ca8f6 Author: Thomas Lukaszewicz <tluk@chromium.org> Date: Wed Apr 22 11:19:07 2026 -0700 [bedrock] Remove BrowserList There are no remaining clients of BrowserList and no behavior changes in this CL. The changes involve removing the files and cleaning up any remaining includes / comments. Bug: 431671320 Change-Id: Ie61bbd3f8371cd5777d179d08ac4f47b9e29dd01 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7744394 Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org> Reviewed-by: Qikai Zhong <qikaizhong@microsoft.com> Cr-Commit-Position: refs/heads/main@{#1618978}
124 lines
4.6 KiB
C++
124 lines
4.6 KiB
C++
// Copyright (c) 2024 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/.
|
|
|
|
// Based on Chromium code subject to the following license:
|
|
// Copyright 2021 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "brave/browser/ui/commander/entity_match.h"
|
|
|
|
#include <algorithm>
|
|
#include <functional>
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "brave/browser/ui/commander/command_source.h"
|
|
#include "chrome/test/base/browser_with_test_window_test.h"
|
|
#include "chrome/test/base/test_browser_window.h"
|
|
#include "chrome/test/base/testing_profile.h"
|
|
#include "chrome/test/base/testing_profile_manager.h"
|
|
#include "chrome/test/base/ui_test_utils.h"
|
|
|
|
namespace commander {
|
|
|
|
class CommanderEntityMatchTest : public BrowserWithTestWindowTest {
|
|
public:
|
|
void SetUp() override {
|
|
BrowserWithTestWindowTest::SetUp();
|
|
ui_test_utils::DeprecatedFakeActivateBrowser(browser());
|
|
}
|
|
|
|
// Creates and returns a browser with `title` as its user title.
|
|
// If `profile` is provided, it is used, otherwise uses the profile of this
|
|
// test's browser.
|
|
std::unique_ptr<Browser> CreateAndActivateBrowser(
|
|
const std::string& title,
|
|
Profile* browser_profile = nullptr) {
|
|
Browser::CreateParams params(browser_profile ? browser_profile : profile(),
|
|
true);
|
|
auto browser = CreateBrowserWithTestWindowForParams(params);
|
|
browser->SetWindowUserTitle(title);
|
|
ui_test_utils::DeprecatedFakeActivateBrowser(browser.get());
|
|
return browser;
|
|
}
|
|
};
|
|
|
|
TEST_F(CommanderEntityMatchTest, WindowExcludesCurrentBrowser) {
|
|
std::string title("Title");
|
|
browser()->SetWindowUserTitle(title);
|
|
auto other_browser = CreateAndActivateBrowser(title);
|
|
|
|
auto matches =
|
|
WindowsMatchingInput(browser(), base::UTF8ToUTF16(title), false);
|
|
EXPECT_EQ(matches.size(), 1u);
|
|
}
|
|
|
|
TEST_F(CommanderEntityMatchTest, WindowIncludesAllProfilesIfUnrestricted) {
|
|
std::string title("Title");
|
|
|
|
auto same_profile_browser = CreateAndActivateBrowser(title);
|
|
TestingProfile* other_profile =
|
|
profile_manager()->CreateTestingProfile("other");
|
|
auto other_profile_browser = CreateAndActivateBrowser(title, other_profile);
|
|
|
|
auto matches =
|
|
WindowsMatchingInput(browser(), base::UTF8ToUTF16(title), false);
|
|
EXPECT_EQ(matches.size(), 2u);
|
|
}
|
|
|
|
TEST_F(CommanderEntityMatchTest, WindowOmitsNonmatchingProfilesIfRestricted) {
|
|
std::string title("Title");
|
|
auto same_profile_browser = CreateAndActivateBrowser(title);
|
|
|
|
TestingProfile* other_profile =
|
|
profile_manager()->CreateTestingProfile("other");
|
|
auto other_profile_browser = CreateAndActivateBrowser(title, other_profile);
|
|
|
|
auto matches =
|
|
WindowsMatchingInput(browser(), base::UTF8ToUTF16(title), true);
|
|
ASSERT_EQ(matches.size(), 1u);
|
|
EXPECT_EQ(matches.at(0).browser, same_profile_browser.get());
|
|
}
|
|
|
|
TEST_F(CommanderEntityMatchTest, WindowOnlyIncludesMatches) {
|
|
auto browser_with_match = CreateAndActivateBrowser("Orange juice");
|
|
auto browser_without_match = CreateAndActivateBrowser("Aqua regia");
|
|
|
|
auto matches = WindowsMatchingInput(browser(), u"orange", true);
|
|
ASSERT_EQ(matches.size(), 1u);
|
|
EXPECT_EQ(matches.at(0).browser, browser_with_match.get());
|
|
}
|
|
|
|
TEST_F(CommanderEntityMatchTest, WindowRanksMatches) {
|
|
auto browser_best_match = CreateAndActivateBrowser("Orange juice");
|
|
auto browser_good_match =
|
|
CreateAndActivateBrowser("Oracular Nouns Gesture Electrically");
|
|
|
|
auto matches = WindowsMatchingInput(browser(), u"orange", true);
|
|
ASSERT_EQ(matches.size(), 2u);
|
|
std::ranges::sort(matches, std::greater<>(), &WindowMatch::score);
|
|
EXPECT_EQ(matches.at(0).browser, browser_best_match.get());
|
|
}
|
|
|
|
TEST_F(CommanderEntityMatchTest, WindowMRUOrderWithNoInput) {
|
|
auto browser1 = CreateAndActivateBrowser("Beep");
|
|
auto browser2 = CreateAndActivateBrowser("Boop");
|
|
|
|
// Browser 2 was activated last, so we expect it to be the top match.
|
|
auto matches = WindowsMatchingInput(browser(), u"", true);
|
|
ASSERT_EQ(matches.size(), 2u);
|
|
std::ranges::sort(matches, std::greater<>(), &WindowMatch::score);
|
|
EXPECT_EQ(matches.at(0).browser, browser2.get());
|
|
|
|
ui_test_utils::DeprecatedFakeActivateBrowser(browser1.get());
|
|
// Activating browser 1 should have brought it to the top.
|
|
matches = WindowsMatchingInput(browser(), u"", true);
|
|
ASSERT_EQ(matches.size(), 2u);
|
|
std::ranges::sort(matches, std::greater<>(), &WindowMatch::score);
|
|
EXPECT_EQ(matches.at(0).browser, browser1.get());
|
|
}
|
|
|
|
} // namespace commander
|