// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/test/with_feature_override.h"
#include "chrome/browser/ui/browser_ui_controller/browser_ui_controller.h"
#include "chrome/browser/ui/browser_window/public/browser_window_interface.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_browsertest_base.h"
#include "chrome/browser/web_applications/test/web_app_test_utils.h"
#include "chrome/common/chrome_features.h"
#include "content/public/test/browser_test.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace web_app {
namespace {

class WebAppStatusBarTest : public base::test::WithFeatureOverride,
                            public WebAppBrowserTestBase {
 public:
  WebAppStatusBarTest()
      : base::test::WithFeatureOverride(::features::kWebAppInstallDialog) {}
};

IN_PROC_BROWSER_TEST_P(WebAppStatusBarTest, NoStatusBar) {
  NavigateViaLinkClickToURLAndWait(
      browser(), embedded_https_test_server().GetURL("/web_apps/basic.html"));
  const webapps::AppId app_id = test::InstallPwaForCurrentUrl(browser());
  BrowserWindowInterface* const app_browser =
      ::web_app::LaunchWebAppBrowserAndWait(profile(), app_id);
  EXPECT_EQ(0u,
            BrowserUiController::From(app_browser)->GetStatusBubbles().size());
}

IN_PROC_BROWSER_TEST_P(WebAppStatusBarTest, DisplayBrowserHasStatusBar) {
  NavigateViaLinkClickToURLAndWait(
      browser(),
      embedded_https_test_server().GetURL("/web_apps/display_browser.html"));
  const webapps::AppId app_id = test::InstallPwaForCurrentUrl(browser());
  BrowserWindowInterface* const app_browser =
      ::web_app::LaunchWebAppBrowserAndWait(profile(), app_id);
  EXPECT_LT(0u,
            BrowserUiController::From(app_browser)->GetStatusBubbles().size());
}

IN_PROC_BROWSER_TEST_P(WebAppStatusBarTest, NoManifestHasStatusBar) {
  NavigateViaLinkClickToURLAndWait(browser(),
                                   embedded_https_test_server().GetURL(
                                       "/banners/no_manifest_test_page.html"));
  const webapps::AppId app_id = test::InstallPwaForCurrentUrl(browser());
  BrowserWindowInterface* const app_browser =
      ::web_app::LaunchWebAppBrowserAndWait(profile(), app_id);
  EXPECT_LT(0u,
            BrowserUiController::From(app_browser)->GetStatusBubbles().size());
}

IN_PROC_BROWSER_TEST_P(WebAppStatusBarTest, DisplayMinimalUiHasStatusBar) {
  NavigateViaLinkClickToURLAndWait(
      browser(),
      embedded_https_test_server().GetURL("/web_apps/minimal_ui/basic.html"));
  const webapps::AppId app_id = test::InstallPwaForCurrentUrl(browser());
  BrowserWindowInterface* const app_browser =
      ::web_app::LaunchWebAppBrowserAndWait(profile(), app_id);
  EXPECT_LT(0u,
            BrowserUiController::From(app_browser)->GetStatusBubbles().size());
}

INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE(WebAppStatusBarTest);

}  // namespace
}  // namespace web_app
