Chromium Code Reviews| Index: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc |
| diff --git a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc |
| index 5e0fbcb4aef207f297d91e469e800ca8a3134369..224437a097a9db8063221e46e30e057f839257e0 100644 |
| --- a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc |
| +++ b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view_browsertest.cc |
| @@ -8,15 +8,24 @@ |
| #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_window.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| +#include "content/public/test/browser_test_utils.h" |
| #include "content/public/test/test_utils.h" |
| +#include "extensions/browser/extension_dialog_auto_confirm.h" |
| #include "extensions/browser/extension_system.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/extension_builder.h" |
| +#include "extensions/common/extension_urls.h" |
| #include "extensions/common/value_builder.h" |
| namespace { |
| +const char kReferrerId[] = "chrome-remove-extension-dialog"; |
| + |
| +// A preference key storing the url loaded when an extension is uninstalled. |
| +const char kUninstallUrl[] = "uninstall_url"; |
| + |
| scoped_refptr<extensions::Extension> BuildTestExtension() { |
| return extensions::ExtensionBuilder() |
| .SetManifest(extensions::DictionaryBuilder() |
| @@ -26,6 +35,19 @@ scoped_refptr<extensions::Extension> BuildTestExtension() { |
| .Build(); |
| } |
| +const GURL& GetActiveUrl(Browser* browser) { |
| + return browser->tab_strip_model() |
| + ->GetActiveWebContents() |
| + ->GetLastCommittedURL(); |
| +} |
| + |
| +void SetUninstallURL(extensions::ExtensionPrefs* prefs, |
| + const std::string& extension_id) { |
| + std::string uninstall_url = "https://www.google.com/"; |
| + prefs->UpdateExtensionPref(extension_id, kUninstallUrl, |
| + base::MakeUnique<base::Value>(uninstall_url)); |
| +} |
| + |
| class TestExtensionUninstallDialogDelegate |
| : public extensions::ExtensionUninstallDialog::Delegate { |
| public: |
| @@ -107,3 +129,117 @@ IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
| run_loop.Run(); |
| EXPECT_TRUE(delegate.canceled()); |
| } |
| + |
| +// Test that when the user clicks Uninstall on the ExtensionUninstallDialog, the |
| +// extension's uninstall url (when it is specified) should open and be the |
| +// active tab. |
| +IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
| + EnsureExtensionUninstallURLIsActiveTabAfterUninstall) { |
| + scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
| + ExtensionService* extension_service = |
| + extensions::ExtensionSystem::Get(browser()->profile()) |
| + ->extension_service(); |
| + std::string uninstall_url = "https://www.google.com/"; |
|
Devlin
2017/05/19 22:56:56
nit: we should pull this up to a const char (near
|
| + extension_service->AddExtension(extension.get()); |
| + SetUninstallURL( |
| + extensions::ExtensionPrefs::Get(extension_service->GetBrowserContext()), |
| + extension->id()); |
| + |
| + // Auto-confirm the uninstall dialog. |
| + extensions::ScopedTestDialogAutoConfirm auto_confirm( |
| + extensions::ScopedTestDialogAutoConfirm::ACCEPT); |
| + |
| + base::RunLoop run_loop; |
| + TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
| + std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
| + extensions::ExtensionUninstallDialog::Create( |
| + browser()->profile(), browser()->window()->GetNativeWindow(), |
| + &delegate)); |
| + content::RunAllPendingInMessageLoop(); |
| + |
| + dialog->ConfirmUninstall(extension, |
| + // UNINSTALL_REASON_USER_INITIATED is used to trigger |
| + // complete uninstallation. |
| + extensions::UNINSTALL_REASON_USER_INITIATED, |
| + extensions::UNINSTALL_SOURCE_FOR_TESTING); |
| + |
| + content::RunAllPendingInMessageLoop(); |
| + |
| + // There should be 2 tabs open: chrome://about and the extension's uninstall |
| + // url. |
| + EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| + // This navigation can fail, since the uninstall url isn't hooked up to the |
| + // test server. That's fine, since we only care about the intended target, |
| + // which is valid. |
| + content::WaitForLoadStop( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| + // Verifying that the extension's uninstall url is the active tab. |
| + EXPECT_EQ(GetActiveUrl(browser()), uninstall_url); |
|
Devlin
2017/05/19 22:56:56
nit: EXPECT_EQ(expected, actual)
so: EXPECT_EQ(uni
|
| + |
| + run_loop.Run(); |
| + // The delegate should not be canceled because the user chose to uninstall the |
| + // extension, which should be successful. |
| + EXPECT_TRUE(!delegate.canceled()); |
| +} |
| + |
| +// Test that when the user clicks the Report Abuse checkbox and clicks Uninstall |
| +// on the ExtensionUninstallDialog, the extension's uninstall url (when it is |
| +// specified) and the CWS Report Abuse survey are opened in the browser, also |
| +// testing that the CWS survey is the active tab. |
| +IN_PROC_BROWSER_TEST_F(ExtensionUninstallDialogViewBrowserTest, |
| + EnsureCWSReportAbusePageIsActiveTabAfterUninstall) { |
| + scoped_refptr<extensions::Extension> extension(BuildTestExtension()); |
| + ExtensionService* extension_service = |
| + extensions::ExtensionSystem::Get(browser()->profile()) |
| + ->extension_service(); |
| + std::string uninstall_url = "https://www.google.com/"; |
| + SetUninstallURL( |
| + extensions::ExtensionPrefs::Get(extension_service->GetBrowserContext()), |
| + extension->id()); |
| + extension_service->AddExtension(extension.get()); |
| + |
| + // Auto-confirm the uninstall dialog. |
| + extensions::ScopedTestDialogAutoConfirm auto_confirm( |
| + extensions::ScopedTestDialogAutoConfirm::ACCEPT_AND_OPTION); |
| + |
| + base::RunLoop run_loop; |
| + TestExtensionUninstallDialogDelegate delegate(run_loop.QuitClosure()); |
| + std::unique_ptr<extensions::ExtensionUninstallDialog> dialog( |
| + extensions::ExtensionUninstallDialog::Create( |
| + browser()->profile(), browser()->window()->GetNativeWindow(), |
| + &delegate)); |
| + content::RunAllPendingInMessageLoop(); |
| + |
| + dialog->ConfirmUninstall(extension, |
| + // UNINSTALL_REASON_USER_INITIATED is used to trigger |
| + // complete uninstallation. |
| + extensions::UNINSTALL_REASON_USER_INITIATED, |
| + extensions::UNINSTALL_SOURCE_FOR_TESTING); |
| + |
| + content::RunAllPendingInMessageLoop(); |
| + // There should be 3 tabs open: chrome://about, the extension's uninstall url, |
| + // and the CWS Report Abuse survey. |
| + EXPECT_EQ(3, browser()->tab_strip_model()->count()); |
| + // This navigation can fail, since the webstore report abuse url isn't hooked |
| + // up to the test server. That's fine, since we only care about the intended |
| + // target, which is valid. |
| + content::WaitForLoadStop( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| + // The CWS Report Abuse survey should be the active tab. |
| + EXPECT_EQ( |
| + extension_urls::GetWebstoreReportAbuseUrl(extension->id(), kReferrerId), |
| + GetActiveUrl(browser())); |
| + // Similar to the scenario above, this navigation can fail. The uninstall url |
| + // isn't hooked up to our test server. |
| + content::WaitForLoadStop(browser()->tab_strip_model()->GetWebContentsAt(1)); |
| + // Verifying that the extension's uninstall url was opened. It should not be |
| + // the active tab. |
| + EXPECT_EQ( |
| + browser()->tab_strip_model()->GetWebContentsAt(1)->GetLastCommittedURL(), |
| + uninstall_url); |
| + |
| + run_loop.Run(); |
| + // The delegate should not be canceled because the user chose to uninstall the |
| + // extension, which should be successful. |
| + EXPECT_TRUE(!delegate.canceled()); |
| +} |