diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 22:59:34 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 22:59:34 +0000 |
commit | a35c5e0ae8f29c0b407bf618d212f7bcbf40b08f (patch) | |
tree | 57ce0a1dff1b7120220107a7178f3e5c12c6e8b9 /ash/drag_drop | |
parent | 071d42d1ce09b0ecd8a53e1c9b14c1e074fe392f (diff) | |
download | chromium_src-a35c5e0ae8f29c0b407bf618d212f7bcbf40b08f.zip chromium_src-a35c5e0ae8f29c0b407bf618d212f7bcbf40b08f.tar.gz chromium_src-a35c5e0ae8f29c0b407bf618d212f7bcbf40b08f.tar.bz2 |
Interactive ui test for drag drop operation across displays.
BUG=244508
TEST=this fails without the fix for 244508
R=sky@chromium.org, varunjain@chromium.org
Review URL: https://codereview.chromium.org/16705006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207103 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/drag_drop')
-rw-r--r-- | ash/drag_drop/drag_drop_interactive_uitest.cc | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/ash/drag_drop/drag_drop_interactive_uitest.cc b/ash/drag_drop/drag_drop_interactive_uitest.cc new file mode 100644 index 0000000..85dfaf8 --- /dev/null +++ b/ash/drag_drop/drag_drop_interactive_uitest.cc @@ -0,0 +1,165 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/drag_drop/drag_drop_controller.h" + +#include "ash/shell.h" +#include "ash/test/ash_test_base.h" +#include "base/bind.h" +#include "base/message_loop.h" +#include "base/strings/utf_string_conversions.h" +#include "ui/aura/root_window.h" +#include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/test/ui_controls.h" +#include "ui/views/view.h" +#include "ui/views/widget/widget.h" + +namespace ash { +namespace internal { +namespace { + +class DraggableView : public views::View { + public: + DraggableView() {} + virtual ~DraggableView() {} + + // views::View overrides: + virtual int GetDragOperations(const gfx::Point& press_pt) OVERRIDE { + return ui::DragDropTypes::DRAG_MOVE; + } + virtual void WriteDragData(const gfx::Point& press_pt, + OSExchangeData* data)OVERRIDE { + data->SetString(UTF8ToUTF16("test")); + } + + private: + DISALLOW_COPY_AND_ASSIGN(DraggableView); +}; + +class TargetView : public views::View { + public: + TargetView() : dropped_(false) {} + virtual ~TargetView() {} + + // views::View overrides: + virtual bool GetDropFormats( + int* formats, + std::set<OSExchangeData::CustomFormat>* custom_formats) OVERRIDE { + *formats = ui::OSExchangeData::STRING; + return true; + } + virtual bool AreDropTypesRequired() OVERRIDE { + return false; + } + virtual bool CanDrop(const OSExchangeData& data) OVERRIDE { + return true; + } + virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE { + return ui::DragDropTypes::DRAG_MOVE; + } + virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE { + dropped_ = true; + return ui::DragDropTypes::DRAG_MOVE; + } + + bool dropped() const { return dropped_; } + + private: + bool dropped_; + + DISALLOW_COPY_AND_ASSIGN(TargetView); +}; + +views::Widget* CreateWidget(views::View* contents_view, + const gfx::Rect& bounds) { + views::Widget* widget = new views::Widget; + views::Widget::InitParams params; + params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; + params.accept_events = true; + params.context = Shell::GetPrimaryRootWindow(); + params.bounds = bounds; + widget->Init(params); + + widget->SetContentsView(contents_view); + widget->Show(); + return widget; +} + +void QuitLoop() { + base::MessageLoop::current()->Quit(); +} + +void DragDropAcrossMultiDisplay_Step4() { + ui_controls::SendMouseEventsNotifyWhenDone( + ui_controls::LEFT, ui_controls::UP, + base::Bind(&QuitLoop)); +} + +void DragDropAcrossMultiDisplay_Step3() { + // Move to the edge of the 1st display so that the mouse + // is moved to 2nd display by ash. + ui_controls::SendMouseMoveNotifyWhenDone( + 399, 10, + base::Bind(&DragDropAcrossMultiDisplay_Step4)); +} + +void DragDropAcrossMultiDisplay_Step2() { + ui_controls::SendMouseMoveNotifyWhenDone( + 20, 10, + base::Bind(&DragDropAcrossMultiDisplay_Step3)); +} + +void DragDropAcrossMultiDisplay_Step1() { + ui_controls::SendMouseEventsNotifyWhenDone( + ui_controls::LEFT, ui_controls::DOWN, + base::Bind(&DragDropAcrossMultiDisplay_Step2)); +} + +} // namespace + +typedef test::AshTestBase DragDropTest; + +#if defined(OS_WIN) +#define MAYBE_DragDropAcrossMultiDisplay DISABLED_DragDropAcrossMultiDisplay +#else +#define MAYBE_DragDropAcrossMultiDisplay DragDropAcrossMultiDisplay +#endif + +// Test if the mouse gets moved properly to another display +// during drag & drop operation. +TEST_F(DragDropTest, MAYBE_DragDropAcrossMultiDisplay) { + if (!SupportsMultipleDisplays()) + return; + + UpdateDisplay("400x400,400x400"); + Shell::RootWindowList root_windows = + Shell::GetInstance()->GetAllRootWindows(); + views::View* draggable_view = new DraggableView(); + draggable_view->set_drag_controller(NULL); + draggable_view->SetBounds(0, 0, 100, 100); + views::Widget* source = + CreateWidget(draggable_view, gfx::Rect(0, 0, 100, 100)); + + TargetView* target_view = new TargetView(); + target_view->SetBounds(0, 0, 100, 100); + views::Widget* target = + CreateWidget(target_view, gfx::Rect(400, 0, 100, 100)); + + // Make sure they're on the different root windows. + EXPECT_EQ(root_windows[0], source->GetNativeView()->GetRootWindow()); + EXPECT_EQ(root_windows[1], target->GetNativeView()->GetRootWindow()); + + ui_controls::SendMouseMoveNotifyWhenDone( + 10, 10, base::Bind(&DragDropAcrossMultiDisplay_Step1)); + + base::MessageLoop::current()->Run(); + + EXPECT_TRUE(target_view->dropped()); + + source->Close(); + target->Close(); +} + +} // namespace internal +} // namespace ash |