Skip to content

Commit

Permalink
[DanglingPtr] Fix BrowserUserData dangling pointer (#26462)
Browse files Browse the repository at this point in the history
This patch was introduced during the switching on of the dangling
pointers detector, as a temporary measure.

The offending tests have been corrected to retrieve the
`BrowserUserData` instance from the active `browser()`, rather than
instantiating it as a `unique_ptr`.

Resolve brave/brave-browser#42187
  • Loading branch information
cdesouza-chromium authored Nov 9, 2024
1 parent db08fcf commit 3506ef6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
11 changes: 3 additions & 8 deletions browser/ui/tabs/test/split_view_browser_data_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class SplitViewBrowserDataBrowserTest : public InProcessBrowserTest {
: feature_list_(tabs::features::kBraveSplitView) {}
~SplitViewBrowserDataBrowserTest() override = default;

SplitViewBrowserData& data() { return *data_; }
SplitViewBrowserData& data() {
return *SplitViewBrowserData::FromBrowser(browser());
}

tabs::TabModel* CreateTabModel() {
content::WebContents::CreateParams params(browser()->profile());
Expand All @@ -36,15 +38,8 @@ class SplitViewBrowserDataBrowserTest : public InProcessBrowserTest {
return result;
}

// InProcessBrowserTest:
void SetUpOnMainThread() override {
CHECK(browser());
data_.reset(new SplitViewBrowserData(browser()));
}

private:
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<SplitViewBrowserData> data_;
};

IN_PROC_BROWSER_TEST_F(SplitViewBrowserDataBrowserTest, TileTabs_AddsTile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ class SplitViewTabStripModelAdapterBrowserTest : public InProcessBrowserTest {
TabStripModel* tab_strip_model() const {
return browser()->tab_strip_model();
}
SplitViewBrowserData& data() const { return *split_view_browser_data_; }
SplitViewBrowserData& data() const {
return *SplitViewBrowserData::FromBrowser(browser());
}
SplitViewTabStripModelAdapter& adapter() const {
return split_view_browser_data_->tab_strip_model_adapter_;
return SplitViewBrowserData::FromBrowser(browser())
->tab_strip_model_adapter_;
}

std::unique_ptr<content::WebContents> CreateWebContents() {
Expand All @@ -41,18 +44,8 @@ class SplitViewTabStripModelAdapterBrowserTest : public InProcessBrowserTest {
return web_contents;
}

// InProcessBrowserTest:
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

CHECK(browser());
split_view_browser_data_.reset(new SplitViewBrowserData(browser()));
}

private:
base::test::ScopedFeatureList feature_list_;

std::unique_ptr<SplitViewBrowserData> split_view_browser_data_;
};

IN_PROC_BROWSER_TEST_F(SplitViewTabStripModelAdapterBrowserTest,
Expand Down
13 changes: 0 additions & 13 deletions patches/chrome-browser-ui-browser_user_data.h.patch

This file was deleted.

0 comments on commit 3506ef6

Please sign in to comment.