#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <memory>
#include "base/files/file_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/extension_action_test_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/zoom/test/zoom_test_utils.h"
#include "components/zoom/zoom_controller.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "extensions/browser/extension_action.h"
#include "extensions/browser/extension_action_manager.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_host_registry.h"
#include "extensions/browser/extension_host_test_helper.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "ui/base/buildflags.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/scrollbar_size.h"
#include "ui/views/widget/widget.h"
#if !BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/download/bubble/download_bubble_ui_controller.h"
#include "chrome/browser/download/bubble/download_display_controller.h"
#include "chrome/browser/ui/download/download_display.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "ui/views/win/hwnd_util.h"
#endif
namespace extensions {
namespace {
#if !BUILDFLAG(IS_CHROMEOS)
bool IsDownloadSurfaceVisible(BrowserWindow* window) { … }
#endif
class PopupHostWatcher : public ExtensionHostRegistry::Observer { … };
class BrowserActionInteractiveTest : public ExtensionApiTest { … };
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_TestOpenPopup …
#else
#define MAYBE_TestOpenPopup …
#endif
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, MAYBE_TestOpenPopup) { … }
#if BUILDFLAG(IS_MAC) && defined(NDEBUG)
#define MAYBE_TestOpenPopupIncognito …
#else
#define MAYBE_TestOpenPopupIncognito …
#endif
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
MAYBE_TestOpenPopupIncognito) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
TestOpenPopupIncognitoFromBackground) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
TestOpenPopupDoesNotCloseOtherPopups) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
TestOpenPopupDoesNotGrantTabPermissions) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, FocusLossClosesPopup1) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, FocusLossClosesPopup2) { … }
#if (BUILDFLAG(IS_MAC) && defined(NDEBUG)) || \
(BUILDFLAG(IS_LINUX) && defined(MEMORY_SANITIZER))
#define MAYBE_TabSwitchClosesPopup …
#else
#define MAYBE_TabSwitchClosesPopup …
#endif
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
MAYBE_TabSwitchClosesPopup) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
DeleteBrowserActionWithPopupOpen) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, PopupZoomsIndependently) { … }
class BrowserActionInteractiveViewsTest : public BrowserActionInteractiveTest { … };
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveViewsTest,
CloseBrowserWithDevTools) { … }
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, DestroyHWNDDoesNotCrash) {
OpenPopupViaAPI(false);
auto test_util = ExtensionActionTestHelper::Create(browser());
const gfx::NativeView popup_view = test_util->GetPopupNativeView();
EXPECT_NE(gfx::NativeView(), popup_view);
const HWND popup_hwnd = views::HWNDForNativeView(popup_view);
EXPECT_EQ(TRUE, ::IsWindow(popup_hwnd));
const HWND browser_hwnd =
views::HWNDForNativeView(browser()->window()->GetNativeWindow());
EXPECT_EQ(TRUE, ::IsWindow(browser_hwnd));
browser()->OpenURL(
content::OpenURLParams(GURL("chrome://version"), content::Referrer(),
WindowOpenDisposition::NEW_WINDOW,
ui::PAGE_TRANSITION_TYPED, false),
{});
EXPECT_EQ(TRUE, ::CloseWindow(browser_hwnd));
EXPECT_EQ(TRUE, ::DestroyWindow(browser_hwnd));
EXPECT_EQ(FALSE, ::IsWindow(browser_hwnd));
EXPECT_EQ(FALSE, ::IsWindow(popup_hwnd));
}
#endif
class MainFrameSizeWaiter : public content::WebContentsObserver { … };
#if BUILDFLAG(IS_WIN)
#define MAYBE_BrowserActionPopup …
#elif BUILDFLAG(IS_LINUX) && \
(defined(THREAD_SANITIZER) || defined(ADDRESS_SANITIZER))
#define MAYBE_BrowserActionPopup …
#elif BUILDFLAG(IS_MAC)
#define MAYBE_BrowserActionPopup …
#else
#define MAYBE_BrowserActionPopup …
#endif
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, MAYBE_BrowserActionPopup) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
BrowserActionPopupDownload) { … }
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, OpenPopupOnPopup) { … }
class RenderFrameChangedWatcher : public content::WebContentsObserver { … };
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
BrowserActionPopupWithIframe) { … }
class BrowserActionInteractiveFencedFrameTest
: public BrowserActionInteractiveTest { … };
IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveFencedFrameTest,
BrowserActionPopupWithFencedFrame) { … }
class NavigatingExtensionPopupInteractiveTest
: public BrowserActionInteractiveTest { … };
IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupInteractiveTest, Webpage_Get) { … }
IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupInteractiveTest, Webpage_Post) { … }
IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupInteractiveTest,
PageInSameExtension_Get) { … }
IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupInteractiveTest,
PageInSameExtension_Post) { … }
IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupInteractiveTest,
PageInOtherExtension_Get) { … }
IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupInteractiveTest,
PageInOtherExtension_Post) { … }
IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupInteractiveTest,
DownloadViaPost) { … }
IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupInteractiveTest,
DownloadViaGet) { … }
}
}