Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Unified Diff: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc

Issue 2474783002: Fix memory leak for extension uninstall dialog. (Closed)
Patch Set: Nits. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc
diff --git a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc
index eb8799ff8e990522b002d7c2200193f39e1a8eea..d41b364358ab9d05845760d5dd0f36f3ef12b38a 100644
--- a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc
+++ b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc
@@ -4,11 +4,13 @@
#include "base/macros.h"
#include "base/run_loop.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/test_utils.h"
+#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
@@ -53,7 +55,8 @@ class TestExtensionUninstallDialogDelegate
typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest;
// Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window
-// which is passed to ExtensionUninstallDialog::Create() is destroyed.
+// which is passed to ExtensionUninstallDialog::Create() is destroyed before
+// ExtensionUninstallDialogDelegateView is created.
IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
TrackParentWindowDestruction) {
// Create a second browser to prevent the app from exiting when the browser is
@@ -61,6 +64,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
CreateBrowser(browser()->profile());
scoped_refptr<extensions::Extension> extension(BuildTestExtension());
+ extensions::ExtensionSystem::Get(browser()->profile())->extension_service()
+ ->AddExtension(extension.get());
base::RunLoop run_loop;
TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure());
@@ -77,3 +82,41 @@ IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
run_loop.Run();
EXPECT_TRUE(delegate.canceled());
}
+
+// Following test does not apply on MACOSX. MACOSX have its own implementation
+// for dialog and view life circle.
+#if !defined(OS_MACOSX)
+// Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window
+// which is passed to ExtensionUninstallDialog::Create() is destroyed after
+// ExtensionUninstallDialogDelegateView is created.
+IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
+ TrackParentWindowDestructionAfterViewCreation) {
+ // Create a second browser to prevent the app from exiting when the browser is
+ // closed.
+ CreateBrowser(browser()->profile());
msw 2016/11/14 20:04:27 nit: use ScopedKeepAlive w/LEAKED_UNINSTALL_VIEW i
lgcheng 2016/11/14 23:51:41 It seems CreateBrowser(browser()->profile()) is no
msw 2016/11/15 00:09:32 If neither is needed; that's great.
+
+ scoped_refptr<extensions::Extension> extension(BuildTestExtension());
+ extensions::ExtensionSystem::Get(browser()->profile())->extension_service()
+ ->AddExtension(extension.get());
+
+ base::RunLoop run_loop;
+ TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure());
+ std::unique_ptr<extensions::ExtensionUninstallDialog> dialog(
+ extensions::ExtensionUninstallDialog::Create(
+ browser()->profile(), browser()->window()->GetNativeWindow(),
+ &delegate));
+ content::RunAllPendingInMessageLoop();
+
+ dialog->ConfirmUninstall(extension.get(),
+ extensions::UNINSTALL_REASON_FOR_TESTING,
+ extensions::UNINSTALL_SOURCE_FOR_TESTING);
+
+ content::RunAllPendingInMessageLoop();
+
+ // Kill parent window.
+ browser()->window()->Close();
+ run_loop.Run();
+ EXPECT_TRUE(delegate.canceled());
+}
+
+#endif // !defined(OS_MACOSX)

Powered by Google App Engine
This is Rietveld 408576698