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 "chrome/browser/extensions/webstore_installer.h" | 5 #include "chrome/browser/extensions/webstore_installer.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 // Test version of WebstoreInstaller that intercepts the destructor. | 35 // Test version of WebstoreInstaller that intercepts the destructor. |
36 class TestWebstoreInstaller : public WebstoreInstaller { | 36 class TestWebstoreInstaller : public WebstoreInstaller { |
37 public: | 37 public: |
38 TestWebstoreInstaller(Profile* profile, | 38 TestWebstoreInstaller(Profile* profile, |
39 Delegate* delegate, | 39 Delegate* delegate, |
40 content::WebContents* web_contents, | 40 content::WebContents* web_contents, |
41 const std::string& id, | 41 const std::string& id, |
42 scoped_ptr<Approval> approval, | 42 scoped_ptr<Approval> approval, |
43 InstallSource source) | 43 InstallSource source) |
44 : WebstoreInstaller( | 44 : WebstoreInstaller(profile, |
45 profile, delegate, web_contents, id, approval.Pass(), source) {} | 45 delegate, |
| 46 web_contents, |
| 47 id, |
| 48 std::move(approval), |
| 49 source) {} |
46 | 50 |
47 void SetDeletedClosure(const base::Closure& cb) { deleted_closure_ = cb; } | 51 void SetDeletedClosure(const base::Closure& cb) { deleted_closure_ = cb; } |
48 | 52 |
49 private: | 53 private: |
50 ~TestWebstoreInstaller() override { | 54 ~TestWebstoreInstaller() override { |
51 if (!deleted_closure_.is_null()) | 55 if (!deleted_closure_.is_null()) |
52 deleted_closure_.Run(); | 56 deleted_closure_.Run(); |
53 } | 57 } |
54 | 58 |
55 base::Closure deleted_closure_; | 59 base::Closure deleted_closure_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 .Set("permissions", std::move(ListBuilder().Append("tabs"))) | 126 .Set("permissions", std::move(ListBuilder().Append("tabs"))) |
123 .Build()); | 127 .Build()); |
124 | 128 |
125 content::WebContents* active_web_contents = | 129 content::WebContents* active_web_contents = |
126 browser()->tab_strip_model()->GetActiveWebContents(); | 130 browser()->tab_strip_model()->GetActiveWebContents(); |
127 ASSERT_TRUE(active_web_contents); | 131 ASSERT_TRUE(active_web_contents); |
128 | 132 |
129 // Create an approval. | 133 // Create an approval. |
130 scoped_ptr<WebstoreInstaller::Approval> approval = | 134 scoped_ptr<WebstoreInstaller::Approval> approval = |
131 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 135 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
132 browser()->profile(), | 136 browser()->profile(), kTestExtensionId, std::move(manifest), false); |
133 kTestExtensionId, | |
134 manifest.Pass(), | |
135 false); | |
136 | 137 |
137 // Create and run a WebstoreInstaller. | 138 // Create and run a WebstoreInstaller. |
138 base::RunLoop run_loop; | 139 base::RunLoop run_loop; |
139 SetDoneClosure(run_loop.QuitClosure()); | 140 SetDoneClosure(run_loop.QuitClosure()); |
140 TestWebstoreInstaller* installer = | 141 TestWebstoreInstaller* installer = new TestWebstoreInstaller( |
141 new TestWebstoreInstaller( | 142 browser()->profile(), this, active_web_contents, kTestExtensionId, |
142 browser()->profile(), | 143 std::move(approval), WebstoreInstaller::INSTALL_SOURCE_OTHER); |
143 this, | |
144 active_web_contents, | |
145 kTestExtensionId, | |
146 approval.Pass(), | |
147 WebstoreInstaller::INSTALL_SOURCE_OTHER); | |
148 installer->Start(); | 144 installer->Start(); |
149 run_loop.Run(); | 145 run_loop.Run(); |
150 | 146 |
151 EXPECT_TRUE(success()); | 147 EXPECT_TRUE(success()); |
152 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 148 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
153 ASSERT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); | 149 ASSERT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); |
154 } | 150 } |
155 | 151 |
156 IN_PROC_BROWSER_TEST_F(WebstoreInstallerBrowserTest, SimultaneousInstall) { | 152 IN_PROC_BROWSER_TEST_F(WebstoreInstallerBrowserTest, SimultaneousInstall) { |
157 scoped_ptr<base::DictionaryValue> manifest( | 153 scoped_ptr<base::DictionaryValue> manifest( |
(...skipping 13 matching lines...) Expand all Loading... |
171 scoped_ptr<WebstoreInstaller::Approval> approval = | 167 scoped_ptr<WebstoreInstaller::Approval> approval = |
172 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 168 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
173 browser()->profile(), | 169 browser()->profile(), |
174 kTestExtensionId, | 170 kTestExtensionId, |
175 scoped_ptr<base::DictionaryValue>(manifest->DeepCopy()), | 171 scoped_ptr<base::DictionaryValue>(manifest->DeepCopy()), |
176 false); | 172 false); |
177 | 173 |
178 // Create and run a WebstoreInstaller. | 174 // Create and run a WebstoreInstaller. |
179 base::RunLoop run_loop; | 175 base::RunLoop run_loop; |
180 SetDoneClosure(run_loop.QuitClosure()); | 176 SetDoneClosure(run_loop.QuitClosure()); |
181 scoped_refptr<TestWebstoreInstaller> installer = | 177 scoped_refptr<TestWebstoreInstaller> installer = new TestWebstoreInstaller( |
182 new TestWebstoreInstaller( | 178 browser()->profile(), this, active_web_contents, kTestExtensionId, |
183 browser()->profile(), | 179 std::move(approval), WebstoreInstaller::INSTALL_SOURCE_OTHER); |
184 this, | |
185 active_web_contents, | |
186 kTestExtensionId, | |
187 approval.Pass(), | |
188 WebstoreInstaller::INSTALL_SOURCE_OTHER); | |
189 installer->Start(); | 180 installer->Start(); |
190 | 181 |
191 // Simulate another mechanism installing the same extension. | 182 // Simulate another mechanism installing the same extension. |
192 scoped_refptr<const Extension> extension = | 183 scoped_refptr<const Extension> extension = |
193 ExtensionBuilder().SetLocation(Manifest::INTERNAL) | 184 ExtensionBuilder() |
194 .SetID(kTestExtensionId) | 185 .SetLocation(Manifest::INTERNAL) |
195 .SetManifest(manifest.Pass()) | 186 .SetID(kTestExtensionId) |
196 .Build(); | 187 .SetManifest(std::move(manifest)) |
| 188 .Build(); |
197 extension_service()->OnExtensionInstalled(extension.get(), | 189 extension_service()->OnExtensionInstalled(extension.get(), |
198 syncer::StringOrdinal(), | 190 syncer::StringOrdinal(), |
199 0); | 191 0); |
200 | 192 |
201 run_loop.Run(); | 193 run_loop.Run(); |
202 | 194 |
203 // Wait for the WebstoreInstaller to be destroyed. Bad things happen if we | 195 // Wait for the WebstoreInstaller to be destroyed. Bad things happen if we |
204 // don't wait for this. | 196 // don't wait for this. |
205 base::RunLoop run_loop2; | 197 base::RunLoop run_loop2; |
206 installer->SetDeletedClosure(run_loop2.QuitClosure()); | 198 installer->SetDeletedClosure(run_loop2.QuitClosure()); |
207 installer = nullptr; | 199 installer = nullptr; |
208 run_loop2.Run(); | 200 run_loop2.Run(); |
209 | 201 |
210 EXPECT_TRUE(success()); | 202 EXPECT_TRUE(success()); |
211 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 203 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
212 // Extension ends up as disabled because of permissions. | 204 // Extension ends up as disabled because of permissions. |
213 ASSERT_TRUE(registry->disabled_extensions().GetByID(kTestExtensionId)); | 205 ASSERT_TRUE(registry->disabled_extensions().GetByID(kTestExtensionId)); |
214 } | 206 } |
215 | 207 |
216 } // namespace extensions | 208 } // namespace extensions |
OLD | NEW |