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_uninstall_dialog.h" | 7 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
12 #include "extensions/browser/extension_registry.h" | |
12 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
13 #include "extensions/common/extension_builder.h" | 14 #include "extensions/common/extension_builder.h" |
14 #include "extensions/common/value_builder.h" | 15 #include "extensions/common/value_builder.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 scoped_refptr<extensions::Extension> BuildTestExtension() { | 19 scoped_refptr<extensions::Extension> BuildTestExtension() { |
19 return extensions::ExtensionBuilder() | 20 return extensions::ExtensionBuilder() |
20 .SetManifest(extensions::DictionaryBuilder() | 21 .SetManifest(extensions::DictionaryBuilder() |
21 .Set("name", "foo") | 22 .Set("name", "foo") |
(...skipping 24 matching lines...) Expand all Loading... | |
46 bool canceled_; | 47 bool canceled_; |
47 | 48 |
48 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate); | 49 DISALLOW_COPY_AND_ASSIGN(TestExtensionUninstallDialogDelegate); |
49 }; | 50 }; |
50 | 51 |
51 } // namespace | 52 } // namespace |
52 | 53 |
53 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest; | 54 typedef InProcessBrowserTest ExtensionUninstallDialogViewBrowserTest; |
54 | 55 |
55 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | 56 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window |
56 // which is passed to ExtensionUninstallDialog::Create() is destroyed. | 57 // which is passed to ExtensionUninstallDialog::Create() is destroyed before |
58 // ExtensionUninstallDialogDelegateView is created. | |
57 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | 59 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
58 TrackParentWindowDestruction) { | 60 TrackParentWindowDestruction) { |
59 // Create a second browser to prevent the app from exiting when the browser is | 61 // Create a second browser to prevent the app from exiting when the browser is |
60 // closed. | 62 // closed. |
61 CreateBrowser(browser()->profile()); | 63 CreateBrowser(browser()->profile()); |
62 | 64 |
63 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | 65 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
64 | 66 |
65 base::RunLoop run_loop; | 67 base::RunLoop run_loop; |
66 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | 68 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
67 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | 69 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
68 extensions::ExtensionUninstallDialog::Create( | 70 extensions::ExtensionUninstallDialog::Create( |
69 browser()->profile(), browser()->window()->GetNativeWindow(), | 71 browser()->profile(), browser()->window()->GetNativeWindow(), |
70 &delegate)); | 72 &delegate)); |
lgcheng
2016/11/03 22:30:50
This test is still working with what I have change
Devlin
2016/11/05 06:26:18
Yeah, we should make sure the extension is added.
lgcheng
2016/11/10 21:39:51
Done.
| |
71 browser()->window()->Close(); | 73 // browser()->window()->Close(); |
72 content::RunAllPendingInMessageLoop(); | 74 content::RunAllPendingInMessageLoop(); |
73 | 75 |
74 dialog->ConfirmUninstall(extension.get(), | 76 dialog->ConfirmUninstall(extension.get(), |
75 extensions::UNINSTALL_REASON_FOR_TESTING, | 77 extensions::UNINSTALL_REASON_FOR_TESTING, |
76 extensions::UNINSTALL_SOURCE_FOR_TESTING); | 78 extensions::UNINSTALL_SOURCE_FOR_TESTING); |
77 run_loop.Run(); | 79 run_loop.Run(); |
78 EXPECT_TRUE(delegate.canceled()); | 80 EXPECT_TRUE(delegate.canceled()); |
79 } | 81 } |
82 | |
83 // Test that ExtensionUninstallDialog cancels the uninstall if the aura::Window | |
84 // which is passed to ExtensionUninstallDialog::Create() is destroyed after | |
85 // ExtensionUninstallDialogDelegateView is created. | |
86 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, | |
87 TrackParentWindowDestructionAfterViewCreation) { | |
88 // Create a second browser to prevent the app from exiting when the browser is | |
89 // closed. | |
90 CreateBrowser(browser()->profile()); | |
91 | |
92 scoped_refptr<extensions::Extension> extension(BuildTestExtension()); | |
93 extensions::ExtensionRegistry* registry = | |
lgcheng
2016/11/03 22:30:50
Add extension to ExtensionRegistry so that uninsta
Devlin
2016/11/05 06:26:18
Doing
ExtensionSystem::Get(browser()->profile())->
lgcheng
2016/11/10 21:39:51
Done.
| |
94 extensions::ExtensionRegistry::Get(browser()->profile()); | |
95 DCHECK(registry); | |
96 | |
97 std::string extension_id = extension->id(); | |
98 DCHECK(registry->AddEnabled(extension)); | |
Devlin
2016/11/05 06:26:18
moot with the above comment, but prefer ASSERT_TRU
lgcheng
2016/11/10 21:39:51
Done.
| |
99 | |
100 base::RunLoop run_loop; | |
101 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); | |
102 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( | |
103 extensions::ExtensionUninstallDialog::Create( | |
104 browser()->profile(), browser()->window()->GetNativeWindow(), | |
105 &delegate)); | |
106 content::RunAllPendingInMessageLoop(); | |
107 | |
108 dialog->ConfirmUninstall( | |
109 registry->GetExtensionById(extension_id, | |
110 extensions::ExtensionRegistry::EVERYTHING), | |
111 extensions::UNINSTALL_REASON_FOR_TESTING, | |
112 extensions::UNINSTALL_SOURCE_FOR_TESTING); | |
113 | |
lgcheng
2016/11/03 22:30:50
The test fails on Mac because on Mac it has differ
| |
114 // Kill parent window. | |
115 browser()->window()->Close(); | |
116 | |
117 run_loop.Run(); | |
118 EXPECT_TRUE(delegate.canceled()); | |
119 } | |
OLD | NEW |