-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BrowserWindowInterface mock for split view tests
Upstream code chains calls to GetBrowserWindowInterface() in several places now, preventing the use of TestTabStripModelDelegate as-is in our SplitView unit tests. This subclass provides a mock implementation of BrowserWindowInterface that can be returned instead.
- Loading branch information
Showing
5 changed files
with
248 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
browser/ui/tabs/test/browser_window_interface_test_tab_strip_delegate.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* 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/. */ | ||
|
||
#include "brave/browser/ui/tabs/test/browser_window_interface_test_tab_strip_delegate.h" | ||
|
||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/browser_window/public/browser_window_features.h" | ||
#include "url/gurl.h" | ||
|
||
BrowserWindowInterfaceTestTabStripModelDelegate::TestBrowserWindowInterface:: | ||
TestBrowserWindowInterface(Profile* profile) | ||
: profile_(profile), | ||
session_id_(SessionID::InvalidValue()), | ||
features_(BrowserWindowFeatures::CreateBrowserWindowFeatures()) {} | ||
|
||
BrowserWindowInterfaceTestTabStripModelDelegate::TestBrowserWindowInterface:: | ||
~TestBrowserWindowInterface() = default; | ||
|
||
views::WebView* BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::GetWebView() { | ||
return nullptr; | ||
} | ||
|
||
Profile* BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::GetProfile() { | ||
return profile_; | ||
} | ||
|
||
void BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::OpenGURL(const GURL& gurl, | ||
WindowOpenDisposition disposition) {} | ||
|
||
content::WebContents* BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::OpenURL( | ||
const content::OpenURLParams& params, | ||
base::OnceCallback<void(content::NavigationHandle&)> | ||
navigation_handle_callback) { | ||
return nullptr; | ||
} | ||
|
||
const SessionID& BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::GetSessionID() { | ||
return session_id_; | ||
} | ||
|
||
bool BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::IsTabStripVisible() { | ||
return false; | ||
} | ||
|
||
views::View* BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::TopContainer() { | ||
return nullptr; | ||
} | ||
|
||
tabs::TabInterface* BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::GetActiveTabInterface() { | ||
return nullptr; | ||
} | ||
|
||
BrowserWindowFeatures& BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::GetFeatures() { | ||
return *features_; | ||
} | ||
|
||
web_modal::WebContentsModalDialogHost* | ||
BrowserWindowInterfaceTestTabStripModelDelegate::TestBrowserWindowInterface:: | ||
GetWebContentsModalDialogHostForWindow() { | ||
return nullptr; | ||
} | ||
|
||
bool BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::IsActive() { | ||
return false; | ||
} | ||
|
||
base::CallbackListSubscription BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::RegisterDidBecomeActive( | ||
DidBecomeActiveCallback callback) { | ||
return did_become_active_callback_list_.Add(std::move(callback)); | ||
} | ||
|
||
base::CallbackListSubscription BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::RegisterDidBecomeInactive( | ||
DidBecomeInactiveCallback callback) { | ||
return did_become_inactive_callback_list_.Add(std::move(callback)); | ||
} | ||
|
||
ExclusiveAccessManager* BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::GetExclusiveAccessManager() { | ||
return nullptr; | ||
} | ||
|
||
BrowserActions* BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::GetActions() { | ||
return nullptr; | ||
} | ||
|
||
BrowserWindowInterface::Type BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
TestBrowserWindowInterface::GetType() const { | ||
return TYPE_NORMAL; | ||
} | ||
|
||
user_education::FeaturePromoController* | ||
BrowserWindowInterfaceTestTabStripModelDelegate::TestBrowserWindowInterface:: | ||
GetFeaturePromoController() { | ||
return nullptr; | ||
} | ||
|
||
BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
BrowserWindowInterfaceTestTabStripModelDelegate(Profile* profile) | ||
: interface_(std::make_unique<TestBrowserWindowInterface>(profile)) {} | ||
|
||
BrowserWindowInterfaceTestTabStripModelDelegate:: | ||
~BrowserWindowInterfaceTestTabStripModelDelegate() = default; | ||
|
||
BrowserWindowInterface* | ||
BrowserWindowInterfaceTestTabStripModelDelegate::GetBrowserWindowInterface() { | ||
return interface_.get(); | ||
} |
98 changes: 98 additions & 0 deletions
98
browser/ui/tabs/test/browser_window_interface_test_tab_strip_delegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* 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/. */ | ||
|
||
#include <memory> | ||
|
||
#include "chrome/browser/ui/browser_window/public/browser_window_features.h" | ||
#include "chrome/browser/ui/browser_window/public/browser_window_interface.h" | ||
#include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" | ||
#include "components/sessions/core/session_id.h" | ||
#include "url/gurl.h" | ||
|
||
class BrowserActions; | ||
class ExclusiveAccessManager; | ||
class Profile; | ||
|
||
namespace content { | ||
class WebContents; | ||
} | ||
|
||
namespace tabs { | ||
class TabInterface; | ||
} | ||
|
||
namespace user_education { | ||
class FeaturePromoController; | ||
} | ||
|
||
namespace views { | ||
class WebView; | ||
} | ||
|
||
// Implements TestTabStripModelDelegate with a mocked BrowserWindowInterface | ||
class BrowserWindowInterfaceTestTabStripModelDelegate | ||
: public TestTabStripModelDelegate { | ||
public: | ||
class TestBrowserWindowInterface : public BrowserWindowInterface { | ||
public: | ||
explicit TestBrowserWindowInterface(Profile* profile); | ||
~TestBrowserWindowInterface() override; | ||
TestBrowserWindowInterface(const TestBrowserWindowInterface&) = delete; | ||
TestBrowserWindowInterface& operator=(const TestBrowserWindowInterface&) = | ||
delete; | ||
|
||
// BrowserWindowInterface: | ||
views::WebView* GetWebView() override; | ||
Profile* GetProfile() override; | ||
void OpenGURL(const GURL& gurl, WindowOpenDisposition disposition) override; | ||
content::WebContents* OpenURL( | ||
const content::OpenURLParams& params, | ||
base::OnceCallback<void(content::NavigationHandle&)> | ||
navigation_handle_callback) override; | ||
const SessionID& GetSessionID() override; | ||
bool IsTabStripVisible() override; | ||
views::View* TopContainer() override; | ||
tabs::TabInterface* GetActiveTabInterface() override; | ||
BrowserWindowFeatures& GetFeatures() override; | ||
web_modal::WebContentsModalDialogHost* | ||
GetWebContentsModalDialogHostForWindow() override; | ||
bool IsActive() override; | ||
base::CallbackListSubscription RegisterDidBecomeActive( | ||
DidBecomeActiveCallback callback) override; | ||
base::CallbackListSubscription RegisterDidBecomeInactive( | ||
DidBecomeInactiveCallback callback) override; | ||
ExclusiveAccessManager* GetExclusiveAccessManager() override; | ||
BrowserActions* GetActions() override; | ||
BrowserWindowInterface::Type GetType() const override; | ||
user_education::FeaturePromoController* GetFeaturePromoController() | ||
override; | ||
|
||
private: | ||
raw_ptr<Profile> profile_; | ||
SessionID session_id_; | ||
std::unique_ptr<BrowserWindowFeatures> features_; | ||
|
||
using DidBecomeActiveCallbackList = | ||
base::RepeatingCallbackList<void(BrowserWindowInterface*)>; | ||
DidBecomeActiveCallbackList did_become_active_callback_list_; | ||
|
||
using DidBecomeInactiveCallbackList = | ||
base::RepeatingCallbackList<void(BrowserWindowInterface*)>; | ||
DidBecomeInactiveCallbackList did_become_inactive_callback_list_; | ||
}; | ||
|
||
explicit BrowserWindowInterfaceTestTabStripModelDelegate(Profile* profile); | ||
~BrowserWindowInterfaceTestTabStripModelDelegate() override; | ||
BrowserWindowInterfaceTestTabStripModelDelegate( | ||
const BrowserWindowInterfaceTestTabStripModelDelegate&) = delete; | ||
BrowserWindowInterfaceTestTabStripModelDelegate& operator=( | ||
const BrowserWindowInterfaceTestTabStripModelDelegate&) = delete; | ||
|
||
// TestTabStripModelDelegate: | ||
BrowserWindowInterface* GetBrowserWindowInterface() override; | ||
|
||
private: | ||
std::unique_ptr<BrowserWindowInterface> interface_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters