Commit e928ce6d authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Fix crash when opening web app menu while no tabs are loaded

This CL adds a simple nullptr check to the web app menu for when the
browser window has no tabs selected.

Screenshot of no minor text:
https://bugs.chromium.org/p/chromium/issues/attachment?aid=457537&signed_aid=Kjcn9nX_y395O5ZsqKkjjw==&inline=1

Bug: 1103331
Change-Id: I79c2f02edebde35772f6cd7c34f8e8c610f56040
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309769
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Auto-Submit: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790585}
parent bfadb3e4
...@@ -527,6 +527,17 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, PopOutDisabledInIncognito) { ...@@ -527,6 +527,17 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, PopOutDisabledInIncognito) {
EXPECT_FALSE(model->IsEnabledAt(index)); EXPECT_FALSE(model->IsEnabledAt(index));
} }
// Tests that web app menus don't crash when no tabs are selected.
IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, NoTabSelectedMenuCrash) {
const GURL app_url = GetSecureAppURL();
const AppId app_id = InstallPWA(app_url);
Browser* const app_browser = LaunchWebAppBrowserAndWait(app_id);
app_browser->tab_strip_model()->CloseAllTabs();
auto app_menu_model = std::make_unique<WebAppMenuModel>(nullptr, app_browser);
app_menu_model->Init();
}
// Tests that PWA menus have an uninstall option. // Tests that PWA menus have an uninstall option.
IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, UninstallMenuOption) { IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, UninstallMenuOption) {
const GURL app_url = GetSecureAppURL(); const GURL app_url = GetSecureAppURL();
......
...@@ -50,11 +50,12 @@ void WebAppMenuModel::Build() { ...@@ -50,11 +50,12 @@ void WebAppMenuModel::Build() {
AddItemWithStringId(IDC_WEB_APP_MENU_APP_INFO, AddItemWithStringId(IDC_WEB_APP_MENU_APP_INFO,
IDS_APP_CONTEXT_MENU_SHOW_INFO); IDS_APP_CONTEXT_MENU_SHOW_INFO);
int app_info_index = GetItemCount() - 1; int app_info_index = GetItemCount() - 1;
SetMinorText(app_info_index, web_app::AppBrowserController::FormatUrlOrigin( content::WebContents* web_contents =
browser() browser()->tab_strip_model()->GetActiveWebContents();
->tab_strip_model() if (web_contents) {
->GetActiveWebContents() SetMinorText(app_info_index, web_app::AppBrowserController::FormatUrlOrigin(
->GetVisibleURL())); web_contents->GetVisibleURL()));
}
SetMinorIcon(app_info_index, SetMinorIcon(app_info_index,
ui::ImageModel::FromVectorIcon( ui::ImageModel::FromVectorIcon(
browser()->location_bar_model()->GetVectorIcon())); browser()->location_bar_model()->GetVectorIcon()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment