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 |
| 30 class WebstoreInlineInstallerForTest; | |
| 31 | |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 31 const char kWebstoreDomain[] = "cws.com"; | 34 const char kWebstoreDomain[] = "cws.com"; |
| 32 const char kAppDomain[] = "app.com"; | 35 const char kAppDomain[] = "app.com"; |
| 33 const char kNonAppDomain[] = "nonapp.com"; | 36 const char kNonAppDomain[] = "nonapp.com"; |
| 34 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; | 37 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; |
| 35 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install"; | 38 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install"; |
| 36 const char kCrxFilename[] = "extension.crx"; | 39 const char kCrxFilename[] = "extension.crx"; |
| 37 | 40 |
| 41 class InstallerFactoryObserver { | |
|
Devlin
2015/11/05 17:40:40
nit: I think this is a little more than we need.
asargent_no_longer_on_chrome
2015/11/18 21:42:44
Much simpler, I like it. Done.
| |
| 42 public: | |
| 43 virtual void OnInstallerCreated( | |
| 44 WebstoreInlineInstallerForTest* installer) = 0; | |
| 45 }; | |
| 46 | |
| 38 } // namespace | 47 } // namespace |
| 39 | 48 |
| 40 class WebstoreInlineInstallerTest : public WebstoreInstallerTest { | 49 class WebstoreInlineInstallerTest : public WebstoreInstallerTest, |
| 50 public InstallerFactoryObserver { | |
| 41 public: | 51 public: |
| 42 WebstoreInlineInstallerTest() | 52 WebstoreInlineInstallerTest() |
| 43 : WebstoreInstallerTest( | 53 : WebstoreInstallerTest(kWebstoreDomain, |
| 44 kWebstoreDomain, | 54 kTestDataPath, |
| 45 kTestDataPath, | 55 kCrxFilename, |
| 46 kCrxFilename, | 56 kAppDomain, |
| 47 kAppDomain, | 57 kNonAppDomain), |
| 48 kNonAppDomain) {} | 58 last_installer_(nullptr) {} |
| 59 | |
| 60 void OnInstallerCreated(WebstoreInlineInstallerForTest* installer) override { | |
| 61 last_installer_ = installer; | |
| 62 } | |
| 63 | |
| 64 protected: | |
| 65 WebstoreInlineInstallerForTest* last_installer_; | |
| 49 }; | 66 }; |
| 50 | 67 |
| 51 class ProgrammableInstallPrompt : public ExtensionInstallPrompt { | 68 class ProgrammableInstallPrompt : public ExtensionInstallPrompt { |
| 52 public: | 69 public: |
| 53 explicit ProgrammableInstallPrompt(WebContents* contents) | 70 explicit ProgrammableInstallPrompt(WebContents* contents) |
| 54 : ExtensionInstallPrompt(contents) | 71 : ExtensionInstallPrompt(contents) |
| 55 {} | 72 {} |
| 56 | 73 |
| 57 ~ProgrammableInstallPrompt() override {} | 74 ~ProgrammableInstallPrompt() override {} |
| 58 | 75 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 80 static Delegate* delegate_; | 97 static Delegate* delegate_; |
| 81 }; | 98 }; |
| 82 | 99 |
| 83 ExtensionInstallPrompt::Delegate* ProgrammableInstallPrompt::delegate_; | 100 ExtensionInstallPrompt::Delegate* ProgrammableInstallPrompt::delegate_; |
| 84 | 101 |
| 85 // Fake inline installer which creates a programmable prompt in place of | 102 // Fake inline installer which creates a programmable prompt in place of |
| 86 // the normal dialog UI. | 103 // the normal dialog UI. |
| 87 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller { | 104 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller { |
| 88 public: | 105 public: |
| 89 WebstoreInlineInstallerForTest(WebContents* contents, | 106 WebstoreInlineInstallerForTest(WebContents* contents, |
| 107 content::RenderFrameHost* host, | |
| 90 const std::string& extension_id, | 108 const std::string& extension_id, |
| 91 const GURL& requestor_url, | 109 const GURL& requestor_url, |
| 92 const Callback& callback) | 110 const Callback& callback) |
| 93 : WebstoreInlineInstaller( | 111 : WebstoreInlineInstaller(contents, |
| 94 contents, | 112 host, |
| 95 kTestExtensionId, | 113 kTestExtensionId, |
| 96 requestor_url, | 114 requestor_url, |
| 97 base::Bind(DummyCallback)), | 115 base::Bind(DummyCallback)), |
| 98 programmable_prompt_(NULL) { | 116 programmable_prompt_(NULL) {} |
| 99 } | |
| 100 | 117 |
| 101 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { | 118 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { |
| 102 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents()); | 119 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents()); |
| 103 return make_scoped_ptr(programmable_prompt_); | 120 return make_scoped_ptr(programmable_prompt_); |
| 104 } | 121 } |
| 105 | 122 |
| 123 bool CheckRequestorAlive() const override { | |
| 124 return WebstoreInlineInstaller::CheckRequestorAlive(); | |
|
Devlin
2015/11/05 17:40:40
Is this needed?
asargent_no_longer_on_chrome
2015/11/18 21:42:44
It's just needed to make the method publicly visib
| |
| 125 } | |
| 126 | |
| 106 private: | 127 private: |
| 107 ~WebstoreInlineInstallerForTest() override {} | 128 ~WebstoreInlineInstallerForTest() override {} |
| 108 | 129 |
| 109 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; | 130 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; |
| 110 | 131 |
| 111 static void DummyCallback(bool success, | 132 static void DummyCallback(bool success, |
| 112 const std::string& error, | 133 const std::string& error, |
| 113 webstore_install::Result result) { | 134 webstore_install::Result result) { |
| 114 } | 135 } |
| 115 | 136 |
| 116 ProgrammableInstallPrompt* programmable_prompt_; | 137 ProgrammableInstallPrompt* programmable_prompt_; |
| 117 }; | 138 }; |
| 118 | 139 |
| 119 class WebstoreInlineInstallerForTestFactory : | 140 class WebstoreInlineInstallerForTestFactory : |
| 120 public WebstoreInlineInstallerFactory { | 141 public WebstoreInlineInstallerFactory { |
| 142 public: | |
| 143 explicit WebstoreInlineInstallerForTestFactory( | |
| 144 InstallerFactoryObserver* observer) | |
| 145 : observer_(observer) {} | |
| 146 | |
| 121 ~WebstoreInlineInstallerForTestFactory() override {} | 147 ~WebstoreInlineInstallerForTestFactory() override {} |
| 122 WebstoreInlineInstaller* CreateInstaller( | 148 WebstoreInlineInstaller* CreateInstaller( |
| 123 WebContents* contents, | 149 WebContents* contents, |
| 150 content::RenderFrameHost* host, | |
| 124 const std::string& webstore_item_id, | 151 const std::string& webstore_item_id, |
| 125 const GURL& requestor_url, | 152 const GURL& requestor_url, |
| 126 const WebstoreStandaloneInstaller::Callback& callback) override { | 153 const WebstoreStandaloneInstaller::Callback& callback) override { |
| 127 return new WebstoreInlineInstallerForTest( | 154 WebstoreInlineInstallerForTest* installer = |
| 128 contents, webstore_item_id, requestor_url, callback); | 155 new WebstoreInlineInstallerForTest(contents, host, webstore_item_id, |
| 156 requestor_url, callback); | |
| 157 observer_->OnInstallerCreated(installer); | |
| 158 return installer; | |
| 129 } | 159 } |
| 160 | |
| 161 protected: | |
| 162 InstallerFactoryObserver* observer_; | |
| 130 }; | 163 }; |
| 131 | 164 |
| 132 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | 165 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, |
| 133 CloseTabBeforeInstallConfirmation) { | 166 CloseTabBeforeInstallConfirmation) { |
| 134 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); | 167 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); |
| 135 ui_test_utils::NavigateToURL(browser(), install_url); | 168 ui_test_utils::NavigateToURL(browser(), install_url); |
| 136 WebContents* web_contents = | 169 WebContents* web_contents = |
| 137 browser()->tab_strip_model()->GetActiveWebContents(); | 170 browser()->tab_strip_model()->GetActiveWebContents(); |
| 138 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); | 171 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); |
| 139 tab_helper->SetWebstoreInlineInstallerFactoryForTests( | 172 tab_helper->SetWebstoreInlineInstallerFactoryForTests( |
| 140 new WebstoreInlineInstallerForTestFactory()); | 173 new WebstoreInlineInstallerForTestFactory(this)); |
| 141 RunTestAsync("runTest"); | 174 RunTestAsync("runTest"); |
| 142 while (!ProgrammableInstallPrompt::Ready()) | 175 while (!ProgrammableInstallPrompt::Ready()) |
| 143 base::RunLoop().RunUntilIdle(); | 176 base::RunLoop().RunUntilIdle(); |
| 144 web_contents->Close(); | 177 web_contents->Close(); |
| 145 ProgrammableInstallPrompt::Accept(); | 178 ProgrammableInstallPrompt::Accept(); |
| 146 } | 179 } |
| 147 | 180 |
| 181 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | |
| 182 NavigateBeforeInstallConfirmation) { | |
| 183 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); | |
| 184 ui_test_utils::NavigateToURL(browser(), install_url); | |
| 185 WebContents* web_contents = | |
| 186 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 187 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); | |
| 188 tab_helper->SetWebstoreInlineInstallerFactoryForTests( | |
| 189 new WebstoreInlineInstallerForTestFactory(this)); | |
| 190 RunTestAsync("runTest"); | |
| 191 while (!ProgrammableInstallPrompt::Ready()) | |
| 192 base::RunLoop().RunUntilIdle(); | |
| 193 GURL new_url = GenerateTestServerUrl(kNonAppDomain, "empty.html"); | |
| 194 web_contents->GetController().LoadURL( | |
| 195 new_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | |
| 196 EXPECT_TRUE(content::WaitForLoadStop(web_contents)); | |
| 197 ASSERT_NE(last_installer_, nullptr); | |
| 198 EXPECT_NE(last_installer_->web_contents(), nullptr); | |
| 199 EXPECT_FALSE(last_installer_->CheckRequestorAlive()); | |
|
Devlin
2015/11/05 17:40:40
Can we also test inline installation from a frame,
asargent_no_longer_on_chrome
2015/11/18 21:42:44
I wrote up a test for it, and in the process of tr
| |
| 200 } | |
| 201 | |
| 148 // Flaky: https://crbug.com/537526. | 202 // Flaky: https://crbug.com/537526. |
| 149 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | 203 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, |
| 150 DISABLED_ShouldBlockInlineInstallFromPopupWindow) { | 204 DISABLED_ShouldBlockInlineInstallFromPopupWindow) { |
| 151 GURL install_url = | 205 GURL install_url = |
| 152 GenerateTestServerUrl(kAppDomain, "install_from_popup.html"); | 206 GenerateTestServerUrl(kAppDomain, "install_from_popup.html"); |
| 153 // Disable popup blocking for the test url. | 207 // Disable popup blocking for the test url. |
| 154 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 208 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 155 ->SetContentSetting(ContentSettingsPattern::FromURL(install_url), | 209 ->SetContentSetting(ContentSettingsPattern::FromURL(install_url), |
| 156 ContentSettingsPattern::Wildcard(), | 210 ContentSettingsPattern::Wildcard(), |
| 157 CONTENT_SETTINGS_TYPE_POPUPS, | 211 CONTENT_SETTINGS_TYPE_POPUPS, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, | 296 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, |
| 243 DownloadProgressListenerTest) { | 297 DownloadProgressListenerTest) { |
| 244 RunTest("download_progress_listener.html"); | 298 RunTest("download_progress_listener.html"); |
| 245 } | 299 } |
| 246 | 300 |
| 247 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { | 301 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { |
| 248 RunTest("both_listeners.html"); | 302 RunTest("both_listeners.html"); |
| 249 } | 303 } |
| 250 | 304 |
| 251 } // namespace extensions | 305 } // namespace extensions |
| OLD | NEW |