#include <initializer_list>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/escape.h"
#include "base/strings/pattern.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/run_until.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "chrome/browser/ui/views/toolbar/toolbar_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/browser/navigation_controller.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/hit_test_region_observer.h"
#include "content/public/test/test_frame_navigation_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "net/base/filename_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/drop_target_event.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/compositor/layer_tree_owner.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace chrome {
namespace {
DragOperation;
class DragAndDropSimulator { … };
class DragStartWaiter : public aura::client::DragDropClient { … };
class DOMDragEventWaiter { … };
class DOMDragEventVerifier { … };
class DOMDragEventCounter { … };
const char kTestPagePath[] = …;
TestParam;
}
class DragAndDropBrowserTest : public InProcessBrowserTest,
public testing::WithParamInterface<TestParam> { … };
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DropTextFromOutside) { … }
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DropValidUrlFromOutside) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH) && defined(NDEBUG)
#define MAYBE_DropUrlIntoOmnibox …
#else
#define MAYBE_DropUrlIntoOmnibox …
#endif
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_DropUrlIntoOmnibox) { … }
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DropFileFromOutside) { … }
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DropForbiddenUrlFromOutside) { … }
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DragStartInFrame) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_DragSameOriginImageBetweenFrames …
#elif BUILDFLAG(IS_LINUX)
#define MAYBE_DragSameOriginImageBetweenFrames …
#else
#define MAYBE_DragSameOriginImageBetweenFrames …
#endif
struct DragAndDropBrowserTest::DragImageBetweenFrames_TestState { … };
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest,
MAYBE_DragSameOriginImageBetweenFrames) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_DragCorsSameOriginImageBetweenFrames …
#elif BUILDFLAG(IS_LINUX)
#define MAYBE_DragCorsSameOriginImageBetweenFrames …
#else
#define MAYBE_DragCorsSameOriginImageBetweenFrames …
#endif
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest,
MAYBE_DragCorsSameOriginImageBetweenFrames) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_DragCrossOriginImageBetweenFrames …
#elif BUILDFLAG(IS_LINUX)
#define MAYBE_DragCrossOriginImageBetweenFrames …
#else
#define MAYBE_DragCrossOriginImageBetweenFrames …
#endif
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest,
MAYBE_DragCrossOriginImageBetweenFrames) { … }
void DragAndDropBrowserTest::DragImageBetweenFrames_Start(
bool image_same_origin,
bool image_crossorigin_attr) { … }
void DragAndDropBrowserTest::DragImageBetweenFrames_Step2(
DragAndDropBrowserTest::DragImageBetweenFrames_TestState* state) { … }
void DragAndDropBrowserTest::DragImageBetweenFrames_Step3(
DragAndDropBrowserTest::DragImageBetweenFrames_TestState* state) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS_LACROS) || \
(BUILDFLAG(IS_CHROMEOS) && defined(ADDRESS_SANITIZER))
#define MAYBE_DragImageFromDisappearingFrame …
#else
#define MAYBE_DragImageFromDisappearingFrame …
#endif
struct DragAndDropBrowserTest::DragImageFromDisappearingFrame_TestState { … };
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest,
MAYBE_DragImageFromDisappearingFrame) { … }
void DragAndDropBrowserTest::DragImageFromDisappearingFrame_Step2(
DragAndDropBrowserTest::DragImageFromDisappearingFrame_TestState* state) { … }
void DragAndDropBrowserTest::DragImageFromDisappearingFrame_Step3(
DragAndDropBrowserTest::DragImageFromDisappearingFrame_TestState* state) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_CrossSiteDrag …
#elif BUILDFLAG(IS_CHROMEOS)
#define MAYBE_CrossSiteDrag …
#else
#define MAYBE_CrossSiteDrag …
#endif
struct DragAndDropBrowserTest::CrossSiteDrag_TestState { … };
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_CrossSiteDrag) { … }
void DragAndDropBrowserTest::CrossSiteDrag_Step2(
DragAndDropBrowserTest::CrossSiteDrag_TestState* state) { … }
void DragAndDropBrowserTest::CrossSiteDrag_Step3(
DragAndDropBrowserTest::CrossSiteDrag_TestState* state) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_CrossNavCrossSiteDrag …
#else
#define MAYBE_CrossNavCrossSiteDrag …
#endif
struct DragAndDropBrowserTest::CrossNavCrossSiteDrag_TestState { … };
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_CrossNavCrossSiteDrag) { … }
void DragAndDropBrowserTest::CrossNavCrossSiteDrag_Step2(
DragAndDropBrowserTest::CrossNavCrossSiteDrag_TestState* state) { … }
void DragAndDropBrowserTest::CrossNavCrossSiteDrag_Step3(
DragAndDropBrowserTest::CrossNavCrossSiteDrag_TestState* state) { … }
#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_CHROMEOS_ASH) && \
(defined(ADDRESS_SANITIZER) || !defined(NDEBUG)))
#define MAYBE_CrossTabDrag …
#else
#define MAYBE_CrossTabDrag …
#endif
struct DragAndDropBrowserTest::CrossTabDrag_TestState { … };
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_CrossTabDrag) { … }
void DragAndDropBrowserTest::CrossTabDrag_Step2(
DragAndDropBrowserTest::CrossTabDrag_TestState* state) { … }
void DragAndDropBrowserTest::CrossTabDrag_Step3(
DragAndDropBrowserTest::CrossTabDrag_TestState* state) { … }
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, DragUpdateScreenCoordinates) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
constexpr std::initializer_list<double> ui_scaling_factors = {1.0, 1.25, 2.0};
#else
constexpr std::initializer_list<double> ui_scaling_factors = …;
#endif
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(IS_CHROMEOS_ASH)
class DragAndDropBrowserTestNoParam : public InProcessBrowserTest {
protected:
void SimulateDragFromOmniboxToWebContents(base::OnceClosure quit) {
chrome::FocusLocationBar(browser());
BrowserView* browser_view =
BrowserView::GetBrowserViewForBrowser(browser());
OmniboxViewViews* omnibox_view =
browser_view->toolbar()->location_bar()->omnibox_view();
gfx::Point point;
views::View::ConvertPointToScreen(omnibox_view, &point);
EXPECT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
point.x(), point.y(),
base::BindOnce(&DragAndDropBrowserTestNoParam::Step2,
base::Unretained(this), std::move(quit))));
}
void Step2(base::OnceClosure quit) {
EXPECT_TRUE(ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT, ui_controls::DOWN,
base::BindOnce(&DragAndDropBrowserTestNoParam::Step3,
base::Unretained(this), std::move(quit))));
}
void Step3(base::OnceClosure quit) {
if (browser()->tab_strip_model()->count() == 1) {
EXPECT_TRUE(ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT, ui_controls::UP, std::move(quit)));
return;
}
gfx::Rect bounds = browser()
->tab_strip_model()
->GetActiveWebContents()
->GetContainerBounds();
EXPECT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
bounds.CenterPoint().x(), bounds.CenterPoint().y(),
base::BindOnce(&DragAndDropBrowserTestNoParam::Step3,
base::Unretained(this), std::move(quit))));
}
};
IN_PROC_BROWSER_TEST_F(DragAndDropBrowserTestNoParam, CloseTabDuringDrag) {
EXPECT_EQ(1, browser()->tab_strip_model()->count());
ui_test_utils::TabAddedWaiter wait_for_new_tab(browser());
ASSERT_TRUE(ExecJs(browser()
->tab_strip_model()
->GetActiveWebContents()
->GetPrimaryMainFrame(),
"window.open('javascript:document.addEventListener("
"\"dragover\", () => {window.close(); })');"));
wait_for_new_tab.Wait();
EXPECT_EQ(2, browser()->tab_strip_model()->count());
base::RunLoop loop;
SimulateDragFromOmniboxToWebContents(loop.QuitClosure());
loop.Run();
EXPECT_EQ(1, browser()->tab_strip_model()->count());
}
#endif
}