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 23 matching lines...) Expand all Loading... | |
45 base::Closure quit_closure_; | 47 base::Closure quit_closure_; |
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 |
57 // Following test does not apply on MACOSX. MACOSX have its own implementation | |
58 // for dialog and view life circle. | |
59 #if !defined(OS_MACOSX) | |
Devlin
2016/11/14 17:49:12
By default, we don't use views on Mac. The only t
lgcheng
2016/11/14 19:10:33
Since this existing test is to verify dialog is de
| |
55 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | 60 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window |
56 // which is passed to ExtensionUninstallDialog::Create() is destroyed. | 61 // which is passed to ExtensionUninstallDialog::Create() is destroyed before |
62 // ExtensionUninstallDialogDelegateView is created. | |
57 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | 63 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
58 TrackParentWindowDestruction) { | 64 TrackParentWindowDestruction) { |
59 // Create a second browser to prevent the app from exiting when the browser is | 65 // Create a second browser to prevent the app from exiting when the browser is |
60 // closed. | 66 // closed. |
61 CreateBrowser(browser()->profile()); | 67 CreateBrowser(browser()->profile()); |
62 | 68 |
63 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | 69 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
70 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() | |
71 ->AddExtension(extension.get()); | |
64 | 72 |
65 base::RunLoop run_loop; | 73 base::RunLoop run_loop; |
66 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | 74 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
67 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | 75 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
68 extensions::ExtensionUninstallDialog::Create( | 76 extensions::ExtensionUninstallDialog::Create( |
69 browser()->profile(), browser()->window()->GetNativeWindow(), | 77 browser()->profile(), browser()->window()->GetNativeWindow(), |
70 &delegate)); | 78 &delegate)); |
71 browser()->window()->Close(); | 79 browser()->window()->Close(); |
72 content::RunAllPendingInMessageLoop(); | 80 content::RunAllPendingInMessageLoop(); |
73 | 81 |
74 dialog->ConfirmUninstall(extension.get(), | 82 dialog->ConfirmUninstall(extension.get(), |
75 extensions::UNINSTALL_REASON_FOR_TESTING, | 83 extensions::UNINSTALL_REASON_FOR_TESTING, |
76 extensions::UNINSTALL_SOURCE_FOR_TESTING); | 84 extensions::UNINSTALL_SOURCE_FOR_TESTING); |
77 run_loop.Run(); | 85 run_loop.Run(); |
78 EXPECT_TRUE(delegate.canceled()); | 86 EXPECT_TRUE(delegate.canceled()); |
79 } | 87 } |
88 | |
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()); | |
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 |