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

Desktop PWAs: Add AppSearchProviderWebAppTest

We add a AppSearchProvider unit test that creates a web app,
and searches for it.

Bug: 1086827
Change-Id: I2d5d985d2ea1d6ac4b961cbcb46be67102308a7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2249265
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779234}
parent e46c66ad
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h" #include "base/test/simple_test_clock.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -34,9 +35,13 @@ ...@@ -34,9 +35,13 @@
#include "chrome/browser/ui/app_list/search/search_result_ranker/ranking_item_util.h" #include "chrome/browser/ui/app_list/search/search_result_ranker/ranking_item_util.h"
#include "chrome/browser/ui/app_list/test/fake_app_list_model_updater.h" #include "chrome/browser/ui/app_list/test/fake_app_list_model_updater.h"
#include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h" #include "chrome/browser/ui/app_list/test/test_app_list_controller_delegate.h"
#include "chrome/browser/web_applications/components/install_finalizer.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/test/web_app_test.h" #include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/web_application_info.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/arc/test/fake_app_instance.h" #include "components/arc/test/fake_app_instance.h"
#include "components/crx_file/id_util.h" #include "components/crx_file/id_util.h"
...@@ -58,6 +63,7 @@ ...@@ -58,6 +63,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using web_app::InstallResultCode;
using web_app::ProviderType; using web_app::ProviderType;
namespace app_list { namespace app_list {
...@@ -87,6 +93,9 @@ constexpr char kRankingNormalAppPackageName[] = "test.ranking.app.normal"; ...@@ -87,6 +93,9 @@ constexpr char kRankingNormalAppPackageName[] = "test.ranking.app.normal";
constexpr char kSettingsInternalName[] = "Settings"; constexpr char kSettingsInternalName[] = "Settings";
constexpr char kWebAppUrl[] = "https://webappone.com/";
constexpr char kWebAppName[] = "WebApp1";
// Waits for base::Time::Now() is updated. // Waits for base::Time::Now() is updated.
void WaitTimeUpdated() { void WaitTimeUpdated() {
base::RunLoop run_loop; base::RunLoop run_loop;
...@@ -696,15 +705,76 @@ TEST_F(AppSearchProviderTest, FetchInternalApp) { ...@@ -696,15 +705,76 @@ TEST_F(AppSearchProviderTest, FetchInternalApp) {
EXPECT_EQ(kSettingsInternalName, RunQuery("Set")); EXPECT_EQ(kSettingsInternalName, RunQuery("Set"));
} }
class AppSearchProviderWebAppTest : public AppSearchProviderTest {
public:
AppSearchProviderWebAppTest() {
scoped_feature_list_.InitAndEnableFeature(
features::kDesktopPWAsWithoutExtensions);
}
~AppSearchProviderWebAppTest() override = default;
web_app::AppId InstallWebApp(const std::string& app_name,
const GURL& app_url) {
DCHECK(
base::FeatureList::IsEnabled(features::kDesktopPWAsWithoutExtensions));
const web_app::AppId app_id = web_app::GenerateAppIdFromURL(app_url);
WebApplicationInfo web_app_info;
web_app_info.app_url = app_url;
web_app_info.scope = app_url;
web_app_info.title = base::UTF8ToUTF16(app_name);
web_app_info.description = base::UTF8ToUTF16(app_name);
web_app_info.open_as_window = true;
web_app::InstallFinalizer::FinalizeOptions options;
options.install_source = WebappInstallSource::EXTERNAL_DEFAULT;
// In unit tests, we do not have Browser or WebContents instances.
// Hence we use FinalizeInstall instead of InstallWebAppFromManifest
// to install the web app.
base::RunLoop run_loop;
web_app::WebAppProviderBase::GetProviderBase(profile_.get())
->install_finalizer()
.FinalizeInstall(web_app_info, options,
base::BindLambdaForTesting(
[&](const web_app::AppId& installed_app_id,
InstallResultCode code) {
EXPECT_EQ(installed_app_id, app_id);
EXPECT_EQ(code,
InstallResultCode::kSuccessNewInstall);
run_loop.Quit();
}));
run_loop.Run();
base::RunLoop().RunUntilIdle();
return app_id;
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(AppSearchProviderWebAppTest, WebApp) {
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(testing_profile());
proxy->FlushMojoCallsForTesting();
const web_app::AppId app_id = InstallWebApp(kWebAppName, GURL(kWebAppUrl));
CreateSearch();
EXPECT_EQ("WebApp1", RunQuery("WebA"));
}
class AppSearchProviderCrostiniTest class AppSearchProviderCrostiniTest
: public AppSearchProviderTest, : public AppSearchProviderTest,
public ::testing::WithParamInterface<ProviderType> { public ::testing::WithParamInterface<ProviderType> {
protected: protected:
AppSearchProviderCrostiniTest() { AppSearchProviderCrostiniTest() {
if (GetParam() == web_app::ProviderType::kWebApps) { if (GetParam() == ProviderType::kWebApps) {
scoped_feature_list_.InitAndEnableFeature( scoped_feature_list_.InitAndEnableFeature(
features::kDesktopPWAsWithoutExtensions); features::kDesktopPWAsWithoutExtensions);
} else if (GetParam() == web_app::ProviderType::kBookmarkApps) { } else if (GetParam() == ProviderType::kBookmarkApps) {
scoped_feature_list_.InitAndDisableFeature( scoped_feature_list_.InitAndDisableFeature(
features::kDesktopPWAsWithoutExtensions); features::kDesktopPWAsWithoutExtensions);
} }
......
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