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 |
| 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 Loading... |
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 #if defined(OS_MACOSX) |
60 // closed. | 69 base::CommandLine::ForCurrentProcess()-> |
61 CreateBrowser(browser()->profile()); | 70 AppendSwitchASCII(switches::kEnableFeatures, |
| 71 chrome::kMacViewsWebUIDialogs.name); |
| 72 #endif |
62 | 73 |
63 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | 74 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
| 75 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() |
| 76 ->AddExtension(extension.get()); |
64 | 77 |
65 base::RunLoop run_loop; | 78 base::RunLoop run_loop; |
66 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | 79 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
67 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | 80 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
68 extensions::ExtensionUninstallDialog::Create( | 81 extensions::ExtensionUninstallDialog::Create( |
69 browser()->profile(), browser()->window()->GetNativeWindow(), | 82 browser()->profile(), browser()->window()->GetNativeWindow(), |
70 &delegate)); | 83 &delegate)); |
71 browser()->window()->Close(); | 84 browser()->window()->Close(); |
72 content::RunAllPendingInMessageLoop(); | 85 content::RunAllPendingInMessageLoop(); |
73 | 86 |
74 dialog->ConfirmUninstall(extension.get(), | 87 dialog->ConfirmUninstall(extension.get(), |
75 extensions::UNINSTALL_REASON_FOR_TESTING, | 88 extensions::UNINSTALL_REASON_FOR_TESTING, |
76 extensions::UNINSTALL_SOURCE_FOR_TESTING); | 89 extensions::UNINSTALL_SOURCE_FOR_TESTING); |
77 run_loop.Run(); | 90 run_loop.Run(); |
78 EXPECT_TRUE(delegate.canceled()); | 91 EXPECT_TRUE(delegate.canceled()); |
79 } | 92 } |
| 93 |
| 94 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window |
| 95 // which is passed to ExtensionUninstallDialog::Create() is destroyed after |
| 96 // ExtensionUninstallDialogDelegateView is created. |
| 97 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
| 98 TrackParentWindowDestructionAfterViewCreation) { |
| 99 #if defined(OS_MACOSX) |
| 100 base::CommandLine::ForCurrentProcess()-> |
| 101 AppendSwitchASCII(switches::kEnableFeatures, |
| 102 chrome::kMacViewsWebUIDialogs.name); |
| 103 #endif |
| 104 |
| 105 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
| 106 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() |
| 107 ->AddExtension(extension.get()); |
| 108 |
| 109 base::RunLoop run_loop; |
| 110 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
| 111 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
| 112 extensions::ExtensionUninstallDialog::Create( |
| 113 browser()->profile(), browser()->window()->GetNativeWindow(), |
| 114 &delegate)); |
| 115 content::RunAllPendingInMessageLoop(); |
| 116 |
| 117 dialog->ConfirmUninstall(extension.get(), |
| 118 extensions::UNINSTALL_REASON_FOR_TESTING, |
| 119 extensions::UNINSTALL_SOURCE_FOR_TESTING); |
| 120 |
| 121 content::RunAllPendingInMessageLoop(); |
| 122 |
| 123 // Kill parent window. |
| 124 browser()->window()->Close(); |
| 125 run_loop.Run(); |
| 126 EXPECT_TRUE(delegate.canceled()); |
| 127 } |
OLD | NEW |