| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 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 std::unique_ptr<Approval> approval, |
| 43 InstallSource source) | 43 InstallSource source) |
| 44 : WebstoreInstaller(profile, | 44 : WebstoreInstaller(profile, |
| 45 delegate, | 45 delegate, |
| 46 web_contents, | 46 web_contents, |
| 47 id, | 47 id, |
| 48 std::move(approval), | 48 std::move(approval), |
| 49 source) {} | 49 source) {} |
| 50 | 50 |
| 51 void SetDeletedClosure(const base::Closure& cb) { deleted_closure_ = cb; } | 51 void SetDeletedClosure(const base::Closure& cb) { deleted_closure_ = cb; } |
| 52 | 52 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 void WebstoreInstallerBrowserTest::OnExtensionInstallFailure( | 111 void WebstoreInstallerBrowserTest::OnExtensionInstallFailure( |
| 112 const std::string& id, | 112 const std::string& id, |
| 113 const std::string& error, | 113 const std::string& error, |
| 114 WebstoreInstaller::FailureReason reason) { | 114 WebstoreInstaller::FailureReason reason) { |
| 115 success_ = false; | 115 success_ = false; |
| 116 done_closure_.Run(); | 116 done_closure_.Run(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 IN_PROC_BROWSER_TEST_F(WebstoreInstallerBrowserTest, WebstoreInstall) { | 119 IN_PROC_BROWSER_TEST_F(WebstoreInstallerBrowserTest, WebstoreInstall) { |
| 120 scoped_ptr<base::DictionaryValue> manifest( | 120 std::unique_ptr<base::DictionaryValue> manifest( |
| 121 DictionaryBuilder() | 121 DictionaryBuilder() |
| 122 .Set("name", kExtensionName) | 122 .Set("name", kExtensionName) |
| 123 .Set("description", "Foo") | 123 .Set("description", "Foo") |
| 124 .Set("manifest_version", 2) | 124 .Set("manifest_version", 2) |
| 125 .Set("version", "1.0") | 125 .Set("version", "1.0") |
| 126 .Set("permissions", ListBuilder().Append("tabs").Build()) | 126 .Set("permissions", ListBuilder().Append("tabs").Build()) |
| 127 .Build()); | 127 .Build()); |
| 128 | 128 |
| 129 content::WebContents* active_web_contents = | 129 content::WebContents* active_web_contents = |
| 130 browser()->tab_strip_model()->GetActiveWebContents(); | 130 browser()->tab_strip_model()->GetActiveWebContents(); |
| 131 ASSERT_TRUE(active_web_contents); | 131 ASSERT_TRUE(active_web_contents); |
| 132 | 132 |
| 133 // Create an approval. | 133 // Create an approval. |
| 134 scoped_ptr<WebstoreInstaller::Approval> approval = | 134 std::unique_ptr<WebstoreInstaller::Approval> approval = |
| 135 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 135 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
| 136 browser()->profile(), kTestExtensionId, std::move(manifest), false); | 136 browser()->profile(), kTestExtensionId, std::move(manifest), false); |
| 137 | 137 |
| 138 // Create and run a WebstoreInstaller. | 138 // Create and run a WebstoreInstaller. |
| 139 base::RunLoop run_loop; | 139 base::RunLoop run_loop; |
| 140 SetDoneClosure(run_loop.QuitClosure()); | 140 SetDoneClosure(run_loop.QuitClosure()); |
| 141 TestWebstoreInstaller* installer = new TestWebstoreInstaller( | 141 TestWebstoreInstaller* installer = new TestWebstoreInstaller( |
| 142 browser()->profile(), this, active_web_contents, kTestExtensionId, | 142 browser()->profile(), this, active_web_contents, kTestExtensionId, |
| 143 std::move(approval), WebstoreInstaller::INSTALL_SOURCE_OTHER); | 143 std::move(approval), WebstoreInstaller::INSTALL_SOURCE_OTHER); |
| 144 installer->Start(); | 144 installer->Start(); |
| 145 run_loop.Run(); | 145 run_loop.Run(); |
| 146 | 146 |
| 147 EXPECT_TRUE(success()); | 147 EXPECT_TRUE(success()); |
| 148 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 148 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 149 ASSERT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); | 149 ASSERT_TRUE(registry->enabled_extensions().GetByID(kTestExtensionId)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 IN_PROC_BROWSER_TEST_F(WebstoreInstallerBrowserTest, SimultaneousInstall) { | 152 IN_PROC_BROWSER_TEST_F(WebstoreInstallerBrowserTest, SimultaneousInstall) { |
| 153 scoped_ptr<base::DictionaryValue> manifest( | 153 std::unique_ptr<base::DictionaryValue> manifest( |
| 154 DictionaryBuilder() | 154 DictionaryBuilder() |
| 155 .Set("name", kExtensionName) | 155 .Set("name", kExtensionName) |
| 156 .Set("description", "Foo") | 156 .Set("description", "Foo") |
| 157 .Set("manifest_version", 2) | 157 .Set("manifest_version", 2) |
| 158 .Set("version", "1.0") | 158 .Set("version", "1.0") |
| 159 .Set("permissions", ListBuilder().Append("tabs").Build()) | 159 .Set("permissions", ListBuilder().Append("tabs").Build()) |
| 160 .Build()); | 160 .Build()); |
| 161 | 161 |
| 162 content::WebContents* active_web_contents = | 162 content::WebContents* active_web_contents = |
| 163 browser()->tab_strip_model()->GetActiveWebContents(); | 163 browser()->tab_strip_model()->GetActiveWebContents(); |
| 164 ASSERT_TRUE(active_web_contents); | 164 ASSERT_TRUE(active_web_contents); |
| 165 | 165 |
| 166 // Create an approval. | 166 // Create an approval. |
| 167 scoped_ptr<WebstoreInstaller::Approval> approval = | 167 std::unique_ptr<WebstoreInstaller::Approval> approval = |
| 168 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 168 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
| 169 browser()->profile(), | 169 browser()->profile(), kTestExtensionId, |
| 170 kTestExtensionId, | 170 std::unique_ptr<base::DictionaryValue>(manifest->DeepCopy()), false); |
| 171 scoped_ptr<base::DictionaryValue>(manifest->DeepCopy()), | |
| 172 false); | |
| 173 | 171 |
| 174 // Create and run a WebstoreInstaller. | 172 // Create and run a WebstoreInstaller. |
| 175 base::RunLoop run_loop; | 173 base::RunLoop run_loop; |
| 176 SetDoneClosure(run_loop.QuitClosure()); | 174 SetDoneClosure(run_loop.QuitClosure()); |
| 177 scoped_refptr<TestWebstoreInstaller> installer = new TestWebstoreInstaller( | 175 scoped_refptr<TestWebstoreInstaller> installer = new TestWebstoreInstaller( |
| 178 browser()->profile(), this, active_web_contents, kTestExtensionId, | 176 browser()->profile(), this, active_web_contents, kTestExtensionId, |
| 179 std::move(approval), WebstoreInstaller::INSTALL_SOURCE_OTHER); | 177 std::move(approval), WebstoreInstaller::INSTALL_SOURCE_OTHER); |
| 180 installer->Start(); | 178 installer->Start(); |
| 181 | 179 |
| 182 // Simulate another mechanism installing the same extension. | 180 // Simulate another mechanism installing the same extension. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 199 installer = nullptr; | 197 installer = nullptr; |
| 200 run_loop2.Run(); | 198 run_loop2.Run(); |
| 201 | 199 |
| 202 EXPECT_TRUE(success()); | 200 EXPECT_TRUE(success()); |
| 203 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 201 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 204 // Extension ends up as disabled because of permissions. | 202 // Extension ends up as disabled because of permissions. |
| 205 ASSERT_TRUE(registry->disabled_extensions().GetByID(kTestExtensionId)); | 203 ASSERT_TRUE(registry->disabled_extensions().GetByID(kTestExtensionId)); |
| 206 } | 204 } |
| 207 | 205 |
| 208 } // namespace extensions | 206 } // namespace extensions |
| OLD | NEW |