Commit dab9fba5 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

WebAppUninstallDialogViewBrowserTest does not rely on extensions

The tests BookmarkAppUninstallDialogViewBrowserTest and
BookmarkAppUninstallDialogViewInteractiveBrowserTest previously relies
on extensions methods to install "bookmark apps". We now refer to
these as web apps, and now use web_app:: functions to install them.


Bug: 1052722
Change-Id: Ie4f81682ffa4282a88f06ca89578b3f093507ea1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067774
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743869}
parent b8b7df1d
...@@ -9,49 +9,42 @@ ...@@ -9,49 +9,42 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h" #include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/web_apps/web_app_uninstall_dialog_view.h" #include "chrome/browser/ui/views/web_apps/web_app_uninstall_dialog_view.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "extensions/browser/extension_system.h" using web_app::AppId;
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/value_builder.h"
namespace { namespace {
scoped_refptr<const extensions::Extension> BuildTestBookmarkApp() { AppId InstallTestWebApp(Profile* profile) {
extensions::ExtensionBuilder extension_builder("foo"); const GURL example_url = GURL("http://example.org/");
extension_builder.AddFlags(extensions::Extension::FROM_BOOKMARK);
extension_builder.SetManifestPath({"app", "launch", "web_url"}, auto web_app_info = std::make_unique<WebApplicationInfo>();
"https://example.com/"); web_app_info->app_url = example_url;
return extension_builder.Build(); web_app_info->scope = example_url;
web_app_info->open_as_window = true;
return web_app::InstallWebApp(profile, std::move(web_app_info));
} }
} // namespace } // namespace
using BookmarkAppUninstallDialogViewBrowserTest = InProcessBrowserTest; using WebAppUninstallDialogViewBrowserTest = InProcessBrowserTest;
// Test that WebAppUninstallDialog cancels the uninstall if the Window // Test that WebAppUninstallDialog cancels the uninstall if the Window
// which is passed to WebAppUninstallDialog::Create() is destroyed before // which is passed to WebAppUninstallDialog::Create() is destroyed before
// WebAppUninstallDialogDelegateView is created. // WebAppUninstallDialogDelegateView is created.
IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest, IN_PROC_BROWSER_TEST_F(WebAppUninstallDialogViewBrowserTest,
TrackParentWindowDestruction) { TrackParentWindowDestruction) {
scoped_refptr<const extensions::Extension> extension(BuildTestBookmarkApp()); AppId app_id = InstallTestWebApp(browser()->profile());
extensions::ExtensionSystem::Get(browser()->profile())
->extension_service()
->AddExtension(extension.get());
std::unique_ptr<web_app::WebAppUninstallDialog> dialog( std::unique_ptr<web_app::WebAppUninstallDialog> dialog(
web_app::WebAppUninstallDialog::Create( web_app::WebAppUninstallDialog::Create(
...@@ -62,7 +55,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest, ...@@ -62,7 +55,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest,
base::RunLoop run_loop; base::RunLoop run_loop;
bool was_uninstalled = false; bool was_uninstalled = false;
dialog->ConfirmUninstall(extension->id(), dialog->ConfirmUninstall(app_id,
base::BindLambdaForTesting([&](bool uninstalled) { base::BindLambdaForTesting([&](bool uninstalled) {
was_uninstalled = uninstalled; was_uninstalled = uninstalled;
run_loop.Quit(); run_loop.Quit();
...@@ -74,12 +67,9 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest, ...@@ -74,12 +67,9 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest,
// Test that WebAppUninstallDialog cancels the uninstall if the Window // Test that WebAppUninstallDialog cancels the uninstall if the Window
// which is passed to WebAppUninstallDialog::Create() is destroyed after // which is passed to WebAppUninstallDialog::Create() is destroyed after
// WebAppUninstallDialogDelegateView is created. // WebAppUninstallDialogDelegateView is created.
IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest, IN_PROC_BROWSER_TEST_F(WebAppUninstallDialogViewBrowserTest,
TrackParentWindowDestructionAfterViewCreation) { TrackParentWindowDestructionAfterViewCreation) {
scoped_refptr<const extensions::Extension> extension(BuildTestBookmarkApp()); AppId app_id = InstallTestWebApp(browser()->profile());
extensions::ExtensionSystem::Get(browser()->profile())
->extension_service()
->AddExtension(extension.get());
std::unique_ptr<web_app::WebAppUninstallDialog> dialog( std::unique_ptr<web_app::WebAppUninstallDialog> dialog(
web_app::WebAppUninstallDialog::Create( web_app::WebAppUninstallDialog::Create(
...@@ -88,7 +78,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest, ...@@ -88,7 +78,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest,
base::RunLoop run_loop; base::RunLoop run_loop;
bool was_uninstalled = false; bool was_uninstalled = false;
dialog->ConfirmUninstall(extension->id(), dialog->ConfirmUninstall(app_id,
base::BindLambdaForTesting([&](bool uninstalled) { base::BindLambdaForTesting([&](bool uninstalled) {
was_uninstalled = uninstalled; was_uninstalled = uninstalled;
run_loop.Quit(); run_loop.Quit();
...@@ -101,22 +91,13 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest, ...@@ -101,22 +91,13 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest,
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Test that we don't crash when uninstalling an extension from a bookmark app // Test that we don't crash when uninstalling a web app from a web app window in
// window in Ash. Context: crbug.com/825554 // Ash. Context: crbug.com/825554
IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest, IN_PROC_BROWSER_TEST_F(WebAppUninstallDialogViewBrowserTest,
BookmarkAppWindowAshCrash) { WebAppWindowAshCrash) {
scoped_refptr<const extensions::Extension> extension(BuildTestBookmarkApp()); AppId app_id = InstallTestWebApp(browser()->profile());
extensions::ExtensionSystem::Get(browser()->profile()) Browser* app_browser =
->extension_service() web_app::LaunchWebAppBrowser(browser()->profile(), app_id);
->AddExtension(extension.get());
WebApplicationInfo info;
info.app_url = GURL("https://test.com/");
const extensions::Extension* bookmark_app =
extensions::browsertest_util::InstallBookmarkApp(browser()->profile(),
info);
Browser* app_browser = extensions::browsertest_util::LaunchAppBrowser(
browser()->profile(), bookmark_app);
std::unique_ptr<web_app::WebAppUninstallDialog> dialog; std::unique_ptr<web_app::WebAppUninstallDialog> dialog;
{ {
...@@ -128,20 +109,17 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest, ...@@ -128,20 +109,17 @@ IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewBrowserTest,
{ {
base::RunLoop run_loop; base::RunLoop run_loop;
dialog->ConfirmUninstall(extension->id(), base::DoNothing()); dialog->ConfirmUninstall(app_id, base::DoNothing());
run_loop.RunUntilIdle(); run_loop.RunUntilIdle();
} }
} }
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
class BookmarkAppUninstallDialogViewInteractiveBrowserTest class WebAppUninstallDialogViewInteractiveBrowserTest
: public DialogBrowserTest { : public DialogBrowserTest {
public: public:
void ShowUi(const std::string& name) override { void ShowUi(const std::string& name) override {
extension_ = BuildTestBookmarkApp(); AppId app_id = InstallTestWebApp(browser()->profile());
extensions::ExtensionSystem::Get(browser()->profile())
->extension_service()
->AddExtension(extension_.get());
dialog_ = web_app::WebAppUninstallDialog::Create( dialog_ = web_app::WebAppUninstallDialog::Create(
browser()->profile(), browser()->window()->GetNativeWindow()); browser()->profile(), browser()->window()->GetNativeWindow());
...@@ -149,7 +127,7 @@ class BookmarkAppUninstallDialogViewInteractiveBrowserTest ...@@ -149,7 +127,7 @@ class BookmarkAppUninstallDialogViewInteractiveBrowserTest
base::RunLoop run_loop; base::RunLoop run_loop;
dialog_->SetDialogShownCallbackForTesting(run_loop.QuitClosure()); dialog_->SetDialogShownCallbackForTesting(run_loop.QuitClosure());
dialog_->ConfirmUninstall(extension_->id(), base::DoNothing()); dialog_->ConfirmUninstall(app_id, base::DoNothing());
run_loop.Run(); run_loop.Run();
} }
...@@ -161,11 +139,10 @@ class BookmarkAppUninstallDialogViewInteractiveBrowserTest ...@@ -161,11 +139,10 @@ class BookmarkAppUninstallDialogViewInteractiveBrowserTest
dialog_.reset(); dialog_.reset();
} }
scoped_refptr<const extensions::Extension> extension_;
std::unique_ptr<web_app::WebAppUninstallDialog> dialog_; std::unique_ptr<web_app::WebAppUninstallDialog> dialog_;
}; };
IN_PROC_BROWSER_TEST_F(BookmarkAppUninstallDialogViewInteractiveBrowserTest, IN_PROC_BROWSER_TEST_F(WebAppUninstallDialogViewInteractiveBrowserTest,
InvokeUi_ManualUninstall) { InvokeUi_ManualUninstall) {
ShowAndVerifyUi(); ShowAndVerifyUi();
} }
...@@ -2065,7 +2065,7 @@ if (!is_android) { ...@@ -2065,7 +2065,7 @@ if (!is_android) {
"../browser/ui/views/translate/translate_bubble_test_utils_views.cc", "../browser/ui/views/translate/translate_bubble_test_utils_views.cc",
"../browser/ui/views/translate/translate_bubble_view_browsertest.cc", "../browser/ui/views/translate/translate_bubble_view_browsertest.cc",
"../browser/ui/views/translate/translate_language_browsertest.cc", "../browser/ui/views/translate/translate_language_browsertest.cc",
"../browser/ui/views/web_apps/bookmark_app_uninstall_dialog_browsertest.cc", "../browser/ui/views/web_apps/web_app_uninstall_dialog_browsertest.cc",
"payments/payment_request_platform_browsertest_base.cc", "payments/payment_request_platform_browsertest_base.cc",
] ]
if (!is_chromeos) { if (!is_chromeos) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment