1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/app_list/app_waiter.h"
#include <memory>
#include <string_view>
#include <utility>
#include <vector>
#include "base/test/test_future.h"
#include "components/account_id/account_id.h"
#include "components/services/app_service/public/cpp/app.h"
#include "components/services/app_service/public/cpp/app_registry_cache.h"
#include "components/services/app_service/public/cpp/app_registry_cache_wrapper.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
constexpr std::string_view kTestAppId = "test-app";
const AccountId kTestAccountId = AccountId::FromUserEmail("test@example.com");
} // namespace
TEST(AppWaiterTest, CacheLoadedLater) {
base::test::TestFuture<std::string> future;
ash::AppWaiter app_waiter(kTestAccountId, future.GetCallback(), kTestAppId);
EXPECT_FALSE(future.IsReady());
apps::AppRegistryCache cache;
std::unique_ptr<apps::App> app = std::make_unique<apps::App>(
apps::AppType::kSystemWeb, std::string(kTestAppId));
app->name = "Test App";
std::vector<apps::AppPtr> apps;
apps.push_back(std::move(app));
cache.OnAppsForTesting(std::move(apps), apps::AppType::kSystemWeb,
/*should_notify_initialized=*/false);
EXPECT_FALSE(future.IsReady());
apps::AppRegistryCacheWrapper::Get().AddAppRegistryCache(kTestAccountId,
&cache);
EXPECT_EQ(future.Get(), "Test App");
}
TEST(AppWaiterTest, AppLoadedWithName) {
base::test::TestFuture<std::string> future;
apps::AppRegistryCache cache;
apps::AppRegistryCacheWrapper::Get().AddAppRegistryCache(kTestAccountId,
&cache);
ash::AppWaiter app_waiter(kTestAccountId, future.GetCallback(), kTestAppId);
std::unique_ptr<apps::App> app = std::make_unique<apps::App>(
apps::AppType::kSystemWeb, std::string(kTestAppId));
app->name = "Test App";
std::vector<apps::AppPtr> apps;
apps.push_back(std::move(app));
cache.OnAppsForTesting(std::move(apps), apps::AppType::kSystemWeb,
/*should_notify_initialized=*/false);
EXPECT_EQ(future.Get(), "Test App");
}
TEST(AppWaiterTest, AppLoadedFirstNameLoadedLater) {
base::test::TestFuture<std::string> future;
apps::AppRegistryCache cache;
apps::AppRegistryCacheWrapper::Get().AddAppRegistryCache(kTestAccountId,
&cache);
ash::AppWaiter app_waiter(kTestAccountId, future.GetCallback(), kTestAppId);
{
std::unique_ptr<apps::App> app = std::make_unique<apps::App>(
apps::AppType::kSystemWeb, std::string(kTestAppId));
std::vector<apps::AppPtr> apps;
apps.push_back(std::move(app));
cache.OnAppsForTesting(std::move(apps), apps::AppType::kSystemWeb,
/*should_notify_initialized=*/false);
}
EXPECT_FALSE(future.IsReady());
{
std::unique_ptr<apps::App> app = std::make_unique<apps::App>(
apps::AppType::kSystemWeb, std::string(kTestAppId));
app->name = "Test App";
std::vector<apps::AppPtr> apps;
apps.push_back(std::move(app));
cache.OnAppsForTesting(std::move(apps), apps::AppType::kSystemWeb,
/*should_notify_initialized=*/false);
}
EXPECT_EQ(future.Get(), "Test App");
}
TEST(AppWaiterTest, AppAlreadyLoaded) {
base::test::TestFuture<std::string> future;
apps::AppRegistryCache cache;
apps::AppRegistryCacheWrapper::Get().AddAppRegistryCache(kTestAccountId,
&cache);
std::unique_ptr<apps::App> app = std::make_unique<apps::App>(
apps::AppType::kSystemWeb, std::string(kTestAppId));
app->name = "Test App";
std::vector<apps::AppPtr> apps;
apps.push_back(std::move(app));
cache.OnAppsForTesting(std::move(apps), apps::AppType::kSystemWeb,
/*should_notify_initialized=*/false);
ash::AppWaiter app_waiter(kTestAccountId, future.GetCallback(), kTestAppId);
EXPECT_EQ(future.Get(), "Test App");
}
|