chromium/extensions/browser/api/app_window/app_window_apitest.cc

// Copyright 2012 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/command_line.h"
#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_profile.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/common/features/feature_channel.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/base/filename_util.h"
#include "ui/base/base_window.h"
#include "ui/gfx/geometry/rect.h"

namespace extensions {

AppWindowApiTest;
ExperimentalAppWindowApiTest;

// Tests chrome.app.window.setIcon.
IN_PROC_BROWSER_TEST_F(ExperimentalAppWindowApiTest, SetIcon) {}

// TODO(crbug.com/40554643): These fail on Linux with HEADLESS env var set.
// TODO(crbug.com/40118868): Revisit the macro expression once build flag switch
// of lacros-chrome is complete.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_OnMinimizedEvent
#define MAYBE_OnMaximizedEvent
#define MAYBE_OnRestoredEvent
#else
#define MAYBE_OnMinimizedEvent
#define MAYBE_OnMaximizedEvent
#define MAYBE_OnRestoredEvent
#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_OnMinimizedEvent) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_OnMaximizedEvent) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_OnRestoredEvent) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, OnBoundsChangedEvent) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlwaysOnTopWithPermissions) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlwaysOnTopWithOldPermissions) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlwaysOnTopNoPermissions) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, Get) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, SetShapeHasPerm) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, SetShapeNoPerm) {}

// Fails on Ozone/X11.  https://crbug.com/1109112
#if BUILDFLAG(IS_OZONE)
#define MAYBE_AlphaEnabledHasPermissions
#else
#define MAYBE_AlphaEnabledHasPermissions
#endif
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_AlphaEnabledHasPermissions) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlphaEnabledNoPermissions) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlphaEnabledInStable) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlphaEnabledWrongFrameType) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, CrossOriginIsolation) {}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, VisibleOnAllWorkspacesInStable) {}

// Tests that component extensions are allowed to open chrome:-scheme URLs in
// app windows, but not other absolute URLs.
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, OpeningAbsoluteURLs) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, ImeWindowHasPermissions) {
  EXPECT_TRUE(
      RunExtensionTest("platform_apps/windows_api_ime/has_permissions_allowed",
                       {}, {.load_as_component = true}))
      << message_;

  EXPECT_TRUE(RunExtensionTest(
      "platform_apps/windows_api_ime/has_permissions_platform_app",
      {.launch_as_platform_app = true}, {.ignore_manifest_warnings = true}))
      << message_;
}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, ImeWindowNoPermissions) {
  EXPECT_TRUE(
      RunExtensionTest("platform_apps/windows_api_ime/no_permissions_allowed",
                       {}, {.load_as_component = true}))
      << message_;

  EXPECT_TRUE(RunExtensionTest(
      "platform_apps/windows_api_ime/no_permissions_platform_app",
      {.launch_as_platform_app = true}))
      << message_;
}

IN_PROC_BROWSER_TEST_F(AppWindowApiTest, ImeWindowNotFullscreen) {
  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
  command_line->AppendSwitch(switches::kForceAppMode);
  command_line->AppendSwitchASCII(switches::kAppId,
                                  "jkghodnilhceideoidjikpgommlajknk");

  EXPECT_TRUE(RunExtensionTest(
      "platform_apps/windows_api_ime/forced_app_mode_not_fullscreen", {},
      {.load_as_component = true}))
      << message_;
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace extensions