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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc

Issue 2474783002: Fix memory leak for extension uninstall dialog. (Closed)
Patch Set: Address Trent's comments. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "chrome/browser/extensions/extension_service.h"
7 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 8 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
11 #include "content/public/test/test_utils.h" 12 #include "content/public/test/test_utils.h"
13 #include "extensions/browser/extension_system.h"
12 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_builder.h" 15 #include "extensions/common/extension_builder.h"
14 #include "extensions/common/value_builder.h" 16 #include "extensions/common/value_builder.h"
15 17
18 #if defined(OS_MACOSX)
19 #include "base/command_line.h"
20 #include "chrome/browser/ui/browser_dialogs.h"
21 #include "content/public/common/content_switches.h"
22 #endif
23
16 namespace { 24 namespace {
17 25
18 scoped_refptr<extensions::Extension> BuildTestExtension() { 26 scoped_refptr<extensions::Extension> BuildTestExtension() {
19 return extensions::ExtensionBuilder() 27 return extensions::ExtensionBuilder()
20 .SetManifest(extensions::DictionaryBuilder() 28 .SetManifest(extensions::DictionaryBuilder()
21 .Set("name", "foo") 29 .Set("name", "foo")
22 .Set("version", "1.0") 30 .Set("version", "1.0")
23 .Build()) 31 .Build())
24 .Build(); 32 .Build();
25 } 33 }
(...skipping 20 matching lines...) Expand all
46 bool canceled_; 54 bool canceled_;
47 55
48 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate); 56 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate);
49 }; 57 };
50 58
51 } // namespace 59 } // namespace
52 60
53 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest; 61 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest;
54 62
55 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window 63 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window
56 // which is passed to ExtensionUninstallDialog::Create() is destroyed. 64 // which is passed to ExtensionUninstallDialog::Create() is destroyed before
65 // ExtensionUninstallDialogDelegateView is created.
57 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, 66 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
58 TrackParentWindowDestruction) { 67 TrackParentWindowDestruction) {
59 // Create a second browser to prevent the app from exiting when the browser is 68
msw 2016/11/15 21:17:16 nit: remove blank line
60 // closed. 69 #if defined(OS_MACOSX)
61 CreateBrowser(browser()->profile()); 70 base::CommandLine::ForCurrentProcess()->
71 AppendSwitchASCII(switches::kEnableFeatures,
72 chrome::kMacViewsWebUIDialogs.name);
73 #endif
62 74
63 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); 75 scoped_refptr<extensions::Extension> extension(BuildTestExtension());
76 extensions::ExtensionSystem::Get(browser()->profile())->extension_service()
77 ->AddExtension(extension.get());
64 78
65 base::RunLoop run_loop; 79 base::RunLoop run_loop;
66 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); 80 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure());
67 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( 81 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog(
68 extensions::ExtensionUninstallDialog::Create( 82 extensions::ExtensionUninstallDialog::Create(
69 browser()->profile(), browser()->window()->GetNativeWindow(), 83 browser()->profile(), browser()->window()->GetNativeWindow(),
70 &delegate)); 84 &delegate));
71 browser()->window()->Close(); 85 browser()->window()->Close();
72 content::RunAllPendingInMessageLoop(); 86 content::RunAllPendingInMessageLoop();
73 87
74 dialog->ConfirmUninstall(extension.get(), 88 dialog->ConfirmUninstall(extension.get(),
75 extensions::UNINSTALL_REASON_FOR_TESTING, 89 extensions::UNINSTALL_REASON_FOR_TESTING,
76 extensions::UNINSTALL_SOURCE_FOR_TESTING); 90 extensions::UNINSTALL_SOURCE_FOR_TESTING);
77 run_loop.Run(); 91 run_loop.Run();
78 EXPECT_TRUE(delegate.canceled()); 92 EXPECT_TRUE(delegate.canceled());
79 } 93 }
94
95 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window
96 // which is passed to ExtensionUninstallDialog::Create() is destroyed after
97 // ExtensionUninstallDialogDelegateView is created.
98 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
99 TrackParentWindowDestructionAfterViewCreation) {
100 #if defined(OS_MACOSX)
101 base::CommandLine::ForCurrentProcess()->
102 AppendSwitchASCII(switches::kEnableFeatures,
103 chrome::kMacViewsWebUIDialogs.name);
104 #endif
105
106 scoped_refptr<extensions::Extension> extension(BuildTestExtension());
107 extensions::ExtensionSystem::Get(browser()->profile())->extension_service()
108 ->AddExtension(extension.get());
109
110 base::RunLoop run_loop;
111 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure());
112 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog(
113 extensions::ExtensionUninstallDialog::Create(
114 browser()->profile(), browser()->window()->GetNativeWindow(),
115 &delegate));
116 content::RunAllPendingInMessageLoop();
117
118 dialog->ConfirmUninstall(extension.get(),
119 extensions::UNINSTALL_REASON_FOR_TESTING,
120 extensions::UNINSTALL_SOURCE_FOR_TESTING);
121
122 content::RunAllPendingInMessageLoop();
123
124 // Kill parent window.
125 browser()->window()->Close();
126 run_loop.Run();
127 EXPECT_TRUE(delegate.canceled());
128 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698