| 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_service.h" |
| 8 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 8 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 13 #include "extensions/browser/extension_system.h" | 13 #include "extensions/browser/extension_system.h" |
| 14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 15 #include "extensions/common/extension_builder.h" | 15 #include "extensions/common/extension_builder.h" |
| 16 #include "extensions/common/value_builder.h" | 16 #include "extensions/common/value_builder.h" |
| 17 | 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 | |
| 24 namespace { | 18 namespace { |
| 25 | 19 |
| 26 scoped_refptr<extensions::Extension> BuildTestExtension() { | 20 scoped_refptr<extensions::Extension> BuildTestExtension() { |
| 27 return extensions::ExtensionBuilder() | 21 return extensions::ExtensionBuilder() |
| 28 .SetManifest(extensions::DictionaryBuilder() | 22 .SetManifest(extensions::DictionaryBuilder() |
| 29 .Set("name", "foo") | 23 .Set("name", "foo") |
| 30 .Set("version", "1.0") | 24 .Set("version", "1.0") |
| 31 .Build()) | 25 .Build()) |
| 32 .Build(); | 26 .Build(); |
| 33 } | 27 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 53 base::Closure quit_closure_; | 47 base::Closure quit_closure_; |
| 54 bool canceled_; | 48 bool canceled_; |
| 55 | 49 |
| 56 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate); | 50 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate); |
| 57 }; | 51 }; |
| 58 | 52 |
| 59 } // namespace | 53 } // namespace |
| 60 | 54 |
| 61 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest; | 55 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest; |
| 62 | 56 |
| 63 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | 57 // Test that ExtensionUninstallDialog cancels the uninstall if the Window which |
| 64 // which is passed to ExtensionUninstallDialog::Create() is destroyed before | 58 // is passed to ExtensionUninstallDialog::Create() is destroyed before |
| 65 // ExtensionUninstallDialogDelegateView is created. | 59 // ExtensionUninstallDialogDelegateView is created. |
| 66 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | 60 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
| 67 TrackParentWindowDestruction) { | 61 TrackParentWindowDestruction) { |
| 68 #if defined(OS_MACOSX) | |
| 69 base::CommandLine::ForCurrentProcess()-> | |
| 70 AppendSwitchASCII(switches::kEnableFeatures, | |
| 71 chrome::kMacViewsWebUIDialogs.name); | |
| 72 #endif | |
| 73 | |
| 74 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | 62 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
| 75 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() | 63 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() |
| 76 ->AddExtension(extension.get()); | 64 ->AddExtension(extension.get()); |
| 77 | 65 |
| 78 base::RunLoop run_loop; | 66 base::RunLoop run_loop; |
| 79 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | 67 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
| 80 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | 68 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
| 81 extensions::ExtensionUninstallDialog::Create( | 69 extensions::ExtensionUninstallDialog::Create( |
| 82 browser()->profile(), browser()->window()->GetNativeWindow(), | 70 browser()->profile(), browser()->window()->GetNativeWindow(), |
| 83 &delegate)); | 71 &delegate)); |
| 84 browser()->window()->Close(); | 72 browser()->window()->Close(); |
| 85 content::RunAllPendingInMessageLoop(); | 73 content::RunAllPendingInMessageLoop(); |
| 86 | 74 |
| 87 dialog->ConfirmUninstall(extension.get(), | 75 dialog->ConfirmUninstall(extension.get(), |
| 88 extensions::UNINSTALL_REASON_FOR_TESTING, | 76 extensions::UNINSTALL_REASON_FOR_TESTING, |
| 89 extensions::UNINSTALL_SOURCE_FOR_TESTING); | 77 extensions::UNINSTALL_SOURCE_FOR_TESTING); |
| 90 run_loop.Run(); | 78 run_loop.Run(); |
| 91 EXPECT_TRUE(delegate.canceled()); | 79 EXPECT_TRUE(delegate.canceled()); |
| 92 } | 80 } |
| 93 | 81 |
| 94 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | 82 // Test that ExtensionUninstallDialog cancels the uninstall if the Window which |
| 95 // which is passed to ExtensionUninstallDialog::Create() is destroyed after | 83 // is passed to ExtensionUninstallDialog::Create() is destroyed after |
| 96 // ExtensionUninstallDialogDelegateView is created. | 84 // ExtensionUninstallDialogDelegateView is created. |
| 97 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | 85 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
| 98 TrackParentWindowDestructionAfterViewCreation) { | 86 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()); | 87 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
| 106 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() | 88 extensions::ExtensionSystem::Get(browser()->profile())->extension_service() |
| 107 ->AddExtension(extension.get()); | 89 ->AddExtension(extension.get()); |
| 108 | 90 |
| 109 base::RunLoop run_loop; | 91 base::RunLoop run_loop; |
| 110 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | 92 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
| 111 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | 93 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
| 112 extensions::ExtensionUninstallDialog::Create( | 94 extensions::ExtensionUninstallDialog::Create( |
| 113 browser()->profile(), browser()->window()->GetNativeWindow(), | 95 browser()->profile(), browser()->window()->GetNativeWindow(), |
| 114 &delegate)); | 96 &delegate)); |
| 115 content::RunAllPendingInMessageLoop(); | 97 content::RunAllPendingInMessageLoop(); |
| 116 | 98 |
| 117 dialog->ConfirmUninstall(extension.get(), | 99 dialog->ConfirmUninstall(extension.get(), |
| 118 extensions::UNINSTALL_REASON_FOR_TESTING, | 100 extensions::UNINSTALL_REASON_FOR_TESTING, |
| 119 extensions::UNINSTALL_SOURCE_FOR_TESTING); | 101 extensions::UNINSTALL_SOURCE_FOR_TESTING); |
| 120 | 102 |
| 121 content::RunAllPendingInMessageLoop(); | 103 content::RunAllPendingInMessageLoop(); |
| 122 | 104 |
| 123 // Kill parent window. | 105 // Kill parent window. |
| 124 browser()->window()->Close(); | 106 browser()->window()->Close(); |
| 125 run_loop.Run(); | 107 run_loop.Run(); |
| 126 EXPECT_TRUE(delegate.canceled()); | 108 EXPECT_TRUE(delegate.canceled()); |
| 127 } | 109 } |
| OLD | NEW |