This source file includes following definitions.
- id
- Observe
- GetCenterInScreenCoordinates
- SetID
- ResetIDs
- IDString
- QuitWhenNotDraggingImpl
- GetTabStripForBrowser
- StopAnimating
- AddTabAndResetBrowser
- CreateAnotherWindowBrowserAndRelayout
- GetDetachY
- GetIsDragged
- GetHostAt
- GetScreenPositionClient
- release_capture_
- ReleaseCaptureOnNextClear
- ClearNativeFocus
- Create
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- SetUpCommandLine
- SetUpOnMainThread
- input_source
- docked_windows_enabled
- SetEventGeneratorRootWindow
- PressInput
- PressInput2
- DragInputTo
- DragInputToAsync
- DragInputToNotifyWhenDone
- DragInputToDelayedNotifyWhenDone
- DragInput2ToNotifyWhenDone
- ReleaseInput
- ReleaseInput2
- ReleaseMouseAsync
- QuitWhenNotDragging
- AddBlankTabAndShow
- browser
- IN_PROC_BROWSER_TEST_P
- DragToSeparateWindowStep2
- IN_PROC_BROWSER_TEST_P
- DetachToOwnWindowStep2
- IsWindowPositionManaged
- HasUserChangedWindowPositionOrSize
- IsWindowPositionManaged
- HasUserChangedWindowPositionOrSize
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- DeleteWhileDetachedStep2
- IN_PROC_BROWSER_TEST_P
- DeleteSourceDetachedStep2
- IN_PROC_BROWSER_TEST_P
- PressEscapeWhileDetachedStep2
- IN_PROC_BROWSER_TEST_P
- DragAllStep2
- IN_PROC_BROWSER_TEST_P
- DragAllToSeparateWindowStep2
- IN_PROC_BROWSER_TEST_P
- DragAllToSeparateWindowAndCancelStep2
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- CancelOnNewTabWhenDraggingStep2
- IN_PROC_BROWSER_TEST_P
- DragInMaximizedWindowStep2
- IN_PROC_BROWSER_TEST_P
- SetUpCommandLine
- DragSingleTabToSeparateWindowInSecondDisplayStep3
- DragSingleTabToSeparateWindowInSecondDisplayStep2
- IN_PROC_BROWSER_TEST_P
- DragTabToWindowInSeparateDisplayStep2
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- IN_PROC_BROWSER_TEST_P
- SetUpCommandLine
- GetCursorDeviceScaleFactor
- CursorDeviceScaleFactorStep
- IN_PROC_BROWSER_TEST_P
- SetUpCommandLine
- Press
- DragTabAndExecuteTaskWhenDone
- QuitWhenNotDragging
- CancelDragTabToWindowInSeparateDisplayStep3
- CancelDragTabToWindowInSeparateDisplayStep2
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- PressSecondFingerWhileDetachedStep2
- IN_PROC_BROWSER_TEST_P
- DetachToDockedWindowNextStep
- IN_PROC_BROWSER_TEST_P
#include "chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.h"
#include "ash/wm/window_state.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/native_browser_frame_factory.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_drag_controller.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/common/chrome_switches.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/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/test/ui_controls.h"
#include "ui/gfx/screen.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#if defined(USE_AURA) && !defined(OS_CHROMEOS)
#include "chrome/browser/ui/views/frame/desktop_browser_frame_aura.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#endif
#if defined(USE_ASH)
#include "ash/ash_switches.h"
#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/test/cursor_manager_test_api.h"
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window_event_dispatcher.h"
#endif
using content::WebContents;
namespace test {
namespace {
const char kTabDragControllerInteractiveUITestUserDataKey[] =
"TabDragControllerInteractiveUITestUserData";
class TabDragControllerInteractiveUITestUserData
: public base::SupportsUserData::Data {
public:
explicit TabDragControllerInteractiveUITestUserData(int id) : id_(id) {}
virtual ~TabDragControllerInteractiveUITestUserData() {}
int id() { return id_; }
private:
int id_;
};
}
class QuitDraggingObserver : public content::NotificationObserver {
public:
QuitDraggingObserver() {
registrar_.Add(this, chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE,
content::NotificationService::AllSources());
}
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
DCHECK_EQ(chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, type);
base::MessageLoopForUI::current()->Quit();
delete this;
}
private:
virtual ~QuitDraggingObserver() {}
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(QuitDraggingObserver);
};
gfx::Point GetCenterInScreenCoordinates(const views::View* view) {
gfx::Point center(view->width() / 2, view->height() / 2);
views::View::ConvertPointToScreen(view, ¢er);
return center;
}
void SetID(WebContents* web_contents, int id) {
web_contents->SetUserData(&kTabDragControllerInteractiveUITestUserDataKey,
new TabDragControllerInteractiveUITestUserData(id));
}
void ResetIDs(TabStripModel* model, int start) {
for (int i = 0; i < model->count(); ++i)
SetID(model->GetWebContentsAt(i), start + i);
}
std::string IDString(TabStripModel* model) {
std::string result;
for (int i = 0; i < model->count(); ++i) {
if (i != 0)
result += " ";
WebContents* contents = model->GetWebContentsAt(i);
TabDragControllerInteractiveUITestUserData* user_data =
static_cast<TabDragControllerInteractiveUITestUserData*>(
contents->GetUserData(
&kTabDragControllerInteractiveUITestUserDataKey));
if (user_data)
result += base::IntToString(user_data->id());
else
result += "?";
}
return result;
}
void QuitWhenNotDraggingImpl() {
new QuitDraggingObserver();
}
TabStrip* GetTabStripForBrowser(Browser* browser) {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
return static_cast<TabStrip*>(browser_view->tabstrip());
}
}
using test::GetCenterInScreenCoordinates;
using test::SetID;
using test::ResetIDs;
using test::IDString;
using test::GetTabStripForBrowser;
TabDragControllerTest::TabDragControllerTest()
: native_browser_list(BrowserList::GetInstance(
chrome::HOST_DESKTOP_TYPE_NATIVE)) {
}
TabDragControllerTest::~TabDragControllerTest() {
}
void TabDragControllerTest::StopAnimating(TabStrip* tab_strip) {
tab_strip->StopAnimating(true);
}
void TabDragControllerTest::AddTabAndResetBrowser(Browser* browser) {
AddBlankTabAndShow(browser);
StopAnimating(GetTabStripForBrowser(browser));
ResetIDs(browser->tab_strip_model(), 0);
}
Browser* TabDragControllerTest::CreateAnotherWindowBrowserAndRelayout() {
Browser* browser2 = CreateBrowser(browser()->profile());
ResetIDs(browser2->tab_strip_model(), 100);
gfx::Rect work_area = gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow(
browser()->window()->GetNativeWindow()).work_area();
gfx::Size half_size =
gfx::Size(work_area.width() / 3 - 10, work_area.height() / 2 - 10);
browser()->window()->SetBounds(gfx::Rect(work_area.origin(), half_size));
browser2->window()->SetBounds(gfx::Rect(
work_area.x() + half_size.width(), work_area.y(),
half_size.width(), half_size.height()));
return browser2;
}
namespace {
enum InputSource {
INPUT_SOURCE_MOUSE = 0,
INPUT_SOURCE_TOUCH = 1
};
int GetDetachY(TabStrip* tab_strip) {
return std::max(TabDragController::kTouchVerticalDetachMagnetism,
TabDragController::kVerticalDetachMagnetism) +
tab_strip->height() + 1;
}
bool GetIsDragged(Browser* browser) {
#if !defined(USE_ASH) || defined(OS_WIN)
return false;
#else
return ash::wm::GetWindowState(browser->window()->GetNativeWindow())->
is_dragged();
#endif
}
}
#if defined(USE_ASH) && !defined(OS_WIN)
class ScreenEventGeneratorDelegate : public aura::test::EventGeneratorDelegate {
public:
explicit ScreenEventGeneratorDelegate(aura::Window* root_window)
: root_window_(root_window) {}
virtual ~ScreenEventGeneratorDelegate() {}
virtual aura::WindowTreeHost* GetHostAt(
const gfx::Point& point) const OVERRIDE {
return root_window_->GetHost();
}
virtual aura::client::ScreenPositionClient* GetScreenPositionClient(
const aura::Window* window) const OVERRIDE {
return aura::client::GetScreenPositionClient(root_window_);
}
private:
aura::Window* root_window_;
DISALLOW_COPY_AND_ASSIGN(ScreenEventGeneratorDelegate);
};
#endif
#if defined(USE_AURA) && !defined(OS_CHROMEOS)
class TestDesktopBrowserFrameAura : public DesktopBrowserFrameAura {
public:
TestDesktopBrowserFrameAura(
BrowserFrame* browser_frame,
BrowserView* browser_view)
: DesktopBrowserFrameAura(browser_frame, browser_view),
release_capture_(false) {}
virtual ~TestDesktopBrowserFrameAura() {}
void ReleaseCaptureOnNextClear() {
release_capture_ = true;
}
virtual void ClearNativeFocus() OVERRIDE {
views::DesktopNativeWidgetAura::ClearNativeFocus();
if (release_capture_) {
release_capture_ = false;
GetWidget()->ReleaseCapture();
}
}
private:
bool release_capture_;
DISALLOW_COPY_AND_ASSIGN(TestDesktopBrowserFrameAura);
};
class TestNativeBrowserFrameFactory : public NativeBrowserFrameFactory {
public:
TestNativeBrowserFrameFactory() {}
virtual ~TestNativeBrowserFrameFactory() {}
virtual NativeBrowserFrame* Create(
BrowserFrame* browser_frame,
BrowserView* browser_view) OVERRIDE {
return new TestDesktopBrowserFrameAura(browser_frame, browser_view);
}
private:
DISALLOW_COPY_AND_ASSIGN(TestNativeBrowserFrameFactory);
};
class TabDragCaptureLostTest : public TabDragControllerTest {
public:
TabDragCaptureLostTest() {
NativeBrowserFrameFactory::Set(new TestNativeBrowserFrameFactory);
}
private:
DISALLOW_COPY_AND_ASSIGN(TabDragCaptureLostTest);
};
IN_PROC_BROWSER_TEST_F(TabDragCaptureLostTest, ReleaseCaptureOnDrag) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_1_center(GetCenterInScreenCoordinates(tab_strip->tab_at(1)));
ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_1_center) &&
ui_test_utils::SendMouseEventsSync(
ui_controls::LEFT, ui_controls::DOWN));
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
TestDesktopBrowserFrameAura* frame =
static_cast<TestDesktopBrowserFrameAura*>(
BrowserView::GetBrowserViewForBrowser(browser())->GetWidget()->
native_widget_private());
frame->ReleaseCaptureOnNextClear();
ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(tab_0_center));
EXPECT_FALSE(tab_strip->IsDragSessionActive());
}
IN_PROC_BROWSER_TEST_F(TabDragControllerTest, GestureEndShouldEndDragTest) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
Tab* tab1 = tab_strip->tab_at(1);
gfx::Point tab_1_center(tab1->width() / 2, tab1->height() / 2);
ui::GestureEvent gesture_begin(ui::ET_GESTURE_BEGIN, tab_1_center.x(),
tab_1_center.x(), 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0.0f, 0.0f), 0);
tab_strip->MaybeStartDrag(tab1, gesture_begin,
tab_strip->GetSelectionModel());
EXPECT_TRUE(TabDragController::IsActive());
ui::GestureEvent gesture_end(ui::ET_GESTURE_END, tab_1_center.x(),
tab_1_center.x(), 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_END, 0.0f, 0.0f), 0);
tab_strip->OnGestureEvent(&gesture_end);
EXPECT_FALSE(TabDragController::IsActive());
EXPECT_FALSE(tab_strip->IsDragSessionActive());
}
#endif
class DetachToBrowserTabDragControllerTest
: public TabDragControllerTest,
public ::testing::WithParamInterface<const char*> {
public:
DetachToBrowserTabDragControllerTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
#if defined(USE_ASH) && !defined(OS_WIN)
if (!docked_windows_enabled()) {
CommandLine::ForCurrentProcess()->AppendSwitch(
ash::switches::kAshDisableDockedWindows);
}
#endif
}
virtual void SetUpOnMainThread() OVERRIDE {
#if defined(USE_ASH) && !defined(OS_WIN)
event_generator_.reset(new aura::test::EventGenerator(
ash::Shell::GetPrimaryRootWindow()));
#endif
}
InputSource input_source() const {
return strstr(GetParam(), "mouse") ?
INPUT_SOURCE_MOUSE : INPUT_SOURCE_TOUCH;
}
bool docked_windows_enabled() const {
return (strstr(GetParam(), "docked") != NULL);
}
void SetEventGeneratorRootWindow(const gfx::Point& point) {
if (input_source() == INPUT_SOURCE_MOUSE)
return;
#if defined(USE_ASH) && !defined(OS_WIN)
event_generator_.reset(new aura::test::EventGenerator(
new ScreenEventGeneratorDelegate(ash::wm::GetRootWindowAt(point))));
#endif
}
bool PressInput(const gfx::Point& location) {
if (input_source() == INPUT_SOURCE_MOUSE) {
return ui_test_utils::SendMouseMoveSync(location) &&
ui_test_utils::SendMouseEventsSync(
ui_controls::LEFT, ui_controls::DOWN);
}
#if defined(USE_ASH) && !defined(OS_WIN)
event_generator_->set_current_location(location);
event_generator_->PressTouch();
#else
NOTREACHED();
#endif
return true;
}
bool PressInput2() {
EXPECT_EQ(INPUT_SOURCE_TOUCH, input_source());
#if defined(USE_ASH) && !defined(OS_WIN)
event_generator_->set_current_location(
event_generator_->current_location());
event_generator_->PressTouchId(1);
#else
NOTREACHED();
#endif
return true;
}
bool DragInputTo(const gfx::Point& location) {
if (input_source() == INPUT_SOURCE_MOUSE)
return ui_test_utils::SendMouseMoveSync(location);
#if defined(USE_ASH) && !defined(OS_WIN)
event_generator_->MoveTouch(location);
#else
NOTREACHED();
#endif
return true;
}
bool DragInputToAsync(const gfx::Point& location) {
if (input_source() == INPUT_SOURCE_MOUSE)
return ui_controls::SendMouseMove(location.x(), location.y());
#if defined(USE_ASH) && !defined(OS_WIN)
event_generator_->MoveTouch(location);
#else
NOTREACHED();
#endif
return true;
}
bool DragInputToNotifyWhenDone(int x,
int y,
const base::Closure& task) {
if (input_source() == INPUT_SOURCE_MOUSE)
return ui_controls::SendMouseMoveNotifyWhenDone(x, y, task);
#if defined(USE_ASH) && !defined(OS_WIN)
base::MessageLoop::current()->PostTask(FROM_HERE, task);
event_generator_->MoveTouch(gfx::Point(x, y));
#else
NOTREACHED();
#endif
return true;
}
bool DragInputToDelayedNotifyWhenDone(int x,
int y,
const base::Closure& task,
base::TimeDelta delay) {
if (input_source() == INPUT_SOURCE_MOUSE)
return ui_controls::SendMouseMoveNotifyWhenDone(x, y, task);
#if defined(USE_ASH) && !defined(OS_WIN)
base::MessageLoop::current()->PostDelayedTask(FROM_HERE, task, delay);
event_generator_->MoveTouch(gfx::Point(x, y));
#else
NOTREACHED();
#endif
return true;
}
bool DragInput2ToNotifyWhenDone(int x,
int y,
const base::Closure& task) {
if (input_source() == INPUT_SOURCE_MOUSE)
return ui_controls::SendMouseMoveNotifyWhenDone(x, y, task);
#if defined(USE_ASH) && !defined(OS_WIN)
base::MessageLoop::current()->PostTask(FROM_HERE, task);
event_generator_->MoveTouchId(gfx::Point(x, y), 1);
#else
NOTREACHED();
#endif
return true;
}
bool ReleaseInput() {
if (input_source() == INPUT_SOURCE_MOUSE) {
return ui_test_utils::SendMouseEventsSync(
ui_controls::LEFT, ui_controls::UP);
}
#if defined(USE_ASH) && !defined(OS_WIN)
event_generator_->ReleaseTouch();
#else
NOTREACHED();
#endif
return true;
}
bool ReleaseInput2() {
if (input_source() == INPUT_SOURCE_MOUSE) {
return ui_test_utils::SendMouseEventsSync(
ui_controls::LEFT, ui_controls::UP);
}
#if defined(USE_ASH) && !defined(OS_WIN)
event_generator_->ReleaseTouchId(1);
#else
NOTREACHED();
#endif
return true;
}
bool ReleaseMouseAsync() {
return input_source() == INPUT_SOURCE_MOUSE &&
ui_controls::SendMouseEvents(ui_controls::LEFT, ui_controls::UP);
}
void QuitWhenNotDragging() {
if (input_source() == INPUT_SOURCE_MOUSE) {
test::QuitWhenNotDraggingImpl();
base::MessageLoop::current()->Run();
} else {
base::RunLoop run_loop;
run_loop.RunUntilIdle();
}
}
void AddBlankTabAndShow(Browser* browser) {
InProcessBrowserTest::AddBlankTabAndShow(browser);
}
Browser* browser() const { return InProcessBrowserTest::browser(); }
private:
#if defined(USE_ASH) && !defined(OS_WIN)
scoped_ptr<aura::test::EventGenerator> event_generator_;
#endif
DISALLOW_COPY_AND_ASSIGN(DetachToBrowserTabDragControllerTest);
};
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, DragInSameWindow) {
if (input_source() == INPUT_SOURCE_TOUCH) {
VLOG(1) << "Test is DISABLED for touch input.";
return;
}
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
TabStripModel* model = browser()->tab_strip_model();
gfx::Point tab_1_center(GetCenterInScreenCoordinates(tab_strip->tab_at(1)));
ASSERT_TRUE(PressInput(tab_1_center));
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(DragInputTo(tab_0_center));
ASSERT_TRUE(ReleaseInput());
EXPECT_EQ("1 0", IDString(model));
EXPECT_FALSE(TabDragController::IsActive());
EXPECT_FALSE(tab_strip->IsDragSessionActive());
EXPECT_FALSE(tab_strip->GetWidget()->HasCapture());
}
namespace {
void DragToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test,
TabStrip* not_attached_tab_strip,
TabStrip* target_tab_strip) {
ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive());
ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
gfx::Point target_point(target_tab_strip->width() -1,
target_tab_strip->height() / 2);
views::View::ConvertPointToScreen(target_tab_strip, &target_point);
ASSERT_TRUE(test->DragInputToAsync(target_point));
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragToSeparateWindow DISABLED_DragToSeparateWindow
#else
#define MAYBE_DragToSeparateWindow DragToSeparateWindow
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DragToSeparateWindow) {
TabStrip* tab_strip = GetTabStripForBrowser(browser());
AddTabAndResetBrowser(browser());
Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragToSeparateWindowStep2,
this, tab_strip, tab_strip2)));
QuitWhenNotDragging();
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
EXPECT_FALSE(GetIsDragged(browser()));
ASSERT_TRUE(ReleaseInput());
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("100 0", IDString(browser2->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(browser2));
EXPECT_FALSE(browser()->window()->IsMaximized());
EXPECT_FALSE(browser2->window()->IsMaximized());
EXPECT_FALSE(tab_strip->GetWidget()->HasCapture());
EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture());
}
namespace {
void DetachToOwnWindowStep2(DetachToBrowserTabDragControllerTest* test) {
if (test->input_source() == INPUT_SOURCE_TOUCH)
ASSERT_TRUE(test->ReleaseInput());
}
#if defined(USE_ASH) && !defined(OS_WIN)
bool IsWindowPositionManaged(aura::Window* window) {
return ash::wm::GetWindowState(window)->window_position_managed();
}
bool HasUserChangedWindowPositionOrSize(aura::Window* window) {
return ash::wm::GetWindowState(window)->bounds_changed_by_user();
}
#else
bool IsWindowPositionManaged(gfx::NativeWindow window) {
return true;
}
bool HasUserChangedWindowPositionOrSize(gfx::NativeWindow window) {
return false;
}
#endif
}
#if defined(OS_CHROMEOS)
#define MAYBE_DetachToOwnWindow DISABLED_DetachToOwnWindow
#else
#define MAYBE_DetachToOwnWindow DetachToOwnWindow
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DetachToOwnWindow) {
const gfx::Rect initial_bounds(browser()->window()->GetBounds());
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DetachToOwnWindowStep2, this)));
if (input_source() == INPUT_SOURCE_MOUSE) {
ASSERT_TRUE(ReleaseMouseAsync());
QuitWhenNotDragging();
}
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
ASSERT_EQ(2u, native_browser_list->size());
Browser* new_browser = native_browser_list->get(1);
ASSERT_TRUE(new_browser->window()->IsActive());
TabStrip* tab_strip2 = GetTabStripForBrowser(new_browser);
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_EQ(initial_bounds.ToString(),
browser()->window()->GetBounds().ToString());
EXPECT_FALSE(GetIsDragged(browser()));
EXPECT_FALSE(GetIsDragged(new_browser));
EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow()));
EXPECT_TRUE(IsWindowPositionManaged(
new_browser->window()->GetNativeWindow()));
EXPECT_FALSE(browser()->window()->IsMaximized());
EXPECT_FALSE(new_browser->window()->IsMaximized());
EXPECT_FALSE(tab_strip->GetWidget()->HasCapture());
EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture());
}
#if defined(OS_CHROMEOS)
#define MAYBE_DetachToOwnWindowFromMaximizedWindow \
DISABLED_DetachToOwnWindowFromMaximizedWindow
#else
#define MAYBE_DetachToOwnWindowFromMaximizedWindow \
DetachToOwnWindowFromMaximizedWindow
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DetachToOwnWindowFromMaximizedWindow) {
browser()->window()->Maximize();
ASSERT_TRUE(browser()->window()->IsMaximized());
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DetachToOwnWindowStep2, this)));
if (input_source() == INPUT_SOURCE_MOUSE) {
ASSERT_TRUE(ReleaseMouseAsync());
QuitWhenNotDragging();
}
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
ASSERT_EQ(2u, native_browser_list->size());
Browser* new_browser = native_browser_list->get(1);
ASSERT_TRUE(new_browser->window()->IsActive());
TabStrip* tab_strip2 = GetTabStripForBrowser(new_browser);
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_TRUE(browser()->window()->IsMaximized());
EXPECT_FALSE(GetIsDragged(browser()));
EXPECT_FALSE(GetIsDragged(new_browser));
EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow()));
EXPECT_TRUE(IsWindowPositionManaged(
new_browser->window()->GetNativeWindow()));
EXPECT_TRUE(new_browser->window()->IsMaximized());
}
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
DeleteBeforeStartedDragging) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
delete browser()->tab_strip_model()->GetWebContentsAt(0);
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(browser()));
}
#if defined(OS_CHROMEOS)
#define MAYBE_DeleteTabWhileAttached DISABLED_DeleteTabWhileAttached
#else
#define MAYBE_DeleteTabWhileAttached DeleteTabWhileAttached
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DeleteTabWhileAttached) {
if (input_source() == INPUT_SOURCE_MOUSE) {
VLOG(1) << "Test is DISABLED for mouse input.";
return;
}
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputTo(
gfx::Point(tab_0_center.x() + 20, tab_0_center.y())));
ASSERT_TRUE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
delete browser()->tab_strip_model()->GetWebContentsAt(0);
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(browser()));
}
namespace {
void DeleteWhileDetachedStep2(WebContents* tab) {
delete tab;
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DeleteTabWhileDetached DISABLED_DeleteTabWhileDetached
#else
#define MAYBE_DeleteTabWhileDetached DeleteTabWhileDetached
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DeleteTabWhileDetached) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
WebContents* to_delete =
browser()->tab_strip_model()->GetWebContentsAt(0);
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DeleteWhileDetachedStep2, to_delete)));
QuitWhenNotDragging();
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(browser()));
}
namespace {
void DeleteSourceDetachedStep2(WebContents* tab,
const BrowserList* browser_list) {
ASSERT_EQ(2u, browser_list->size());
Browser* new_browser = browser_list->get(1);
delete tab;
ui_controls::SendKeyPress(new_browser->window()->GetNativeWindow(),
ui::VKEY_ESCAPE, false, false, false, false);
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DeleteSourceDetached DISABLED_DeleteSourceDetached
#else
#define MAYBE_DeleteSourceDetached DeleteSourceDetached
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DeleteSourceDetached) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
WebContents* to_delete = browser()->tab_strip_model()->GetWebContentsAt(1);
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DeleteSourceDetachedStep2, to_delete, native_browser_list)));
QuitWhenNotDragging();
ASSERT_EQ(1u, native_browser_list->size());
Browser* new_browser = native_browser_list->get(0);
ASSERT_FALSE(GetTabStripForBrowser(new_browser)->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(new_browser));
EXPECT_FALSE(new_browser->window()->IsMaximized());
}
namespace {
void PressEscapeWhileDetachedStep2(const BrowserList* browser_list) {
ASSERT_EQ(2u, browser_list->size());
Browser* new_browser = browser_list->get(1);
ui_controls::SendKeyPress(
new_browser->window()->GetNativeWindow(), ui::VKEY_ESCAPE, false, false,
false, false);
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_PressEscapeWhileDetached DISABLED_PressEscapeWhileDetached
#else
#define MAYBE_PressEscapeWhileDetached PressEscapeWhileDetached
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_PressEscapeWhileDetached) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&PressEscapeWhileDetachedStep2, native_browser_list)));
QuitWhenNotDragging();
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ(1u, native_browser_list->size());
EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(browser()->window()->IsMaximized());
EXPECT_FALSE(tab_strip->GetWidget()->HasCapture());
}
namespace {
void DragAllStep2(DetachToBrowserTabDragControllerTest* test,
const BrowserList* browser_list) {
ASSERT_EQ(1u, browser_list->size());
if (test->input_source() == INPUT_SOURCE_TOUCH) {
ASSERT_TRUE(test->ReleaseInput());
} else {
ASSERT_TRUE(test->ReleaseMouseAsync());
}
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragAll DISABLED_DragAll
#else
#define MAYBE_DragAll DragAll
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, MAYBE_DragAll) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
browser()->tab_strip_model()->AddTabAtToSelection(0);
browser()->tab_strip_model()->AddTabAtToSelection(1);
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragAllStep2, this, native_browser_list)));
QuitWhenNotDragging();
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ(1u, native_browser_list->size());
EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(browser()));
EXPECT_FALSE(browser()->window()->IsMaximized());
}
namespace {
void DragAllToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test,
TabStrip* attached_tab_strip,
TabStrip* target_tab_strip,
const BrowserList* browser_list) {
ASSERT_TRUE(attached_tab_strip->IsDragSessionActive());
ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(2u, browser_list->size());
gfx::Point target_point(target_tab_strip->width() - 1,
target_tab_strip->height() / 2);
views::View::ConvertPointToScreen(target_tab_strip, &target_point);
ASSERT_TRUE(test->DragInputToAsync(target_point));
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragAllToSeparateWindow DISABLED_DragAllToSeparateWindow
#else
#define MAYBE_DragAllToSeparateWindow DragAllToSeparateWindow
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DragAllToSeparateWindow) {
TabStrip* tab_strip = GetTabStripForBrowser(browser());
AddTabAndResetBrowser(browser());
Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
browser()->tab_strip_model()->AddTabAtToSelection(0);
browser()->tab_strip_model()->AddTabAtToSelection(1);
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2,
native_browser_list)));
QuitWhenNotDragging();
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(1u, native_browser_list->size());
ASSERT_TRUE(ReleaseInput());
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("100 0 1", IDString(browser2->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(browser2));
EXPECT_FALSE(browser2->window()->IsMaximized());
}
namespace {
void DragAllToSeparateWindowAndCancelStep2(
DetachToBrowserTabDragControllerTest* test,
TabStrip* attached_tab_strip,
TabStrip* target_tab_strip,
const BrowserList* browser_list) {
ASSERT_TRUE(attached_tab_strip->IsDragSessionActive());
ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(2u, browser_list->size());
gfx::Point target_point(target_tab_strip->width() - 1,
target_tab_strip->height() / 2);
views::View::ConvertPointToScreen(target_tab_strip, &target_point);
ASSERT_TRUE(test->DragInputToAsync(target_point));
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragAllToSeparateWindowAndCancel \
DISABLED_DragAllToSeparateWindowAndCancel
#else
#define MAYBE_DragAllToSeparateWindowAndCancel DragAllToSeparateWindowAndCancel
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DragAllToSeparateWindowAndCancel) {
TabStrip* tab_strip = GetTabStripForBrowser(browser());
AddTabAndResetBrowser(browser());
Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
browser()->tab_strip_model()->AddTabAtToSelection(0);
browser()->tab_strip_model()->AddTabAtToSelection(1);
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragAllToSeparateWindowAndCancelStep2, this,
tab_strip, tab_strip2, native_browser_list)));
QuitWhenNotDragging();
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(1u, native_browser_list->size());
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser2, ui::VKEY_ESCAPE, false, false, false, false));
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("100 0 1", IDString(browser2->tab_strip_model()));
ASSERT_EQ(1u, native_browser_list->size());
EXPECT_FALSE(GetIsDragged(browser2));
EXPECT_FALSE(browser2->window()->IsMaximized());
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragDirectlyToSecondWindow DISABLED_DragDirectlyToSecondWindow
#else
#define MAYBE_DragDirectlyToSecondWindow DragDirectlyToSecondWindow
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DragDirectlyToSecondWindow) {
TabStrip* tab_strip = GetTabStripForBrowser(browser());
AddTabAndResetBrowser(browser());
Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
gfx::Rect bounds(browser2->window()->GetBounds());
bounds.Offset(0, 100);
browser2->window()->SetBounds(bounds);
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
gfx::Point b2_location(5, 0);
views::View::ConvertPointToScreen(tab_strip2, &b2_location);
ASSERT_TRUE(DragInputTo(b2_location));
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_TRUE(ReleaseInput());
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0 100", IDString(browser2->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(browser()));
EXPECT_FALSE(GetIsDragged(browser2));
EXPECT_FALSE(browser()->window()->IsMaximized());
EXPECT_FALSE(browser2->window()->IsMaximized());
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragSingleTabToSeparateWindow \
DISABLED_DragSingleTabToSeparateWindow
#else
#define MAYBE_DragSingleTabToSeparateWindow DragSingleTabToSeparateWindow
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DragSingleTabToSeparateWindow) {
TabStrip* tab_strip = GetTabStripForBrowser(browser());
ResetIDs(browser()->tab_strip_model(), 0);
Browser* browser2 = CreateAnotherWindowBrowserAndRelayout();
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
const gfx::Rect initial_bounds(browser2->window()->GetBounds());
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragAllToSeparateWindowStep2, this, tab_strip, tab_strip2,
native_browser_list)));
QuitWhenNotDragging();
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(1u, native_browser_list->size());
ASSERT_TRUE(ReleaseInput());
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("100 0", IDString(browser2->tab_strip_model()));
EXPECT_FALSE(GetIsDragged(browser2));
EXPECT_FALSE(browser2->window()->IsMaximized());
EXPECT_TRUE(IsWindowPositionManaged(browser2->window()->GetNativeWindow()));
EXPECT_FALSE(HasUserChangedWindowPositionOrSize(
browser2->window()->GetNativeWindow()));
EXPECT_EQ(initial_bounds.ToString(),
browser2->window()->GetBounds().ToString());
}
namespace {
void CancelOnNewTabWhenDraggingStep2(
DetachToBrowserTabDragControllerTest* test,
const BrowserList* browser_list) {
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(2u, browser_list->size());
test->AddBlankTabAndShow(browser_list->GetLastActive());
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_CancelOnNewTabWhenDragging DISABLED_CancelOnNewTabWhenDragging
#else
#define MAYBE_CancelOnNewTabWhenDragging CancelOnNewTabWhenDragging
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_CancelOnNewTabWhenDragging) {
TabStrip* tab_strip = GetTabStripForBrowser(browser());
AddTabAndResetBrowser(browser());
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&CancelOnNewTabWhenDraggingStep2, this, native_browser_list)));
QuitWhenNotDragging();
ASSERT_FALSE(TabDragController::IsActive());
ASSERT_EQ(2u, native_browser_list->size());
for (chrome::BrowserIterator it; !it.done(); it.Next()) {
EXPECT_FALSE(GetIsDragged(*it));
EXPECT_FALSE(it->window()->IsMaximized());
}
}
#if defined(USE_ASH) && !defined(OS_WIN)
namespace {
void DragInMaximizedWindowStep2(DetachToBrowserTabDragControllerTest* test,
Browser* browser,
TabStrip* tab_strip,
const BrowserList* browser_list) {
ASSERT_EQ(2u, browser_list->size());
Browser* new_browser = browser_list->get(1);
EXPECT_NE(browser, new_browser);
ASSERT_TRUE(new_browser->window()->IsActive());
TabStrip* tab_strip2 = GetTabStripForBrowser(new_browser);
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
EXPECT_TRUE(tab_strip->GetWidget()->IsVisible());
EXPECT_TRUE(tab_strip2->GetWidget()->IsVisible());
ASSERT_TRUE(test->ReleaseInput());
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragInMaximizedWindow DISABLED_DragInMaximizedWindow
#else
#define MAYBE_DragInMaximizedWindow DragInMaximizedWindow
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DragInMaximizedWindow) {
AddTabAndResetBrowser(browser());
browser()->window()->Maximize();
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragInMaximizedWindowStep2, this, browser(), tab_strip,
native_browser_list)));
QuitWhenNotDragging();
ASSERT_FALSE(TabDragController::IsActive());
ASSERT_EQ(2u, native_browser_list->size());
Browser* new_browser = native_browser_list->get(1);
ASSERT_TRUE(new_browser->window()->IsActive());
EXPECT_TRUE(browser()->window()->GetNativeWindow()->IsVisible());
EXPECT_TRUE(new_browser->window()->GetNativeWindow()->IsVisible());
EXPECT_FALSE(GetIsDragged(browser()));
EXPECT_FALSE(GetIsDragged(new_browser));
EXPECT_TRUE(browser()->window()->IsMaximized());
EXPECT_TRUE(new_browser->window()->IsMaximized());
}
class DetachToBrowserInSeparateDisplayTabDragControllerTest
: public DetachToBrowserTabDragControllerTest {
public:
DetachToBrowserInSeparateDisplayTabDragControllerTest() {}
virtual ~DetachToBrowserInSeparateDisplayTabDragControllerTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
DetachToBrowserTabDragControllerTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII("ash-host-window-bounds",
"0+0-600x600,601+0-600x600");
}
private:
DISALLOW_COPY_AND_ASSIGN(
DetachToBrowserInSeparateDisplayTabDragControllerTest);
};
class DetachToBrowserTabDragControllerTestTouch
: public DetachToBrowserTabDragControllerTest {
public:
DetachToBrowserTabDragControllerTestTouch() {}
virtual ~DetachToBrowserTabDragControllerTestTouch() {}
private:
DISALLOW_COPY_AND_ASSIGN(DetachToBrowserTabDragControllerTestTouch);
};
namespace {
void DragSingleTabToSeparateWindowInSecondDisplayStep3(
DetachToBrowserTabDragControllerTest* test) {
ASSERT_TRUE(test->ReleaseInput());
}
void DragSingleTabToSeparateWindowInSecondDisplayStep2(
DetachToBrowserTabDragControllerTest* test,
const gfx::Point& target_point) {
ASSERT_TRUE(test->DragInputToNotifyWhenDone(
target_point.x(), target_point.y(),
base::Bind(&DragSingleTabToSeparateWindowInSecondDisplayStep3, test)));
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragSingleTabToSeparateWindowInSecondDisplay \
DISABLED_DragSingleTabToSeparateWindowInSecondDisplay
#else
#define MAYBE_DragSingleTabToSeparateWindow \
DragSingleTabToSeparateWindowInSecondDisplay
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
MAYBE_DragSingleTabToSeparateWindowInSecondDisplay) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragSingleTabToSeparateWindowInSecondDisplayStep2,
this, gfx::Point(600 + tab_0_center.x(),
tab_0_center.y()
+ GetDetachY(tab_strip)))));
QuitWhenNotDragging();
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
ASSERT_EQ(2u, native_browser_list->size());
Browser* new_browser = native_browser_list->get(1);
ASSERT_TRUE(new_browser->window()->IsActive());
TabStrip* tab_strip2 = GetTabStripForBrowser(new_browser);
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
if (input_source() == INPUT_SOURCE_MOUSE) {
aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
aura::Window* second_root = roots[1];
EXPECT_EQ(second_root,
new_browser->window()->GetNativeWindow()->GetRootWindow());
}
EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(browser()->window()->IsMaximized());
EXPECT_FALSE(new_browser->window()->IsMaximized());
}
namespace {
void DragTabToWindowInSeparateDisplayStep2(
DetachToBrowserTabDragControllerTest* test,
TabStrip* not_attached_tab_strip,
TabStrip* target_tab_strip) {
ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive());
ASSERT_FALSE(target_tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
gfx::Point target_point(
GetCenterInScreenCoordinates(target_tab_strip->tab_at(0)));
target_point.set_x(
target_point.x() - target_tab_strip->tab_at(0)->width() / 2 + 10);
ASSERT_TRUE(test->DragInputToAsync(target_point));
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragTabToWindowInSeparateDisplay \
DISABLED_DragTabToWindowInSeparateDisplay
#else
#define MAYBE_DragTabToWindowInSeparateDisplay DragTabToWindowInSeparateDisplay
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
MAYBE_DragTabToWindowInSeparateDisplay) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
Browser* browser2 = CreateBrowser(browser()->profile());
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
ResetIDs(browser2->tab_strip_model(), 100);
aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
aura::Window* second_root = roots[1];
gfx::Rect work_area = gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow(
second_root).work_area();
browser2->window()->SetBounds(work_area);
EXPECT_EQ(second_root,
browser2->window()->GetNativeWindow()->GetRootWindow());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragTabToWindowInSeparateDisplayStep2,
this, tab_strip, tab_strip2)));
QuitWhenNotDragging();
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_TRUE(ReleaseInput());
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0 100", IDString(browser2->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(browser()->window()->IsMaximized());
EXPECT_FALSE(browser2->window()->IsMaximized());
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragTabToWindowOnSecondDisplay \
DISABLED_DragTabToWindowOnSecondDisplay
#else
#define MAYBE_DragTabToWindowOnSecondDisplay DragTabToWindowOnSecondDisplay
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
MAYBE_DragTabToWindowOnSecondDisplay) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
Browser* browser2 = CreateBrowser(browser()->profile());
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
ResetIDs(browser2->tab_strip_model(), 100);
aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
aura::Window* second_root = roots[1];
gfx::Rect work_area = gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow(
second_root).work_area();
browser()->window()->SetBounds(work_area);
gfx::Rect work_area2(work_area);
work_area.set_width(work_area.width()/2);
browser()->window()->SetBounds(work_area);
work_area2.set_x(work_area2.x() + work_area2.width()/2);
work_area2.set_width(work_area2.width()/2);
browser2->window()->SetBounds(work_area2);
EXPECT_EQ(second_root,
browser()->window()->GetNativeWindow()->GetRootWindow());
EXPECT_EQ(second_root,
browser2->window()->GetNativeWindow()->GetRootWindow());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
SetEventGeneratorRootWindow(tab_0_center);
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragTabToWindowInSeparateDisplayStep2,
this, tab_strip, tab_strip2)));
QuitWhenNotDragging();
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_TRUE(ReleaseInput());
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0 100", IDString(browser2->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_FALSE(browser()->window()->IsMaximized());
EXPECT_FALSE(browser2->window()->IsMaximized());
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragMaxTabToNonMaxWindowInSeparateDisplay \
DISABLED_DragMaxTabToNonMaxWindowInSeparateDisplay
#else
#define MAYBE_DragMaxTabToNonMaxWindowInSeparateDisplay \
DragMaxTabToNonMaxWindowInSeparateDisplay
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
MAYBE_DragMaxTabToNonMaxWindowInSeparateDisplay) {
AddTabAndResetBrowser(browser());
browser()->window()->Maximize();
TabStrip* tab_strip = GetTabStripForBrowser(browser());
aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
aura::Window* first_root = roots[0];
aura::Window* second_root = roots[1];
gfx::Rect work_area = gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow(
second_root).work_area();
work_area.Inset(20,20,20,60);
Browser::CreateParams params(browser()->profile(),
browser()->host_desktop_type());
params.initial_show_state = ui::SHOW_STATE_NORMAL;
params.initial_bounds = work_area;
Browser* browser2 = new Browser(params);
AddBlankTabAndShow(browser2);
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
ResetIDs(browser2->tab_strip_model(), 100);
EXPECT_EQ(second_root,
browser2->window()->GetNativeWindow()->GetRootWindow());
EXPECT_EQ(first_root,
browser()->window()->GetNativeWindow()->GetRootWindow());
EXPECT_EQ(2, tab_strip->tab_count());
EXPECT_EQ(1, tab_strip2->tab_count());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragTabToWindowInSeparateDisplayStep2,
this, tab_strip, tab_strip2)));
QuitWhenNotDragging();
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_TRUE(ReleaseInput());
EXPECT_EQ(1, tab_strip->tab_count());
EXPECT_EQ(2, tab_strip2->tab_count());
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0 100", IDString(browser2->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_TRUE(browser()->window()->IsMaximized());
EXPECT_FALSE(browser2->window()->IsMaximized());
}
#if defined(OS_CHROMEOS)
#define MAYBE_DragTabToImmersiveBrowserOnSeparateDisplay \
DISABLED_DragTabToImmersiveBrowserOnSeparateDisplay
IN_PROC_BROWSER_TEST_P(DetachToBrowserInSeparateDisplayTabDragControllerTest,
MAYBE_DragTabToImmersiveBrowserOnSeparateDisplay) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
Browser* browser2 = CreateBrowser(browser()->profile());
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
ResetIDs(browser2->tab_strip_model(), 100);
aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
aura::Window* second_root = roots[1];
gfx::Rect work_area = gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow(
second_root).work_area();
browser2->window()->SetBounds(work_area);
EXPECT_EQ(second_root,
browser2->window()->GetNativeWindow()->GetRootWindow());
BrowserView* browser_view2 = BrowserView::GetBrowserViewForBrowser(browser2);
ImmersiveModeController* immersive_controller2 =
browser_view2->immersive_mode_controller();
immersive_controller2->SetupForTest();
chrome::ToggleFullscreenMode(browser2);
ASSERT_TRUE(immersive_controller2->IsEnabled());
ASSERT_FALSE(immersive_controller2->IsRevealed());
ASSERT_TRUE(tab_strip2->IsImmersiveStyle());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DragTabToWindowInSeparateDisplayStep2,
this, tab_strip, tab_strip2)));
QuitWhenNotDragging();
ASSERT_TRUE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_TRUE(immersive_controller2->IsRevealed());
ASSERT_FALSE(tab_strip2->IsImmersiveStyle());
ASSERT_TRUE(ReleaseInput());
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0 100", IDString(browser2->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
aura::Window* primary_root = roots[0];
ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
primary_root->GetBoundsInScreen().CenterPoint()));
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
EXPECT_FALSE(browser_view->immersive_mode_controller()->IsEnabled());
EXPECT_TRUE(immersive_controller2->IsEnabled());
EXPECT_FALSE(immersive_controller2->IsRevealed());
EXPECT_TRUE(tab_strip2->IsImmersiveStyle());
}
#endif
class DifferentDeviceScaleFactorDisplayTabDragControllerTest
: public DetachToBrowserTabDragControllerTest {
public:
DifferentDeviceScaleFactorDisplayTabDragControllerTest() {}
virtual ~DifferentDeviceScaleFactorDisplayTabDragControllerTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
DetachToBrowserTabDragControllerTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII("ash-host-window-bounds",
"400x400,0+400-800x800*2");
}
float GetCursorDeviceScaleFactor() const {
ash::test::CursorManagerTestApi cursor_test_api(
ash::Shell::GetInstance()->cursor_manager());
return cursor_test_api.GetDisplay().device_scale_factor();
}
private:
DISALLOW_COPY_AND_ASSIGN(
DifferentDeviceScaleFactorDisplayTabDragControllerTest);
};
namespace {
const struct DragPoint {
int x;
int y;
} kDragPoints[] = {
{300, 200},
{399, 200},
{500, 200},
{400, 200},
{300, 200},
};
const float kDeviceScaleFactorExpectations[] = {
1.0f,
1.0f,
2.0f,
2.0f,
1.0f,
};
COMPILE_ASSERT(
arraysize(kDragPoints) == arraysize(kDeviceScaleFactorExpectations),
kDragPoints_and_kDeviceScaleFactorExpectations_must_have_same_size);
void CursorDeviceScaleFactorStep(
DifferentDeviceScaleFactorDisplayTabDragControllerTest* test,
TabStrip* not_attached_tab_strip,
size_t index) {
ASSERT_FALSE(not_attached_tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
if (index < arraysize(kDragPoints)) {
EXPECT_EQ(kDeviceScaleFactorExpectations[index],
test->GetCursorDeviceScaleFactor());
const DragPoint p = kDragPoints[index];
ASSERT_TRUE(test->DragInputToNotifyWhenDone(
p.x, p.y, base::Bind(&CursorDeviceScaleFactorStep,
test, not_attached_tab_strip, index + 1)));
} else {
EXPECT_EQ(1.0f, test->GetCursorDeviceScaleFactor());
ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
ui_controls::LEFT, ui_controls::UP));
}
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_CursorDeviceScaleFactor DISABLED_CursorDeviceScaleFactor
#else
#define MAYBE_CursorDeviceScaleFactor CursorDeviceScaleFactor
#endif
IN_PROC_BROWSER_TEST_P(DifferentDeviceScaleFactorDisplayTabDragControllerTest,
MAYBE_CursorDeviceScaleFactor) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&CursorDeviceScaleFactorStep,
this, tab_strip, 0)));
QuitWhenNotDragging();
}
namespace {
class DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest
: public TabDragControllerTest {
public:
DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
TabDragControllerTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII("ash-host-window-bounds",
"0+0-250x250,251+0-250x250");
}
bool Press(const gfx::Point& position) {
return ui_test_utils::SendMouseMoveSync(position) &&
ui_test_utils::SendMouseEventsSync(ui_controls::LEFT,
ui_controls::DOWN);
}
bool DragTabAndExecuteTaskWhenDone(const gfx::Point& position,
const base::Closure& task) {
return ui_controls::SendMouseMoveNotifyWhenDone(
position.x(), position.y(), task);
}
void QuitWhenNotDragging() {
test::QuitWhenNotDraggingImpl();
base::MessageLoop::current()->Run();
}
private:
DISALLOW_COPY_AND_ASSIGN(
DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest);
};
void CancelDragTabToWindowInSeparateDisplayStep3(
TabStrip* tab_strip,
const BrowserList* browser_list) {
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(2u, browser_list->size());
ash::DisplayManager* display_manager =
ash::Shell::GetInstance()->display_manager();
display_manager->AddRemoveDisplay();
}
void CancelDragTabToWindowInSeparateDisplayStep2(
DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest* test,
TabStrip* tab_strip,
aura::Window* current_root,
gfx::Point final_destination,
const BrowserList* browser_list) {
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(2u, browser_list->size());
Browser* new_browser = browser_list->get(1);
EXPECT_EQ(current_root,
new_browser->window()->GetNativeWindow()->GetRootWindow());
ASSERT_TRUE(test->DragTabAndExecuteTaskWhenDone(
final_destination,
base::Bind(&CancelDragTabToWindowInSeparateDisplayStep3,
tab_strip, browser_list)));
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_CancelDragTabToWindowIn2ndDisplay \
DISABLED_CancelDragTabToWindowIn2ndDisplay
#else
#define MAYBE_CancelDragTabToWindowIn2ndDisplay \
CancelDragTabToWindowIn2ndDisplay
#endif
IN_PROC_BROWSER_TEST_F(
DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest,
MAYBE_CancelDragTabToWindowIn2ndDisplay) {
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
gfx::Point final_destination =
gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow(
roots[1]).work_area().CenterPoint();
gfx::Point tab_0_dst(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(Press(tab_0_dst));
tab_0_dst.Offset(0, GetDetachY(tab_strip));
ASSERT_TRUE(DragTabAndExecuteTaskWhenDone(
tab_0_dst, base::Bind(&CancelDragTabToWindowInSeparateDisplayStep2,
this, tab_strip, roots[0], final_destination,
native_browser_list)));
QuitWhenNotDragging();
ASSERT_EQ(1u, native_browser_list->size());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
ui_controls::LEFT, ui_controls::UP));
}
#if defined(OS_CHROMEOS)
#define MAYBE_CancelDragTabToWindowIn1stDisplay \
DISABLED_CancelDragTabToWindowIn1stDisplay
#else
#define MAYBE_CancelDragTabToWindowIn1stDisplay \
CancelDragTabToWindowIn1stDisplay
#endif
IN_PROC_BROWSER_TEST_F(
DetachToBrowserInSeparateDisplayAndCancelTabDragControllerTest,
MAYBE_CancelDragTabToWindowIn1stDisplay) {
aura::Window::Windows roots = ash::Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
EXPECT_EQ(roots[0], browser()->window()->GetNativeWindow()->GetRootWindow());
gfx::Rect work_area = gfx::Screen::GetNativeScreen()->
GetDisplayNearestWindow(roots[1]).work_area();
browser()->window()->SetBounds(work_area);
EXPECT_EQ(roots[1], browser()->window()->GetNativeWindow()->GetRootWindow());
gfx::Point final_destination =
gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow(
roots[0]).work_area().CenterPoint();
gfx::Point tab_0_dst(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(Press(tab_0_dst));
tab_0_dst.Offset(0, GetDetachY(tab_strip));
ASSERT_TRUE(DragTabAndExecuteTaskWhenDone(
tab_0_dst, base::Bind(&CancelDragTabToWindowInSeparateDisplayStep2,
this, tab_strip, roots[1], final_destination,
native_browser_list)));
QuitWhenNotDragging();
ASSERT_EQ(1u, native_browser_list->size());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
ui_controls::LEFT, ui_controls::UP));
}
namespace {
void PressSecondFingerWhileDetachedStep2(
DetachToBrowserTabDragControllerTest* test) {
ASSERT_TRUE(TabDragController::IsActive());
ASSERT_EQ(2u, test->native_browser_list->size());
Browser* new_browser = test->native_browser_list->get(1);
ASSERT_TRUE(new_browser->window()->IsActive());
ASSERT_TRUE(test->PressInput2());
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_PressSecondFingerWhileDetached DISABLED_PressSecondFingerWhileDetached
#else
#define MAYBE_PressSecondFingerWhileDetached PressSecondFingerWhileDetached
#endif
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTestTouch,
MAYBE_PressSecondFingerWhileDetached) {
gfx::Rect bounds(browser()->window()->GetBounds());
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
ASSERT_TRUE(DragInputToDelayedNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&PressSecondFingerWhileDetachedStep2, this),
base::TimeDelta::FromMilliseconds(60)));
QuitWhenNotDragging();
ASSERT_EQ(1u, native_browser_list->size());
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
EXPECT_EQ("0 1", IDString(browser()->tab_strip_model()));
ASSERT_TRUE(ReleaseInput());
ASSERT_TRUE(ReleaseInput2());
}
class DetachToDockedTabDragControllerTest
: public DetachToBrowserTabDragControllerTest {
public:
DetachToDockedTabDragControllerTest() {}
virtual ~DetachToDockedTabDragControllerTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(DetachToDockedTabDragControllerTest);
};
namespace {
void DetachToDockedWindowNextStep(
DetachToDockedTabDragControllerTest* test,
const gfx::Point& target_point,
int iteration) {
ASSERT_EQ(2u, test->native_browser_list->size());
Browser* new_browser = test->native_browser_list->get(1);
ASSERT_TRUE(new_browser->window()->IsActive());
if (!iteration) {
ASSERT_TRUE(test->ReleaseInput());
return;
}
ASSERT_TRUE(test->DragInputToNotifyWhenDone(
target_point.x(), target_point.y(),
base::Bind(&DetachToDockedWindowNextStep,
test,
gfx::Point(target_point.x(), 1 + target_point.y()),
iteration - 1)));
}
}
#if defined(OS_CHROMEOS)
#define MAYBE_DetachToDockedWindowFromMaximizedWindow \
DISABLED_DetachToDockedWindowFromMaximizedWindow
#else
#define MAYBE_DetachToDockedWindowFromMaximizedWindow \
DetachToDockedWindowFromMaximizedWindow
#endif
IN_PROC_BROWSER_TEST_P(DetachToDockedTabDragControllerTest,
MAYBE_DetachToDockedWindowFromMaximizedWindow) {
if (docked_windows_enabled()) {
VLOG(1) << "Test is DISABLED for docked windows.";
return;
}
browser()->window()->Maximize();
ASSERT_TRUE(browser()->window()->IsMaximized());
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
gfx::Point tab_0_center(
GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
ASSERT_TRUE(PressInput(tab_0_center));
const int kNumIterations = 25 * 5 + 10;
ASSERT_TRUE(DragInputToNotifyWhenDone(
tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
base::Bind(&DetachToDockedWindowNextStep, this,
gfx::Point(0, tab_0_center.y() + GetDetachY(tab_strip)),
kNumIterations)));
QuitWhenNotDragging();
ASSERT_FALSE(tab_strip->IsDragSessionActive());
ASSERT_FALSE(TabDragController::IsActive());
ASSERT_EQ(2u, native_browser_list->size());
Browser* new_browser = native_browser_list->get(1);
ASSERT_TRUE(new_browser->window()->IsActive());
TabStrip* tab_strip2 = GetTabStripForBrowser(new_browser);
ASSERT_FALSE(tab_strip2->IsDragSessionActive());
EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
EXPECT_TRUE(browser()->window()->IsMaximized());
EXPECT_FALSE(GetIsDragged(browser()));
EXPECT_FALSE(GetIsDragged(new_browser));
EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow()));
EXPECT_TRUE(IsWindowPositionManaged(
new_browser->window()->GetNativeWindow()));
ash::wm::WindowState* window_state =
ash::wm::GetWindowState(new_browser->window()->GetNativeWindow());
EXPECT_FALSE(new_browser->window()->IsMaximized());
if (docked_windows_enabled()) {
EXPECT_TRUE(window_state->IsDocked());
EXPECT_FALSE(window_state->IsSnapped());
} else {
EXPECT_FALSE(window_state->IsDocked());
EXPECT_TRUE(window_state->IsSnapped());
}
}
#endif
#if defined(USE_ASH) && !defined(OS_WIN)
INSTANTIATE_TEST_CASE_P(TabDragging,
DetachToBrowserInSeparateDisplayTabDragControllerTest,
::testing::Values("mouse", "touch"));
INSTANTIATE_TEST_CASE_P(TabDragging,
DifferentDeviceScaleFactorDisplayTabDragControllerTest,
::testing::Values("mouse"));
INSTANTIATE_TEST_CASE_P(TabDragging,
DetachToBrowserTabDragControllerTest,
::testing::Values("mouse", "touch"));
INSTANTIATE_TEST_CASE_P(TabDragging,
DetachToDockedTabDragControllerTest,
::testing::Values("mouse", "mouse docked"));
INSTANTIATE_TEST_CASE_P(TabDragging,
DetachToBrowserTabDragControllerTestTouch,
::testing::Values("touch", "touch docked"));
#else
INSTANTIATE_TEST_CASE_P(TabDragging,
DetachToBrowserTabDragControllerTest,
::testing::Values("mouse"));
#endif