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

Fix crash when uninstalling extension from PWA window

This CL fixes a null pointer crash when uninstalling an extension from
the app menu of a PWA window. The existing code expected the main UI
toolbar to be present.

Bug: 825554
Change-Id: I89353dd246168393747cca02f02444859b4457c6
Reviewed-on: https://chromium-review.googlesource.com/981839
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546743}
parent 5145a016
...@@ -46,8 +46,9 @@ ToolbarActionView* GetExtensionAnchorView(const std::string& extension_id, ...@@ -46,8 +46,9 @@ ToolbarActionView* GetExtensionAnchorView(const std::string& extension_id,
BrowserView::GetBrowserViewForNativeWindow(window); BrowserView::GetBrowserViewForNativeWindow(window);
if (!browser_view) if (!browser_view)
return nullptr; return nullptr;
ToolbarActionView* reference_view = ToolbarActionView* reference_view = browser_view->button_provider()
browser_view->toolbar()->browser_actions()->GetViewForId(extension_id); ->GetBrowserActionsContainer()
->GetViewForId(extension_id);
return reference_view && reference_view->visible() ? reference_view : nullptr; return reference_view && reference_view->visible() ? reference_view : nullptr;
#else #else
// Anchoring is not supported when using Cocoa. // Anchoring is not supported when using Cocoa.
......
...@@ -6,12 +6,16 @@ ...@@ -6,12 +6,16 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h" #include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h" #include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/web_application_info.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
...@@ -135,6 +139,46 @@ IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, ...@@ -135,6 +139,46 @@ IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
EXPECT_TRUE(delegate.canceled()); EXPECT_TRUE(delegate.canceled());
} }
#if defined(OS_CHROMEOS)
// Test that we don't crash when uninstalling an extension from a bookmark app
// window in Ash. Context: crbug.com/825554
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
BookmarkAppWindowAshCrash) {
base::test::ScopedFeatureList scoped_feature_list_;
scoped_feature_list_.InitAndEnableFeature(features::kDesktopPWAWindowing);
scoped_refptr<extensions::Extension> extension(BuildTestExtension());
extensions::ExtensionSystem::Get(browser()->profile())
->extension_service()
->AddExtension(extension.get());
WebApplicationInfo info;
info.app_url = GURL("https://test.com/");
const extensions::Extension* bookmark_app =
extensions::browsertest_util::InstallBookmarkApp(browser()->profile(),
info);
Browser* app_browser = extensions::browsertest_util::LaunchAppBrowser(
browser()->profile(), bookmark_app);
std::unique_ptr<extensions::ExtensionUninstallDialog> dialog;
{
base::RunLoop run_loop;
dialog.reset(extensions::ExtensionUninstallDialog::Create(
app_browser->profile(), app_browser->window()->GetNativeWindow(),
nullptr));
run_loop.RunUntilIdle();
}
{
base::RunLoop run_loop;
dialog->ConfirmUninstall(extension.get(),
extensions::UNINSTALL_REASON_FOR_TESTING,
extensions::UNINSTALL_SOURCE_FOR_TESTING);
run_loop.RunUntilIdle();
}
}
#endif // defined(OS_CHROMEOS)
// Test that when the user clicks Uninstall on the ExtensionUninstallDialog, the // Test that when the user clicks Uninstall on the ExtensionUninstallDialog, the
// extension's uninstall url (when it is specified) should open and be the // extension's uninstall url (when it is specified) should open and be the
// active tab. // active tab.
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
# Direct access to ash window frames, tablet mode, overview mode, etc. # Direct access to ash window frames, tablet mode, overview mode, etc.
-BrowserNonClientFrameViewAshBackButtonTest.* -BrowserNonClientFrameViewAshBackButtonTest.*
-BrowserNonClientFrameViewAshTest.* -BrowserNonClientFrameViewAshTest.*
-ExtensionUninstallDialogViewBrowserTest.BookmarkAppWindowAshCrash
-HostedAppNonClientFrameViewAshTest.* -HostedAppNonClientFrameViewAshTest.*
-ImmersiveModeControllerAshHostedAppBrowserTest.* -ImmersiveModeControllerAshHostedAppBrowserTest.*
......
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