diff options
author | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-13 18:15:14 +0000 |
---|---|---|
committer | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-13 18:15:14 +0000 |
commit | 14c0a03a516a1904225068e135e30769f2b36cb4 (patch) | |
tree | a26111b7f2dbeae57caadb38717b0f260fe14c8d /chrome | |
parent | c799366e36aca3488f2941663cfc3448e77634c6 (diff) | |
download | chromium_src-14c0a03a516a1904225068e135e30769f2b36cb4.zip chromium_src-14c0a03a516a1904225068e135e30769f2b36cb4.tar.gz chromium_src-14c0a03a516a1904225068e135e30769f2b36cb4.tar.bz2 |
A few more UI commands: duplicate tab, open window.
Convert them to synchronous mode, move to
AutoMatedUITestBase, add unit test.
Review URL: http://codereview.chromium.org/66066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
7 files changed, 140 insertions, 46 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 9dee930..1f1adc2 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -422,6 +422,36 @@ class TabClosedNotificationObserver : public TabStripNotificationObserver { IPC::Message* reply_message_; }; +class BrowserOpenedNotificationObserver : public NotificationObserver { + public: + BrowserOpenedNotificationObserver(AutomationProvider* automation, + IPC::Message* reply_message) + : automation_(automation), + reply_message_(reply_message) { + registrar_.Add(this, NotificationType::BROWSER_OPENED, + NotificationService::AllSources()); + } + + ~BrowserOpenedNotificationObserver() { + } + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NotificationType::BROWSER_OPENED) { + automation_->Send(reply_message_); + delete this; + } else { + NOTREACHED(); + } + } + + private: + AutomationProvider* automation_; + IPC::Message* reply_message_; + NotificationRegistrar registrar_; +}; + class BrowserClosedNotificationObserver : public NotificationObserver { public: BrowserClosedNotificationObserver(Browser* browser, @@ -463,6 +493,7 @@ struct CommandNotification { }; const struct CommandNotification command_notifications[] = { + {IDC_DUPLICATE_TAB, NotificationType::TAB_PARENTED}, {IDC_NEW_TAB, NotificationType::TAB_PARENTED} }; @@ -922,8 +953,8 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { SetFilteredInet); IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory); - IPC_MESSAGE_HANDLER(AutomationMsg_OpenNewBrowserWindow, - OpenNewBrowserWindow); + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow, + OpenNewBrowserWindow); IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser); IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser, @@ -2106,7 +2137,9 @@ void AutomationProvider::GetDownloadDirectory( } } -void AutomationProvider::OpenNewBrowserWindow(bool show) { +void AutomationProvider::OpenNewBrowserWindow(bool show, + IPC::Message* reply_message) { + new BrowserOpenedNotificationObserver(this, reply_message); // We may have no current browser windows open so don't rely on // asking an existing browser to execute the IDC_NEWWINDOW command Browser* browser = Browser::Create(profile_); diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index eafd5fe..d704fa3 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -267,7 +267,7 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, int* autocomplete_edit_handle); // If |show| is true, call Show() on the new window after creating it. - void OpenNewBrowserWindow(bool show); + void OpenNewBrowserWindow(bool show, IPC::Message* reply_message); void ShowInterstitialPage(int tab_handle, const std::string& html_text, 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 3a3733b..5ad7f97 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.cc @@ -18,6 +18,42 @@ void AutomatedUITestBase::LogErrorMessage(const std::string& error) {} void AutomatedUITestBase::LogWarningMessage(const std::string& warning) {} +void AutomatedUITestBase::LogInfoMessage(const std::string& info) {} + +void AutomatedUITestBase::SetUp() { + UITest::SetUp(); + set_active_browser(automation()->GetBrowserWindow(0)); +} + +bool AutomatedUITestBase::DuplicateTab() { + return RunCommand(IDC_DUPLICATE_TAB); +} + +bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow() { + if (!automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)) { + LogWarningMessage("failed_to_open_new_browser_window"); + return false; + } + int num_browser_windows; + automation()->GetBrowserWindowCount(&num_browser_windows); + // Get the most recently opened browser window and activate the tab + // in order to activate this browser window. + scoped_ptr<BrowserProxy> browser( + automation()->GetBrowserWindow(num_browser_windows - 1)); + if (browser.get() == NULL) { + LogErrorMessage("browser_window_not_found"); + return false; + } + bool is_timeout; + if (!browser->ActivateTabWithTimeout(0, action_max_timeout_ms(), + &is_timeout)) { + LogWarningMessage("failed_to_activate_tab"); + return false; + } + set_active_browser(browser.release()); + 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. 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 d097ca8..3783def 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.h +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.h @@ -12,17 +12,29 @@ class AutomatedUITestBase : public UITest { AutomatedUITestBase(); virtual ~AutomatedUITestBase(); + virtual void SetUp(); + virtual void LogErrorMessage(const std::string &error); virtual void LogWarningMessage(const std::string &warning); + virtual void LogInfoMessage(const std::string &info); // Actions // NOTE: This list is sorted alphabetically. + // Duplicates the current tab. + // Returns true if a duplicated tab is added. + bool DuplicateTab(); + // Opens a new tab in the active window using an accelerator. // Returns true if a new tab is successfully opened. bool NewTab(); + // Opens a new browser window by calling automation()->OpenNewBrowserWindow. + // Then activates the tab opened in the new window. + // Returns true if window is successfully created. + bool OpenAndActivateNewBrowserWindow(); + // 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. @@ -42,6 +54,7 @@ class AutomatedUITestBase : public UITest { void set_active_browser(BrowserProxy* browser) { active_browser_.reset(browser); } + BrowserProxy* release_active_browser() { return active_browser_.release(); } BrowserProxy* active_browser() const { return active_browser_.get(); } private: 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 33d891f..7dcdb3f 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_test.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_test.cc @@ -7,8 +7,6 @@ #include "chrome/test/ui/ui_test.h" TEST_F(AutomatedUITestBase, NewTab) { - ASSERT_TRUE(automation()->WaitForInitialLoads()); - set_active_browser(automation()->GetBrowserWindow(0)); int tab_count; active_browser()->GetTabCount(&tab_count); ASSERT_EQ(1, tab_count); @@ -19,3 +17,52 @@ TEST_F(AutomatedUITestBase, NewTab) { active_browser()->GetTabCount(&tab_count); ASSERT_EQ(3, tab_count); } + +TEST_F(AutomatedUITestBase, DuplicateTab) { + int tab_count; + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); + DuplicateTab(); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(2, tab_count); + DuplicateTab(); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(3, tab_count); +} + +TEST_F(AutomatedUITestBase, OpenNewBrowserWindow) { + int num_browser_windows; + int tab_count; + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(1, num_browser_windows); + scoped_ptr<BrowserProxy>browser_1(release_active_browser()); + browser_1->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); + + ASSERT_TRUE(OpenAndActivateNewBrowserWindow()); + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(2, num_browser_windows); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); + NewTab(); + scoped_ptr<BrowserProxy>browser_2(release_active_browser()); + browser_1->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); + browser_2->GetTabCount(&tab_count); + ASSERT_EQ(2, tab_count); + + ASSERT_TRUE(OpenAndActivateNewBrowserWindow()); + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(3, num_browser_windows); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); + NewTab(); + NewTab(); + scoped_ptr<BrowserProxy>browser_3(release_active_browser()); + browser_1->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); + browser_2->GetTabCount(&tab_count); + ASSERT_EQ(2, tab_count); + browser_3->GetTabCount(&tab_count); + ASSERT_EQ(3, tab_count); +} diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index 42301ae..e162b62 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -391,30 +391,6 @@ bool AutomatedUITest::DoAction(const std::string & action) { return did_complete_action; } -bool AutomatedUITest::OpenAndActivateNewBrowserWindow() { - if (!automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)) { - AddWarningAttribute("failed_to_open_new_browser_window"); - return false; - } - int num_browser_windows; - automation()->GetBrowserWindowCount(&num_browser_windows); - // Get the most recently opened browser window and activate the tab - // in order to activate this browser window. - scoped_ptr<BrowserProxy> browser( - automation()->GetBrowserWindow(num_browser_windows - 1)); - if (browser.get() == NULL) { - AddErrorAttribute("browser_window_not_found"); - return false; - } - bool is_timeout; - if (!browser->ActivateTabWithTimeout(0, action_max_timeout_ms(), - &is_timeout)) { - AddWarningAttribute("failed_to_activate_tab"); - return false; - } - return true; -} - bool AutomatedUITest::BackButton() { return RunCommandAsync(IDC_BACK); } @@ -477,10 +453,6 @@ bool AutomatedUITest::CloseActiveTab() { return return_value; } -bool AutomatedUITest::DuplicateTab() { - return RunCommandAsync(IDC_DUPLICATE_TAB); -} - bool AutomatedUITest::FindInPage() { return RunCommandAsync(IDC_FIND); } @@ -921,6 +893,10 @@ void AutomatedUITest::LogWarningMessage(const std::string &warning) { AddWarningAttribute(warning); } +void AutomatedUITest::LogInfoMessage(const std::string &info) { + AddWarningAttribute(info); +} + std::wstring AutomatedUITest::GetMostRecentCrashDump() { std::wstring crash_dump_path; int file_count = 0; diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.h b/chrome/test/automated_ui_tests/automated_ui_tests.h index 4966c76..fc557cf 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.h +++ b/chrome/test/automated_ui_tests/automated_ui_tests.h @@ -142,11 +142,6 @@ class AutomatedUITest : public AutomatedUITestBase { // XML element: <CloseTab/> bool CloseActiveTab(); - // Duplicates the current tab. - // Returns true if call to activate the accelerator is successful. - // XML element: <DuplicateTab/> - bool DuplicateTab(); - // Opens one of the dialogs (chosen randomly) and exercises it. // XML element: <Dialog/> bool ExerciseDialog(); @@ -186,12 +181,6 @@ class AutomatedUITest : public AutomatedUITestBase { // Optional Attributes: url="|address|" will navigate to |address| bool Navigate(); - // Opens a new browser window by calling automation()->OpenNewBrowserWindow - // Then activates the tab opened in the new window. - // Returns true if window is successfully created. - // XML element: <OpenWindow/> - bool OpenAndActivateNewBrowserWindow(); - // 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/> @@ -445,8 +434,8 @@ class AutomatedUITest : public AutomatedUITestBase { // Override the message logging in AutomatedUITestBase. virtual void LogErrorMessage(const std::string &error); - virtual void LogWarningMessage(const std::string &warning); + virtual void LogInfoMessage(const std::string &info); // Overridden so that UI Test doesn't set up when the tests start. // We use DoAction("SetUp") to set up, because it logs it and makes |