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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc

Issue 2860663003: Make CWS Report Abuse page the active tab after report abuse and uninstall (Closed)
Patch Set: Added Tests Created 3 years, 7 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/macros.h" 5 #include "base/macros.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 8 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
12 #include "content/public/test/test_utils.h" 13 #include "content/public/test/test_utils.h"
14 #include "extensions/browser/extension_dialog_auto_confirm.h"
13 #include "extensions/browser/extension_system.h" 15 #include "extensions/browser/extension_system.h"
14 #include "extensions/common/extension.h" 16 #include "extensions/common/extension.h"
15 #include "extensions/common/extension_builder.h" 17 #include "extensions/common/extension_builder.h"
18 #include "extensions/common/extension_urls.h"
16 #include "extensions/common/value_builder.h" 19 #include "extensions/common/value_builder.h"
17 20
18 namespace { 21 namespace {
19 22
23 const char kReferrerId[] = "chrome-remove-extension-dialog";
24
25 // A preference key storing the url loaded when an extension is uninstalled.
26 const char kUninstallUrl[] = "uninstall_url";
27
20 scoped_refptr<extensions::Extension> BuildTestExtension() { 28 scoped_refptr<extensions::Extension> BuildTestExtension() {
21 return extensions::ExtensionBuilder() 29 return extensions::ExtensionBuilder()
22 .SetManifest(extensions::DictionaryBuilder() 30 .SetManifest(extensions::DictionaryBuilder()
23 .Set("name", "foo") 31 .Set("name", "foo")
24 .Set("version", "1.0") 32 .Set("version", "1.0")
25 .Build()) 33 .Build())
26 .Build(); 34 .Build();
27 } 35 }
28 36
37 const GURL& GetActiveUrl(Browser* browser) {
38 return browser->tab_strip_model()->GetActiveWebContents()->GetVisibleURL();
Devlin 2017/05/15 23:28:04 We should use GetLastCommittedURL() (everywhere in
catmullings 2017/05/18 18:26:00 GetLastCommitedURL returns an empty string when us
Devlin 2017/05/18 19:14:20 Ah, I see. We're checking this a bit too soon in
catmullings 2017/05/19 22:04:50 Done.
39 }
40
41 void SetUninstallURL(extensions::ExtensionPrefs* prefs,
42 const std::string& extension_id,
43 const std::string& url_string) {
44 prefs->UpdateExtensionPref(extension_id, kUninstallUrl,
45 base::MakeUnique<base::Value>(url_string));
46 }
47
29 class TestExtensionUninstallDialogDelegate 48 class TestExtensionUninstallDialogDelegate
30 : public extensions::ExtensionUninstallDialog::Delegate { 49 : public extensions::ExtensionUninstallDialog::Delegate {
31 public: 50 public:
32 explicit TestExtensionUninstallDialogDelegate( 51 explicit TestExtensionUninstallDialogDelegate(
33 const base::Closure& quit_closure) 52 const base::Closure& quit_closure)
34 : quit_closure_(quit_closure), canceled_(false) {} 53 : quit_closure_(quit_closure), canceled_(false) {}
35 54
36 ~TestExtensionUninstallDialogDelegate() override {} 55 ~TestExtensionUninstallDialogDelegate() override {}
37 56
38 bool canceled() { return canceled_; } 57 bool canceled() { return canceled_; }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 extensions::UNINSTALL_REASON_FOR_TESTING, 119 extensions::UNINSTALL_REASON_FOR_TESTING,
101 extensions::UNINSTALL_SOURCE_FOR_TESTING); 120 extensions::UNINSTALL_SOURCE_FOR_TESTING);
102 121
103 content::RunAllPendingInMessageLoop(); 122 content::RunAllPendingInMessageLoop();
104 123
105 // Kill parent window. 124 // Kill parent window.
106 browser()->window()->Close(); 125 browser()->window()->Close();
107 run_loop.Run(); 126 run_loop.Run();
108 EXPECT_TRUE(delegate.canceled()); 127 EXPECT_TRUE(delegate.canceled());
109 } 128 }
129
130 // Test that when the user clicks Uninstall on the ExtensionUninstallDialog, the
131 // extension's uninstall url (when it is specified) should open and be the
132 // active tab.
133 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
134 EnsureExtensionUninstallURLIsActiveTabAfterUninstall) {
135 scoped_refptr<extensions::Extension> extension(BuildTestExtension());
136 ExtensionService* extension_service =
137 extensions::ExtensionSystem::Get(browser()->profile())
138 ->extension_service();
139 std::string uninstall_url = "https://www.google.com/";
140 SetUninstallURL(
141 extensions::ExtensionPrefs::Get(extension_service->GetBrowserContext()),
Devlin 2017/05/15 23:28:04 Since we always set the same uninstall url, we cou
catmullings 2017/05/18 18:26:00 Did you mean profile or extension prefs?
Devlin 2017/05/18 19:14:20 I meant profile so that SetUninstallUrl() could ge
catmullings 2017/05/19 22:04:50 Sg. I will keep the prefs as a param.
catmullings 2017/05/19 22:04:50 Done.
142 extension->id(), uninstall_url);
143 extension_service->AddExtension(extension.get());
Devlin 2017/05/15 23:28:04 nit: let's AddExtension() before setting its unins
catmullings 2017/05/18 18:26:00 Done.
144
145 // Auto-confirm the uninstall dialog.
146 extensions::ScopedTestDialogAutoConfirm auto_confirm(
147 extensions::ScopedTestDialogAutoConfirm::ACCEPT);
148
149 base::RunLoop run_loop;
150 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure());
151 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog(
152 extensions::ExtensionUninstallDialog::Create(
153 browser()->profile(), browser()->window()->GetNativeWindow(),
154 &delegate));
155 content::RunAllPendingInMessageLoop();
156
157 dialog->ConfirmUninstall(extension,
158 // UNINSTALL_REASON_USER_INITIATED is used to trigger
159 // complete uninstallation.
160 extensions::UNINSTALL_REASON_USER_INITIATED,
161 extensions::UNINSTALL_SOURCE_FOR_TESTING);
162
163 content::RunAllPendingInMessageLoop();
164
165 // There should be 2 tabs open: chrome://about and the extension's uninstall
166 // url.
167 EXPECT_EQ(2, browser()->tab_strip_model()->count());
168 // Verifying that the extension's uninstall url is the active tab.
169 EXPECT_EQ(GetActiveUrl(browser()), uninstall_url);
170
171 // Kill parent window.
Devlin 2017/05/15 23:28:04 Is this necessary?
catmullings 2017/05/18 18:26:00 The comment? Or the code (browser()->window()->Clo
Devlin 2017/05/18 19:14:20 The code. The previous tests were checking destru
catmullings 2017/05/19 22:04:50 Done.
172 browser()->window()->Close();
173 run_loop.Run();
174 // The delegate should not be canceled because the user chose to uninstall the
175 // extension, which should be successful.
176 EXPECT_TRUE(!delegate.canceled());
177 }
178
179 // Test that when the user clicks the Report Abuse checkbox and clicks Uninstall
180 // on the ExtensionUninstallDialog, the extension's uninstall url (when it is
181 // specified) and the CWS Report Abuse survey are opened in the browser, also
182 // testing that the CWS survey is the active tab.
183 IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest,
184 EnsureCWSReportAbusePageIsActiveTabAfterUninstall) {
185 scoped_refptr<extensions::Extension> extension(BuildTestExtension());
186 ExtensionService* extension_service =
187 extensions::ExtensionSystem::Get(browser()->profile())
188 ->extension_service();
189 std::string uninstall_url = "https://www.google.com/";
190 SetUninstallURL(
191 extensions::ExtensionPrefs::Get(extension_service->GetBrowserContext()),
192 extension->id(), uninstall_url);
193 extension_service->AddExtension(extension.get());
194
195 // Auto-confirm the uninstall dialog.
196 extensions::ScopedTestDialogAutoConfirm auto_confirm(
197 extensions::ScopedTestDialogAutoConfirm::ACCEPT_AND_OPTION);
198
199 base::RunLoop run_loop;
200 TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure());
201 std::unique_ptr<extensions::ExtensionUninstallDialog> dialog(
202 extensions::ExtensionUninstallDialog::Create(
203 browser()->profile(), browser()->window()->GetNativeWindow(),
204 &delegate));
205 content::RunAllPendingInMessageLoop();
206
207 dialog->ConfirmUninstall(extension,
208 // UNINSTALL_REASON_USER_INITIATED is used to trigger
209 // complete uninstallation.
210 extensions::UNINSTALL_REASON_USER_INITIATED,
211 extensions::UNINSTALL_SOURCE_FOR_TESTING);
212
213 content::RunAllPendingInMessageLoop();
214
215 // There should be 3 tabs open: chrome://about, the extension's uninstall url,
216 // and the CWS Report Abuse survey.
217 EXPECT_EQ(3, browser()->tab_strip_model()->count());
218 // Verifying that the extension's uninstall url was opened. It should not be
219 // the active tab.
220 EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1)->GetVisibleURL(),
221 uninstall_url);
222 // The CWS Report Abuse survey should be the active tab.
223 EXPECT_EQ(
224 extension_urls::GetWebstoreReportAbuseUrl(extension->id(), kReferrerId),
225 GetActiveUrl(browser()));
226
227 // Kill parent window.
228 browser()->window()->Close();
229 run_loop.Run();
230 // The delegate should not be canceled because the user chose to uninstall the
231 // extension, which should be successful.
232 EXPECT_TRUE(!delegate.canceled());
233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698