chromium/chrome/browser/extensions/api/tabs/tabs_interactive_test.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 <stddef.h>

#include "apps/test/app_window_waiter.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/pattern.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/extensions/api/tabs/tabs_api.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/common/extension_builder.h"
#include "extensions/test/result_catcher.h"
#include "extensions/test/test_extension_dir.h"
#include "ui/base/ozone_buildflags.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"

namespace extensions {

keys;
utils;

ContextType;
ExtensionTabsTest;

IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, GetLastFocusedWindow) {}

// Flaky on LaCrOS: crbug.com/1179817
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_QueryLastFocusedWindowTabs
#else
#define MAYBE_QueryLastFocusedWindowTabs
#endif
IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, MAYBE_QueryLastFocusedWindowTabs) {}

class NonPersistentExtensionTabsTest
    : public ExtensionApiTest,
      public testing::WithParamInterface<ContextType> {};

// Crashes on Lacros only. http://crbug.com/1150133
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_TabCurrentWindow
// Flakes on Linux Tests. http://crbug.com/1162432
#elif BUILDFLAG(IS_LINUX)
#define MAYBE_TabCurrentWindow
#else
#define MAYBE_TabCurrentWindow
#endif

// Tests chrome.windows.create and chrome.windows.getCurrent.
// TODO(crbug.com/40636155): Expand the test to verify that setSelfAsOpener
// param is ignored from Service Worker extension scripts.
IN_PROC_BROWSER_TEST_P(NonPersistentExtensionTabsTest, MAYBE_TabCurrentWindow) {}

// Crashes on Lacros and Linux-ozone-rel. http://crbug.com/1196709
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_OZONE)
#define MAYBE_TabGetLastFocusedWindow
#else
#define MAYBE_TabGetLastFocusedWindow
#endif

// Tests chrome.windows.getLastFocused.
IN_PROC_BROWSER_TEST_P(NonPersistentExtensionTabsTest,
                       MAYBE_TabGetLastFocusedWindow) {}

// TODO(http://crbug.com/58229): The Linux and Lacros window managers
// behave differently, which complicates the test. A separate  test should
// be written for them to avoid complicating this one.
#if !BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS_LACROS)
IN_PROC_BROWSER_TEST_P(NonPersistentExtensionTabsTest, WindowSetFocus) {
  ASSERT_TRUE(RunExtensionTest("window_update/set_focus")) << message_;
}
#endif

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

// TODO(llandwerlin): Activating a browser window and waiting for the
// action to happen requires views::Widget which is not available on
// MacOSX. Deactivate for now.
#if !BUILDFLAG(IS_MAC)
class ExtensionWindowLastFocusedTest : public PlatformAppBrowserTest {};

void ExtensionWindowLastFocusedTest::SetUpOnMainThread() {}

void ExtensionWindowLastFocusedTest::ActivateBrowserWindow(Browser* browser) {}

Browser* ExtensionWindowLastFocusedTest::CreateBrowserWithEmptyTab(
    bool as_popup) {}

int ExtensionWindowLastFocusedTest::GetTabId(
    const base::Value::Dict& dict) const {}

std::optional<base::Value> ExtensionWindowLastFocusedTest::RunFunction(
    ExtensionFunction* function,
    const std::string& params) {}

IN_PROC_BROWSER_TEST_F(ExtensionWindowLastFocusedTest,
                       NoDevtoolsAndAppWindows) {}

IN_PROC_BROWSER_TEST_F(ExtensionWindowLastFocusedTest,
                       NoTabIdForDevToolsAndAppWindows) {}
#endif  // !BUILDFLAG(IS_MAC)

TabsApiInteractiveTest;

// Tests that a window created with `focused: false` does not cover the focused
// window. Regression test for https://crbug.com/1302159.
IN_PROC_BROWSER_TEST_F(TabsApiInteractiveTest,
                       OpeningAnUnfocusedWindowDoesntCoverTheFocusedWindow) {}

}  // namespace extensions