diff options
author | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-08 00:04:27 +0000 |
---|---|---|
committer | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-08 00:04:27 +0000 |
commit | 4e41709d76504c389bb8c29b61a71773b5db6239 (patch) | |
tree | e26b7327785ff0afcba4126f2ea45276e4ca7e63 /chrome | |
parent | 0cbd8e66a343e15f144d88f6f984082936499b6f (diff) | |
download | chromium_src-4e41709d76504c389bb8c29b61a71773b5db6239.zip chromium_src-4e41709d76504c389bb8c29b61a71773b5db6239.tar.gz chromium_src-4e41709d76504c389bb8c29b61a71773b5db6239.tar.bz2 |
Skeleton setup for new Automated UI test framework.
- Add automated_ui_test_base.{cc,h} that defines an
AutomatedUITestBase class. This class can be used
for both UI test suites and automated UI test running
on ChromeBot.
- Add automated_ui_test_test and include it in UI
test suite so we can individually test all commands
provided in AutomatedUITestBase.
- Change AutomatedUITest to be a subclass of
AutomatedUITestBase. Move RunCommandAsync(),
RunCommand(), and NewTab() from AutomatedUITest
to AutomatedUITestBase. The plan is moving all
individual UI command functions (after they are
converted to sync mode) to AutomatedUITestBase so
they can be shared by UI test suites and automated
UI test.
- In automation_provider.cc, add a mapping mechanism
from command to notification type. This will make it
easy to add more command types.
Review URL: http://codereview.chromium.org/56190
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13312 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 56 | ||||
-rw-r--r-- | chrome/test/automated_ui_tests/automated_ui_test_base.cc | 63 | ||||
-rw-r--r-- | chrome/test/automated_ui_tests/automated_ui_test_base.h | 53 | ||||
-rw-r--r-- | chrome/test/automated_ui_tests/automated_ui_test_test.cc | 21 | ||||
-rw-r--r-- | chrome/test/automated_ui_tests/automated_ui_tests.cc | 45 | ||||
-rw-r--r-- | chrome/test/automated_ui_tests/automated_ui_tests.h | 31 | ||||
-rw-r--r-- | chrome/test/automated_ui_tests/automated_ui_tests.vcproj | 8 | ||||
-rw-r--r-- | chrome/test/ui/ui_tests.vcproj | 16 |
8 files changed, 221 insertions, 72 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index c8292ec..8a9aa98 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -453,22 +453,39 @@ class BrowserClosedNotificationObserver : public NotificationObserver { IPC::Message* reply_message_; }; +namespace { + +// Define mapping from command to notification +struct CommandNotification { + int command; + NotificationType::Type notification_type; +}; + +const struct CommandNotification command_notifications[] = { + {IDC_NEW_TAB, NotificationType::TAB_PARENTED} +}; + +} // namespace + class ExecuteBrowserCommandObserver : public NotificationObserver { public: - ExecuteBrowserCommandObserver( - AutomationProvider* automation, - NotificationType::Type notification_type, - IPC::Message* reply_message) + ExecuteBrowserCommandObserver(AutomationProvider* automation, + IPC::Message* reply_message) : automation_(automation), - notification_type_(notification_type), reply_message_(reply_message) { - registrar_.Add(this, notification_type, - NotificationService::AllSources()); } ~ExecuteBrowserCommandObserver() { } + bool Register(int command) { + if (!GetNotificationType(command, ¬ification_type_)) + return false; + registrar_.Add(this, notification_type_, + NotificationService::AllSources()); + return true; + } + virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { @@ -483,6 +500,20 @@ class ExecuteBrowserCommandObserver : public NotificationObserver { } private: + bool GetNotificationType(int command, NotificationType::Type* type) { + if (!type) + return false; + bool found = false; + for (unsigned int i = 0; i < arraysize(command_notifications); i++) { + if (command_notifications[i].command == command) { + *type = command_notifications[i].notification_type; + found = true; + break; + } + } + return found; + } + AutomationProvider* automation_; NotificationType::Type notification_type_; IPC::Message* reply_message_; @@ -1326,11 +1357,12 @@ void AutomationProvider::ExecuteBrowserCommandWithNotification( Browser* browser = browser_tracker_->GetResource(handle); if (browser->command_updater()->SupportsCommand(command) && browser->command_updater()->IsCommandEnabled(command)) { - // TODO(huanr): mapping command to notification type. - // For now only IDC_NEW_TAB uses this code path. - NotificationType::Type type = NotificationType::TAB_PARENTED; - new ExecuteBrowserCommandObserver(this, type, reply_message); - browser->ExecuteCommand(command); + ExecuteBrowserCommandObserver* observer = + new ExecuteBrowserCommandObserver(this, reply_message); + if (observer->Register(command)) + browser->ExecuteCommand(command); + else + delete observer; return; } } diff --git a/chrome/test/automated_ui_tests/automated_ui_test_base.cc b/chrome/test/automated_ui_tests/automated_ui_test_base.cc new file mode 100644 index 0000000..3a3733b --- /dev/null +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.cc @@ -0,0 +1,63 @@ +// 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 "base/scoped_ptr.h" +#include "chrome/app/chrome_dll_resource.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" + +AutomatedUITestBase::AutomatedUITestBase() {} + +AutomatedUITestBase::~AutomatedUITestBase() {} + +void AutomatedUITestBase::LogErrorMessage(const std::string& error) {} + +void AutomatedUITestBase::LogWarningMessage(const std::string& warning) {} + +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::RunCommandAsync(int browser_command) { + scoped_ptr<BrowserProxy> last_browser; + BrowserProxy* browser = active_browser(); + if (NULL == browser) { + last_browser.reset(automation()->GetLastActiveBrowserWindow()); + browser = last_browser.get(); + } + if (NULL == browser) { + LogErrorMessage("browser_window_not_found"); + return false; + } + + if (!browser->RunCommandAsync(browser_command)) { + LogWarningMessage("failure_running_browser_command"); + return false; + } + return true; +} + +bool AutomatedUITestBase::RunCommand(int browser_command) { + scoped_ptr<BrowserProxy> last_browser; + BrowserProxy* browser = active_browser(); + if (NULL == browser) { + last_browser.reset(automation()->GetLastActiveBrowserWindow()); + browser = last_browser.get(); + } + if (NULL == browser) { + LogErrorMessage("browser_window_not_found"); + return false; + } + + if (!browser->RunCommand(browser_command)) { + LogWarningMessage("failure_running_browser_command"); + return false; + } + return true; +} diff --git a/chrome/test/automated_ui_tests/automated_ui_test_base.h b/chrome/test/automated_ui_tests/automated_ui_test_base.h new file mode 100644 index 0000000..d097ca8 --- /dev/null +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.h @@ -0,0 +1,53 @@ +// 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. + +#ifndef CHROME_TEST_AUTOMATED_UI_TESTS_AUTOMATED_UI_TEST_BASE_H_ +#define CHROME_TEST_AUTOMATED_UI_TESTS_AUTOMATED_UI_TEST_BASE_H_ + +#include "chrome/test/ui/ui_test.h" + +class AutomatedUITestBase : public UITest { + protected: + AutomatedUITestBase(); + virtual ~AutomatedUITestBase(); + + virtual void LogErrorMessage(const std::string &error); + virtual void LogWarningMessage(const std::string &warning); + + // Actions + + // NOTE: This list is sorted alphabetically. + + // Opens a new tab in the active window using an accelerator. + // Returns true if a new tab is successfully opened. + bool NewTab(); + + // 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. + // Possible failures include the active window is not a browser window or + // the message to apply the accelerator fails. + bool RunCommandAsync(int browser_command); + + // Runs the specified browser command in the current active browser, wait + // and return until the command has finished executing. + // See browser_commands.cc for the list of commands. + // Returns true if the call is successfully dispatched and executed. + // Possible failures include the active window is not a browser window, or + // the message to apply the accelerator fails, or the command execution + // fails. + bool RunCommand(int browser_command); + + void set_active_browser(BrowserProxy* browser) { + active_browser_.reset(browser); + } + BrowserProxy* active_browser() const { return active_browser_.get(); } + + private: + scoped_ptr<BrowserProxy> active_browser_; + + DISALLOW_COPY_AND_ASSIGN(AutomatedUITestBase); +}; + +#endif // CHROME_TEST_AUTOMATED_UI_TESTS_AUTOMATED_UI_TEST_BASE_H_ diff --git a/chrome/test/automated_ui_tests/automated_ui_test_test.cc b/chrome/test/automated_ui_tests/automated_ui_test_test.cc new file mode 100644 index 0000000..33d891f --- /dev/null +++ b/chrome/test/automated_ui_tests/automated_ui_test_test.cc @@ -0,0 +1,21 @@ +// 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/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); + NewTab(); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(2, tab_count); + NewTab(); + active_browser()->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 d1fa0f1..42301ae 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -539,17 +539,6 @@ bool AutomatedUITest::Navigate() { return true; } -bool AutomatedUITest::NewTab() { - scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); - if (browser.get() == NULL) { - AddErrorAttribute("browser_window_not_found"); - return false; - } - // 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 AutomatedUITest::OpenAboutDialog() { return RunCommandAsync(IDC_ABOUT); } @@ -829,32 +818,6 @@ WindowProxy* AutomatedUITest::GetAndActivateWindowForBrowser( return window; } -bool AutomatedUITest::RunCommandAsync(int browser_command) { - scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); - if (browser.get() == NULL) { - AddErrorAttribute("browser_window_not_found"); - return false; - } - if (!browser->RunCommandAsync(browser_command)) { - AddWarningAttribute("failure_running_browser_command"); - return false; - } - return true; -} - -bool AutomatedUITest::RunCommand(int browser_command) { - scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); - if (browser.get() == NULL) { - AddErrorAttribute("browser_window_not_found"); - return false; - } - if (!browser->RunCommand(browser_command)) { - AddWarningAttribute("failure_running_browser_command"); - return false; - } - return true; -} - bool AutomatedUITest::SimulateKeyPressInActiveWindow(wchar_t key, int flags) { scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); @@ -950,6 +913,14 @@ void AutomatedUITest::AddErrorAttribute(const std::string &error) { xml_writer_.AddAttribute("error", error); } +void AutomatedUITest::LogErrorMessage(const std::string &error) { + AddErrorAttribute(error); +} + +void AutomatedUITest::LogWarningMessage(const std::string &warning) { + AddWarningAttribute(warning); +} + 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 a7b4c6d..4966c76 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.h +++ b/chrome/test/automated_ui_tests/automated_ui_tests.h @@ -101,12 +101,13 @@ // after each action. Useful for debugging. // +#include "chrome/test/automated_ui_tests/automated_ui_test_base.h" #include "chrome/test/ui/ui_test.h" -class AutomatedUITest : public UITest { +class AutomatedUITest : public AutomatedUITestBase { protected: AutomatedUITest(); - ~AutomatedUITest(); + virtual ~AutomatedUITest(); // Runs a reproduction of one set of actions, reporting whether they crash // or not. @@ -185,11 +186,6 @@ class AutomatedUITest : public UITest { // Optional Attributes: url="|address|" will navigate to |address| bool Navigate(); - // Opens a new tab in the active window using an accelerator. - // Returns true if call to activate the accelerator is successful. - // XML element: <NewTab/> - 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. @@ -388,22 +384,6 @@ class AutomatedUITest : public UITest { // window to the top. WindowProxy* GetAndActivateWindowForBrowser(BrowserProxy* browser); - // 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. - // Possible failures include the active window is not a browser window or - // the message to apply the accelerator fails. - bool RunCommandAsync(int browser_command); - - // Runs the specified browser command in the current active browser, wait - // and return until the command has finished executing. - // See browser_commands.cc for the list of commands. - // Returns true if the call is successfully dispatched and executed. - // Possible failures include the active window is not a browser window, or - // the message to apply the accelerator fails, or the command execution - // fails. - bool RunCommand(int browser_command); - // 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). @@ -463,6 +443,11 @@ class AutomatedUITest : public UITest { // with |update_total_crashes| set to true. bool DidCrash(bool update_total_crashes); + // Override the message logging in AutomatedUITestBase. + virtual void LogErrorMessage(const std::string &error); + + virtual void LogWarningMessage(const std::string &warning); + // 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 // it easier to check for crashes when we start the browser. diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.vcproj b/chrome/test/automated_ui_tests/automated_ui_tests.vcproj index 23188fc..ff233cc 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.vcproj +++ b/chrome/test/automated_ui_tests/automated_ui_tests.vcproj @@ -201,6 +201,14 @@ RelativePath=".\automated_ui_tests.h" > </File> + <File + RelativePath=".\automated_ui_test_base.cc" + > + </File> + <File + RelativePath=".\automated_ui_test_base.h" + > + </File> </Filter> </Files> <Globals> diff --git a/chrome/test/ui/ui_tests.vcproj b/chrome/test/ui/ui_tests.vcproj index 5a3ed55..48df244 100644 --- a/chrome/test/ui/ui_tests.vcproj +++ b/chrome/test/ui/ui_tests.vcproj @@ -403,6 +403,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_test.cc" + > + </File> + </Filter> + <Filter Name="TestSandbox" > <File |