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

desktop-pwas: WebAppEngagementBrowserTest

Test helper functions are introduced in
web_app_browsertest_util.h

BookmarkAppTest is renamed to WebAppEngagementBrowserTest.

The test no longer references extensions.

TBR=calamity@chromium.org

Bug: 966290
Change-Id: I630fa2873766a5a2955fe96f91008fd3bb9bc84e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787761Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698408}
parent f79a55bf
...@@ -37,6 +37,10 @@ namespace history { ...@@ -37,6 +37,10 @@ namespace history {
class HistoryService; class HistoryService;
} }
namespace web_app {
class WebAppEngagementBrowserTest;
}
class GURL; class GURL;
class HostContentSettingsMap; class HostContentSettingsMap;
class Profile; class Profile;
...@@ -185,9 +189,9 @@ class SiteEngagementService : public KeyedService, ...@@ -185,9 +189,9 @@ class SiteEngagementService : public KeyedService,
void AddPointsForTesting(const GURL& url, double points); void AddPointsForTesting(const GURL& url, double points);
private: private:
friend class BookmarkAppTest;
friend class SiteEngagementObserver; friend class SiteEngagementObserver;
friend class SiteEngagementServiceTest; friend class SiteEngagementServiceTest;
friend class web_app::WebAppEngagementBrowserTest;
FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms); FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CheckHistograms);
FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores); FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, CleanupEngagementScores);
FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest, FRIEND_TEST_ALL_PREFIXES(SiteEngagementServiceTest,
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "base/run_loop.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/ui/browser_finder.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/components/external_install_options.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h"
#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 "testing/gtest/include/gtest/gtest.h"
namespace web_app {
Browser* LaunchWebAppBrowser(Profile* profile, const AppId& app_id) {
EXPECT_TRUE(
apps::LaunchService::Get(profile)->OpenApplication(AppLaunchParams(
profile, app_id, apps::mojom::LaunchContainer::kLaunchContainerWindow,
WindowOpenDisposition::CURRENT_TAB,
apps::mojom::AppLaunchSource::kSourceTest)));
Browser* browser = chrome::FindLastActive();
bool is_correct_app_browser =
browser && GetAppIdFromApplicationName(browser->app_name()) == app_id;
EXPECT_TRUE(is_correct_app_browser);
return is_correct_app_browser ? browser : nullptr;
}
Browser* LaunchBrowserForWebAppInTab(Profile* profile, const AppId& app_id) {
content::WebContents* web_contents =
apps::LaunchService::Get(profile)->OpenApplication(AppLaunchParams(
profile, app_id, apps::mojom::LaunchContainer::kLaunchContainerTab,
WindowOpenDisposition::NEW_FOREGROUND_TAB,
apps::mojom::AppLaunchSource::kSourceTest));
DCHECK(web_contents);
WebAppTabHelper* tab_helper = WebAppTabHelper::FromWebContents(web_contents);
DCHECK(tab_helper);
EXPECT_EQ(app_id, tab_helper->app_id());
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
EXPECT_EQ(browser, chrome::FindLastActive());
EXPECT_EQ(web_contents, browser->tab_strip_model()->GetActiveWebContents());
return browser;
}
ExternalInstallOptions CreateInstallOptions(const GURL& url) {
ExternalInstallOptions install_options(
url, LaunchContainer::kWindow, ExternalInstallSource::kInternalDefault);
// Avoid creating real shortcuts in tests.
install_options.add_to_applications_menu = false;
install_options.add_to_desktop = false;
install_options.add_to_quick_launch_bar = false;
return install_options;
}
InstallResultCode InstallApp(Profile* profile,
ExternalInstallOptions install_options) {
base::RunLoop run_loop;
InstallResultCode result_code;
WebAppProviderBase::GetProviderBase(profile)->pending_app_manager().Install(
std::move(install_options),
base::BindLambdaForTesting(
[&result_code, &run_loop](const GURL& provided_url,
InstallResultCode code) {
result_code = code;
run_loop.Quit();
}));
run_loop.Run();
return result_code;
}
} // namespace web_app
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#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 "chrome/browser/web_applications/components/web_app_helpers.h"
class Browser;
class Profile;
namespace web_app {
struct ExternalInstallOptions;
enum class InstallResultCode;
// Launches a new app window for |app| in |profile|.
Browser* LaunchWebAppBrowser(Profile*, const AppId&);
// Launches a new tab for |app| in |profile|.
Browser* LaunchBrowserForWebAppInTab(Profile*, const AppId&);
ExternalInstallOptions CreateInstallOptions(const GURL& url);
InstallResultCode InstallApp(Profile*, ExternalInstallOptions);
} // namespace web_app
#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_WEB_APP_BROWSERTEST_UTIL_H_
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/extensions/browsertest_util.h" #include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/installable/installable_metrics.h" #include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/predictors/loading_predictor_config.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/install_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_provider.h" #include "chrome/browser/web_applications/web_app_provider.h"
...@@ -38,21 +39,7 @@ WebAppControllerBrowserTestBase::WebAppControllerBrowserTestBase() { ...@@ -38,21 +39,7 @@ WebAppControllerBrowserTestBase::WebAppControllerBrowserTestBase() {
WebAppControllerBrowserTestBase::~WebAppControllerBrowserTestBase() = default; WebAppControllerBrowserTestBase::~WebAppControllerBrowserTestBase() = default;
WebAppControllerBrowserTest::WebAppControllerBrowserTest() AppId WebAppControllerBrowserTestBase::InstallPWA(const GURL& app_url) {
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
scoped_feature_list_.InitWithFeatures(
{}, {predictors::kSpeculativePreconnectFeature});
}
WebAppControllerBrowserTest::~WebAppControllerBrowserTest() = default;
void WebAppControllerBrowserTest::SetUp() {
https_server_.AddDefaultHandlers(GetChromeTestDataDir());
extensions::ExtensionBrowserTest::SetUp();
}
AppId WebAppControllerBrowserTest::InstallPWA(const GURL& app_url) {
auto web_app_info = std::make_unique<WebApplicationInfo>(); auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info->app_url = app_url; web_app_info->app_url = app_url;
web_app_info->scope = app_url.GetWithoutFilename(); web_app_info->scope = app_url.GetWithoutFilename();
...@@ -60,18 +47,18 @@ AppId WebAppControllerBrowserTest::InstallPWA(const GURL& app_url) { ...@@ -60,18 +47,18 @@ AppId WebAppControllerBrowserTest::InstallPWA(const GURL& app_url) {
return InstallWebApp(std::move(web_app_info)); return InstallWebApp(std::move(web_app_info));
} }
AppId WebAppControllerBrowserTest::InstallWebApp( AppId WebAppControllerBrowserTestBase::InstallWebApp(
std::unique_ptr<WebApplicationInfo>&& web_app_info) { std::unique_ptr<WebApplicationInfo>&& web_app_info) {
AppId app_id; AppId app_id;
base::RunLoop run_loop; base::RunLoop run_loop;
auto* provider = web_app::WebAppProvider::Get(profile()); auto* provider = WebAppProvider::Get(profile());
DCHECK(provider); DCHECK(provider);
provider->install_manager().InstallWebAppFromInfo( provider->install_manager().InstallWebAppFromInfo(
std::move(web_app_info), ForInstallableSite::kYes, std::move(web_app_info), ForInstallableSite::kYes,
WebappInstallSource::OMNIBOX_INSTALL_ICON, WebappInstallSource::OMNIBOX_INSTALL_ICON,
base::BindLambdaForTesting( base::BindLambdaForTesting(
[&](const AppId& installed_app_id, web_app::InstallResultCode code) { [&](const AppId& installed_app_id, InstallResultCode code) {
EXPECT_EQ(web_app::InstallResultCode::kSuccessNewInstall, code); EXPECT_EQ(InstallResultCode::kSuccessNewInstall, code);
app_id = installed_app_id; app_id = installed_app_id;
run_loop.Quit(); run_loop.Quit();
})); }));
...@@ -80,9 +67,40 @@ AppId WebAppControllerBrowserTest::InstallWebApp( ...@@ -80,9 +67,40 @@ AppId WebAppControllerBrowserTest::InstallWebApp(
return app_id; return app_id;
} }
Browser* WebAppControllerBrowserTestBase::LaunchWebAppBrowser(
const AppId& app_id) {
return web_app::LaunchWebAppBrowser(profile(), app_id);
}
Browser* WebAppControllerBrowserTestBase::LaunchBrowserForWebAppInTab(
const AppId& app_id) {
return web_app::LaunchBrowserForWebAppInTab(profile(), app_id);
}
base::Optional<AppId> WebAppControllerBrowserTestBase::FindAppWithUrlInScope(
const GURL& url) {
auto* provider = WebAppProvider::Get(profile());
DCHECK(provider);
return provider->registrar().FindAppWithUrlInScope(url);
}
WebAppControllerBrowserTest::WebAppControllerBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
scoped_feature_list_.InitWithFeatures(
{}, {predictors::kSpeculativePreconnectFeature});
}
WebAppControllerBrowserTest::~WebAppControllerBrowserTest() = default;
void WebAppControllerBrowserTest::SetUp() {
https_server_.AddDefaultHandlers(GetChromeTestDataDir());
extensions::ExtensionBrowserTest::SetUp();
}
content::WebContents* WebAppControllerBrowserTest::OpenApplication( content::WebContents* WebAppControllerBrowserTest::OpenApplication(
const AppId& app_id) { const AppId& app_id) {
auto* provider = web_app::WebAppProvider::Get(profile()); auto* provider = WebAppProvider::Get(profile());
DCHECK(provider); DCHECK(provider);
ui_test_utils::UrlLoadObserver url_observer( ui_test_utils::UrlLoadObserver url_observer(
provider->registrar().GetAppLaunchURL(app_id), provider->registrar().GetAppLaunchURL(app_id),
......
...@@ -40,6 +40,18 @@ class WebAppControllerBrowserTestBase ...@@ -40,6 +40,18 @@ class WebAppControllerBrowserTestBase
WebAppControllerBrowserTestBase(); WebAppControllerBrowserTestBase();
~WebAppControllerBrowserTestBase() = 0; ~WebAppControllerBrowserTestBase() = 0;
AppId InstallPWA(const GURL& app_url);
AppId InstallWebApp(std::unique_ptr<WebApplicationInfo>&& web_app_info);
// Launches the app as a window and returns the browser.
Browser* LaunchWebAppBrowser(const AppId&);
// Launches the app as a tab and returns the browser.
Browser* LaunchBrowserForWebAppInTab(const AppId&);
base::Optional<AppId> FindAppWithUrlInScope(const GURL& url);
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
...@@ -55,10 +67,6 @@ class WebAppControllerBrowserTest : public WebAppControllerBrowserTestBase { ...@@ -55,10 +67,6 @@ class WebAppControllerBrowserTest : public WebAppControllerBrowserTestBase {
void SetUp() override; void SetUp() override;
protected: protected:
AppId InstallPWA(const GURL& app_url);
AppId InstallWebApp(std::unique_ptr<WebApplicationInfo>&& web_app_info);
content::WebContents* OpenApplication(const AppId&); content::WebContents* OpenApplication(const AppId&);
net::EmbeddedTestServer* https_server() { return &https_server_; } net::EmbeddedTestServer* https_server() { return &https_server_; }
......
...@@ -9,10 +9,11 @@ ...@@ -9,10 +9,11 @@
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/engagement/site_engagement_service.h" #include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h" #include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h"
#include "chrome/browser/ui/web_applications/web_app_metrics.h" #include "chrome/browser/ui/web_applications/web_app_metrics.h"
#include "chrome/browser/web_applications/components/external_install_options.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h" #include "chrome/browser/web_applications/components/pending_app_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
...@@ -22,7 +23,6 @@ ...@@ -22,7 +23,6 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "extensions/common/extension.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace { namespace {
...@@ -38,19 +38,6 @@ void NavigateToURLAndWait(Browser* browser, const GURL& url) { ...@@ -38,19 +38,6 @@ void NavigateToURLAndWait(Browser* browser, const GURL& url) {
observer.WaitForNavigationFinished(); observer.WaitForNavigationFinished();
} }
// TODO(loyso): Merge this with PendingBookmarkAppManagerBrowserTest's
// implementation in some test_support library.
web_app::ExternalInstallOptions CreateInstallOptions(const GURL& url) {
web_app::ExternalInstallOptions install_options(
url, web_app::LaunchContainer::kWindow,
web_app::ExternalInstallSource::kInternalDefault);
// Avoid creating real shortcuts in tests.
install_options.add_to_applications_menu = false;
install_options.add_to_desktop = false;
install_options.add_to_quick_launch_bar = false;
return install_options;
}
GURL GetUrlForSuffix(const std::string& prefix, int suffix) { GURL GetUrlForSuffix(const std::string& prefix, int suffix) {
return GURL(prefix + base::NumberToString(suffix) + ".com/"); return GURL(prefix + base::NumberToString(suffix) + ".com/");
} }
...@@ -134,10 +121,12 @@ void ExpectTotalCounts(const base::HistogramTester& tester, ...@@ -134,10 +121,12 @@ void ExpectTotalCounts(const base::HistogramTester& tester,
} // namespace } // namespace
class BookmarkAppTest : public web_app::WebAppControllerBrowserTestBase { namespace web_app {
class WebAppEngagementBrowserTest : public WebAppControllerBrowserTestBase {
public: public:
BookmarkAppTest() = default; WebAppEngagementBrowserTest() = default;
~BookmarkAppTest() override = default; ~WebAppEngagementBrowserTest() override = default;
void TestEngagementEventWebAppLaunch(const base::HistogramTester& tester, void TestEngagementEventWebAppLaunch(const base::HistogramTester& tester,
const Histograms& histograms) { const Histograms& histograms) {
...@@ -181,63 +170,43 @@ class BookmarkAppTest : public web_app::WebAppControllerBrowserTestBase { ...@@ -181,63 +170,43 @@ class BookmarkAppTest : public web_app::WebAppControllerBrowserTestBase {
protected: protected:
void CountUserInstalledApps() { void CountUserInstalledApps() {
web_app::WebAppMetrics* web_app_metrics = WebAppMetrics* web_app_metrics = WebAppMetrics::Get(profile());
web_app::WebAppMetrics::Get(profile());
web_app_metrics->CountUserInstalledAppsForTesting(); web_app_metrics->CountUserInstalledAppsForTesting();
} }
const extensions::Extension* InstallBookmarkAppAndCountApps( AppId InstallWebAppAndCountApps(
WebApplicationInfo info) { std::unique_ptr<WebApplicationInfo> web_app_info) {
const extensions::Extension* app = AppId app_id = InstallWebApp(std::move(web_app_info));
ExtensionBrowserTest::InstallBookmarkApp(std::move(info));
CountUserInstalledApps(); CountUserInstalledApps();
return app; return app_id;
} }
// TODO(loyso): Merge this method with void InstallDefaultAppAndCountApps(ExternalInstallOptions install_options) {
// PendingBookmarkAppManagerBrowserTest::InstallApp in some result_code_ = InstallApp(browser()->profile(), std::move(install_options));
// test_support library.
void InstallDefaultAppAndCountApps(
web_app::ExternalInstallOptions install_options) {
base::RunLoop run_loop;
web_app::WebAppProvider::Get(browser()->profile())
->pending_app_manager()
.Install(std::move(install_options),
base::BindLambdaForTesting(
[this, &run_loop](const GURL& provided_url,
web_app::InstallResultCode code) {
result_code_ = code;
run_loop.Quit();
}));
run_loop.Run();
ASSERT_TRUE(result_code_.has_value());
CountUserInstalledApps(); CountUserInstalledApps();
} }
base::Optional<web_app::InstallResultCode> result_code_; base::Optional<InstallResultCode> result_code_;
private: private:
DISALLOW_COPY_AND_ASSIGN(BookmarkAppTest); DISALLOW_COPY_AND_ASSIGN(WebAppEngagementBrowserTest);
}; };
IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramForAppInWindow) { IN_PROC_BROWSER_TEST_P(WebAppEngagementBrowserTest, AppInWindow) {
base::HistogramTester tester; base::HistogramTester tester;
const GURL example_url = GURL("http://example.org/"); const GURL example_url = GURL("http://example.org/");
WebApplicationInfo web_app_info; auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info.app_url = example_url; web_app_info->app_url = example_url;
web_app_info.scope = example_url; web_app_info->scope = example_url;
web_app_info.open_as_window = true; web_app_info->open_as_window = true;
const extensions::Extension* app = AppId app_id = InstallWebAppAndCountApps(std::move(web_app_info));
InstallBookmarkAppAndCountApps(web_app_info);
Browser* app_browser = LaunchAppBrowser(app); Browser* app_browser = LaunchWebAppBrowser(app_id);
NavigateToURLAndWait(app_browser, example_url); NavigateToURLAndWait(app_browser, example_url);
EXPECT_EQ(web_app::GetAppIdFromApplicationName(app_browser->app_name()), EXPECT_EQ(GetAppIdFromApplicationName(app_browser->app_name()), app_id);
app->id());
Histograms histograms; Histograms histograms;
histograms[kHistogramInWindow] = true; histograms[kHistogramInWindow] = true;
...@@ -249,19 +218,18 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramForAppInWindow) { ...@@ -249,19 +218,18 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramForAppInWindow) {
TestEngagementEventsAfterLaunch(histograms, app_browser); TestEngagementEventsAfterLaunch(histograms, app_browser);
} }
IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramForAppInTab) { IN_PROC_BROWSER_TEST_P(WebAppEngagementBrowserTest, AppInTab) {
base::HistogramTester tester; base::HistogramTester tester;
const GURL example_url = GURL("http://example.org/"); const GURL example_url = GURL("http://example.org/");
WebApplicationInfo web_app_info; auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info.app_url = example_url; web_app_info->app_url = example_url;
web_app_info.scope = example_url; web_app_info->scope = example_url;
web_app_info.open_as_window = false; web_app_info->open_as_window = false;
const extensions::Extension* app = AppId app_id = InstallWebAppAndCountApps(std::move(web_app_info));
InstallBookmarkAppAndCountApps(web_app_info);
Browser* browser = LaunchBrowserForAppInTab(app); Browser* browser = LaunchBrowserForWebAppInTab(app_id);
EXPECT_FALSE(browser->app_controller()); EXPECT_FALSE(browser->app_controller());
NavigateToURLAndWait(browser, example_url); NavigateToURLAndWait(browser, example_url);
...@@ -275,24 +243,22 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramForAppInTab) { ...@@ -275,24 +243,22 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramForAppInTab) {
TestEngagementEventsAfterLaunch(histograms, browser); TestEngagementEventsAfterLaunch(histograms, browser);
} }
IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramAppWithoutScope) { IN_PROC_BROWSER_TEST_P(WebAppEngagementBrowserTest, AppWithoutScope) {
base::HistogramTester tester; base::HistogramTester tester;
const GURL example_url = GURL("http://example.org/"); const GURL example_url = GURL("http://example.org/");
WebApplicationInfo web_app_info; auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info.app_url = example_url; web_app_info->app_url = example_url;
// If app has no scope then UrlHandlers::GetUrlHandlers are empty. Therefore, // If app has no scope then UrlHandlers::GetUrlHandlers are empty. Therefore,
// the app is counted as installed via the Create Shortcut button. // the app is counted as installed via the Create Shortcut button.
web_app_info.scope = GURL(); web_app_info->scope = GURL();
web_app_info.open_as_window = true; web_app_info->open_as_window = true;
const extensions::Extension* app = AppId app_id = InstallWebAppAndCountApps(std::move(web_app_info));
InstallBookmarkAppAndCountApps(web_app_info);
Browser* browser = LaunchAppBrowser(app); Browser* browser = LaunchWebAppBrowser(app_id);
EXPECT_EQ(web_app::GetAppIdFromApplicationName(browser->app_name()), EXPECT_EQ(GetAppIdFromApplicationName(browser->app_name()), app_id);
app->id());
EXPECT_TRUE(browser->app_controller()); EXPECT_TRUE(browser->app_controller());
NavigateToURLAndWait(browser, example_url); NavigateToURLAndWait(browser, example_url);
...@@ -306,41 +272,38 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramAppWithoutScope) { ...@@ -306,41 +272,38 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramAppWithoutScope) {
TestEngagementEventsAfterLaunch(histograms, browser); TestEngagementEventsAfterLaunch(histograms, browser);
} }
IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramTwoApps) { IN_PROC_BROWSER_TEST_P(WebAppEngagementBrowserTest, TwoApps) {
base::HistogramTester tester; base::HistogramTester tester;
const GURL example_url1 = GURL("http://example.org/"); const GURL example_url1 = GURL("http://example.org/");
const GURL example_url2 = GURL("http://example.com/"); const GURL example_url2 = GURL("http://example.com/");
const extensions::Extension *app1, *app2; AppId app_id1, app_id2;
// Install two apps. // Install two apps.
{ {
WebApplicationInfo web_app_info; auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info.app_url = example_url1; web_app_info->app_url = example_url1;
web_app_info.scope = example_url1; web_app_info->scope = example_url1;
app1 = InstallBookmarkAppAndCountApps(web_app_info); app_id1 = InstallWebAppAndCountApps(std::move(web_app_info));
} }
{ {
WebApplicationInfo web_app_info; auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info.app_url = example_url2; web_app_info->app_url = example_url2;
web_app_info.scope = example_url2; web_app_info->scope = example_url2;
app2 = InstallBookmarkAppAndCountApps(web_app_info); app_id2 = InstallWebAppAndCountApps(std::move(web_app_info));
} }
// Launch them three times. This ensures that each launch only logs once. // Launch them three times. This ensures that each launch only logs once.
// (Since all apps receive the notification on launch, there is a danger that // (Since all apps receive the notification on launch, there is a danger that
// we might log too many times.) // we might log too many times.)
Browser* app_browser1 = LaunchAppBrowser(app1); Browser* app_browser1 = LaunchWebAppBrowser(app_id1);
Browser* app_browser2 = LaunchAppBrowser(app1); Browser* app_browser2 = LaunchWebAppBrowser(app_id1);
Browser* app_browser3 = LaunchAppBrowser(app2); Browser* app_browser3 = LaunchWebAppBrowser(app_id2);
EXPECT_EQ(web_app::GetAppIdFromApplicationName(app_browser1->app_name()), EXPECT_EQ(GetAppIdFromApplicationName(app_browser1->app_name()), app_id1);
app1->id()); EXPECT_EQ(GetAppIdFromApplicationName(app_browser2->app_name()), app_id1);
EXPECT_EQ(web_app::GetAppIdFromApplicationName(app_browser2->app_name()), EXPECT_EQ(GetAppIdFromApplicationName(app_browser3->app_name()), app_id2);
app1->id());
EXPECT_EQ(web_app::GetAppIdFromApplicationName(app_browser3->app_name()),
app2->id());
Histograms histograms; Histograms histograms;
histograms[kHistogramInWindow] = true; histograms[kHistogramInWindow] = true;
...@@ -354,30 +317,29 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramTwoApps) { ...@@ -354,30 +317,29 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramTwoApps) {
ExpectTotalCounts(tester, ~histograms, 0); ExpectTotalCounts(tester, ~histograms, 0);
} }
IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramManyUserApps) { IN_PROC_BROWSER_TEST_P(WebAppEngagementBrowserTest, ManyUserApps) {
base::HistogramTester tester; base::HistogramTester tester;
// More than 3 user-installed apps: // More than 3 user-installed apps:
const int num_user_apps = 4; const int num_user_apps = 4;
std::vector<const extensions::Extension*> apps; std::vector<AppId> app_ids;
// Install apps. // Install apps.
const std::string base_url = "http://example"; const std::string base_url = "http://example";
for (int i = 0; i < num_user_apps; ++i) { for (int i = 0; i < num_user_apps; ++i) {
const GURL url = GetUrlForSuffix(base_url, i); const GURL url = GetUrlForSuffix(base_url, i);
WebApplicationInfo web_app_info; auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info.app_url = url; web_app_info->app_url = url;
web_app_info.scope = url; web_app_info->scope = url;
const extensions::Extension* app = AppId app_id = InstallWebAppAndCountApps(std::move(web_app_info));
InstallBookmarkAppAndCountApps(web_app_info); app_ids.push_back(app_id);
apps.push_back(app);
} }
// Launch apps in windows. // Launch apps in windows.
for (int i = 0; i < num_user_apps; ++i) { for (int i = 0; i < num_user_apps; ++i) {
Browser* browser = LaunchAppBrowser(apps[i]); Browser* browser = LaunchWebAppBrowser(app_ids[i]);
const GURL url = GetUrlForSuffix(base_url, i); const GURL url = GetUrlForSuffix(base_url, i);
NavigateToURLAndWait(browser, url); NavigateToURLAndWait(browser, url);
...@@ -395,22 +357,20 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramManyUserApps) { ...@@ -395,22 +357,20 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramManyUserApps) {
ExpectTotalCounts(tester, ~histograms, 0); ExpectTotalCounts(tester, ~histograms, 0);
} }
IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramDefaultApp) { IN_PROC_BROWSER_TEST_P(WebAppEngagementBrowserTest, DefaultApp) {
base::HistogramTester tester; base::HistogramTester tester;
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
GURL example_url( GURL example_url(
embedded_test_server()->GetURL("/banners/manifest_test_page.html")); embedded_test_server()->GetURL("/banners/manifest_test_page.html"));
InstallDefaultAppAndCountApps(CreateInstallOptions(example_url)); InstallDefaultAppAndCountApps(CreateInstallOptions(example_url));
ASSERT_EQ(web_app::InstallResultCode::kSuccessNewInstall, ASSERT_EQ(InstallResultCode::kSuccessNewInstall, result_code_.value());
result_code_.value());
const extensions::Extension* app = extensions::util::GetInstalledPwaForUrl( base::Optional<AppId> app_id = FindAppWithUrlInScope(example_url);
browser()->profile(), example_url); ASSERT_TRUE(app_id);
ASSERT_TRUE(app); // TODO(ericwilligers): Assert app_id was installed by default.
EXPECT_TRUE(app->was_installed_by_default());
Browser* browser = LaunchAppBrowser(app); Browser* browser = LaunchWebAppBrowser(*app_id);
NavigateToURLAndWait(browser, example_url); NavigateToURLAndWait(browser, example_url);
Histograms histograms; Histograms histograms;
...@@ -422,19 +382,17 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramDefaultApp) { ...@@ -422,19 +382,17 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramDefaultApp) {
TestEngagementEventsAfterLaunch(histograms, browser); TestEngagementEventsAfterLaunch(histograms, browser);
} }
IN_PROC_BROWSER_TEST_P(BookmarkAppTest, IN_PROC_BROWSER_TEST_P(WebAppEngagementBrowserTest, NavigateAwayFromAppTab) {
EngagementHistogramNavigateAwayFromAppTab) {
const GURL app_url = GURL("http://example.org/app/"); const GURL app_url = GURL("http://example.org/app/");
const GURL outer_url = GURL("http://example.org/"); const GURL outer_url = GURL("http://example.org/");
WebApplicationInfo web_app_info; auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info.app_url = app_url; web_app_info->app_url = app_url;
web_app_info.scope = app_url; web_app_info->scope = app_url;
web_app_info.open_as_window = false; web_app_info->open_as_window = false;
const extensions::Extension* app = AppId app_id = InstallWebAppAndCountApps(std::move(web_app_info));
InstallBookmarkAppAndCountApps(web_app_info);
Browser* browser = LaunchBrowserForAppInTab(app); Browser* browser = LaunchBrowserForWebAppInTab(app_id);
EXPECT_FALSE(browser->app_controller()); EXPECT_FALSE(browser->app_controller());
NavigateToURLAndWait(browser, app_url); NavigateToURLAndWait(browser, app_url);
...@@ -456,7 +414,7 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, ...@@ -456,7 +414,7 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest,
} }
} }
IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramRecordedForNonApps) { IN_PROC_BROWSER_TEST_P(WebAppEngagementBrowserTest, RecordedForNonApps) {
base::HistogramTester tester; base::HistogramTester tester;
CountUserInstalledApps(); CountUserInstalledApps();
...@@ -477,7 +435,8 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramRecordedForNonApps) { ...@@ -477,7 +435,8 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppTest, EngagementHistogramRecordedForNonApps) {
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
/* no prefix */, /* no prefix */,
BookmarkAppTest, WebAppEngagementBrowserTest,
::testing::Values( ::testing::Values(ControllerType::kHostedAppController,
web_app::ControllerType::kHostedAppController, ControllerType::kUnifiedControllerWithBookmarkApp));
web_app::ControllerType::kUnifiedControllerWithBookmarkApp));
} // namespace web_app
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.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/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/components/app_registrar.h" #include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/external_install_options.h"
#include "chrome/browser/web_applications/components/externally_installed_web_app_prefs.h" #include "chrome/browser/web_applications/components/externally_installed_web_app_prefs.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h" #include "chrome/browser/web_applications/components/web_app_provider_base.h"
...@@ -26,17 +28,6 @@ ...@@ -26,17 +28,6 @@
namespace web_app { namespace web_app {
ExternalInstallOptions CreateInstallOptions(const GURL& url) {
ExternalInstallOptions install_options(
url, LaunchContainer::kWindow, ExternalInstallSource::kInternalDefault);
// Avoid creating real shortcuts in tests.
install_options.add_to_applications_menu = false;
install_options.add_to_desktop = false;
install_options.add_to_quick_launch_bar = false;
return install_options;
}
class PendingAppManagerImplBrowserTest : public InProcessBrowserTest { class PendingAppManagerImplBrowserTest : public InProcessBrowserTest {
protected: protected:
AppRegistrar& registrar() { AppRegistrar& registrar() {
...@@ -50,19 +41,7 @@ class PendingAppManagerImplBrowserTest : public InProcessBrowserTest { ...@@ -50,19 +41,7 @@ class PendingAppManagerImplBrowserTest : public InProcessBrowserTest {
} }
void InstallApp(ExternalInstallOptions install_options) { void InstallApp(ExternalInstallOptions install_options) {
base::RunLoop run_loop; result_code_ = web_app::InstallApp(browser()->profile(), install_options);
WebAppProviderBase::GetProviderBase(browser()->profile())
->pending_app_manager()
.Install(std::move(install_options),
base::BindLambdaForTesting(
[this, &run_loop](const GURL& provided_url,
InstallResultCode code) {
result_code_ = code;
run_loop.Quit();
}));
run_loop.Run();
ASSERT_TRUE(result_code_.has_value());
} }
void CheckServiceWorkerStatus(const GURL& url, void CheckServiceWorkerStatus(const GURL& url,
......
...@@ -356,6 +356,8 @@ static_library("test_support") { ...@@ -356,6 +356,8 @@ static_library("test_support") {
"../browser/extensions/extension_browsertest.h", "../browser/extensions/extension_browsertest.h",
"../browser/extensions/permissions_test_util.cc", "../browser/extensions/permissions_test_util.cc",
"../browser/extensions/permissions_test_util.h", "../browser/extensions/permissions_test_util.h",
"../browser/ui/web_applications/test/web_app_browsertest_util.cc",
"../browser/ui/web_applications/test/web_app_browsertest_util.h",
"../browser/ui/web_applications/web_app_controller_browsertest.cc", "../browser/ui/web_applications/web_app_controller_browsertest.cc",
"../browser/ui/web_applications/web_app_controller_browsertest.h", "../browser/ui/web_applications/web_app_controller_browsertest.h",
] ]
...@@ -1267,8 +1269,8 @@ if (!is_android) { ...@@ -1267,8 +1269,8 @@ if (!is_android) {
"../browser/ui/views/webauthn/authenticator_qr_code_test.cc", "../browser/ui/views/webauthn/authenticator_qr_code_test.cc",
"../browser/ui/views/webview_accessibility_browsertest.cc", "../browser/ui/views/webview_accessibility_browsertest.cc",
"../browser/ui/web_applications/app_browser_controller_browsertest.cc", "../browser/ui/web_applications/app_browser_controller_browsertest.cc",
"../browser/ui/web_applications/bookmark_app_browsertest.cc",
"../browser/ui/web_applications/web_app_badging_browsertest.cc", "../browser/ui/web_applications/web_app_badging_browsertest.cc",
"../browser/ui/web_applications/web_app_engagement_browsertest.cc",
"../browser/ui/web_applications/web_app_file_handling_browsertest.cc", "../browser/ui/web_applications/web_app_file_handling_browsertest.cc",
"../browser/ui/web_applications/web_app_ui_manager_impl_browsertest.cc", "../browser/ui/web_applications/web_app_ui_manager_impl_browsertest.cc",
"../browser/ui/webauthn/authenticator_dialog_browsertest.cc", "../browser/ui/webauthn/authenticator_dialog_browsertest.cc",
......
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