Skip to content

Do not open brave://welcome in guest windows #17577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions browser/brave_scheme_load_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/omnibox/browser/location_bar_model.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/common/url_constants.h"
Expand Down Expand Up @@ -59,6 +60,31 @@ class BraveSchemeLoadBrowserTest : public InProcessBrowserTest,
return WaitForLoadStop(active_contents());
}

// Check loading |url| in guest window is not allowed for an url.
void TestURLIsNotLoadedInGuestWindow(const GURL& url) {
Browser* guest_browser = CreateGuestBrowser();
TabStripModel* guest_model = guest_browser->tab_strip_model();

// Check guest window has one blank tab.
EXPECT_EQ("about:blank",
guest_model->GetActiveWebContents()->GetVisibleURL().spec());
EXPECT_EQ(1, guest_model->count());
EXPECT_EQ("about:blank", active_contents()->GetVisibleURL().spec());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
Comment on lines +72 to +73
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these line can be deleted as we don't need to check normal window's state

// Unable to navigate expected url.
EXPECT_FALSE(
content::NavigateToURL(guest_model->GetActiveWebContents(), url));
auto* entry = guest_model->GetActiveWebContents()
->GetController()
.GetLastCommittedEntry();
EXPECT_EQ(entry->GetPageType(), content::PageType::PAGE_TYPE_ERROR);
EXPECT_STREQ("about:blank",
base::UTF16ToUTF8(
browser()->location_bar_model()->GetFormattedFullURL())
.c_str());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
Comment on lines +81 to +85
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, do you want to check normal window is not affected?
If so, ignore my comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

}

// Check loading |url| in private window is redirected to normal
// window.
void TestURLIsNotLoadedInPrivateWindow(const std::string& url) {
Expand Down Expand Up @@ -260,3 +286,8 @@ IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest,
BraveWelcomePageIsNotAllowedInPrivateWindow) {
TestURLIsNotLoadedInPrivateWindow("brave://welcome");
}

IN_PROC_BROWSER_TEST_F(BraveSchemeLoadBrowserTest,
BraveWelcomePageIsNotAllowedInGuestWindow) {
TestURLIsNotLoadedInGuestWindow(GURL("brave://welcome"));
}
2 changes: 1 addition & 1 deletion browser/ui/webui/brave_web_ui_controller_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) {
return new RewardsPanelUI(web_ui);
#endif // !BUILDFLAG(IS_ANDROID)
#if !BUILDFLAG(IS_ANDROID)
} else if (host == kWelcomeHost) {
} else if (host == kWelcomeHost && !profile->IsGuestSession()) {
return new BraveWelcomeUI(web_ui, url.host());
} else if (host == chrome::kChromeUISettingsHost) {
return new BraveSettingsUI(web_ui, url.host());
Expand Down