Skip to content

Commit

Permalink
Added testing of Chromium dialogs to the automated ui tests.
Browse files Browse the repository at this point in the history
The new dialog command fires up a dialog (chosen randomly) and exercises it.

BUG=None
TEST=Run the automated_ui_test

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@333 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jcampan@google.com committed Aug 4, 2008
1 parent b334523 commit 856ac4b
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 54 deletions.
19 changes: 19 additions & 0 deletions chrome/browser/automation/automation_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowActiveRequest, IsWindowActive)
IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow);
IPC_MESSAGE_HANDLER(AutomationMsg_WindowHWNDRequest, GetWindowHWND)
IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandRequest,
ExecuteBrowserCommand)
IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBoundsRequest,
WindowGetViewBounds)
IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisibleRequest, SetWindowVisible)
Expand Down Expand Up @@ -1091,6 +1093,23 @@ void AutomationProvider::GetWindowHWND(const IPC::Message& message,
win32_handle));
}

void AutomationProvider::ExecuteBrowserCommand(const IPC::Message& message,
int handle,
int command) {

bool success = false;
if (browser_tracker_->ContainsHandle(handle)) {
Browser* browser = browser_tracker_->GetResource(handle);
if (browser->SupportsCommand(command) &&
browser->IsCommandEnabled(command)) {
browser->ExecuteCommand(command);
success = true;
}
}
Send(new AutomationMsg_WindowExecuteCommandResponse(message.routing_id(),
success));
}

