#include "chrome/browser/ui/unload_controller.h"
#include "base/json/json_reader.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/test/prevent_close_test_base.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/web_app_id_constants.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/browser/browser_policy_connector_base.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"
namespace {
constexpr char kCalculatorAppUrl[] = …;
constexpr char kPreventCloseEnabledForCalculator[] = …;
constexpr char kCalculatorForceInstalled[] = …;
#if BUILDFLAG(IS_CHROMEOS)
constexpr bool kShouldPreventClose = true;
#else
constexpr bool kShouldPreventClose = …;
#endif
}
UnloadControllerPreventCloseTest;
IN_PROC_BROWSER_TEST_F(UnloadControllerPreventCloseTest,
PreventCloseEnforcedByPolicy) { … }
IN_PROC_BROWSER_TEST_F(UnloadControllerPreventCloseTest,
PreventCloseEnforcedByPolicyTabbedAppShallBeClosable) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
class UnloadControllerWithOnTaskTest : public InProcessBrowserTest {
protected:
webapps::AppId InstallMockApp() {
return web_app::test::InstallDummyWebApp(
browser()->profile(), "Mock app",
GURL("https://www.example.com/"));
}
};
IN_PROC_BROWSER_TEST_F(UnloadControllerWithOnTaskTest,
PreventCloseWhenLockedForOnTask) {
webapps::AppId app_id = InstallMockApp();
Browser* const app_browser =
web_app::LaunchWebAppBrowser(browser()->profile(), app_id);
app_browser->SetLockedForOnTask(true);
content::WebContents* const active_web_contents =
app_browser->tab_strip_model()->GetWebContentsAt(0);
UnloadController unload_controller(app_browser);
EXPECT_FALSE(unload_controller.CanCloseContents(active_web_contents));
}
IN_PROC_BROWSER_TEST_F(UnloadControllerWithOnTaskTest,
AllowCloseWhenNotLockedForOnTask) {
webapps::AppId app_id = InstallMockApp();
Browser* const app_browser =
web_app::LaunchWebAppBrowser(browser()->profile(), app_id);
app_browser->SetLockedForOnTask(false);
content::WebContents* const active_web_contents =
app_browser->tab_strip_model()->GetWebContentsAt(0);
UnloadController unload_controller(app_browser);
EXPECT_TRUE(unload_controller.CanCloseContents(active_web_contents));
}
#endif