From 1bdffff7418eec3f0cac4385078484628a9ed35e Mon Sep 17 00:00:00 2001 From: "phajdan.jr@chromium.org" Date: Tue, 15 Sep 2009 21:57:52 +0000 Subject: First part of automated_ui_tests improvements. - disable unreliable RestoreTab action - make more command sync, waiting for their completion TEST=none BUG=21547, 21636 Review URL: http://codereview.chromium.org/196096 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26272 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/automation/automation_provider.cc | 21 +++++ .../automated_ui_tests/automated_ui_test_base.cc | 46 +++++++++++ .../automated_ui_tests/automated_ui_test_base.h | 27 +++++++ .../automated_ui_tests/automated_ui_test_test.cc | 93 ++++++++++++++++++++++ .../test/automated_ui_tests/automated_ui_tests.cc | 30 +------ .../test/automated_ui_tests/automated_ui_tests.h | 30 ------- chrome/test/ui/ui_test.cc | 5 -- .../auto_ui_test_input_generator.py | 5 +- .../automated_ui_test_tools/possible_actions.txt | 4 +- 9 files changed, 196 insertions(+), 65 deletions(-) diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 7e0d803..b461636 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -761,10 +761,31 @@ void AutomationProvider::ExecuteBrowserCommandAsync(int handle, int command, void AutomationProvider::ExecuteBrowserCommand( int handle, int command, IPC::Message* reply_message) { + // List of commands which just finish synchronously and don't require + // setting up an observer. + static const int kSynchronousCommands[] = { + IDC_HOME, + IDC_SELECT_NEXT_TAB, + IDC_SELECT_PREVIOUS_TAB, + IDC_SHOW_DOWNLOADS, + IDC_SHOW_HISTORY, + }; if (browser_tracker_->ContainsHandle(handle)) { Browser* browser = browser_tracker_->GetResource(handle); if (browser->command_updater()->SupportsCommand(command) && browser->command_updater()->IsCommandEnabled(command)) { + // First check if we can handle the command without using an observer. + for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { + if (command == kSynchronousCommands[i]) { + browser->ExecuteCommand(command); + AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, + true); + Send(reply_message); + return; + } + } + + // Use an observer if we have one, otherwise fail. if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( this, browser, command, reply_message)) { browser->ExecuteCommand(command); 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 bf39831..5f2ef95 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.cc @@ -241,6 +241,13 @@ bool AutomatedUITestBase::DragActiveTab(bool drag_right) { } #endif +bool AutomatedUITestBase::FindInPage() { + if (!RunCommandAsync(IDC_FIND)) + return false; + + return WaitForFindWindowVisibilityChange(active_browser(), true); +} + bool AutomatedUITestBase::ForwardButton() { return RunCommand(IDC_FORWARD); } @@ -249,6 +256,10 @@ bool AutomatedUITestBase::GoOffTheRecord() { return RunCommand(IDC_NEW_INCOGNITO_WINDOW); } +bool AutomatedUITestBase::Home() { + return RunCommand(IDC_HOME); +} + bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( scoped_refptr* previous_browser) { if (!automation()->OpenNewBrowserWindow(true /* SW_SHOWNORMAL */)) { @@ -317,6 +328,41 @@ bool AutomatedUITestBase::RestoreTab() { return RunCommand(IDC_RESTORE_TAB); } +bool AutomatedUITestBase::SelectNextTab() { + return RunCommand(IDC_SELECT_NEXT_TAB); +} + +bool AutomatedUITestBase::SelectPreviousTab() { + return RunCommand(IDC_SELECT_PREVIOUS_TAB); +} + +bool AutomatedUITestBase::ShowBookmarkBar() { + bool is_visible; + bool is_animating; + if (!active_browser()->GetBookmarkBarVisibility(&is_visible, + &is_animating)) { + return false; + } + + if (is_visible) { + // If the bar is visible, then issuing the command again will toggle it. + return true; + } + + if (!RunCommandAsync(IDC_SHOW_BOOKMARK_BAR)) + return false; + + return WaitForBookmarkBarVisibilityChange(active_browser(), true); +} + +bool AutomatedUITestBase::ShowDownloads() { + return RunCommand(IDC_SHOW_DOWNLOADS); +} + +bool AutomatedUITestBase::ShowHistory() { + return RunCommand(IDC_SHOW_HISTORY); +} + bool AutomatedUITestBase::RunCommandAsync(int browser_command) { BrowserProxy* browser = active_browser(); if (NULL == browser) { 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 cc4fb8648..c4b9429 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.h +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.h @@ -57,6 +57,9 @@ class AutomatedUITestBase : public UITest { // drag the active tab over. bool DragActiveTab(bool drag_right); + // Activates "find in page" on the current page. Returns true on success. + bool FindInPage(); + // Go forward in active tab. // Returns true if successful, false otherwise. bool ForwardButton(); @@ -64,6 +67,10 @@ class AutomatedUITestBase : public UITest { // Opens an OffTheRecord browser window. bool GoOffTheRecord(); + // Navigates to the Home page. + // Returns true if call to activate the accelerator is successful. + bool Home(); + // Navigates the activate tab to given url. bool Navigate(const GURL& url); @@ -88,6 +95,26 @@ class AutomatedUITestBase : public UITest { // Returns true if the tab is successfully restored. bool RestoreTab(); + // Activates the next tab on the active browser window. + // Returns true on success. + bool SelectNextTab(); + + // Activates the previous tab on the active browser window. + // Returns true on success. + bool SelectPreviousTab(); + + // Displays the bookmark bar. + // Returns true on success. + bool ShowBookmarkBar(); + + // Opens the Downloads page in the current active browser window. + // Returns true on success. + bool ShowDownloads(); + + // Opens the History page in the current active browser window. + // Returns true on success. + bool ShowHistory(); + // Runs the specified browser command in the current active browser. // See browser_commands.cc for the list of commands. // Returns true if the call is successfully dispatched. diff --git a/chrome/test/automated_ui_tests/automated_ui_test_test.cc b/chrome/test/automated_ui_tests/automated_ui_test_test.cc index 383a1e7..b206ef4 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_test.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_test.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "chrome/app/chrome_dll_resource.h" +#include "chrome/common/url_constants.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" @@ -32,6 +33,29 @@ #define MAYBE_CloseBrowserWindow CloseBrowserWindow #endif +TEST_F(AutomatedUITestBase, FindInPage) { + ASSERT_TRUE(FindInPage()); + bool is_visible; + ASSERT_TRUE(active_browser()->IsFindWindowFullyVisible(&is_visible)); + EXPECT_TRUE(is_visible); +} + +TEST_F(AutomatedUITestBase, Home) { + FilePath path_prefix(test_data_directory_.AppendASCII("session_history")); + GURL bot1(net::FilePathToFileURL(path_prefix.AppendASCII("bot1.html"))); + NavigateToURL(bot1); // To help verify that Home does something. + + ASSERT_TRUE(Home()); + + GURL url; + ASSERT_TRUE(active_browser()->GetActiveTab()->GetCurrentURL(&url)); + EXPECT_EQ(GURL(chrome::kAboutBlankURL), url); + + std::wstring title; + ASSERT_TRUE(active_browser()->GetActiveTab()->GetTabTitle(&title)); + EXPECT_EQ(L"", title); +} + TEST_F(AutomatedUITestBase, NewTab) { int tab_count; active_browser()->GetTabCount(&tab_count); @@ -294,3 +318,72 @@ TEST_F(AutomatedUITestBase, Navigate) { ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); ASSERT_EQ(url2, url); } + +TEST_F(AutomatedUITestBase, SelectTab) { + FilePath filename(test_data_directory_); + filename = filename.AppendASCII("title2.html"); + GURL url = net::FilePathToFileURL(filename); + + ASSERT_TRUE(active_browser()->AppendTab(url)); + ASSERT_TRUE(active_browser()->AppendTab(url)); + + int active_tab_index; + ASSERT_TRUE(active_browser()->GetActiveTabIndex(&active_tab_index)); + ASSERT_EQ(2, active_tab_index); + + ASSERT_TRUE(SelectNextTab()); + ASSERT_TRUE(active_browser()->GetActiveTabIndex(&active_tab_index)); + ASSERT_EQ(0, active_tab_index); + + ASSERT_TRUE(SelectNextTab()); + ASSERT_TRUE(active_browser()->GetActiveTabIndex(&active_tab_index)); + ASSERT_EQ(1, active_tab_index); + + ASSERT_TRUE(SelectPreviousTab()); + ASSERT_TRUE(active_browser()->GetActiveTabIndex(&active_tab_index)); + ASSERT_EQ(0, active_tab_index); + + ASSERT_TRUE(SelectPreviousTab()); + ASSERT_TRUE(active_browser()->GetActiveTabIndex(&active_tab_index)); + ASSERT_EQ(2, active_tab_index); + + ASSERT_TRUE(SelectPreviousTab()); + ASSERT_TRUE(active_browser()->GetActiveTabIndex(&active_tab_index)); + ASSERT_EQ(1, active_tab_index); + + ASSERT_TRUE(SelectNextTab()); + ASSERT_TRUE(active_browser()->GetActiveTabIndex(&active_tab_index)); + ASSERT_EQ(2, active_tab_index); +} + +TEST_F(AutomatedUITestBase, ShowBookmarkBar) { + ASSERT_TRUE(ShowBookmarkBar()); + bool is_visible; + bool is_animating; + ASSERT_TRUE(active_browser()->GetBookmarkBarVisibility(&is_visible, + &is_animating)); + ASSERT_TRUE(is_visible); + ASSERT_FALSE(is_animating); + + // Try second time to make sure it won't make the bookmark bar + // disappear. + ASSERT_TRUE(ShowBookmarkBar()); + ASSERT_TRUE(active_browser()->GetBookmarkBarVisibility(&is_visible, + &is_animating)); + ASSERT_TRUE(is_visible); + ASSERT_FALSE(is_animating); +} + +TEST_F(AutomatedUITestBase, ShowDownloads) { + ASSERT_TRUE(ShowDownloads()); + GURL url; + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(GURL(chrome::kChromeUIDownloadsURL), url); +} + +TEST_F(AutomatedUITestBase, ShowHistory) { + ASSERT_TRUE(ShowHistory()); + GURL url; + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(GURL(chrome::kChromeUIHistoryURL), url); +} diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index 02afb67..394b91c 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -425,6 +425,8 @@ bool AutomatedUITest::DoAction(const std::string& action) { << action.c_str(); } + EXPECT_TRUE(did_complete_action) << action; + if (!did_complete_action) xml_writer_.AddAttribute("failed_to_complete", "yes"); xml_writer_.EndElement(); @@ -455,14 +457,6 @@ bool AutomatedUITest::ChangeEncoding() { return RunCommandAsync((*encodings)[index].encoding_id); } -bool AutomatedUITest::FindInPage() { - return RunCommandAsync(IDC_FIND); -} - -bool AutomatedUITest::Home() { - return RunCommandAsync(IDC_HOME); -} - bool AutomatedUITest::JavaScriptConsole() { return RunCommandAsync(IDC_DEV_TOOLS); } @@ -527,26 +521,6 @@ bool AutomatedUITest::PressUpArrow() { return SimulateKeyPressInActiveWindow(base::VKEY_UP, 0); } -bool AutomatedUITest::SelectNextTab() { - return RunCommandAsync(IDC_SELECT_NEXT_TAB); -} - -bool AutomatedUITest::SelectPreviousTab() { - return RunCommandAsync(IDC_SELECT_PREVIOUS_TAB); -} - -bool AutomatedUITest::ShowBookmarkBar() { - return RunCommandAsync(IDC_SHOW_BOOKMARK_BAR); -} - -bool AutomatedUITest::ShowDownloads() { - return RunCommandAsync(IDC_SHOW_DOWNLOADS); -} - -bool AutomatedUITest::ShowHistory() { - return RunCommandAsync(IDC_SHOW_HISTORY); -} - bool AutomatedUITest::StarPage() { return RunCommandAsync(IDC_STAR); } diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.h b/chrome/test/automated_ui_tests/automated_ui_tests.h index 1db44bb..d370b70 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.h +++ b/chrome/test/automated_ui_tests/automated_ui_tests.h @@ -141,15 +141,6 @@ class AutomatedUITest : public AutomatedUITestBase { // XML element: bool ExerciseDialog(); - // Activates "find in page" on the current page. - // XML element: - bool FindInPage(); - - // Navigates to the Home page. - // Returns true if call to activate the accelerator is successful. - // XML element: - bool Home(); - // Opens the JavaScriptConsole window. While it isn't modal, it takes focus // from the current browser window, so most of the test can't continue until // it is dismissed. @@ -226,27 +217,6 @@ class AutomatedUITest : public AutomatedUITestBase { // XML element: bool PressUpArrow(); - // Activates the next tab on the active browser window. - // XML element: - bool SelectNextTab(); - - // Activates the previous tab on the active browser window. - // XML element: - bool SelectPreviousTab(); - - // Displays the bookmark bar. - // Returns true if call to activate the accelerator is successful. - // XML element: - bool ShowBookmarkBar(); - - // Opens the Downloads page in the current active browser window. - // XML element: - bool ShowDownloads(); - - // Opens the History page in the current active browser window. - // XML element: - bool ShowHistory(); - // Stars the current page. This opens a dialog that may or may not be // dismissed. // XML element: diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index b59d71f..cacd59d0 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -500,10 +500,6 @@ bool UITest::WaitForDownloadShelfVisibilityChange(BrowserProxy* browser, return false; } -// TODO(port): this #if effectively cuts out half of this file on -// non-Windows platforms, and is a temporary hack to get things -// building. -#if defined(OS_WIN) bool UITest::WaitForFindWindowVisibilityChange(BrowserProxy* browser, bool wait_for_open) { const int kCycles = 10; @@ -536,7 +532,6 @@ bool UITest::WaitForBookmarkBarVisibilityChange(BrowserProxy* browser, } return false; } -#endif // defined(OS_WIN) GURL UITest::GetActiveTabURL(int window_index) { scoped_refptr tab_proxy(GetActiveTab(window_index)); diff --git a/chrome/tools/automated_ui_test_tools/auto_ui_test_input_generator.py b/chrome/tools/automated_ui_test_tools/auto_ui_test_input_generator.py index df9bc22..4c335e6 100755 --- a/chrome/tools/automated_ui_test_tools/auto_ui_test_input_generator.py +++ b/chrome/tools/automated_ui_test_tools/auto_ui_test_input_generator.py @@ -245,7 +245,10 @@ class AutomatedTestInputGenerator: def __init__(self): (options,args) = ParseCommandLine() input_file = open(options.input_file_name) - actions_list = input_file.readlines() + actions_list = [] + for line in input_file.readlines(): + if not line.startswith('#'): + actions_list.append(line) input_file.close() self.__commands_per_file = options.commands_per_file diff --git a/chrome/tools/automated_ui_test_tools/possible_actions.txt b/chrome/tools/automated_ui_test_tools/possible_actions.txt index 9e5ad61..c69406f9 100644 --- a/chrome/tools/automated_ui_test_tools/possible_actions.txt +++ b/chrome/tools/automated_ui_test_tools/possible_actions.txt @@ -1,3 +1,4 @@ +# Please keep the list sorted. Back ChangeEncoding CloseTab @@ -16,7 +17,8 @@ DragTabRight DragTabOut OpenWindow Reload -RestoreTab +# Disabled, it doesn't work reliably (http://crbug.com/21636). +# RestoreTab SelectNextTab SelectPrevTab ShowBookmarks -- cgit v1.1