diff options
author | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 18:41:39 +0000 |
---|---|---|
committer | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 18:41:39 +0000 |
commit | 27e1c9e03d66d18f1cd42a5355735206dfa1bfec (patch) | |
tree | c9e0ca8ca0fa4331d73162b0ebf77892348e0b00 /chrome | |
parent | 279cc48f803ddf0de28e5ea700ad2132f2aecd56 (diff) | |
download | chromium_src-27e1c9e03d66d18f1cd42a5355735206dfa1bfec.zip chromium_src-27e1c9e03d66d18f1cd42a5355735206dfa1bfec.tar.gz chromium_src-27e1c9e03d66d18f1cd42a5355735206dfa1bfec.tar.bz2 |
Making navigate, back, forward, and reload
synchronous in automated ui test.
Review URL: http://codereview.chromium.org/115279
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15978 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
6 files changed, 96 insertions, 56 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 30a52ff..69ea1e9 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -245,7 +245,6 @@ class NavigationNotificationObserver : public NotificationObserver { automation_->Send(reply_message_); reply_message_ = NULL; - automation_->RemoveNavigationStatusListener(this); delete this; } @@ -260,6 +259,8 @@ class NavigationNotificationObserver : public NotificationObserver { reply_message_ = NULL; } + automation_->RemoveNavigationStatusListener(this); + NotificationService* service = NotificationService::current(); service->RemoveObserver(this, NotificationType::NAV_ENTRY_COMMITTED, Source<NavigationController>(controller_)); @@ -569,6 +570,18 @@ class ExecuteBrowserCommandObserver : public NotificationObserver { observer->set_for_browser_command(true); break; } + case IDC_BACK: + case IDC_FORWARD: + case IDC_RELOAD: { + automation-> + AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>( + &browser->GetSelectedTabContents()->controller(), + reply_message, + AUTOMATION_MSG_NAVIGATION_SUCCESS, + AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, + AUTOMATION_MSG_NAVIGATION_ERROR); + break; + } default: { ExecuteBrowserCommandObserver* observer = new ExecuteBrowserCommandObserver(automation, reply_message); 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 2a16b9b..abd0cf3 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.cc @@ -25,6 +25,10 @@ void AutomatedUITestBase::SetUp() { set_active_browser(automation()->GetBrowserWindow(0)); } +bool AutomatedUITestBase::BackButton() { + return RunCommand(IDC_BACK); +} + bool AutomatedUITestBase::CloseActiveTab() { BrowserProxy* browser = active_browser(); int tab_count; @@ -75,6 +79,10 @@ bool AutomatedUITestBase::DuplicateTab() { return RunCommand(IDC_DUPLICATE_TAB); } +bool AutomatedUITestBase::ForwardButton() { + return RunCommand(IDC_FORWARD); +} + bool AutomatedUITestBase::GoOffTheRecord() { return RunCommand(IDC_NEW_INCOGNITO_WINDOW); } @@ -108,12 +116,34 @@ bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( return true; } +bool AutomatedUITestBase::Navigate(const GURL& url) { + scoped_ptr<TabProxy> tab(GetActiveTab()); + if (tab.get() == NULL) { + LogErrorMessage("active_tab_not_found"); + return false; + } + bool did_timeout = false; + tab->NavigateToURLWithTimeout(url, + command_execution_timeout_ms(), + &did_timeout); + + if (did_timeout) { + LogWarningMessage("timeout"); + return false; + } + return true; +} + bool AutomatedUITestBase::NewTab() { // Apply accelerator and wait for a new tab to open, if either // fails, return false. Apply Accelerator takes care of logging its failure. return RunCommand(IDC_NEW_TAB); } +bool AutomatedUITestBase::ReloadPage() { + return RunCommand(IDC_RELOAD); +} + bool AutomatedUITestBase::RestoreTab() { return RunCommand(IDC_RESTORE_TAB); } 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 80268bc..731bf40 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.h +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.h @@ -23,6 +23,10 @@ class AutomatedUITestBase : public UITest { // NOTE: This list is sorted alphabetically. // All functions are synchronous unless specified with Async. + // Go back in active tab. + // Returns true if successful, false otherwise. + bool BackButton(); + // Close the selected tab in the current browser window. The function will // not try close the tab if it is the only tab of the last normal window, so // the application is not got closed. @@ -38,9 +42,16 @@ class AutomatedUITestBase : public UITest { // Returns true if a duplicated tab is added. bool DuplicateTab(); + // Go forward in active tab. + // Returns true if successful, false otherwise. + bool ForwardButton(); + // Opens an OffTheRecord browser window. bool GoOffTheRecord(); + // Navigates the activate tab to given url. + bool Navigate(const GURL& url); + // Opens a new tab in the active window using an accelerator. // Returns true if a new tab is successfully opened. bool NewTab(); @@ -53,6 +64,10 @@ class AutomatedUITestBase : public UITest { // caller owns previous_browser. bool OpenAndActivateNewBrowserWindow(BrowserProxy** previous_browser); + // Reload the active tab. + // Returns true if successful, false otherwise. + bool ReloadPage(); + // Restores a previously closed tab. // Returns true if the tab is successfully restored. bool RestoreTab(); 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 e09996f..0262353 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_test.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_test.cc @@ -7,6 +7,8 @@ #include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/ui/ui_test.h" +#include "googleurl/src/gurl.h" +#include "net/base/net_util.h" TEST_F(AutomatedUITestBase, NewTab) { int tab_count; @@ -241,3 +243,32 @@ TEST_F(AutomatedUITestBase, OpenCloseBrowserWindowWithAccelerator) { automation()->GetBrowserWindowCount(&num_browser_windows); ASSERT_EQ(1, num_browser_windows); } + +TEST_F(AutomatedUITestBase, Navigate) { + FilePath path_prefix(test_data_directory_.AppendASCII("session_history")); + GURL url1(net::FilePathToFileURL(path_prefix.AppendASCII("bot1.html"))); + GURL url2(net::FilePathToFileURL(path_prefix.AppendASCII("bot2.html"))); + GURL url3(net::FilePathToFileURL(path_prefix.AppendASCII("bot3.html"))); + GURL url; + ASSERT_TRUE(Navigate(url1)); + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(url1, url); + ASSERT_TRUE(Navigate(url2)); + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(url2, url); + ASSERT_TRUE(Navigate(url3)); + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(url3, url); + ASSERT_TRUE(BackButton()); + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(url2, url); + ASSERT_TRUE(BackButton()); + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(url1, url); + ASSERT_TRUE(ForwardButton()); + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(url2, url); + ASSERT_TRUE(ReloadPage()); + ASSERT_TRUE(GetActiveTab()->GetCurrentURL(&url)); + ASSERT_EQ(url2, url); +} diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index c4a7686..d935387 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -310,7 +310,12 @@ bool AutomatedUITest::DoAction(const std::string & action) { } else if (LowerCaseEqualsASCII(action, "javascriptdebugger")) { did_complete_action = JavaScriptDebugger(); } else if (LowerCaseEqualsASCII(action, "navigate")) { - did_complete_action = Navigate(); + std::string url = "about:blank"; + if (init_reader_.NodeAttribute("url", &url)) { + xml_writer_.AddAttribute("url", url); + } + GURL test_url(url); + did_complete_action = Navigate(test_url); } else if (LowerCaseEqualsASCII(action, "newtab")) { did_complete_action = NewTab(); } else if (LowerCaseEqualsASCII(action, "openwindow")) { @@ -393,10 +398,6 @@ bool AutomatedUITest::DoAction(const std::string & action) { return did_complete_action; } -bool AutomatedUITest::BackButton() { - return RunCommandAsync(IDC_BACK); -} - bool AutomatedUITest::ChangeEncoding() { // Get the encoding list that is used to populate the UI (encoding menu) std::wstring cur_locale = g_browser_process->GetApplicationLocale(); @@ -421,10 +422,6 @@ bool AutomatedUITest::FindInPage() { return RunCommandAsync(IDC_FIND); } -bool AutomatedUITest::ForwardButton() { - return RunCommandAsync(IDC_FORWARD); -} - bool AutomatedUITest::Home() { return RunCommandAsync(IDC_HOME); } @@ -437,29 +434,6 @@ bool AutomatedUITest::JavaScriptDebugger() { return RunCommandAsync(IDC_DEBUGGER); } -bool AutomatedUITest::Navigate() { - scoped_ptr<TabProxy> tab(GetActiveTab()); - if (tab.get() == NULL) { - AddErrorAttribute("active_tab_not_found"); - return false; - } - std::string url = "about:blank"; - if (init_reader_.NodeAttribute("url", &url)) { - xml_writer_.AddAttribute("url", url); - } - GURL test_url(url); - bool did_timeout = false; - tab->NavigateToURLWithTimeout(test_url, - command_execution_timeout_ms(), - &did_timeout); - - if (did_timeout) { - AddWarningAttribute("timeout"); - return false; - } - return true; -} - bool AutomatedUITest::OpenAboutDialog() { return RunCommandAsync(IDC_ABOUT); } @@ -520,10 +494,6 @@ bool AutomatedUITest::PressUpArrow() { return SimulateKeyPressInActiveWindow(VK_UP, 0); } -bool AutomatedUITest::ReloadPage() { - return RunCommandAsync(IDC_RELOAD); -} - bool AutomatedUITest::SelectNextTab() { return RunCommandAsync(IDC_SELECT_NEXT_TAB); } diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.h b/chrome/test/automated_ui_tests/automated_ui_tests.h index a58b2dc..39c12c4 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.h +++ b/chrome/test/automated_ui_tests/automated_ui_tests.h @@ -130,11 +130,6 @@ class AutomatedUITest : public AutomatedUITestBase { // NOTE: This list is sorted alphabetically, so that we can easily detect // missing actions. - // Activates back button in active window. - // Returns true if call to activate the accelerator is successful. - // XML element: <Back/> - bool BackButton(); - // Changes the encoding of the page (the encoding is selected at random // from a list of encodings). // Returns true if call to activate the accelerator is successful. @@ -149,11 +144,6 @@ class AutomatedUITest : public AutomatedUITestBase { // XML element: <FindInPage/> bool FindInPage(); - // Activates forward button in active window. - // Returns true if call to activate the accelerator is successful. - // XML element: <Forward/> - bool ForwardButton(); - // Navigates to the Home page. // Returns true if call to activate the accelerator is successful. // XML element: <Home/> @@ -171,11 +161,6 @@ class AutomatedUITest : public AutomatedUITestBase { // XML element: <JavaScriptDebugger/> bool JavaScriptDebugger(); - // Navigates the activate tab to about:blank. - // XML element: <Navigate/> - // Optional Attributes: url="|address|" will navigate to |address| - bool Navigate(); - // Opens the About dialog. This dialog is modal so a majority of the test // can't be completed until it is dismissed. // XML element: <About/> @@ -246,10 +231,6 @@ class AutomatedUITest : public AutomatedUITestBase { // XML element: <UpArrow/> bool PressUpArrow(); - // Reload the active tab. Returns false on failure. - // XML element: <Reload/> - bool ReloadPage(); - // Activates the next tab on the active browser window. // XML element: <SelectNextTab/> bool SelectNextTab(); |