#include "content/browser/installedapp/installed_app_provider_impl.h"
#include "base/functional/bind.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "content/browser/installedapp/installed_app_provider_impl.h"
#include "content/browser/installedapp/test/installed_app_provider_impl_test_utils.h"
#include "content/common/features.h"
#include "content/public/common/content_features.h"
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/installedapp/related_application.mojom.h"
#if BUILDFLAG(IS_WIN)
#include "content/browser/installedapp/native_win_app_fetcher.h"
#endif
namespace content {
namespace {
Contains;
IsEmpty;
Not;
const char kInstalledWinAppId[] = …;
const char kInstalledWebAppId[] = …;
const std::vector<std::string> kInstalledWinAppIds = …;
const std::vector<std::string> kInstalledWebAppIds = …;
}
class InstalledAppProviderImplTest : public RenderViewHostImplTestHarness { … };
MATCHER_P(RelatedAppById, app_id, "") { … }
TEST_F(InstalledAppProviderImplTest, GetRelatedApps) { … }
TEST_F(InstalledAppProviderImplTest,
ShouldReturnNothingWithEmptyRelatedApplications) { … }
TEST_F(InstalledAppProviderImplTest,
ShouldNotReturnWebAppIfManifestIdIsInvalid) { … }
#if BUILDFLAG(IS_WIN)
TEST_F(InstalledAppProviderImplTest, LimitNumberOfMatchedApps) {
std::vector<blink::mojom::RelatedApplicationPtr> related_applications;
for (const std::string& id : kInstalledWebAppIds) {
related_applications.push_back(
CreateRelatedApplicationFromPlatformAndId("webapp", id));
}
for (const std::string& id : kInstalledWinAppIds) {
related_applications.push_back(
CreateRelatedApplicationFromPlatformAndId("windows", id));
}
EXPECT_EQ(related_applications.size(), 11u);
base::test::TestFuture<std::vector<blink::mojom::RelatedApplicationPtr>>
future;
remote()->FilterInstalledApps(std::move(related_applications),
GURL("http://foo.com/manifest.json"),
future.GetCallback());
ASSERT_TRUE(future.Wait());
const std::vector<blink::mojom::RelatedApplicationPtr>& result = future.Get();
EXPECT_EQ(result.size(), 10u);
}
#endif
}