void AutomationProvider::WindowGetViewBounds(const IPC::Message& message,
int handle,
int view_id,
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/automation/automation_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void GetLastActiveBrowserWindow(const IPC::Message& message);
void GetActiveWindow(const IPC::Message& message);
void GetWindowHWND(const IPC::Message& message, int handle);
void ExecuteBrowserCommand(const IPC::Message& message,
int handle,
int command);
void WindowGetViewBounds(const IPC::Message& message,
int handle,
int view_id,
Expand Down
141 changes: 108 additions & 33 deletions chrome/test/automated_ui_tests/automated_ui_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const wchar_t* const kOutputFilePathSwitch = L"output";

const wchar_t* const kDebugModeSwitch = L"debug";

const wchar_t* const kWaitSwitch = L"wait-after-action";

const wchar_t* const kDefaultInputFilePath = L"C:\\automated_ui_tests.txt";

const wchar_t* const kDefaultOutputFilePath
Expand All @@ -73,21 +75,43 @@ const int kTestDialogActionsToRun = 7;

// This subset of commands is used to test dialog boxes, which aren't likely
// to respond to most other commands.
std::string AutomatedUITest::test_dialog_possible_actions_[] = {
const std::string kTestDialogPossibleActions[] = {
"PressTabKey",
"PressEnterKey",
"PressSpaceBar",
"DownArrow"
};

// The list of dialogs that can be shown.
const std::string kDialogs[] = {
"About",
"Options",
"TaskManager",
"JavaScriptDebugger",
"JavaScriptConsole",
"ClearBrowsingData",
"Import",
"EditSearchEngines",
"ViewPasswords"
};

AutomatedUITest::AutomatedUITest()
: total_crashes_(0),
debug_logging_enabled_(false) {
debug_logging_enabled_(false),
post_action_delay_(0) {
show_window_ = true;
GetSystemTimeAsFileTime(&test_start_time_);
CommandLine parsed_command_line;
if (parsed_command_line.HasSwitch(kDebugModeSwitch))
debug_logging_enabled_ = true;
if (parsed_command_line.HasSwitch(kWaitSwitch)) {
std::wstring str = parsed_command_line.GetSwitchValue(kWaitSwitch);
if (str.empty()) {
post_action_delay_ = 1;
} else {
post_action_delay_ = static_cast<int>(StringToInt64(str));
}
}
}

AutomatedUITest::~AutomatedUITest() {}
Expand Down Expand Up @@ -283,14 +307,28 @@ bool AutomatedUITest::DoAction(const std::string & action) {
did_complete_action = ShowHistory();
} else if (LowerCaseEqualsASCII(action, "downloads")) {
did_complete_action = ShowDownloads();
} else if (LowerCaseEqualsASCII(action, "importsettings")) {
did_complete_action = ImportSettings();
} else if (LowerCaseEqualsASCII(action, "dialog")) {
did_complete_action = ExerciseDialog();
} else if (LowerCaseEqualsASCII(action, "viewpasswords")) {
did_complete_action = ViewPasswords();
} else if (LowerCaseEqualsASCII(action, "clearbrowserdata")) {
did_complete_action = ClearBrowserData();
} else if (LowerCaseEqualsASCII(action, "about")) {
did_complete_action = About();
} else if (LowerCaseEqualsASCII(action, "options")) {
did_complete_action = Options();
} else if (LowerCaseEqualsASCII(action, "taskmanager")) {
did_complete_action = TaskManager();
} else if (LowerCaseEqualsASCII(action, "clearbrowsingdata")) {
did_complete_action = ClearBrowserData();
} else if (LowerCaseEqualsASCII(action, "javascriptdebugger")) {
did_complete_action = JavaScriptDebugger();
} else if (LowerCaseEqualsASCII(action, "javascriptconsole")) {
did_complete_action = JavaScriptConsole();
} else if (LowerCaseEqualsASCII(action, "import")) {
did_complete_action = ImportSettings();
} else if (LowerCaseEqualsASCII(action, "editsearchengines")) {
did_complete_action = EditSearchEngines();
} else if (LowerCaseEqualsASCII(action, "viewpasswords")) {
did_complete_action = ViewPasswords();
} else if (LowerCaseEqualsASCII(action, "goofftherecord")) {
did_complete_action = GoOffTheRecord();
} else if (LowerCaseEqualsASCII(action, "pressescapekey")) {
Expand All @@ -315,10 +353,14 @@ bool AutomatedUITest::DoAction(const std::string & action) {
did_complete_action = UpArrow();
} else if (LowerCaseEqualsASCII(action, "downarrow")) {
did_complete_action = DownArrow();
} else if (LowerCaseEqualsASCII(action, "options")) {
did_complete_action = Options();
} else if (LowerCaseEqualsASCII(action, "testeditkeywords")) {
did_complete_action = TestEditKeywords();
} else if (LowerCaseEqualsASCII(action, "testtaskmanager")) {
did_complete_action = TestTaskManager();
} else if (LowerCaseEqualsASCII(action, "testoptions")) {
did_complete_action = TestOptions();
} else if (LowerCaseEqualsASCII(action, "testviewpasswords")) {
did_complete_action = TestViewPasswords();
} else if (LowerCaseEqualsASCII(action, "testclearbrowserdata")) {
Expand All @@ -343,6 +385,9 @@ bool AutomatedUITest::DoAction(const std::string & action) {
xml_writer_.AddAttribute("failed_to_complete", "yes");
xml_writer_.EndElement();

if (post_action_delay_)
::Sleep(1000 * post_action_delay_);

return did_complete_action;
}

Expand Down Expand Up @@ -391,7 +436,7 @@ bool AutomatedUITest::NewTab() {
&is_timeout);
// Apply accelerator and wait for a new tab to open, if either
// fails, return false. Apply Accelerator takes care of logging its failure.
bool return_value = ApplyAccelerator(IDC_NEWTAB);
bool return_value = RunCommand(IDC_NEWTAB);
if (!browser->WaitForTabCountToChange(
old_tab_count, &new_tab_count, kWaitForActionMaxMsec)) {
AddWarningAttribute("tab_count_failed_to_change");
Expand All @@ -401,11 +446,11 @@ bool AutomatedUITest::NewTab() {
}

bool AutomatedUITest::BackButton() {
return ApplyAccelerator(IDC_BACK);
return RunCommand(IDC_BACK);
}

bool AutomatedUITest::ForwardButton() {
return ApplyAccelerator(IDC_FORWARD);
return RunCommand(IDC_FORWARD);
}

bool AutomatedUITest::CloseActiveTab() {
Expand All @@ -424,7 +469,7 @@ bool AutomatedUITest::CloseActiveTab() {
// Avoid quitting the application by not closing the last window.
if (tab_count > 1) {
int new_tab_count;
return_value = browser->ApplyAccelerator(IDC_CLOSETAB);
return_value = browser->RunCommand(IDC_CLOSETAB);
// Wait for the tab to close before we continue.
if (!browser->WaitForTabCountToChange(
tab_count, &new_tab_count, kWaitForActionMaxMsec)) {
Expand All @@ -433,7 +478,7 @@ bool AutomatedUITest::CloseActiveTab() {
}
} else if (tab_count == 1 && browser_windows_count > 1) {
int new_window_count;
return_value = browser->ApplyAccelerator(IDC_CLOSETAB);
return_value = browser->RunCommand(IDC_CLOSETAB);
// Wait for the window to close before we continue.
if (!automation()->WaitForWindowCountToChange(
browser_windows_count, &new_window_count, kWaitForActionMaxMsec)) {
Expand Down Expand Up @@ -472,59 +517,79 @@ bool AutomatedUITest::OpenAndActivateNewBrowserWindow() {
}

bool AutomatedUITest::ReloadPage() {
return ApplyAccelerator(IDC_RELOAD);
return RunCommand(IDC_RELOAD);
}

bool AutomatedUITest::StarPage() {
return ApplyAccelerator(IDC_STAR);
return RunCommand(IDC_STAR);
}

bool AutomatedUITest::FindInPage() {
return ApplyAccelerator(IDC_FIND);
return RunCommand(IDC_FIND);
}

bool AutomatedUITest::SelectNextTab() {
return ApplyAccelerator(IDC_SELECT_NEXT_TAB);
return RunCommand(IDC_SELECT_NEXT_TAB);
}

bool AutomatedUITest::SelectPreviousTab() {
return ApplyAccelerator(IDC_SELECT_PREV_TAB);
return RunCommand(IDC_SELECT_PREV_TAB);
}

bool AutomatedUITest::ZoomPlus() {
return ApplyAccelerator(IDC_ZOOM_PLUS);
return RunCommand(IDC_ZOOM_PLUS);
}

bool AutomatedUITest::ZoomMinus() {
return ApplyAccelerator(IDC_ZOOM_MINUS);
return RunCommand(IDC_ZOOM_MINUS);
}

bool AutomatedUITest::ShowHistory() {
return ApplyAccelerator(IDC_SHOW_HISTORY);
return RunCommand(IDC_SHOW_HISTORY);
}

bool AutomatedUITest::ShowDownloads() {
return ApplyAccelerator(IDC_SHOW_DOWNLOADS);
return RunCommand(IDC_SHOW_DOWNLOADS);
}

bool AutomatedUITest::ImportSettings() {
return ApplyAccelerator(IDC_IMPORT_SETTINGS);
return RunCommand(IDC_IMPORT_SETTINGS);
}

bool AutomatedUITest::EditSearchEngines() {
return RunCommand(IDC_EDIT_SEARCH_ENGINES);
}

bool AutomatedUITest::ViewPasswords() {
return ApplyAccelerator(IDC_VIEW_PASSWORDS);
return RunCommand(IDC_VIEW_PASSWORDS);
}

bool AutomatedUITest::ClearBrowserData() {
return ApplyAccelerator(IDC_CLEAR_BROWSING_DATA);
return RunCommand(IDC_CLEAR_BROWSING_DATA);
}

bool AutomatedUITest::TaskManager() {
return ApplyAccelerator(IDC_TASKMANAGER);
return RunCommand(IDC_TASKMANAGER);
}

bool AutomatedUITest::Options() {
return RunCommand(IDC_OPTIONS);
}

bool AutomatedUITest::JavaScriptConsole() {
return RunCommand(IDC_SHOW_JS_CONSOLE);
}

bool AutomatedUITest::JavaScriptDebugger() {
return RunCommand(IDC_DEBUGGER);
}

bool AutomatedUITest::About() {
return RunCommand(IDC_ABOUT);
}

bool AutomatedUITest::GoOffTheRecord() {
return ApplyAccelerator(IDC_GOOFFTHERECORD);
return RunCommand(IDC_GOOFFTHERECORD);
}

bool AutomatedUITest::PressEscapeKey() {
Expand Down Expand Up @@ -570,6 +635,11 @@ bool AutomatedUITest::TestTaskManager() {
return TestDialog(kTestDialogActionsToRun);
}

bool AutomatedUITest::TestOptions() {
DoAction("Options");
return TestDialog(kTestDialogActionsToRun);
}

bool AutomatedUITest::TestViewPasswords() {
DoAction("ViewPasswords");
return TestDialog(kTestDialogActionsToRun);
Expand All @@ -585,13 +655,20 @@ bool AutomatedUITest::TestImportSettings() {
return TestDialog(kTestDialogActionsToRun);
}

bool AutomatedUITest::ExerciseDialog() {
int index = rand_util::RandInt(0, arraysize(kDialogs) - 1);
return DoAction(kDialogs[index]) && TestDialog(kTestDialogActionsToRun);
}

bool AutomatedUITest::TestDialog(int num_actions) {
bool return_value = true;

for (int i = 0; i < num_actions; i++) {
int action_index = rand_util::RandInt(0, kNumTestDialogActions - 1);
int action_index = rand_util::RandInt(i == 0 ? 1 : 0,
arraysize(kTestDialogPossibleActions)
- 1);
return_value = return_value &&
DoAction(test_dialog_possible_actions_[action_index]);
DoAction(kTestDialogPossibleActions[action_index]);
if (DidCrash(false))
break;
}
Expand Down Expand Up @@ -711,23 +788,21 @@ WindowProxy* AutomatedUITest::GetAndActivateWindowForBrowser(
return window;
}

bool AutomatedUITest::ApplyAccelerator(int id) {
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->ApplyAccelerator(id)) {
AddWarningAttribute("failure_applying_accelerator");
if (!browser->RunCommand(browser_command)) {
AddWarningAttribute("failure_running_browser_command");
return false;
}
return true;
}

bool AutomatedUITest::SimulateKeyPressInActiveWindow(wchar_t key, int flags) {
scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow());
scoped_ptr<WindowProxy> window(
GetAndActivateWindowForBrowser(browser.get()));
scoped_ptr<WindowProxy> window(automation()->GetActiveWindow());
if (window.get() == NULL) {
AddErrorAttribute("active_window_not_found");
return false;
Expand Down
Loading

0 comments on commit 856ac4b

Please sign in to comment.