Commit 70ba9cd4 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

desktop-pwas: WebAppUiManagerImplBrowserTest

The test WebAppUiManagerImplBrowserTest no longer
references extensions.

The helper function browsertest_util::InstallWebApp is
extracted from WebAppControllerBrowserTest.

Bug: 966290
Change-Id: Ifff8e054293e627aa085d51671c6092d161a06e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787487
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698420}
parent 313010bc
......@@ -8,6 +8,7 @@
#include "base/test/bind_test_util.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/components/external_install_options.h"
......@@ -15,10 +16,31 @@
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/browser/web_applications/components/web_app_tab_helper.h"
#include "chrome/common/web_application_info.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace web_app {
AppId InstallWebApp(Profile* profile,
std::unique_ptr<WebApplicationInfo> web_app_info) {
AppId app_id;
base::RunLoop run_loop;
auto* provider = WebAppProviderBase::GetProviderBase(profile);
DCHECK(provider);
provider->install_manager().InstallWebAppFromInfo(
std::move(web_app_info), ForInstallableSite::kYes,
WebappInstallSource::OMNIBOX_INSTALL_ICON,
base::BindLambdaForTesting(
[&](const AppId& installed_app_id, InstallResultCode code) {
EXPECT_EQ(InstallResultCode::kSuccessNewInstall, code);
app_id = installed_app_id;
run_loop.Quit();
}));
run_loop.Run();
return app_id;
}
Browser* LaunchWebAppBrowser(Profile* profile, const AppId& app_id) {
EXPECT_TRUE(
apps::LaunchService::Get(profile)->OpenApplication(AppLaunchParams(
......
......@@ -5,16 +5,21 @@
#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_WEB_APP_BROWSERTEST_UTIL_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_WEB_APP_BROWSERTEST_UTIL_H_
#include <memory>
#include "chrome/browser/web_applications/components/web_app_helpers.h"
class Browser;
class Profile;
struct WebApplicationInfo;
namespace web_app {
struct ExternalInstallOptions;
enum class InstallResultCode;
AppId InstallWebApp(Profile* profile, std::unique_ptr<WebApplicationInfo>);
// Launches a new app window for |app| in |profile|.
Browser* LaunchWebAppBrowser(Profile*, const AppId&);
......
......@@ -4,14 +4,11 @@
#include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h"
#include "base/test/bind_test_util.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/predictors/loading_predictor_config.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/components/install_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h"
......@@ -44,27 +41,12 @@ AppId WebAppControllerBrowserTestBase::InstallPWA(const GURL& app_url) {
web_app_info->app_url = app_url;
web_app_info->scope = app_url.GetWithoutFilename();
web_app_info->open_as_window = true;
return InstallWebApp(std::move(web_app_info));
return web_app::InstallWebApp(profile(), std::move(web_app_info));
}
AppId WebAppControllerBrowserTestBase::InstallWebApp(
std::unique_ptr<WebApplicationInfo>&& web_app_info) {
AppId app_id;
base::RunLoop run_loop;
auto* provider = WebAppProvider::Get(profile());
DCHECK(provider);
provider->install_manager().InstallWebAppFromInfo(
std::move(web_app_info), ForInstallableSite::kYes,
WebappInstallSource::OMNIBOX_INSTALL_ICON,
base::BindLambdaForTesting(
[&](const AppId& installed_app_id, InstallResultCode code) {
EXPECT_EQ(InstallResultCode::kSuccessNewInstall, code);
app_id = installed_app_id;
run_loop.Quit();
}));
run_loop.Run();
return app_id;
std::unique_ptr<WebApplicationInfo> web_app_info) {
return web_app::InstallWebApp(profile(), std::move(web_app_info));
}
Browser* WebAppControllerBrowserTestBase::LaunchWebAppBrowser(
......
......@@ -42,7 +42,7 @@ class WebAppControllerBrowserTestBase
AppId InstallPWA(const GURL& app_url);
AppId InstallWebApp(std::unique_ptr<WebApplicationInfo>&& web_app_info);
AppId InstallWebApp(std::unique_ptr<WebApplicationInfo> web_app_info);
// Launches the app as a window and returns the browser.
Browser* LaunchWebAppBrowser(const AppId&);
......
......@@ -8,18 +8,17 @@
#include "base/test/bind_test_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/apps/app_service/built_in_chromeos_apps.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/system_web_app_manager.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/web_application_info.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "extensions/common/extension.h"
#include "url/gurl.h"
#if defined(OS_CHROMEOS)
......@@ -77,16 +76,15 @@ class WebAppUiManagerImplBrowserTest : public InProcessBrowserTest {
protected:
Profile* profile() { return browser()->profile(); }
const extensions::Extension* InstallWebApp(const GURL& app_url) {
WebApplicationInfo web_app_info;
web_app_info.app_url = app_url;
web_app_info.open_as_window = true;
return extensions::browsertest_util::InstallBookmarkApp(profile(),
web_app_info);
const AppId InstallWebApp(const GURL& app_url) {
auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info->app_url = app_url;
web_app_info->open_as_window = true;
return web_app::InstallWebApp(profile(), std::move(web_app_info));
}
Browser* LaunchApp(const extensions::Extension* app) {
return extensions::browsertest_util::LaunchAppBrowser(profile(), app);
Browser* LaunchWebApp(const AppId& app_id) {
return web_app::LaunchWebAppBrowser(profile(), app_id);
}
WebAppUiManager& ui_manager() {
......@@ -99,47 +97,46 @@ IN_PROC_BROWSER_TEST_F(WebAppUiManagerImplBrowserTest,
// Zero apps on start:
EXPECT_EQ(0u, ui_manager().GetNumWindowsForApp(AppId()));
const auto* foo_app = InstallWebApp(kFooUrl);
LaunchApp(foo_app);
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(foo_app->id()));
AppId foo_app_id = InstallWebApp(kFooUrl);
LaunchWebApp(foo_app_id);
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(foo_app_id));
LaunchApp(foo_app);
EXPECT_EQ(2u, ui_manager().GetNumWindowsForApp(foo_app->id()));
LaunchWebApp(foo_app_id);
EXPECT_EQ(2u, ui_manager().GetNumWindowsForApp(foo_app_id));
}
IN_PROC_BROWSER_TEST_F(WebAppUiManagerImplBrowserTest,
GetNumWindowsForApp_AppWindowsRemoved) {
const auto* foo_app = InstallWebApp(kFooUrl);
auto* foo_window1 = LaunchApp(foo_app);
auto* foo_window2 = LaunchApp(foo_app);
AppId foo_app_id = InstallWebApp(kFooUrl);
auto* foo_window1 = LaunchWebApp(foo_app_id);
auto* foo_window2 = LaunchWebApp(foo_app_id);
const auto* bar_app = InstallWebApp(kBarUrl);
LaunchApp(bar_app);
AppId bar_app_id = InstallWebApp(kBarUrl);
LaunchWebApp(bar_app_id);
EXPECT_EQ(2u, ui_manager().GetNumWindowsForApp(foo_app->id()));
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(bar_app->id()));
EXPECT_EQ(2u, ui_manager().GetNumWindowsForApp(foo_app_id));
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(bar_app_id));
CloseAndWait(foo_window1);
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(foo_app->id()));
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(bar_app->id()));
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(foo_app_id));
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(bar_app_id));
CloseAndWait(foo_window2);
EXPECT_EQ(0u, ui_manager().GetNumWindowsForApp(foo_app->id()));
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(bar_app->id()));
EXPECT_EQ(0u, ui_manager().GetNumWindowsForApp(foo_app_id));
EXPECT_EQ(1u, ui_manager().GetNumWindowsForApp(bar_app_id));
}
IN_PROC_BROWSER_TEST_F(WebAppUiManagerImplBrowserTest,
NotifyOnAllAppWindowsClosed_NoOpenedWindows) {
const auto* foo_app = InstallWebApp(kFooUrl);
const auto* bar_app = InstallWebApp(kBarUrl);
LaunchApp(bar_app);
AppId foo_app_id = InstallWebApp(kFooUrl);
AppId bar_app_id = InstallWebApp(kBarUrl);
LaunchWebApp(bar_app_id);
base::RunLoop run_loop;
// Should return early; no windows for |foo_app|.
ui_manager().NotifyOnAllAppWindowsClosed(foo_app->id(),
run_loop.QuitClosure());
ui_manager().NotifyOnAllAppWindowsClosed(foo_app_id, run_loop.QuitClosure());
run_loop.Run();
}
......@@ -147,19 +144,19 @@ IN_PROC_BROWSER_TEST_F(WebAppUiManagerImplBrowserTest,
// app window.
IN_PROC_BROWSER_TEST_F(WebAppUiManagerImplBrowserTest,
NotifyOnAllAppWindowsClosed_MultipleOpenedWindows) {
const auto* foo_app = InstallWebApp(kFooUrl);
const auto* bar_app = InstallWebApp(kBarUrl);
AppId foo_app_id = InstallWebApp(kFooUrl);
AppId bar_app_id = InstallWebApp(kBarUrl);
// Test that NotifyOnAllAppWindowsClosed can be called more than once for
// the same app.
for (int i = 0; i < 2; i++) {
auto* foo_window1 = LaunchApp(foo_app);
auto* foo_window2 = LaunchApp(foo_app);
auto* bar_window = LaunchApp(bar_app);
auto* foo_window1 = LaunchWebApp(foo_app_id);
auto* foo_window2 = LaunchWebApp(foo_app_id);
auto* bar_window = LaunchWebApp(bar_app_id);
bool callback_ran = false;
base::RunLoop run_loop;
ui_manager().NotifyOnAllAppWindowsClosed(foo_app->id(),
ui_manager().NotifyOnAllAppWindowsClosed(foo_app_id,
base::BindLambdaForTesting([&]() {
callback_ran = true;
run_loop.Quit();
......@@ -210,8 +207,7 @@ IN_PROC_BROWSER_TEST_F(WebAppUiManagerMigrationBrowserTest,
scoped_feature_list.InitAndEnableFeature(features::kSystemWebApps);
auto& system_web_app_manager =
web_app::WebAppProvider::Get(browser()->profile())
->system_web_app_manager();
WebAppProvider::Get(browser()->profile())->system_web_app_manager();
auto* app_list_service =
app_list::AppListSyncableServiceFactory::GetForProfile(
......
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