diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-11 23:29:59 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-11 23:29:59 +0000 |
commit | aa9387daf0c639b82627dc003237023130a8c693 (patch) | |
tree | 7e9645ee84ebbac14e9313e84eb1371c1a84d178 /chrome/test/reliability | |
parent | 378b4516b5e7970ae1011599ed397b3d03010c7a (diff) | |
download | chromium_src-aa9387daf0c639b82627dc003237023130a8c693.zip chromium_src-aa9387daf0c639b82627dc003237023130a8c693.tar.gz chromium_src-aa9387daf0c639b82627dc003237023130a8c693.tar.bz2 |
Get rid of ui_controls.h usage in shipping browser code. In a followup change, I'll move the code to a test directory.
I switched the page_load reliablity test to send synthesized keystrokes instead. I removed the reliablity tag drag tests, since these duplicate the newer interactive_ui_tests. The ChromeDriver method has been deprecated after discussion with kkania.
Review URL: https://codereview.chromium.org/11875004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176470 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/reliability')
-rw-r--r-- | chrome/test/reliability/automated_ui_test_base.cc | 140 | ||||
-rw-r--r-- | chrome/test/reliability/automated_ui_test_base.h | 15 | ||||
-rw-r--r-- | chrome/test/reliability/automated_ui_test_interactive_test.cc | 70 | ||||
-rw-r--r-- | chrome/test/reliability/automated_ui_tests.cc | 37 | ||||
-rw-r--r-- | chrome/test/reliability/automated_ui_tests.h | 6 | ||||
-rw-r--r-- | chrome/test/reliability/page_load_test.cc | 23 |
6 files changed, 20 insertions, 271 deletions
diff --git a/chrome/test/reliability/automated_ui_test_base.cc b/chrome/test/reliability/automated_ui_test_base.cc index 617b386..426f0ae 100644 --- a/chrome/test/reliability/automated_ui_test_base.cc +++ b/chrome/test/reliability/automated_ui_test_base.cc @@ -87,146 +87,6 @@ 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; - } - - int tab_count; - if (!browser->GetTabCount(&tab_count)) { - LogErrorMessage("get_tab_count_failed"); - return false; - } - - if (tab_count < 2) { - LogWarningMessage("not_enough_tabs_to_drag_out"); - return false; - } - - int tab_index; - if (!browser->GetActiveTabIndex(&tab_index)) { - LogWarningMessage("no_active_tab"); - return false; - } - - if (tab_index < 0) { - LogInfoMessage("invalid_active_tab_index"); - return false; - } - - gfx::Rect dragged_tab_bounds; - if (!window->GetViewBounds(VIEW_ID_TAB_0 + tab_index, - &dragged_tab_bounds, false)) { - LogWarningMessage("no_tab_view_found"); - return false; - } - - gfx::Rect urlbar_bounds; - if (!window->GetViewBounds(VIEW_ID_LOCATION_BAR, - &urlbar_bounds, false)) { - LogWarningMessage("no_location_bar_found"); - return false; - } - - // Click on the center of the tab, and drag it downwards. - gfx::Point start; - gfx::Point end; - start.set_x(dragged_tab_bounds.x() + dragged_tab_bounds.width() / 2); - start.set_y(dragged_tab_bounds.y() + dragged_tab_bounds.height() / 2); - end.set_x(start.x()); - end.set_y(start.y() + 3 * urlbar_bounds.height()); - - if (!browser->SimulateDrag(start, end, ui::EF_LEFT_MOUSE_BUTTON, 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; - } - - int tab_count; - if (!browser->GetTabCount(&tab_count)) { - LogErrorMessage("get_tab_count_failed"); - return false; - } - - if (tab_count < 2) { - LogWarningMessage("not_enough_tabs_to_drag_around"); - return false; - } - - int tab_index; - if (!browser->GetActiveTabIndex(&tab_index)) { - LogWarningMessage("no_active_tab"); - return false; - } - - gfx::Rect dragged_tab_bounds; - if (!window->GetViewBounds(VIEW_ID_TAB_0 + tab_index, - &dragged_tab_bounds, false)) { - LogWarningMessage("no_tab_view_found"); - return false; - } - - // Click on the center of the tab, and drag it to the left or the right. - gfx::Point dragged_tab_point = dragged_tab_bounds.CenterPoint(); - gfx::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.Offset(2 * dragged_tab_bounds.width() / 3, 0); - } else { - if (tab_index <= 0) { - LogInfoMessage("cant_drag_to_left"); - return false; - } - new_tab_index = tab_index - 1; - destination_point.Offset(-2 * dragged_tab_bounds.width() / 3, 0); - } - - if (!browser->SimulateDrag(dragged_tab_point, destination_point, - ui::EF_LEFT_MOUSE_BUTTON, false)) { - LogWarningMessage("failed_to_simulate_drag"); - return false; - } - - if (!browser->WaitForTabToBecomeActive(new_tab_index, - TestTimeouts::action_timeout())) { - LogWarningMessage("failed_to_reindex_tab"); - return false; - } - - return true; -} - bool AutomatedUITestBase::FindInPage() { if (!RunCommandAsync(IDC_FIND)) return false; diff --git a/chrome/test/reliability/automated_ui_test_base.h b/chrome/test/reliability/automated_ui_test_base.h index 8fbf138..fce6773 100644 --- a/chrome/test/reliability/automated_ui_test_base.h +++ b/chrome/test/reliability/automated_ui_test_base.h @@ -46,21 +46,6 @@ 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); - // Activates "find in page" on the current page. Returns true on success. bool FindInPage(); diff --git a/chrome/test/reliability/automated_ui_test_interactive_test.cc b/chrome/test/reliability/automated_ui_test_interactive_test.cc deleted file mode 100644 index 04c0969..0000000 --- a/chrome/test/reliability/automated_ui_test_interactive_test.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2012 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 "base/test/test_timeouts.h" -#include "base/threading/platform_thread.h" -#include "chrome/test/automation/automation_proxy.h" -#include "chrome/test/automation/browser_proxy.h" -#include "chrome/test/automation/tab_proxy.h" -#include "chrome/test/reliability/automated_ui_test_base.h" -#include "chrome/test/ui/ui_test.h" - -TEST_F(AutomatedUITestBase, DragOut) { - NewTab(); - NewTab(); - ASSERT_TRUE(active_browser()->WaitForTabCountToBecome(3)); - base::PlatformThread::Sleep(TestTimeouts::action_timeout()); - ASSERT_TRUE(DragTabOut()); - int window_count; - ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); - ASSERT_EQ(2, window_count); -} - -TEST_F(AutomatedUITestBase, DragLeftRight) { - NewTab(); - NewTab(); - ASSERT_TRUE(active_browser()->WaitForTabCountToBecome(3)); - // TODO(phajdan.jr): We need a WaitForTabstripAnimationsToEnd() function. - // Every sleep in this file should be replaced with it. - const base::TimeDelta kDelay = TestTimeouts::action_timeout(); - base::PlatformThread::Sleep(kDelay); - - scoped_refptr<TabProxy> dragged_tab(active_browser()->GetActiveTab()); - int tab_index; - ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index)); - EXPECT_EQ(2, tab_index); - - // Drag the active tab to left. Now it should be the middle tab. - ASSERT_TRUE(DragActiveTab(false)); - // We wait for the animation to be over. - base::PlatformThread::Sleep(kDelay); - ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index)); - EXPECT_EQ(1, tab_index); - - // Drag the active tab to left. Now it should be the leftmost tab. - ASSERT_TRUE(DragActiveTab(false)); - base::PlatformThread::Sleep(kDelay); - ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index)); - EXPECT_EQ(0, tab_index); - - // 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 it should be the middle tab. - ASSERT_TRUE(DragActiveTab(true)); - base::PlatformThread::Sleep(kDelay); - ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index)); - EXPECT_EQ(1, tab_index); - - // Drag the active tab to right. Now it should be the rightmost tab. - ASSERT_TRUE(DragActiveTab(true)); - base::PlatformThread::Sleep(kDelay); - ASSERT_TRUE(dragged_tab->GetTabIndex(&tab_index)); - EXPECT_EQ(2, tab_index); - - // 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/reliability/automated_ui_tests.cc b/chrome/test/reliability/automated_ui_tests.cc index b214c68..6b78a4a 100644 --- a/chrome/test/reliability/automated_ui_tests.cc +++ b/chrome/test/reliability/automated_ui_tests.cc @@ -391,12 +391,6 @@ bool AutomatedUITest::DoAction(const std::string& action) { did_complete_action = PressDownArrow(); } else if (LowerCaseEqualsASCII(action, "downloads")) { did_complete_action = ShowDownloads(); - } else if (LowerCaseEqualsASCII(action, "dragtableft")) { - did_complete_action = DragActiveTab(false); - } else if (LowerCaseEqualsASCII(action, "dragtabout")) { - did_complete_action = DragTabOut(); - } else if (LowerCaseEqualsASCII(action, "dragtabright")) { - did_complete_action = DragActiveTab(true); } else if (LowerCaseEqualsASCII(action, "duplicatetab")) { did_complete_action = DuplicateTab(); } else if (LowerCaseEqualsASCII(action, "editsearchengines")) { @@ -559,35 +553,35 @@ bool AutomatedUITest::Options() { } bool AutomatedUITest::PressDownArrow() { - return SimulateKeyPressInActiveWindow(ui::VKEY_DOWN, 0); + return SimulateKeyPress(ui::VKEY_DOWN); } bool AutomatedUITest::PressEnterKey() { - return SimulateKeyPressInActiveWindow(ui::VKEY_RETURN, 0); + return SimulateKeyPress(ui::VKEY_RETURN); } bool AutomatedUITest::PressEscapeKey() { - return SimulateKeyPressInActiveWindow(ui::VKEY_ESCAPE, 0); + return SimulateKeyPress(ui::VKEY_ESCAPE); } bool AutomatedUITest::PressPageDown() { - return SimulateKeyPressInActiveWindow(ui::VKEY_PRIOR, 0); + return SimulateKeyPress(ui::VKEY_PRIOR); } bool AutomatedUITest::PressPageUp() { - return SimulateKeyPressInActiveWindow(ui::VKEY_NEXT, 0); + return SimulateKeyPress(ui::VKEY_NEXT); } bool AutomatedUITest::PressSpaceBar() { - return SimulateKeyPressInActiveWindow(ui::VKEY_SPACE, 0); + return SimulateKeyPress(ui::VKEY_SPACE); } bool AutomatedUITest::PressTabKey() { - return SimulateKeyPressInActiveWindow(ui::VKEY_TAB, 0); + return SimulateKeyPress(ui::VKEY_TAB); } bool AutomatedUITest::PressUpArrow() { - return SimulateKeyPressInActiveWindow(ui::VKEY_UP, 0); + return SimulateKeyPress(ui::VKEY_UP); } bool AutomatedUITest::StarPage() { @@ -677,18 +671,9 @@ bool AutomatedUITest::ForceCrash() { return true; } -bool AutomatedUITest::SimulateKeyPressInActiveWindow(ui::KeyboardCode key, - int flags) { - scoped_refptr<BrowserProxy> browser(active_browser()); - scoped_refptr<WindowProxy> window(browser->GetWindow()); - if (window.get() == NULL) { - AddErrorAttribute("active_window_not_found"); - return false; - } - if (!window->SimulateOSKeyPress(key, flags)) { - AddWarningAttribute("failure_simulating_key_press"); - return false; - } +bool AutomatedUITest::SimulateKeyPress(ui::KeyboardCode key) { + scoped_refptr<TabProxy> tab(GetActiveTab()); + tab->SimulateKeyPress(key); return true; } diff --git a/chrome/test/reliability/automated_ui_tests.h b/chrome/test/reliability/automated_ui_tests.h index cf9cb24..5a05c07 100644 --- a/chrome/test/reliability/automated_ui_tests.h +++ b/chrome/test/reliability/automated_ui_tests.h @@ -292,10 +292,8 @@ class AutomatedUITest : public AutomatedUITestBase { // Utility functions -------------------------------------------------------- - // 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). - bool SimulateKeyPressInActiveWindow(ui::KeyboardCode key, int flags); + // Calls SimulateKeyPress on the active tab. |key| is the key pressed. + bool SimulateKeyPress(ui::KeyboardCode key); // Opens init file, reads it into the reader, and closes the file. // Returns false if there are any errors. diff --git a/chrome/test/reliability/page_load_test.cc b/chrome/test/reliability/page_load_test.cc index c0590d0..ce333e8 100644 --- a/chrome/test/reliability/page_load_test.cc +++ b/chrome/test/reliability/page_load_test.cc @@ -353,22 +353,13 @@ class PageLoadTest : public UITest { if (result == AUTOMATION_MSG_NAVIGATION_SUCCESS) { if (g_page_down) { // Page down twice. - scoped_refptr<BrowserProxy> browser( - automation()->GetBrowserWindow(0)); - if (browser.get()) { - scoped_refptr<WindowProxy> window(browser->GetWindow()); - if (window.get()) { - if (browser->BringToFront()) { - // Sleep for 2 seconds between commands. - // This used to be settable but the flag went away. - base::TimeDelta sleep_time = base::TimeDelta::FromSeconds(2); - window->SimulateOSKeyPress(ui::VKEY_NEXT, 0); - base::PlatformThread::Sleep(sleep_time); - window->SimulateOSKeyPress(ui::VKEY_NEXT, 0); - base::PlatformThread::Sleep(sleep_time); - } - } - } + // Sleep for 2 seconds between commands. + // This used to be settable but the flag went away. + base::TimeDelta sleep_time = base::TimeDelta::FromSeconds(2); + tab_proxy->SimulateKeyPress(ui::VKEY_NEXT); + base::PlatformThread::Sleep(sleep_time); + tab_proxy->SimulateKeyPress(ui::VKEY_NEXT); + base::PlatformThread::Sleep(sleep_time); } } } |