summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 15:10:54 +0000
committerhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-12 15:10:54 +0000
commit6fe46e64b98318fa867892403e9cfb7037523c60 (patch)
tree9688e7b6dd8418cd1aea05351478a716a3d2d8b8 /chrome/test
parent113550f55b0c70e49b755a41f3dc4fffaa68d573 (diff)
downloadchromium_src-6fe46e64b98318fa867892403e9cfb7037523c60.zip
chromium_src-6fe46e64b98318fa867892403e9cfb7037523c60.tar.gz
chromium_src-6fe46e64b98318fa867892403e9cfb7037523c60.tar.bz2
Fix tab dragging test in automated UI test.
Review URL: http://codereview.chromium.org/119394 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_test_base.cc172
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_test_base.h22
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_test_interactive_test.cc100
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_tests.cc105
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_tests.h19
-rw-r--r--chrome/test/interactive_ui/interactive_ui.vcproj16
6 files changed, 312 insertions, 122 deletions
diff --git a/chrome/test/automated_ui_tests/automated_ui_test_base.cc b/chrome/test/automated_ui_tests/automated_ui_test_base.cc
index bb96fd32..45aa1b9 100644
--- a/chrome/test/automated_ui_tests/automated_ui_test_base.cc
+++ b/chrome/test/automated_ui_tests/automated_ui_test_base.cc
@@ -3,11 +3,13 @@
// found in the LICENSE file.
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/view_ids.h"
#include "chrome/test/automated_ui_tests/automated_ui_test_base.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
+#include "views/view.h"
AutomatedUITestBase::AutomatedUITestBase() {}
@@ -15,7 +17,8 @@ AutomatedUITestBase::~AutomatedUITestBase() {}
void AutomatedUITestBase::LogErrorMessage(const std::string& error) {}
-void AutomatedUITestBase::LogWarningMessage(const std::string& warning) {}
+void AutomatedUITestBase::LogWarningMessage(const std::string& warning) {
+}
void AutomatedUITestBase::LogInfoMessage(const std::string& info) {}
@@ -78,6 +81,161 @@ bool AutomatedUITestBase::DuplicateTab() {
return RunCommand(IDC_DUPLICATE_TAB);
}
+bool AutomatedUITestBase::DragTabOut() {
+ BrowserProxy* browser = active_browser();
+ if (browser == NULL) {
+ LogErrorMessage("browser_window_not_found");
+ return false;
+ }
+
+ scoped_refptr<WindowProxy> window(
+ GetAndActivateWindowForBrowser(browser));
+ if (window.get() == NULL) {
+ LogErrorMessage("active_window_not_found");
+ return false;
+ }
+ bool is_timeout;
+
+ int tab_count;
+ browser->GetTabCountWithTimeout(&tab_count,
+ action_max_timeout_ms(),
+ &is_timeout);
+
+ if (tab_count < 2) {
+ LogWarningMessage("not_enough_tabs_to_drag_out");
+ return false;
+ }
+
+ int tab_index;
+ if (!browser->GetActiveTabIndexWithTimeout(&tab_index,
+ action_max_timeout_ms(),
+ &is_timeout)) {
+ LogWarningMessage("no_active_tab");
+ return false;
+ }
+
+ if (tab_index < 0) {
+ LogInfoMessage("invalid_active_tab_index");
+ return false;
+ }
+
+ gfx::Rect dragged_tab_bounds;
+ if (!window->GetViewBoundsWithTimeout(VIEW_ID_TAB_0 + tab_index,
+ &dragged_tab_bounds, false,
+ action_max_timeout_ms(),
+ &is_timeout)) {
+ LogWarningMessage("no_tab_view_found");
+ return false;
+ }
+
+ gfx::Rect urlbar_bounds;
+ if (!window->GetViewBoundsWithTimeout(VIEW_ID_LOCATION_BAR,
+ &urlbar_bounds, false,
+ action_max_timeout_ms(),
+ &is_timeout)) {
+ LogWarningMessage("no_location_bar_found");
+ return false;
+ }
+
+ // Click on the center of the tab, and drag it downwads.
+ POINT start;
+ POINT end;
+ start.x = dragged_tab_bounds.x() + dragged_tab_bounds.width()/2;
+ start.y = dragged_tab_bounds.y() + dragged_tab_bounds.height()/2;
+ end.x = start.x;
+ end.y = start.y + 3*urlbar_bounds.height();
+
+ if (!browser->SimulateDragWithTimeout(start, end,
+ views::Event::EF_LEFT_BUTTON_DOWN,
+ action_max_timeout_ms(),
+ &is_timeout, false)) {
+ LogWarningMessage("failed_to_simulate_drag");
+ return false;
+ }
+
+ return true;
+}
+
+bool AutomatedUITestBase::DragActiveTab(bool drag_right) {
+ BrowserProxy* browser = active_browser();
+ if (browser == NULL) {
+ LogErrorMessage("browser_window_not_found");
+ return false;
+ }
+
+ scoped_refptr<WindowProxy> window(
+ GetAndActivateWindowForBrowser(browser));
+ if (window.get() == NULL) {
+ LogErrorMessage("active_window_not_found");
+ return false;
+ }
+ bool is_timeout;
+
+ int tab_count;
+ browser->GetTabCountWithTimeout(&tab_count,
+ action_max_timeout_ms(),
+ &is_timeout);
+
+ if (tab_count < 2) {
+ LogWarningMessage("not_enough_tabs_to_drag_around");
+ return false;
+ }
+
+ int tab_index;
+ if (!browser->GetActiveTabIndexWithTimeout(&tab_index,
+ action_max_timeout_ms(),
+ &is_timeout)) {
+ LogWarningMessage("no_active_tab");
+ return false;
+ }
+
+ gfx::Rect dragged_tab_bounds;
+ if (!window->GetViewBoundsWithTimeout(VIEW_ID_TAB_0 + tab_index,
+ &dragged_tab_bounds, false,
+ action_max_timeout_ms(),
+ &is_timeout)) {
+ LogWarningMessage("no_tab_view_found");
+ return false;
+ }
+
+ // Click on the center of the tab, and drag it to the left or the right.
+ POINT dragged_tab_point(dragged_tab_bounds.CenterPoint().ToPOINT());
+ POINT destination_point(dragged_tab_point);
+
+ int new_tab_index;
+ if (drag_right) {
+ if (tab_index >= (tab_count - 1)) {
+ LogInfoMessage("cant_drag_to_right");
+ return false;
+ }
+ new_tab_index = tab_index + 1;
+ destination_point.x += 2 * dragged_tab_bounds.width() / 3;
+ } else {
+ if (tab_index <= 0) {
+ LogInfoMessage("cant_drag_to_left");
+ return false;
+ }
+ new_tab_index = tab_index - 1;
+ destination_point.x -= 2 * dragged_tab_bounds.width() / 3;
+ }
+
+ if (!browser->SimulateDragWithTimeout(dragged_tab_point,
+ destination_point,
+ views::Event::EF_LEFT_BUTTON_DOWN,
+ action_max_timeout_ms(),
+ &is_timeout, false)) {
+ LogWarningMessage("failed_to_simulate_drag");
+ return false;
+ }
+
+ if (!browser->WaitForTabToBecomeActive(new_tab_index, action_timeout_ms())) {
+ LogWarningMessage("failed_to_reindex_tab");
+ return false;
+ }
+
+ return true;
+}
+
bool AutomatedUITestBase::ForwardButton() {
return RunCommand(IDC_FORWARD);
}
@@ -192,3 +350,15 @@ scoped_refptr<TabProxy> AutomatedUITestBase::GetActiveTab() {
return NULL;
return tab;
}
+
+scoped_refptr<WindowProxy> AutomatedUITestBase::GetAndActivateWindowForBrowser(
+ BrowserProxy* browser) {
+ bool did_timeout;
+ if (!browser->BringToFrontWithTimeout(action_max_timeout_ms(),
+ &did_timeout)) {
+ LogWarningMessage("failed_to_bring_window_to_front");
+ return NULL;
+ }
+
+ return browser->GetWindow();
+}
diff --git a/chrome/test/automated_ui_tests/automated_ui_test_base.h b/chrome/test/automated_ui_tests/automated_ui_test_base.h
index 4724f83..cc4fb8648 100644
--- a/chrome/test/automated_ui_tests/automated_ui_test_base.h
+++ b/chrome/test/automated_ui_tests/automated_ui_test_base.h
@@ -42,6 +42,21 @@ class AutomatedUITestBase : public UITest {
// Returns true if a duplicated tab is added.
bool DuplicateTab();
+ // Drags the active tab. The tab is dragged vertically to remove it from the
+ // tabstrip. Returns true if the tab is dragged, false otherwise.
+ // Note: returning true doesn't necessarily create a new window as the tab
+ // could be dragged in to another window.
+ bool DragTabOut();
+
+ // Drags the active tab.
+ // If |drag_right| is true, if there is a tab to the right of the active tab,
+ // the active tab is dragged to that tabs position. If |drag_right| is false,
+ // if there is a tab to the left of the active tab, the active tab is dragged
+ // to that tabs position. Returns true if the tab is dragged. If it returns
+ // false, the tab is not dragged, probably because no other tab exists to
+ // drag the active tab over.
+ bool DragActiveTab(bool drag_right);
+
// Go forward in active tab.
// Returns true if successful, false otherwise.
bool ForwardButton();
@@ -99,6 +114,13 @@ class AutomatedUITestBase : public UITest {
// If success return the pointer to the newly created TabProxy and the
// caller owns the TabProxy. Return NULL otherwise.
scoped_refptr<TabProxy> GetActiveTab();
+
+ // Returns the WindowProxy associated with the given BrowserProxy
+ // (transferring ownership of the pointer to the caller) and brings that
+ // window to the top.
+ scoped_refptr<WindowProxy> GetAndActivateWindowForBrowser(
+ BrowserProxy* browser);
+
private:
scoped_refptr<BrowserProxy> active_browser_;
diff --git a/chrome/test/automated_ui_tests/automated_ui_test_interactive_test.cc b/chrome/test/automated_ui_tests/automated_ui_test_interactive_test.cc
new file mode 100644
index 0000000..66f57b0
--- /dev/null
+++ b/chrome/test/automated_ui_tests/automated_ui_test_interactive_test.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2009 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 "chrome/test/automated_ui_tests/automated_ui_test_base.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/ui/ui_test.h"
+
+namespace {
+
+bool WaitForURLDisplayedForTab(BrowserProxy* browser, int tab_index,
+ GURL url) {
+ int i = 0;
+ while (i < 10) {
+ scoped_refptr<TabProxy> tab(browser->GetTab(tab_index));
+ GURL tab_url;
+ if (tab->GetCurrentURL(&tab_url))
+ if (tab_url == url)
+ return true;
+ i++;
+ PlatformThread::Sleep(automation::kSleepTime);
+ }
+ return false;
+}
+
+}
+
+TEST_F(AutomatedUITestBase, DragOut) {
+ int tab_count;
+ active_browser()->GetTabCount(&tab_count);
+ ASSERT_EQ(1, tab_count);
+ ASSERT_FALSE(DragTabOut());
+ NewTab();
+ Navigate(GURL(L"about:"));
+ active_browser()->GetTabCount(&tab_count);
+ ASSERT_EQ(2, tab_count);
+ NewTab();
+ active_browser()->GetTabCount(&tab_count);
+ ASSERT_EQ(3, tab_count);
+ GURL chrome_downloads_url(L"chrome://downloads/");
+ Navigate(chrome_downloads_url);
+ ASSERT_TRUE(WaitForURLDisplayedForTab(active_browser(), 2,
+ chrome_downloads_url));
+ ASSERT_TRUE(DragTabOut());
+ int window_count;
+ automation()->GetBrowserWindowCount(&window_count);
+ ASSERT_EQ(2, window_count);
+}
+
+TEST_F(AutomatedUITestBase, DragLeftRight) {
+ int tab_count;
+ active_browser()->GetTabCount(&tab_count);
+ ASSERT_EQ(1, tab_count);
+ ASSERT_FALSE(DragActiveTab(false));
+
+ NewTab();
+ active_browser()->GetTabCount(&tab_count);
+ ASSERT_EQ(2, tab_count);
+ GURL about_url(L"about:");
+ Navigate(about_url);
+
+ NewTab();
+ active_browser()->GetTabCount(&tab_count);
+ ASSERT_EQ(3, tab_count);
+ GURL chrome_downloads_url(L"chrome://downloads/");
+ Navigate(chrome_downloads_url);
+ ASSERT_TRUE(WaitForURLDisplayedForTab(active_browser(), 2,
+ chrome_downloads_url));
+
+ // Drag the active tab to left. Now download tab should be the middle tab.
+ ASSERT_TRUE(DragActiveTab(false));
+ ASSERT_TRUE(WaitForURLDisplayedForTab(active_browser(), 1,
+ chrome_downloads_url));
+
+ // Drag the active tab to left. Now download tab should be the leftmost
+ // tab.
+ ASSERT_TRUE(DragActiveTab(false));
+ ASSERT_TRUE(WaitForURLDisplayedForTab(active_browser(), 0,
+ chrome_downloads_url));
+
+ // Drag the active tab to left. It should fail since the active tab is
+ // already the leftmost tab.
+ ASSERT_FALSE(DragActiveTab(false));
+
+ // Drag the active tab to right. Now download tab should be the middle tab.
+ ASSERT_TRUE(DragActiveTab(true));
+ ASSERT_TRUE(WaitForURLDisplayedForTab(active_browser(), 1,
+ chrome_downloads_url));
+
+ // Drag the active tab to right. Now download tab should be the rightmost
+ // tab.
+ ASSERT_TRUE(DragActiveTab(true));
+ ASSERT_TRUE(WaitForURLDisplayedForTab(active_browser(), 2,
+ chrome_downloads_url));
+
+ // Drag the active tab to right. It should fail since the active tab is
+ // already the rightmost tab.
+ ASSERT_FALSE(DragActiveTab(true));
+}
diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc
index 23c1ae4..a4082a0 100644
--- a/chrome/test/automated_ui_tests/automated_ui_tests.cc
+++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc
@@ -284,11 +284,11 @@ bool AutomatedUITest::DoAction(const std::string & action) {
} else if (LowerCaseEqualsASCII(action, "downloads")) {
did_complete_action = ShowDownloads();
} else if (LowerCaseEqualsASCII(action, "dragtableft")) {
- did_complete_action = DragActiveTab(false, false);
+ did_complete_action = DragActiveTab(false);
} else if (LowerCaseEqualsASCII(action, "dragtabout")) {
- did_complete_action = DragActiveTab(false, true);
+ did_complete_action = DragTabOut();
} else if (LowerCaseEqualsASCII(action, "dragtabright")) {
- did_complete_action = DragActiveTab(true, false);
+ did_complete_action = DragActiveTab(true);
} else if (LowerCaseEqualsASCII(action, "duplicatetab")) {
did_complete_action = DuplicateTab();
} else if (LowerCaseEqualsASCII(action, "editsearchengines")) {
@@ -602,105 +602,6 @@ bool AutomatedUITest::ForceCrash() {
return true;
}
-bool AutomatedUITest::DragActiveTab(bool drag_right, bool drag_out) {
- BrowserProxy* browser = active_browser();
- if (browser == NULL) {
- AddErrorAttribute("browser_window_not_found");
- return false;
- }
-
- scoped_refptr<WindowProxy> window(
- GetAndActivateWindowForBrowser(browser));
- if (window.get() == NULL) {
- AddErrorAttribute("active_window_not_found");
- return false;
- }
- bool is_timeout;
-
- int tab_count;
- browser->GetTabCountWithTimeout(&tab_count,
- action_max_timeout_ms(),
- &is_timeout);
- // As far as we're concerned, if we can't get a view for a tab, it doesn't
- // exist, so cap tab_count at the number of tab view ids there are.
- tab_count = std::min(tab_count, VIEW_ID_TAB_LAST - VIEW_ID_TAB_0);
-
- int tab_index;
- if (!browser->GetActiveTabIndexWithTimeout(&tab_index,
- action_max_timeout_ms(),
- &is_timeout)) {
- AddWarningAttribute("no_active_tab");
- return false;
- }
-
- gfx::Rect dragged_tab_bounds;
- if (!window->GetViewBoundsWithTimeout(VIEW_ID_TAB_0 + tab_index,
- &dragged_tab_bounds, false,
- action_max_timeout_ms(),
- &is_timeout)) {
- AddWarningAttribute("no_tab_view_found");
- return false;
- }
-
- // Click on the center of the tab, and drag it to the left or the right.
- POINT dragged_tab_point(dragged_tab_bounds.CenterPoint().ToPOINT());
- POINT destination_point(dragged_tab_point);
-
- int window_count;
- if (drag_out) {
- destination_point.y += 3*dragged_tab_bounds.height();
- automation()->GetBrowserWindowCount(&window_count);
- } else if (drag_right) {
- if (tab_index >= (tab_count-1)) {
- AddInfoAttribute("index_cant_be_moved");
- return false;
- }
- destination_point.x += 2*dragged_tab_bounds.width()/3;
- } else {
- if (tab_index <= 0) {
- AddInfoAttribute("index_cant_be_moved");
- return false;
- }
- destination_point.x -= 2*dragged_tab_bounds.width()/3;
- }
-
- if (!browser->SimulateDragWithTimeout(dragged_tab_point,
- destination_point,
- views::Event::EF_LEFT_BUTTON_DOWN,
- action_max_timeout_ms(),
- &is_timeout, false)) {
- AddWarningAttribute("failed_to_simulate_drag");
- return false;
- }
-
- // If we try to drag the tab out and the window we drag from contains more
- // than just the dragged tab, we would expect the window count to increase
- // because the dragged tab should open in a new window. If not, we probably
- // just dragged into another tabstrip.
- if (drag_out && tab_count > 1) {
- int new_window_count;
- automation()->GetBrowserWindowCount(&new_window_count);
- if (new_window_count == window_count) {
- AddInfoAttribute("no_new_browser_window");
- return false;
- }
- }
- return true;
-}
-
-scoped_refptr<WindowProxy> AutomatedUITest::GetAndActivateWindowForBrowser(
- BrowserProxy* browser) {
- bool did_timeout;
- if (!browser->BringToFrontWithTimeout(action_max_timeout_ms(),
- &did_timeout)) {
- AddWarningAttribute("failed_to_bring_window_to_front");
- return NULL;
- }
-
- return browser->GetWindow();
-}
-
-
bool AutomatedUITest::SimulateKeyPressInActiveWindow(wchar_t key, int flags) {
scoped_refptr<WindowProxy> window(automation()->GetActiveWindow());
if (window.get() == NULL) {
diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.h b/chrome/test/automated_ui_tests/automated_ui_tests.h
index 9b35349..9d850ef 100644
--- a/chrome/test/automated_ui_tests/automated_ui_tests.h
+++ b/chrome/test/automated_ui_tests/automated_ui_tests.h
@@ -323,27 +323,8 @@ class AutomatedUITest : public AutomatedUITestBase {
// XML element: <Crash/>
bool ForceCrash();
- // Drags the active tab. If |drag_out| is true, |drag_right| is ignored and
- // the tab is dragged vertically to remove it from the tabstrip. Otherwise,
- // If |drag_right| is true, if there is a tab to the right of the active tab,
- // the active tab is dragged to that tabs position. If |drag_right| is false,
- // if there is a tab to the left of the active tab, the active tab is dragged
- // to that tabs position. Returns false if the tab isn't dragged, or if an
- // attempt to drag out doesn't create a new window (likely because it was
- // dragged in to another window).
- // XML element (multiple elements use this):
- // <DragTabRight/> - Calls DragActiveTab(true, false) (attempt to drag right)
- // <DragTabLeft/> - Calls DragActiveTab(false, false) (attempt to drag left)
- // <DragTabOut/> - Calls DragActiveTab(false, true) (attempt to drag tab out)
- bool DragActiveTab(bool drag_right, bool drag_out);
-
// Utility functions --------------------------------------------------------
- // Returns the WindowProxy associated with the given BrowserProxy
- // (transferring ownership of the pointer to the caller) and brings that
- // window to the top.
- scoped_refptr<WindowProxy> GetAndActivateWindowForBrowser(BrowserProxy* browser);
-
// Calls SimulateOSKeyPress on the active window. Simulates a key press at
// the OS level. |key| is the key pressed and |flags| specifies which
// modifiers keys are also pressed (as defined in chrome/views/event.h).
diff --git a/chrome/test/interactive_ui/interactive_ui.vcproj b/chrome/test/interactive_ui/interactive_ui.vcproj
index 5038d88..de8f276 100644
--- a/chrome/test/interactive_ui/interactive_ui.vcproj
+++ b/chrome/test/interactive_ui/interactive_ui.vcproj
@@ -357,6 +357,22 @@
</File>
</Filter>
<Filter
+ Name="TestAutomatedUI"
+ >
+ <File
+ RelativePath="..\automated_ui_tests\automated_ui_test_base.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\automated_ui_tests\automated_ui_test_base.h"
+ >
+ </File>
+ <File
+ RelativePath="..\automated_ui_tests\automated_ui_test_interactive_test.cc"
+ >
+ </File>
+ </Filter>
+ <Filter
Name="TestTabDragging"
>
<File