From 5e0f30c03417379891c4e0df39d935e4fbdb40ec Mon Sep 17 00:00:00 2001 From: "sidchat@google.com" Date: Thu, 14 Aug 2008 22:52:44 +0000 Subject: git-svn-id: svn://svn.chromium.org/chrome/trunk/src@904 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/automation/automation_provider.cc | 14 +- chrome/browser/automation/automation_provider.h | 3 +- chrome/browser/tabs/tab_dragging_test.cc | 154 ++++++++++++++++++--- .../test/automated_ui_tests/automated_ui_tests.cc | 2 +- .../test/automation/automation_messages_internal.h | 4 +- chrome/test/automation/browser_proxy.cc | 12 +- chrome/test/automation/browser_proxy.h | 12 +- 7 files changed, 170 insertions(+), 31 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 818c321..f23e7d1 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -1272,7 +1272,8 @@ void AutomationProvider::WindowSimulateClick(const IPC::Message& message, void AutomationProvider::WindowSimulateDrag(const IPC::Message& message, int handle, std::vector drag_path, - int flags) { + int flags, + bool press_escape_en_route) { bool succeeded = false; if (browser_tracker_->ContainsHandle(handle) && (drag_path.size() > 1)) { succeeded = true; @@ -1313,6 +1314,17 @@ void AutomationProvider::WindowSimulateDrag(const IPC::Message& message, } POINT end = drag_path[drag_path.size() - 1]; SetCursorPos(end.x, end.y); + + if (press_escape_en_route) { + // Press Escape. + ui_controls::SendKeyPress(VK_ESCAPE, + ((flags & ChromeViews::Event::EF_CONTROL_DOWN) + == ChromeViews::Event::EF_CONTROL_DOWN), + ((flags & ChromeViews::Event::EF_SHIFT_DOWN) == + ChromeViews::Event::EF_SHIFT_DOWN), + ((flags & ChromeViews::Event::EF_ALT_DOWN) == + ChromeViews::Event::EF_ALT_DOWN)); + } SendMessage(top_level_hwnd, up_message, wparam_flags, MAKELPARAM(end.x, end.y)); diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 35827c8..20f34a1 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -144,7 +144,8 @@ class AutomationProvider : public base::RefCounted, void WindowSimulateDrag(const IPC::Message& message, int handle, std::vector drag_path, - int flags); + int flags, + bool press_escape_en_route); void WindowSimulateClick(const IPC::Message& message, int handle, POINT click, diff --git a/chrome/browser/tabs/tab_dragging_test.cc b/chrome/browser/tabs/tab_dragging_test.cc index ecda371..a976d42 100644 --- a/chrome/browser/tabs/tab_dragging_test.cc +++ b/chrome/browser/tabs/tab_dragging_test.cc @@ -51,8 +51,8 @@ protected: } }; -// Automated UI test to open three tabs in a new window, and drag Tab-1 into -// the position of Tab-2. +// Automated UI test to open three tabs in a new window, and drag Tab_1 into +// the position of Tab_2. TEST_F(TabDraggingTest, Tab1Tab2) { scoped_ptr browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -63,20 +63,21 @@ TEST_F(TabDraggingTest, Tab1Tab2) { // Get initial tab count. int initial_tab_count = 0; ASSERT_TRUE(browser->GetTabCount(&initial_tab_count)); + ASSERT_TRUE(1 == initial_tab_count); - // Get Tab-1 which comes with the browser window. + // Get Tab_1 which comes with the browser window. scoped_ptr tab1(browser->GetTab(0)); ASSERT_TRUE(tab1.get()); GURL tab1_url; ASSERT_TRUE(tab1->GetCurrentURL(&tab1_url)); - // Add Tab-2. + // Add Tab_2. GURL tab2_url("about:"); ASSERT_TRUE(browser->AppendTab(tab2_url)); scoped_ptr tab2(browser->GetTab(1)); ASSERT_TRUE(tab2.get()); - // Add Tab-3. + // Add Tab_3. GURL tab3_url("about:plugins"); ASSERT_TRUE(browser->AppendTab(tab3_url)); scoped_ptr tab3(browser->GetTab(2)); @@ -119,15 +120,15 @@ TEST_F(TabDraggingTest, Tab1Tab2) { EXPECT_LT(0, urlbar_bounds.width()); EXPECT_LT(0, urlbar_bounds.height()); - // TEST: Move Tab-1 to the position of Tab-2 + // TEST: Move Tab_1 to the position of Tab_2 // ____________ ____________ ____________ // / \ / \ / \ - // | Tab-1 | Tab-2 | Tab-3 | + // | Tab_1 | Tab_2 | Tab_3 | // ---- ---- ---- ---- ---- ---- ---- ---- ---- // x---- ----> // ____________ // / X \ - // | Tab-1 | + // | Tab_1 | // ---- ---- ---- POINT start; @@ -137,7 +138,8 @@ TEST_F(TabDraggingTest, Tab1Tab2) { end.x = start.x + 2*bounds1.width()/3; end.y = start.y; ASSERT_TRUE(browser->SimulateDrag(start, end, - ChromeViews::Event::EF_LEFT_BUTTON_DOWN)); + ChromeViews::Event::EF_LEFT_BUTTON_DOWN, + false)); // Now check for expected results. tab1.reset(browser->GetTab(0)); @@ -154,7 +156,7 @@ TEST_F(TabDraggingTest, Tab1Tab2) { EXPECT_EQ(tab2_url.spec(), tab1_new_url.spec()); } -// Drag Tab-1 into the position of Tab-3. +// Drag Tab_1 into the position of Tab_3. TEST_F(TabDraggingTest, Tab1Tab3) { scoped_ptr browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -165,20 +167,21 @@ TEST_F(TabDraggingTest, Tab1Tab3) { // Get initial tab count. int initial_tab_count = 0; ASSERT_TRUE(browser->GetTabCount(&initial_tab_count)); + ASSERT_TRUE(1 == initial_tab_count); - // Get Tab-1 which comes with the browser window. + // Get Tab_1 which comes with the browser window. scoped_ptr tab1(browser->GetTab(0)); ASSERT_TRUE(tab1.get()); GURL tab1_url; ASSERT_TRUE(tab1->GetCurrentURL(&tab1_url)); - // Add Tab-2. + // Add Tab_2. GURL tab2_url("about:"); ASSERT_TRUE(browser->AppendTab(tab2_url)); scoped_ptr tab2(browser->GetTab(1)); ASSERT_TRUE(tab2.get()); - // Add Tab-3. + // Add Tab_3. GURL tab3_url("about:plugins"); ASSERT_TRUE(browser->AppendTab(tab3_url)); scoped_ptr tab3(browser->GetTab(2)); @@ -221,15 +224,15 @@ TEST_F(TabDraggingTest, Tab1Tab3) { EXPECT_LT(0, urlbar_bounds.width()); EXPECT_LT(0, urlbar_bounds.height()); - // TEST: Move Tab-1 to the middle position of Tab-3 + // TEST: Move Tab_1 to the middle position of Tab_3 // ____________ ____________ ____________ // / \ / \ / \ - // | Tab-1 | Tab-2 | Tab-3 | + // | Tab_1 | Tab_2 | Tab_3 | // ---- ---- ---- ---- ---- ---- ---- ---- ---- // x---- ---- ---- ---- ---- ----> // ____________ // / X \ - // | Tab-1 | + // | Tab_1 | // ---- ---- ---- POINT start; @@ -239,7 +242,8 @@ TEST_F(TabDraggingTest, Tab1Tab3) { end.x = start.x + bounds1.width()/2 + bounds2.width() + bounds3.width()/2; end.y = start.y; ASSERT_TRUE(browser->SimulateDrag(start, end, - ChromeViews::Event::EF_LEFT_BUTTON_DOWN)); + ChromeViews::Event::EF_LEFT_BUTTON_DOWN, + false)); // Now check for expected results. tab1.reset(browser->GetTab(0)); @@ -261,3 +265,119 @@ TEST_F(TabDraggingTest, Tab1Tab3) { EXPECT_EQ(tab2_new_url.spec(), tab3_url.spec()); EXPECT_EQ(tab3_new_url.spec(), tab1_url.spec()); } + +// Drag Tab_1 into the position of Tab_3, and press ESCAPE before releasing the +// left mouse button. +TEST_F(TabDraggingTest, Tab1Tab3Escape) { + scoped_ptr browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + scoped_ptr window( + automation()->GetWindowForBrowser(browser.get())); + ASSERT_TRUE(window.get()); + + // Get initial tab count. + int initial_tab_count = 0; + ASSERT_TRUE(browser->GetTabCount(&initial_tab_count)); + ASSERT_TRUE(1 == initial_tab_count); + + // Get Tab_1 which comes with the browser window. + scoped_ptr tab1(browser->GetTab(0)); + ASSERT_TRUE(tab1.get()); + GURL tab1_url; + ASSERT_TRUE(tab1->GetCurrentURL(&tab1_url)); + + // Add Tab_2. + GURL tab2_url("about:"); + ASSERT_TRUE(browser->AppendTab(tab2_url)); + scoped_ptr tab2(browser->GetTab(1)); + ASSERT_TRUE(tab2.get()); + + // Add Tab_3. + GURL tab3_url("about:plugins"); + ASSERT_TRUE(browser->AppendTab(tab3_url)); + scoped_ptr tab3(browser->GetTab(2)); + ASSERT_TRUE(tab3.get()); + + // Make sure 3 tabs are open + int final_tab_count = 0; + ASSERT_TRUE(browser->WaitForTabCountToChange(initial_tab_count, + &final_tab_count, + 10000)); + ASSERT_TRUE(final_tab_count == initial_tab_count + 2); + + // Get bounds for the tabs. + gfx::Rect bounds1; + ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_0, &bounds1, false)); + EXPECT_LT(0, bounds1.x()); + EXPECT_LT(0, bounds1.width()); + EXPECT_LT(0, bounds1.height()); + + gfx::Rect bounds2; + ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_1, &bounds2, false)); + EXPECT_LT(0, bounds2.width()); + EXPECT_LT(0, bounds2.height()); + EXPECT_LT(bounds1.x(), bounds2.x()); + EXPECT_EQ(bounds2.y(), bounds1.y()); + + gfx::Rect bounds3; + ASSERT_TRUE(window->GetViewBounds(VIEW_ID_TAB_2, &bounds3, false)); + EXPECT_LT(0, bounds3.width()); + EXPECT_LT(0, bounds3.height()); + EXPECT_LT(bounds2.x(), bounds3.x()); + EXPECT_EQ(bounds3.y(), bounds2.y()); + + // Get url Bar bounds. + gfx::Rect urlbar_bounds; + ASSERT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &urlbar_bounds, + false)); + EXPECT_LT(0, urlbar_bounds.x()); + EXPECT_LT(0, urlbar_bounds.y()); + EXPECT_LT(0, urlbar_bounds.width()); + EXPECT_LT(0, urlbar_bounds.height()); + + // TEST: Move Tab_1 to the middle position of Tab_3 + // ____________ ____________ ____________ + // / \ / \ / \ + // | Tab_1 | Tab_2 | Tab_3 | + // ---- ---- ---- ---- ---- ---- ---- ---- ---- + // x---- ---- ---- ---- ---- ----> + ESCAPE + // ____________ + // / X \ + // | Tab_1 | + // ---- ---- ---- + + POINT start; + POINT end; + start.x = bounds1.x() + bounds1.width()/2; + start.y = bounds1.y() + bounds1.height()/2; + end.x = start.x + bounds1.width()/2 + bounds2.width() + bounds3.width()/2; + end.y = start.y; + + // Simulate drag with 'true' as the last parameter. This will interrupt + // in-flight with Escape. + ASSERT_TRUE(browser->SimulateDrag(start, end, + ChromeViews::Event::EF_LEFT_BUTTON_DOWN, + true)); + + // Now check for expected results. + tab1.reset(browser->GetTab(0)); + ASSERT_TRUE(tab1.get()); + GURL tab1_new_url; + ASSERT_TRUE(tab1->GetCurrentURL(&tab1_new_url)); + + tab2.reset(browser->GetTab(1)); + ASSERT_TRUE(tab2.get()); + GURL tab2_new_url; + ASSERT_TRUE(tab2->GetCurrentURL(&tab2_new_url)); + + tab3.reset(browser->GetTab(2)); + ASSERT_TRUE(tab3.get()); + GURL tab3_new_url; + ASSERT_TRUE(tab3->GetCurrentURL(&tab3_new_url)); + + // The tabs should be in their original positions. + EXPECT_EQ(tab1_new_url.spec(), tab1_url.spec()); + EXPECT_EQ(tab2_new_url.spec(), tab2_url.spec()); + EXPECT_EQ(tab3_new_url.spec(), tab3_url.spec()); +} + diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index b831fb1..f7767d1 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -820,7 +820,7 @@ bool AutomatedUITest::DragActiveTab(bool drag_right, bool drag_out) { destination_point, ChromeViews::Event::EF_LEFT_BUTTON_DOWN, kWaitForActionMaxMsec, - &is_timeout)) { + &is_timeout, false)) { AddWarningAttribute("failed_to_simulate_drag"); return false; } diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index bbd1782..e21a2cc 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -317,8 +317,8 @@ IPC_BEGIN_MESSAGES(Automation, 0) // defined in chrome/views/event.h // Response: // bool - true if the drag could be performed - IPC_MESSAGE_ROUTED3(AutomationMsg_WindowDragRequest, - int, std::vector, int) + IPC_MESSAGE_ROUTED4(AutomationMsg_WindowDragRequest, + int, std::vector, int, bool) IPC_MESSAGE_ROUTED1(AutomationMsg_WindowDragResponse, bool) // Similar to AutomationMsg_InitialLoadsComplete, this indicates that the diff --git a/chrome/test/automation/browser_proxy.cc b/chrome/test/automation/browser_proxy.cc index 68e41ba..73f1938 100644 --- a/chrome/test/automation/browser_proxy.cc +++ b/chrome/test/automation/browser_proxy.cc @@ -254,15 +254,18 @@ bool BrowserProxy::ApplyAccelerator(int id) { bool BrowserProxy::SimulateDrag(const POINT& start, const POINT& end, - int flags) { - return SimulateDragWithTimeout(start, end, flags, INFINITE, NULL); + int flags, + bool press_escape_en_route) { + return SimulateDragWithTimeout(start, end, flags, INFINITE, NULL, + press_escape_en_route); } bool BrowserProxy::SimulateDragWithTimeout(const POINT& start, const POINT& end, int flags, uint32 timeout_ms, - bool* is_timeout) { + bool* is_timeout, + bool press_escape_en_route) { if (!is_valid()) return false; @@ -272,7 +275,8 @@ bool BrowserProxy::SimulateDragWithTimeout(const POINT& start, IPC::Message* response = NULL; bool succeeded = sender_->SendAndWaitForResponseWithTimeout( - new AutomationMsg_WindowDragRequest(0, handle_, drag_path, flags), + new AutomationMsg_WindowDragRequest(0, handle_, drag_path, flags, + press_escape_en_route), &response, AutomationMsg_WindowDragResponse::ID, timeout_ms, is_timeout); scoped_ptr response_deleter(response); // Delete on return. diff --git a/chrome/test/automation/browser_proxy.h b/chrome/test/automation/browser_proxy.h index 17d7385..3eeef77 100644 --- a/chrome/test/automation/browser_proxy.h +++ b/chrome/test/automation/browser_proxy.h @@ -27,8 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef CHROME_TEST_AUTOMATION_BROWSER_PROXY_H__ -#define CHROME_TEST_AUTOMATION_BROWSER_PROXY_H__ +#ifndef CHROME_TEST_AUTOMATION_BROWSER_PROXY_H_ +#define CHROME_TEST_AUTOMATION_BROWSER_PROXY_H_ #include #include @@ -130,13 +130,15 @@ class BrowserProxy : public AutomationResourceProxy { // Performs a drag operation between the start and end points (both defined // in window coordinates). |flags| specifies which buttons are pressed for // the drag, as defined in chrome/views/event.h. - virtual bool SimulateDrag(const POINT& start, const POINT& end, int flags); + virtual bool SimulateDrag(const POINT& start, const POINT& end, int flags, + bool press_escape_en_route); // Like SimulateDrag, but returns false if response is not received before // the specified timeout. virtual bool SimulateDragWithTimeout(const POINT& start, const POINT& end, int flags, uint32 timeout_ms, - bool* is_timeout); + bool* is_timeout, + bool press_escape_en_route); // Block the thread until the tab count changes. // |count| is the original tab count. @@ -166,4 +168,4 @@ class BrowserProxy : public AutomationResourceProxy { DISALLOW_EVIL_CONSTRUCTORS(BrowserProxy); }; -#endif // #define CHROME_TEST_AUTOMATION_BROWSER_PROXY_H__ +#endif // CHROME_TEST_AUTOMATION_BROWSER_PROXY_H_ -- cgit v1.1