OLD | NEW |
---|---|
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 |
16 namespace { | 18 namespace { |
17 | 19 |
18 scoped_refptr<extensions::Extension> BuildTestExtension() { | 20 scoped_refptr<extensions::Extension> BuildTestExtension() { |
19 return extensions::ExtensionBuilder() | 21 return extensions::ExtensionBuilder() |
20 .SetManifest(extensions::DictionaryBuilder() | 22 .SetManifest(extensions::DictionaryBuilder() |
21 .Set("name", "foo") | 23 .Set("name", "foo") |
(...skipping 24 matching lines...) Expand all Loading... | |
46 bool canceled_; | 48 bool canceled_; |
47 | 49 |
48 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate); | 50 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate); |
49 }; | 51 }; |
50 | 52 |
51 } // namespace | 53 } // namespace |
52 | 54 |
53 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest; | 55 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest; |
54 | 56 |
55 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | 57 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window |
56 // which is passed to ExtensionUninstallDialog::Create() is destroyed. | 58 // which is passed to ExtensionUninstallDialog::Create() is destroyed before |
59 // ExtensionUninstallDialogDelegateView is created. | |
57 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | 60 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
58 TrackParentWindowDestruction) { | 61 TrackParentWindowDestruction) { |
59 // Create a second browser to prevent the app from exiting when the browser is | 62 // Create a second browser to prevent the app from exiting when the browser is |
60 // closed. | 63 // closed. |
61 CreateBrowser(browser()->profile()); | 64 CreateBrowser(browser()->profile()); |
62 | 65 |
63 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | 66 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
67 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() | |
68 ->AddExtension(extension.get()); | |
64 | 69 |
65 base::RunLoop run_loop; | 70 base::RunLoop run_loop; |
66 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | 71 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
67 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | 72 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
68 extensions::ExtensionUninstallDialog::Create( | 73 extensions::ExtensionUninstallDialog::Create( |
69 browser()->profile(), browser()->window()->GetNativeWindow(), | 74 browser()->profile(), browser()->window()->GetNativeWindow(), |
70 &delegate)); | 75 &delegate)); |
71 browser()->window()->Close(); | 76 browser()->window()->Close(); |
72 content::RunAllPendingInMessageLoop(); | 77 content::RunAllPendingInMessageLoop(); |
73 | 78 |
74 dialog->ConfirmUninstall(extension.get(), | 79 dialog->ConfirmUninstall(extension.get(), |
75 extensions::UNINSTALL_REASON_FOR_TESTING, | 80 extensions::UNINSTALL_REASON_FOR_TESTING, |
76 extensions::UNINSTALL_SOURCE_FOR_TESTING); | 81 extensions::UNINSTALL_SOURCE_FOR_TESTING); |
77 run_loop.Run(); | 82 run_loop.Run(); |
78 EXPECT_TRUE(delegate.canceled()); | 83 EXPECT_TRUE(delegate.canceled()); |
79 } | 84 } |
85 | |
86 // Following test does not apply on MACOSX. MACOSX have its own implementation | |
87 // for dialog and view life circle. | |
88 #if !defined(OS_MACOSX) | |
89 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | |
90 // which is passed to ExtensionUninstallDialog::Create() is destroyed after | |
91 // ExtensionUninstallDialogDelegateView is created. | |
92 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | |
93 TrackParentWindowDestructionAfterViewCreation) { | |
94 // Create a second browser to prevent the app from exiting when the browser is | |
95 // closed. | |
96 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.
| |
97 | |
98 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | |
99 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() | |
100 ->AddExtension(extension.get()); | |
101 | |
102 base::RunLoop run_loop; | |
103 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | |
104 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | |
105 extensions::ExtensionUninstallDialog::Create( | |
106 browser()->profile(), browser()->window()->GetNativeWindow(), | |
107 &delegate)); | |
108 content::RunAllPendingInMessageLoop(); | |
109 | |
110 dialog->ConfirmUninstall(extension.get(), | |
111 extensions::UNINSTALL_REASON_FOR_TESTING, | |
112 extensions::UNINSTALL_SOURCE_FOR_TESTING); | |
113 | |
114 content::RunAllPendingInMessageLoop(); | |
115 | |
116 // Kill parent window. | |
117 browser()->window()->Close(); | |
118 run_loop.Run(); | |
119 EXPECT_TRUE(delegate.canceled()); | |
120 } | |
121 | |
122 #endif // !defined(OS_MACOSX) | |
OLD | NEW |