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

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: fix unit test compile failure 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
31 const char kWebstoreDomain[] = "cws.com"; 32 const char kWebstoreDomain[] = "cws.com";
32 const char kAppDomain[] = "app.com"; 33 const char kAppDomain[] = "app.com";
33 const char kNonAppDomain[] = "nonapp.com"; 34 const char kNonAppDomain[] = "nonapp.com";
34 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje"; 35 const char kTestExtensionId[] = "ecglahbcnmdpdciemllbhojghbkagdje";
35 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install"; 36 const char kTestDataPath[] = "extensions/api_test/webstore_inline_install";
36 const char kCrxFilename[] = "extension.crx"; 37 const char kCrxFilename[] = "extension.crx";
37 38
39 // A struct for letting us store the actual parameters that were passed to
40 // the install callback.
41 struct InstallResult {
42 bool success = false;
43 std::string error;
44 webstore_install::Result result = webstore_install::RESULT_LAST;
45 };
46
38 } // namespace 47 } // namespace
39 48
40 class WebstoreInlineInstallerTest : public WebstoreInstallerTest { 49 class WebstoreInlineInstallerTest : public WebstoreInstallerTest {
41 public: 50 public:
42 WebstoreInlineInstallerTest() 51 WebstoreInlineInstallerTest()
43 : WebstoreInstallerTest( 52 : WebstoreInstallerTest(
44 kWebstoreDomain, 53 kWebstoreDomain,
45 kTestDataPath, 54 kTestDataPath,
46 kCrxFilename, 55 kCrxFilename,
47 kAppDomain, 56 kAppDomain,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 static Delegate* delegate_; 89 static Delegate* delegate_;
81 }; 90 };
82 91
83 ExtensionInstallPrompt::Delegate* ProgrammableInstallPrompt::delegate_; 92 ExtensionInstallPrompt::Delegate* ProgrammableInstallPrompt::delegate_;
84 93
85 // Fake inline installer which creates a programmable prompt in place of 94 // Fake inline installer which creates a programmable prompt in place of
86 // the normal dialog UI. 95 // the normal dialog UI.
87 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller { 96 class WebstoreInlineInstallerForTest : public WebstoreInlineInstaller {
88 public: 97 public:
89 WebstoreInlineInstallerForTest(WebContents* contents, 98 WebstoreInlineInstallerForTest(WebContents* contents,
99 content::RenderFrameHost* host,
90 const std::string& extension_id, 100 const std::string& extension_id,
91 const GURL& requestor_url, 101 const GURL& requestor_url,
92 const Callback& callback) 102 const Callback& callback)
93 : WebstoreInlineInstaller( 103 : WebstoreInlineInstaller(
94 contents, 104 contents,
105 host,
95 kTestExtensionId, 106 kTestExtensionId,
96 requestor_url, 107 requestor_url,
97 base::Bind(DummyCallback)), 108 base::Bind(&WebstoreInlineInstallerForTest::InstallCallback,
98 programmable_prompt_(NULL) { 109 base::Unretained(this))),
99 } 110 install_result_target_(nullptr),
111 programmable_prompt_(nullptr) {}
100 112
101 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { 113 scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override {
102 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents()); 114 programmable_prompt_ = new ProgrammableInstallPrompt(web_contents());
103 return make_scoped_ptr(programmable_prompt_); 115 return make_scoped_ptr(programmable_prompt_);
104 } 116 }
105 117
118 // Added here to make it public so that test cases can call it below.
119 bool CheckRequestorAlive() const override {
120 return WebstoreInlineInstaller::CheckRequestorAlive();
121 }
122
123 // Tests that care about the actual arguments to the install callback can use
124 // this to receive a copy in |install_result_target|.
125 void set_install_result_target(
126 scoped_ptr<InstallResult>* install_result_target) {
127 install_result_target_ = install_result_target;
128 }
129
106 private: 130 private:
107 ~WebstoreInlineInstallerForTest() override {} 131 ~WebstoreInlineInstallerForTest() override {}
108 132
109 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>; 133 friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>;
110 134
111 static void DummyCallback(bool success, 135 void InstallCallback(bool success,
112 const std::string& error, 136 const std::string& error,
113 webstore_install::Result result) { 137 webstore_install::Result result) {
138 if (install_result_target_) {
139 install_result_target_->reset(new InstallResult);
140 (*install_result_target_)->success = success;
141 (*install_result_target_)->error = error;
142 (*install_result_target_)->result = result;
143 }
114 } 144 }
115 145
146 // This can be set by tests that want to get the actual install callback
147 // arguments.
148 scoped_ptr<InstallResult>* install_result_target_;
149
116 ProgrammableInstallPrompt* programmable_prompt_; 150 ProgrammableInstallPrompt* programmable_prompt_;
117 }; 151 };
118 152
119 class WebstoreInlineInstallerForTestFactory : 153 class WebstoreInlineInstallerForTestFactory :
120 public WebstoreInlineInstallerFactory { 154 public WebstoreInlineInstallerFactory {
155 public:
156 WebstoreInlineInstallerForTestFactory() : last_installer_(nullptr) {}
121 ~WebstoreInlineInstallerForTestFactory() override {} 157 ~WebstoreInlineInstallerForTestFactory() override {}
158
159 WebstoreInlineInstallerForTest* last_installer() { return last_installer_; }
160
122 WebstoreInlineInstaller* CreateInstaller( 161 WebstoreInlineInstaller* CreateInstaller(
123 WebContents* contents, 162 WebContents* contents,
163 content::RenderFrameHost* host,
124 const std::string& webstore_item_id, 164 const std::string& webstore_item_id,
125 const GURL& requestor_url, 165 const GURL& requestor_url,
126 const WebstoreStandaloneInstaller::Callback& callback) override { 166 const WebstoreStandaloneInstaller::Callback& callback) override {
127 return new WebstoreInlineInstallerForTest( 167 last_installer_ = new WebstoreInlineInstallerForTest(
128 contents, webstore_item_id, requestor_url, callback); 168 contents, host, webstore_item_id, requestor_url, callback);
169 return last_installer_;
129 } 170 }
171
172 private:
173 // The last installer that was created.
174 WebstoreInlineInstallerForTest* last_installer_;
130 }; 175 };
131 176
132 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, 177 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
133 CloseTabBeforeInstallConfirmation) { 178 CloseTabBeforeInstallConfirmation) {
134 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); 179 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html");
135 ui_test_utils::NavigateToURL(browser(), install_url); 180 ui_test_utils::NavigateToURL(browser(), install_url);
136 WebContents* web_contents = 181 WebContents* web_contents =
137 browser()->tab_strip_model()->GetActiveWebContents(); 182 browser()->tab_strip_model()->GetActiveWebContents();
138 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); 183 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents);
139 tab_helper->SetWebstoreInlineInstallerFactoryForTests( 184 tab_helper->SetWebstoreInlineInstallerFactoryForTests(
140 new WebstoreInlineInstallerForTestFactory()); 185 new WebstoreInlineInstallerForTestFactory());
141 RunTestAsync("runTest"); 186 RunTestAsync("runTest");
142 while (!ProgrammableInstallPrompt::Ready()) 187 while (!ProgrammableInstallPrompt::Ready())
143 base::RunLoop().RunUntilIdle(); 188 base::RunLoop().RunUntilIdle();
144 web_contents->Close(); 189 web_contents->Close();
145 ProgrammableInstallPrompt::Accept(); 190 ProgrammableInstallPrompt::Accept();
146 } 191 }
147 192
193 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
194 NavigateBeforeInstallConfirmation) {
195 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html");
196 ui_test_utils::NavigateToURL(browser(), install_url);
197 WebContents* web_contents =
198 browser()->tab_strip_model()->GetActiveWebContents();
199 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents);
200 WebstoreInlineInstallerForTestFactory* factory =
201 new WebstoreInlineInstallerForTestFactory();
202 tab_helper->SetWebstoreInlineInstallerFactoryForTests(factory);
203 RunTestAsync("runTest");
204 while (!ProgrammableInstallPrompt::Ready())
205 base::RunLoop().RunUntilIdle();
206 GURL new_url = GenerateTestServerUrl(kNonAppDomain, "empty.html");
207 web_contents->GetController().LoadURL(
208 new_url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
209 EXPECT_TRUE(content::WaitForLoadStop(web_contents));
210 ASSERT_NE(factory->last_installer(), nullptr);
211 EXPECT_NE(factory->last_installer()->web_contents(), nullptr);
212 EXPECT_FALSE(factory->last_installer()->CheckRequestorAlive());
213
214 // Right now the way we handle navigations away from the frame that began the
215 // inline install is to just declare the requestor to be dead, but not to
216 // kill the prompt (that would be a better UX, but more complicated to
217 // implement). If we ever do change things to kill the prompt in this case,
218 // the following code can be removed (it verifies that clicking ok on the
219 // dialog does not result in an install).
220 scoped_ptr<InstallResult> install_result;
221 factory->last_installer()->set_install_result_target(&install_result);
222 ASSERT_TRUE(ProgrammableInstallPrompt::Ready());
223 ProgrammableInstallPrompt::Accept();
224 ASSERT_NE(install_result.get(), nullptr);
225 EXPECT_EQ(install_result->success, false);
226 EXPECT_EQ(install_result->result, webstore_install::ABORTED);
227 }
228
148 // Flaky: https://crbug.com/537526. 229 // Flaky: https://crbug.com/537526.
149 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, 230 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest,
150 DISABLED_ShouldBlockInlineInstallFromPopupWindow) { 231 DISABLED_ShouldBlockInlineInstallFromPopupWindow) {
151 GURL install_url = 232 GURL install_url =
152 GenerateTestServerUrl(kAppDomain, "install_from_popup.html"); 233 GenerateTestServerUrl(kAppDomain, "install_from_popup.html");
153 // Disable popup blocking for the test url. 234 // Disable popup blocking for the test url.
154 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 235 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
155 ->SetContentSetting(ContentSettingsPattern::FromURL(install_url), 236 ->SetContentSetting(ContentSettingsPattern::FromURL(install_url),
156 ContentSettingsPattern::Wildcard(), 237 ContentSettingsPattern::Wildcard(),
157 CONTENT_SETTINGS_TYPE_POPUPS, 238 CONTENT_SETTINGS_TYPE_POPUPS,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, 323 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest,
243 DownloadProgressListenerTest) { 324 DownloadProgressListenerTest) {
244 RunTest("download_progress_listener.html"); 325 RunTest("download_progress_listener.html");
245 } 326 }
246 327
247 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { 328 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) {
248 RunTest("both_listeners.html"); 329 RunTest("both_listeners.html");
249 } 330 }
250 331
251 } // namespace extensions 332 } // 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