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
|
// 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 "chrome/browser/apps/app_service/publishers/chrome_app_deprecation.h"
#include "base/notreached.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test.h"
#include "extensions/test/test_extension_dir.h"
#include "ui/message_center/message_center.h"
namespace apps {
using extensions::Extension;
class ChromeAppDeprecationUserInstalledAppsBrowserTest
: public extensions::PlatformAppBrowserTest {
protected:
const Extension* LoadPlatformApp() {
const base::FilePath& root_path = test_data_dir_;
base::FilePath extension_path =
root_path.AppendASCII("platform_apps/launch");
return LoadExtension(extension_path);
}
void RunPlatformApp(const Extension* extension) {
AppLaunchParams params(
extension->id(), LaunchContainer::kLaunchContainerNone,
WindowOpenDisposition::NEW_WINDOW, LaunchSource::kFromTest);
params.command_line = *base::CommandLine::ForCurrentProcess();
AppServiceProxyFactory::GetForProfile(browser()->profile())
->LaunchAppWithParams(std::move(params));
}
};
IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationUserInstalledAppsBrowserTest,
NotAllowlisted) {
auto* center = message_center::MessageCenter::Get();
auto notifications_count = center->GetNotifications().size();
const Extension* app = LoadPlatformApp();
ASSERT_TRUE(app);
RunPlatformApp(app);
ASSERT_TRUE(center->GetNotifications().size() == notifications_count + 1);
}
IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationUserInstalledAppsBrowserTest,
Allowlisted) {
auto* center = message_center::MessageCenter::Get();
auto notifications_count = center->GetNotifications().size();
const Extension* app = LoadPlatformApp();
ASSERT_TRUE(app);
chrome_app_deprecation::AddAppToAllowlistForTesting(app->id());
RunPlatformApp(app);
ASSERT_TRUE(center->GetNotifications().size() == notifications_count);
}
} // namespace apps
|