Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chrome/browser/extensions/webstore_inline_installer_browsertest.cc

Issue 1403293008: Don't allow inline install if frame is deleted before user accepts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more fixes Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(
94 contents, 96 contents,
97 host,
95 kTestExtensionId, 98 kTestExtensionId,
96 requestor_url, 99 requestor_url,
97 base::Bind(DummyCallback)), 100 base::Bind(&WebstoreInlineInstallerForTest::InstallCallback)),
98 programmable_prompt_(NULL) { 101 programmable_prompt_(NULL) {}
99 }
100 102
101 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { 103 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override {
102 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents()); 104 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents());
103 return make_scoped_ptr(programmable_prompt_); 105 return make_scoped_ptr(programmable_prompt_);
104 } 106 }
105 107
108 // Added here to make it public so that test cases can call it below.
109 bool CheckRequestorAlive() const override {
110 return WebstoreInlineInstaller::CheckRequestorAlive();
111 }
112
113 // A struct for letting us store the actual parameters that were passed to
114 // the install callback.
115 struct InstallResult {
116 bool success;
Devlin 2015/11/20 01:27:19 nitty nit: please initialize these (feel free to u
asargent_no_longer_on_chrome 2015/11/20 23:56:46 Done.
117 std::string error;
118 webstore_install::Result result;
119 };
120
121 static InstallResult* last_install_result() { return g_last_install_result_; }
122
106 private: 123 private:
107 ~WebstoreInlineInstallerForTest() override {} 124 ~WebstoreInlineInstallerForTest() override {}
108 125
109 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; 126 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>;
110 127
111 static void DummyCallback(bool success, 128 static void InstallCallback(bool success,
112 const std::string& error, 129 const std::string& error,
113 webstore_install::Result result) { 130 webstore_install::Result result) {
131 g_last_install_result_ = new InstallResult;
132 g_last_install_result_->success = success;
133 g_last_install_result_->error = error;
134 g_last_install_result_->result = result;
114 } 135 }
115 136
137 static InstallResult* g_last_install_result_;
Devlin 2015/11/20 01:27:19 nitty nit: This isn't entirely POD (because of the
asargent_no_longer_on_chrome 2015/11/20 23:56:46 Yeah, that was probably a little too fast and loos
138
116 ProgrammableInstallPrompt* programmable_prompt_; 139 ProgrammableInstallPrompt* programmable_prompt_;
117 }; 140 };
118 141
142 WebstoreInlineInstallerForTest::InstallResult*
143 WebstoreInlineInstallerForTest::g_last_install_result_ = nullptr;
144
119 class WebstoreInlineInstallerForTestFactory : 145 class WebstoreInlineInstallerForTestFactory :
120 public WebstoreInlineInstallerFactory { 146 public WebstoreInlineInstallerFactory {
147 public:
148 WebstoreInlineInstallerForTestFactory() : last_installer_(nullptr) {}
121 ~WebstoreInlineInstallerForTestFactory() override {} 149 ~WebstoreInlineInstallerForTestFactory() override {}
150
151 WebstoreInlineInstallerForTest* last_installer() { return last_installer_; }
152
122 WebstoreInlineInstaller* CreateInstaller( 153 WebstoreInlineInstaller* CreateInstaller(
123 WebContents* contents, 154 WebContents* contents,
155 content::RenderFrameHost* host,
124 const std::string& webstore_item_id, 156 const std::string& webstore_item_id,
125 const GURL& requestor_url, 157 const GURL& requestor_url,
126 const WebstoreStandaloneInstaller::Callback& callback) override { 158 const WebstoreStandaloneInstaller::Callback& callback) override {
127 return new WebstoreInlineInstallerForTest( 159 last_installer_ = new WebstoreInlineInstallerForTest(
128 contents, webstore_item_id, requestor_url, callback); 160 contents, host, webstore_item_id, requestor_url, callback);
161 return last_installer_;
129 } 162 }
163
164 private:
165 // The last installer that was created.
166 WebstoreInlineInstallerForTest* last_installer_;
130 }; 167 };
131 168
132 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, 169 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
133 CloseTabBeforeInstallConfirmation) { 170 CloseTabBeforeInstallConfirmation) {
134 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); 171 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html");
135 ui_test_utils::NavigateToURL(browser(), install_url); 172 ui_test_utils::NavigateToURL(browser(), install_url);
136 WebContents* web_contents = 173 WebContents* web_contents =
137 browser()->tab_strip_model()->GetActiveWebContents(); 174 browser()->tab_strip_model()->GetActiveWebContents();
138 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); 175 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents);
139 tab_helper->SetWebstoreInlineInstallerFactoryForTests( 176 tab_helper->SetWebstoreInlineInstallerFactoryForTests(
140 new WebstoreInlineInstallerForTestFactory()); 177 new WebstoreInlineInstallerForTestFactory());
141 RunTestAsync("runTest"); 178 RunTestAsync("runTest");
142 while (!ProgrammableInstallPrompt::Ready()) 179 while (!ProgrammableInstallPrompt::Ready())
143 base::RunLoop().RunUntilIdle(); 180 base::RunLoop().RunUntilIdle();
144 web_contents->Close(); 181 web_contents->Close();
145 ProgrammableInstallPrompt::Accept(); 182 ProgrammableInstallPrompt::Accept();
146 } 183 }
147 184
185 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
186 NavigateBeforeInstallConfirmation) {
187 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html");
188 ui_test_utils::NavigateToURL(browser(), install_url);
189 WebContents* web_contents =
190 browser()->tab_strip_model()->GetActiveWebContents();
191 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents);
192 WebstoreInlineInstallerForTestFactory* factory =
193 new WebstoreInlineInstallerForTestFactory();
194 tab_helper->SetWebstoreInlineInstallerFactoryForTests(factory);
195 RunTestAsync("runTest");
196 while (!ProgrammableInstallPrompt::Ready())
197 base::RunLoop().RunUntilIdle();
198 GURL new_url = GenerateTestServerUrl(kNonAppDomain, "empty.html");
199 web_contents->GetController().LoadURL(
200 new_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
201 EXPECT_TRUE(content::WaitForLoadStop(web_contents));
202 ASSERT_NE(factory->last_installer(), nullptr);
203 EXPECT_NE(factory->last_installer()->web_contents(), nullptr);
204 EXPECT_FALSE(factory->last_installer()->CheckRequestorAlive());
205
206 // Right now the way we handle navigations away from the frame that began the
207 // inline install is to just declare the requestor to be dead, but not to
208 // kill the prompt (that would be a better UX, but more complicated to
209 // implement). If we ever do change things to kill the prompt in this case,
210 // the following code can be removed (it verifies that clicking ok on the
211 // dialog does not result in an install).
212 ASSERT_TRUE(ProgrammableInstallPrompt::Ready());
213 ProgrammableInstallPrompt::Accept();
214 WebstoreInlineInstallerForTest::InstallResult* install_result =
215 WebstoreInlineInstallerForTest::last_install_result();
216 ASSERT_NE(install_result, nullptr);
217 EXPECT_EQ(install_result->success, false);
218 EXPECT_EQ(install_result->result, webstore_install::ABORTED);
219 }
220
148 // Flaky: https://crbug.com/537526. 221 // Flaky: https://crbug.com/537526.
149 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, 222 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
150 DISABLED_ShouldBlockInlineInstallFromPopupWindow) { 223 DISABLED_ShouldBlockInlineInstallFromPopupWindow) {
151 GURL install_url = 224 GURL install_url =
152 GenerateTestServerUrl(kAppDomain, "install_from_popup.html"); 225 GenerateTestServerUrl(kAppDomain, "install_from_popup.html");
153 // Disable popup blocking for the test url. 226 // Disable popup blocking for the test url.
154 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 227 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
155 ->SetContentSetting(ContentSettingsPattern::FromURL(install_url), 228 ->SetContentSetting(ContentSettingsPattern::FromURL(install_url),
156 ContentSettingsPattern::Wildcard(), 229 ContentSettingsPattern::Wildcard(),
157 CONTENT_SETTINGS_TYPE_POPUPS, 230 CONTENT_SETTINGS_TYPE_POPUPS,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, 315 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest,
243 DownloadProgressListenerTest) { 316 DownloadProgressListenerTest) {
244 RunTest("download_progress_listener.html"); 317 RunTest("download_progress_listener.html");
245 } 318 }
246 319
247 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { 320 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) {
248 RunTest("both_listeners.html"); 321 RunTest("both_listeners.html");
249 } 322 }
250 323
251 } // namespace extensions 324 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/webstore_inline_installer.cc ('k') | chrome/browser/extensions/webstore_inline_installer_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698