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 | |
msw
2016/11/15 00:09:32
grammar nits: "The following tests do not apply to
| |
58 // for dialog and view life circle. | |
59 #if !defined(OS_MACOSX) | |
lgcheng
2016/11/14 23:51:41
This test won't run on MAC.
1. It run on MAC befo
msw
2016/11/15 00:09:32
extension_uninstall_dialog_cocoa should not be use
tapted
2016/11/15 00:30:14
Try adding
#if defined(OS_MACOSX)
#include "chro
| |
60 | |
55 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | 61 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window |
56 // which is passed to ExtensionUninstallDialog::Create() is destroyed. | 62 // which is passed to ExtensionUninstallDialog::Create() is destroyed before |
63 // ExtensionUninstallDialogDelegateView is created. | |
57 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | 64 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
58 TrackParentWindowDestruction) { | 65 TrackParentWindowDestruction) { |
59 // Create a second browser to prevent the app from exiting when the browser is | |
60 // closed. | |
61 CreateBrowser(browser()->profile()); | |
62 | |
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 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | |
87 // which is passed to ExtensionUninstallDialog::Create() is destroyed after | |
88 // ExtensionUninstallDialogDelegateView is created. | |
89 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | |
90 TrackParentWindowDestructionAfterViewCreation) { | |
91 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | |
92 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() | |
93 ->AddExtension(extension.get()); | |
94 | |
95 base::RunLoop run_loop; | |
96 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | |
97 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | |
98 extensions::ExtensionUninstallDialog::Create( | |
99 browser()->profile(), browser()->window()->GetNativeWindow(), | |
100 &delegate)); | |
101 content::RunAllPendingInMessageLoop(); | |
102 | |
103 dialog->ConfirmUninstall(extension.get(), | |
104 extensions::UNINSTALL_REASON_FOR_TESTING, | |
105 extensions::UNINSTALL_SOURCE_FOR_TESTING); | |
106 | |
107 content::RunAllPendingInMessageLoop(); | |
108 | |
109 // Kill parent window. | |
110 browser()->window()->Close(); | |
111 run_loop.Run(); | |
112 EXPECT_TRUE(delegate.canceled()); | |
113 } | |
114 | |
115 #endif // !defined(OS_MACOSX) | |
OLD | NEW |