Chromium Code Reviews| 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 7 #include "chrome/browser/extensions/extension_install_prompt.h" | 7 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/tab_helper.h" | 9 #include "chrome/browser/extensions/tab_helper.h" |
| 10 #include "chrome/browser/extensions/webstore_inline_installer.h" | 10 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 11 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" | 11 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" |
| 12 #include "chrome/browser/extensions/webstore_installer_test.h" | 12 #include "chrome/browser/extensions/webstore_installer_test.h" |
| 13 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 13 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "components/content_settings/core/browser/host_content_settings_map.h" | 19 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/test/browser_test_utils.h" | |
| 21 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
| 22 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
| 23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 24 | 25 |
| 25 using content::WebContents; | 26 using content::WebContents; |
| 26 | 27 |
| 27 namespace extensions { | 28 namespace extensions { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 static Delegate* delegate_; | 81 static Delegate* delegate_; |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 ExtensionInstallPrompt::Delegate* ProgrammableInstallPrompt::delegate_; | 84 ExtensionInstallPrompt::Delegate* ProgrammableInstallPrompt::delegate_; |
| 84 | 85 |
| 85 // Fake inline installer which creates a programmable prompt in place of | 86 // Fake inline installer which creates a programmable prompt in place of |
| 86 // the normal dialog UI. | 87 // the normal dialog UI. |
| 87 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller { | 88 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller { |
| 88 public: | 89 public: |
| 89 WebstoreInlineInstallerForTest(WebContents* contents, | 90 WebstoreInlineInstallerForTest(WebContents* contents, |
| 91 content::RenderFrameHost* host, | |
| 90 const std::string& extension_id, | 92 const std::string& extension_id, |
| 91 const GURL& requestor_url, | 93 const GURL& requestor_url, |
| 92 const Callback& callback) | 94 const Callback& callback) |
| 93 : WebstoreInlineInstaller( | 95 : WebstoreInlineInstaller(contents, |
| 94 contents, | 96 host, |
| 95 kTestExtensionId, | 97 kTestExtensionId, |
| 96 requestor_url, | 98 requestor_url, |
| 97 base::Bind(DummyCallback)), | 99 base::Bind(DummyCallback)), |
| 98 programmable_prompt_(NULL) { | 100 programmable_prompt_(NULL) {} |
| 99 } | |
| 100 | 101 |
| 101 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { | 102 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { |
| 102 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents()); | 103 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents()); |
| 103 return make_scoped_ptr(programmable_prompt_); | 104 return make_scoped_ptr(programmable_prompt_); |
| 104 } | 105 } |
| 105 | 106 |
| 107 // Added here to make it public so that test cases can call it below. | |
| 108 bool CheckRequestorAlive() const override { | |
| 109 return WebstoreInlineInstaller::CheckRequestorAlive(); | |
| 110 } | |
| 111 | |
| 106 private: | 112 private: |
| 107 ~WebstoreInlineInstallerForTest() override {} | 113 ~WebstoreInlineInstallerForTest() override {} |
| 108 | 114 |
| 109 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; | 115 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; |
| 110 | 116 |
| 111 static void DummyCallback(bool success, | 117 static void DummyCallback(bool success, |
| 112 const std::string& error, | 118 const std::string& error, |
| 113 webstore_install::Result result) { | 119 webstore_install::Result result) { |
| 114 } | 120 } |
| 115 | 121 |
| 116 ProgrammableInstallPrompt* programmable_prompt_; | 122 ProgrammableInstallPrompt* programmable_prompt_; |
| 117 }; | 123 }; |
| 118 | 124 |
| 119 class WebstoreInlineInstallerForTestFactory : | 125 class WebstoreInlineInstallerForTestFactory : |
| 120 public WebstoreInlineInstallerFactory { | 126 public WebstoreInlineInstallerFactory { |
| 127 public: | |
| 128 WebstoreInlineInstallerForTestFactory() : last_installer_(nullptr) {} | |
| 121 ~WebstoreInlineInstallerForTestFactory() override {} | 129 ~WebstoreInlineInstallerForTestFactory() override {} |
| 130 | |
| 131 // Returns a pointer to the last installer that was created. | |
|
Devlin
2015/11/18 21:48:26
nitty nit: I think it's more common to put the des
asargent_no_longer_on_chrome
2015/11/20 01:11:47
Done.
| |
| 132 WebstoreInlineInstallerForTest* last_installer() { return last_installer_; } | |
| 133 | |
| 122 WebstoreInlineInstaller* CreateInstaller( | 134 WebstoreInlineInstaller* CreateInstaller( |
| 123 WebContents* contents, | 135 WebContents* contents, |
| 136 content::RenderFrameHost* host, | |
| 124 const std::string& webstore_item_id, | 137 const std::string& webstore_item_id, |
| 125 const GURL& requestor_url, | 138 const GURL& requestor_url, |
| 126 const WebstoreStandaloneInstaller::Callback& callback) override { | 139 const WebstoreStandaloneInstaller::Callback& callback) override { |
| 127 return new WebstoreInlineInstallerForTest( | 140 last_installer_ = new WebstoreInlineInstallerForTest( |
| 128 contents, webstore_item_id, requestor_url, callback); | 141 contents, host, webstore_item_id, requestor_url, callback); |
| 142 return last_installer_; | |
| 129 } | 143 } |
| 144 | |
| 145 protected: | |
|
Devlin
2015/11/18 21:48:26
nit: Let's do private (unless there's a reason for
asargent_no_longer_on_chrome
2015/11/20 01:11:47
Done.
| |
| 146 WebstoreInlineInstallerForTest* last_installer_; | |
| 130 }; | 147 }; |
| 131 | 148 |
| 132 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | 149 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, |
| 133 CloseTabBeforeInstallConfirmation) { | 150 CloseTabBeforeInstallConfirmation) { |
| 134 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); | 151 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); |
| 135 ui_test_utils::NavigateToURL(browser(), install_url); | 152 ui_test_utils::NavigateToURL(browser(), install_url); |
| 136 WebContents* web_contents = | 153 WebContents* web_contents = |
| 137 browser()->tab_strip_model()->GetActiveWebContents(); | 154 browser()->tab_strip_model()->GetActiveWebContents(); |
| 138 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); | 155 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); |
| 139 tab_helper->SetWebstoreInlineInstallerFactoryForTests( | 156 tab_helper->SetWebstoreInlineInstallerFactoryForTests( |
| 140 new WebstoreInlineInstallerForTestFactory()); | 157 new WebstoreInlineInstallerForTestFactory()); |
| 141 RunTestAsync("runTest"); | 158 RunTestAsync("runTest"); |
| 142 while (!ProgrammableInstallPrompt::Ready()) | 159 while (!ProgrammableInstallPrompt::Ready()) |
| 143 base::RunLoop().RunUntilIdle(); | 160 base::RunLoop().RunUntilIdle(); |
| 144 web_contents->Close(); | 161 web_contents->Close(); |
| 145 ProgrammableInstallPrompt::Accept(); | 162 ProgrammableInstallPrompt::Accept(); |
| 146 } | 163 } |
| 147 | 164 |
| 165 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | |
| 166 NavigateBeforeInstallConfirmation) { | |
| 167 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); | |
| 168 ui_test_utils::NavigateToURL(browser(), install_url); | |
| 169 WebContents* web_contents = | |
| 170 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 171 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); | |
| 172 WebstoreInlineInstallerForTestFactory* factory = | |
| 173 new WebstoreInlineInstallerForTestFactory(); | |
| 174 tab_helper->SetWebstoreInlineInstallerFactoryForTests(factory); | |
| 175 RunTestAsync("runTest"); | |
| 176 while (!ProgrammableInstallPrompt::Ready()) | |
| 177 base::RunLoop().RunUntilIdle(); | |
| 178 GURL new_url = GenerateTestServerUrl(kNonAppDomain, "empty.html"); | |
| 179 web_contents->GetController().LoadURL( | |
| 180 new_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | |
| 181 EXPECT_TRUE(content::WaitForLoadStop(web_contents)); | |
| 182 ASSERT_NE(factory->last_installer(), nullptr); | |
| 183 EXPECT_NE(factory->last_installer()->web_contents(), nullptr); | |
| 184 EXPECT_FALSE(factory->last_installer()->CheckRequestorAlive()); | |
|
Devlin
2015/11/18 21:48:26
Since we don't cancel the installation here, can w
asargent_no_longer_on_chrome
2015/11/20 01:11:47
Good suggestion - I ended up having to add a bit o
| |
| 185 } | |
| 186 | |
| 148 // Flaky: https://crbug.com/537526. | 187 // Flaky: https://crbug.com/537526. |
| 149 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | 188 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, |
| 150 DISABLED_ShouldBlockInlineInstallFromPopupWindow) { | 189 DISABLED_ShouldBlockInlineInstallFromPopupWindow) { |
| 151 GURL install_url = | 190 GURL install_url = |
| 152 GenerateTestServerUrl(kAppDomain, "install_from_popup.html"); | 191 GenerateTestServerUrl(kAppDomain, "install_from_popup.html"); |
| 153 // Disable popup blocking for the test url. | 192 // Disable popup blocking for the test url. |
| 154 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 193 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 155 ->SetContentSetting(ContentSettingsPattern::FromURL(install_url), | 194 ->SetContentSetting(ContentSettingsPattern::FromURL(install_url), |
| 156 ContentSettingsPattern::Wildcard(), | 195 ContentSettingsPattern::Wildcard(), |
| 157 CONTENT_SETTINGS_TYPE_POPUPS, | 196 CONTENT_SETTINGS_TYPE_POPUPS, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, | 281 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, |
| 243 DownloadProgressListenerTest) { | 282 DownloadProgressListenerTest) { |
| 244 RunTest("download_progress_listener.html"); | 283 RunTest("download_progress_listener.html"); |
| 245 } | 284 } |
| 246 | 285 |
| 247 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { | 286 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { |
| 248 RunTest("both_listeners.html"); | 287 RunTest("both_listeners.html"); |
| 249 } | 288 } |
| 250 | 289 |
| 251 } // namespace extensions | 290 } // namespace extensions |
| OLD | NEW |