This chage corrects several places where `BrowserList::begin()/end()` were being used to iterate over the existing browsers, and replaces it with `GlobalBrowserCollection::GetInstance()->ForEach`. This is a crude fix, and there are possibly better ways to approach some of these problems. Chromium changes: https://chromium.googlesource.com/chromium/src/+/c109836647bb0459d8076484ba1b1cc5b5b44b4d commit c109836647bb0459d8076484ba1b1cc5b5b44b4d Author: Qikai <qikaizhong@microsoft.com> Date: Thu Jan 29 00:51:37 2026 -0800 [bedrock] Migrate last BrowserList begin/end usages Migrate BrowserList::begin()/end() to GlobalBrowserCollection and BrowserListObserver to BrowserCollectionObserver where appropriate. Changes: - Update callers of begin()/end() to use GlobalBrowserCollection::ForEach() - Migrate BrowserListObserver to BrowserCollectionObserver - Move BrowserList::begin()/end() to private section - Remove deprecated BrowserList apis Bug: 431671320 Change-Id: I8b1b1556081590df2f0a02796452be53dd5d28ca Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7508892 Reviewed-by: Tom Lukaszewicz <tluk@chromium.org> Commit-Queue: Qikai Zhong <qikaizhong@microsoft.com> Cr-Commit-Position: refs/heads/main@{#1576420}
82 lines
3.1 KiB
C++
82 lines
3.1 KiB
C++
// Copyright (c) 2025 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 "base/test/run_until.h"
|
|
#include "base/test/scoped_feature_list.h"
|
|
#include "brave/browser/ui/brave_ui_features.h"
|
|
#include "chrome/browser/ui/browser_finder.h"
|
|
#include "chrome/browser/ui/browser_window/public/global_browser_collection.h"
|
|
#include "chrome/test/base/in_process_browser_test.h"
|
|
#include "chrome/test/base/ui_test_utils.h"
|
|
#include "components/blocked_content/popup_blocker_tab_helper.h"
|
|
#include "content/public/test/browser_test.h"
|
|
#include "content/public/test/browser_test_utils.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
class BrowserNavigatorPopupAsTabBrowserTest
|
|
: public InProcessBrowserTest,
|
|
public ::testing::WithParamInterface<bool> {
|
|
public:
|
|
BrowserNavigatorPopupAsTabBrowserTest() {
|
|
EXPECT_FALSE(
|
|
base::FeatureList::IsEnabled(features::kForcePopupToBeOpenedAsTab))
|
|
<< "Feature should be disabled by default";
|
|
if (GetParam()) {
|
|
feature_list_.InitAndEnableFeature(features::kForcePopupToBeOpenedAsTab);
|
|
} else {
|
|
feature_list_.InitAndDisableFeature(features::kForcePopupToBeOpenedAsTab);
|
|
}
|
|
}
|
|
~BrowserNavigatorPopupAsTabBrowserTest() override = default;
|
|
|
|
bool ShouldOpenPopupAsTab() const {
|
|
return base::FeatureList::IsEnabled(features::kForcePopupToBeOpenedAsTab);
|
|
}
|
|
|
|
private:
|
|
base::test::ScopedFeatureList feature_list_;
|
|
};
|
|
|
|
IN_PROC_BROWSER_TEST_P(BrowserNavigatorPopupAsTabBrowserTest, OpenPopupAsTab) {
|
|
ASSERT_EQ(1, browser()->tab_strip_model()->count());
|
|
auto* web_contents = browser()->GetTabStripModel()->GetWebContentsAt(0);
|
|
ASSERT_TRUE(content::ExecJs(
|
|
web_contents->GetPrimaryMainFrame(),
|
|
"window.open('about:blank', '_blank', 'height=200,width=150');"));
|
|
auto* popup_blocker_tab_helper =
|
|
blocked_content::PopupBlockerTabHelper::FromWebContents(web_contents);
|
|
ASSERT_TRUE(popup_blocker_tab_helper);
|
|
|
|
if (ShouldOpenPopupAsTab()) {
|
|
EXPECT_TRUE(base::test::RunUntil([&]() {
|
|
if (popup_blocker_tab_helper->GetBlockedPopupsCount() != 0) {
|
|
popup_blocker_tab_helper->ShowAllBlockedPopups();
|
|
}
|
|
return browser()->tab_strip_model()->count() == 2;
|
|
}));
|
|
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
|
|
} else {
|
|
EXPECT_TRUE(base::test::RunUntil([&]() {
|
|
if (popup_blocker_tab_helper->GetBlockedPopupsCount() != 0) {
|
|
popup_blocker_tab_helper->ShowAllBlockedPopups();
|
|
}
|
|
return chrome::GetTotalBrowserCount() == 2;
|
|
}));
|
|
GlobalBrowserCollection::GetInstance()->ForEach(
|
|
[this](BrowserWindowInterface* b) {
|
|
if (b == browser()) {
|
|
return true;
|
|
}
|
|
EXPECT_TRUE(b->GetBrowserForMigrationOnly()->is_type_popup());
|
|
return true;
|
|
});
|
|
EXPECT_EQ(1, browser()->tab_strip_model()->count());
|
|
}
|
|
}
|
|
|
|
INSTANTIATE_TEST_SUITE_P(All,
|
|
BrowserNavigatorPopupAsTabBrowserTest,
|
|
::testing::Bool());
|