| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_inline_installer.h" |
| 6 |
| 5 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 8 #include "chrome/browser/extensions/extension_install_prompt.h" | 11 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
| 11 #include "chrome/browser/extensions/webstore_inline_installer.h" | |
| 12 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" | 14 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" |
| 13 #include "chrome/browser/extensions/webstore_installer_test.h" | 15 #include "chrome/browser/extensions/webstore_installer_test.h" |
| 14 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 16 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "components/content_settings/core/browser/host_content_settings_map.h" | 22 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 explicit ProgrammableInstallPrompt(WebContents* contents) | 66 explicit ProgrammableInstallPrompt(WebContents* contents) |
| 65 : ExtensionInstallPrompt(contents) | 67 : ExtensionInstallPrompt(contents) |
| 66 {} | 68 {} |
| 67 | 69 |
| 68 ~ProgrammableInstallPrompt() override { g_done_callback = nullptr; } | 70 ~ProgrammableInstallPrompt() override { g_done_callback = nullptr; } |
| 69 | 71 |
| 70 void ShowDialog( | 72 void ShowDialog( |
| 71 const ExtensionInstallPrompt::DoneCallback& done_callback, | 73 const ExtensionInstallPrompt::DoneCallback& done_callback, |
| 72 const Extension* extension, | 74 const Extension* extension, |
| 73 const SkBitmap* icon, | 75 const SkBitmap* icon, |
| 74 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt, | 76 std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt, |
| 75 scoped_ptr<const extensions::PermissionSet> custom_permissions, | 77 std::unique_ptr<const extensions::PermissionSet> custom_permissions, |
| 76 const ShowDialogCallback& show_dialog_callback) override { | 78 const ShowDialogCallback& show_dialog_callback) override { |
| 77 done_callback_ = done_callback; | 79 done_callback_ = done_callback; |
| 78 g_done_callback = &done_callback_; | 80 g_done_callback = &done_callback_; |
| 79 } | 81 } |
| 80 | 82 |
| 81 static bool Ready() { return g_done_callback != nullptr; } | 83 static bool Ready() { return g_done_callback != nullptr; } |
| 82 | 84 |
| 83 static void Accept() { | 85 static void Accept() { |
| 84 g_done_callback->Run(ExtensionInstallPrompt::Result::ACCEPTED); | 86 g_done_callback->Run(ExtensionInstallPrompt::Result::ACCEPTED); |
| 85 } | 87 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 111 : WebstoreInlineInstaller( | 113 : WebstoreInlineInstaller( |
| 112 contents, | 114 contents, |
| 113 host, | 115 host, |
| 114 kTestExtensionId, | 116 kTestExtensionId, |
| 115 requestor_url, | 117 requestor_url, |
| 116 base::Bind(&WebstoreInlineInstallerForTest::InstallCallback, | 118 base::Bind(&WebstoreInlineInstallerForTest::InstallCallback, |
| 117 base::Unretained(this))), | 119 base::Unretained(this))), |
| 118 install_result_target_(nullptr), | 120 install_result_target_(nullptr), |
| 119 programmable_prompt_(nullptr) {} | 121 programmable_prompt_(nullptr) {} |
| 120 | 122 |
| 121 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { | 123 std::unique_ptr<ExtensionInstallPrompt> CreateInstallUI() override { |
| 122 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents()); | 124 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents()); |
| 123 return make_scoped_ptr(programmable_prompt_); | 125 return base::WrapUnique(programmable_prompt_); |
| 124 } | 126 } |
| 125 | 127 |
| 126 // Added here to make it public so that test cases can call it below. | 128 // Added here to make it public so that test cases can call it below. |
| 127 bool CheckRequestorAlive() const override { | 129 bool CheckRequestorAlive() const override { |
| 128 return WebstoreInlineInstaller::CheckRequestorAlive(); | 130 return WebstoreInlineInstaller::CheckRequestorAlive(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // Tests that care about the actual arguments to the install callback can use | 133 // Tests that care about the actual arguments to the install callback can use |
| 132 // this to receive a copy in |install_result_target|. | 134 // this to receive a copy in |install_result_target|. |
| 133 void set_install_result_target( | 135 void set_install_result_target( |
| 134 scoped_ptr<InstallResult>* install_result_target) { | 136 std::unique_ptr<InstallResult>* install_result_target) { |
| 135 install_result_target_ = install_result_target; | 137 install_result_target_ = install_result_target; |
| 136 } | 138 } |
| 137 | 139 |
| 138 private: | 140 private: |
| 139 ~WebstoreInlineInstallerForTest() override {} | 141 ~WebstoreInlineInstallerForTest() override {} |
| 140 | 142 |
| 141 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; | 143 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; |
| 142 | 144 |
| 143 void InstallCallback(bool success, | 145 void InstallCallback(bool success, |
| 144 const std::string& error, | 146 const std::string& error, |
| 145 webstore_install::Result result) { | 147 webstore_install::Result result) { |
| 146 if (install_result_target_) { | 148 if (install_result_target_) { |
| 147 install_result_target_->reset(new InstallResult); | 149 install_result_target_->reset(new InstallResult); |
| 148 (*install_result_target_)->success = success; | 150 (*install_result_target_)->success = success; |
| 149 (*install_result_target_)->error = error; | 151 (*install_result_target_)->error = error; |
| 150 (*install_result_target_)->result = result; | 152 (*install_result_target_)->result = result; |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 | 155 |
| 154 // This can be set by tests that want to get the actual install callback | 156 // This can be set by tests that want to get the actual install callback |
| 155 // arguments. | 157 // arguments. |
| 156 scoped_ptr<InstallResult>* install_result_target_; | 158 std::unique_ptr<InstallResult>* install_result_target_; |
| 157 | 159 |
| 158 ProgrammableInstallPrompt* programmable_prompt_; | 160 ProgrammableInstallPrompt* programmable_prompt_; |
| 159 }; | 161 }; |
| 160 | 162 |
| 161 class WebstoreInlineInstallerForTestFactory : | 163 class WebstoreInlineInstallerForTestFactory : |
| 162 public WebstoreInlineInstallerFactory { | 164 public WebstoreInlineInstallerFactory { |
| 163 public: | 165 public: |
| 164 WebstoreInlineInstallerForTestFactory() : last_installer_(nullptr) {} | 166 WebstoreInlineInstallerForTestFactory() : last_installer_(nullptr) {} |
| 165 ~WebstoreInlineInstallerForTestFactory() override {} | 167 ~WebstoreInlineInstallerForTestFactory() override {} |
| 166 | 168 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ASSERT_NE(factory->last_installer(), nullptr); | 220 ASSERT_NE(factory->last_installer(), nullptr); |
| 219 EXPECT_NE(factory->last_installer()->web_contents(), nullptr); | 221 EXPECT_NE(factory->last_installer()->web_contents(), nullptr); |
| 220 EXPECT_FALSE(factory->last_installer()->CheckRequestorAlive()); | 222 EXPECT_FALSE(factory->last_installer()->CheckRequestorAlive()); |
| 221 | 223 |
| 222 // Right now the way we handle navigations away from the frame that began the | 224 // Right now the way we handle navigations away from the frame that began the |
| 223 // inline install is to just declare the requestor to be dead, but not to | 225 // inline install is to just declare the requestor to be dead, but not to |
| 224 // kill the prompt (that would be a better UX, but more complicated to | 226 // kill the prompt (that would be a better UX, but more complicated to |
| 225 // implement). If we ever do change things to kill the prompt in this case, | 227 // implement). If we ever do change things to kill the prompt in this case, |
| 226 // the following code can be removed (it verifies that clicking ok on the | 228 // the following code can be removed (it verifies that clicking ok on the |
| 227 // dialog does not result in an install). | 229 // dialog does not result in an install). |
| 228 scoped_ptr<InstallResult> install_result; | 230 std::unique_ptr<InstallResult> install_result; |
| 229 factory->last_installer()->set_install_result_target(&install_result); | 231 factory->last_installer()->set_install_result_target(&install_result); |
| 230 ASSERT_TRUE(ProgrammableInstallPrompt::Ready()); | 232 ASSERT_TRUE(ProgrammableInstallPrompt::Ready()); |
| 231 ProgrammableInstallPrompt::Accept(); | 233 ProgrammableInstallPrompt::Accept(); |
| 232 ASSERT_NE(install_result.get(), nullptr); | 234 ASSERT_NE(install_result.get(), nullptr); |
| 233 EXPECT_EQ(install_result->success, false); | 235 EXPECT_EQ(install_result->success, false); |
| 234 EXPECT_EQ(install_result->result, webstore_install::ABORTED); | 236 EXPECT_EQ(install_result->result, webstore_install::ABORTED); |
| 235 } | 237 } |
| 236 | 238 |
| 237 // Flaky: https://crbug.com/537526. | 239 // Flaky: https://crbug.com/537526. |
| 238 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | 240 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, | 331 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, |
| 330 DownloadProgressListenerTest) { | 332 DownloadProgressListenerTest) { |
| 331 RunTest("download_progress_listener.html"); | 333 RunTest("download_progress_listener.html"); |
| 332 } | 334 } |
| 333 | 335 |
| 334 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { | 336 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { |
| 335 RunTest("both_listeners.html"); | 337 RunTest("both_listeners.html"); |
| 336 } | 338 } |
| 337 | 339 |
| 338 } // namespace extensions | 340 } // namespace extensions |
| OLD | NEW |