Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4688)

Unified Diff: chrome/test/automated_ui_tests/automated_ui_test_base.cc

Issue 99268: Making CloseWindow and CloseTab automation API... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/automated_ui_tests/automated_ui_test_base.cc
===================================================================
--- chrome/test/automated_ui_tests/automated_ui_test_base.cc (revision 14951)
+++ chrome/test/automated_ui_tests/automated_ui_test_base.cc (working copy)
@@ -25,6 +25,54 @@
set_active_browser(automation()->GetBrowserWindow(0));
}
+bool AutomatedUITestBase::CloseActiveTab() {
+ BrowserProxy* browser = active_browser();
+ int tab_count;
+ bool is_timeout;
+ browser->GetTabCountWithTimeout(&tab_count,
+ action_max_timeout_ms(),
+ &is_timeout);
+
+ if (is_timeout) {
+ LogInfoMessage("get_tab_count_time_out");
Finnur 2009/05/01 04:05:49 nit: add a 'd' after time (timed_out)
+ return false;
+ }
+
+ if (tab_count > 1) {
+ scoped_ptr<TabProxy> tab(GetActiveTab());
+ // Wait until tab is closed
Finnur 2009/05/01 04:05:49 nit: End the comment in a period.
+ return tab->Close(true);
+ } else if (tab_count == 1) {
+ // Synchronously close the window if it is not the last window.
+ return CloseActiveWindow();
+ } else {
+ LogInfoMessage("invalid_tab_count");
+ return false;
+ }
+}
+
+bool AutomatedUITestBase::CloseActiveWindow() {
+ int browser_windows_count = 0;
+ if (!automation()->GetNormalBrowserWindowCount(&browser_windows_count))
+ return false;
+ // Avoid quitting the application by not closing the last window.
+ if (browser_windows_count < 2)
+ return false;
+ bool application_closed;
+ CloseBrowser(active_browser(), &application_closed);
+ if (application_closed) {
+ LogErrorMessage("Application closed unexpectedly.");
+ return false;
+ }
+ BrowserProxy* browser = automation()->FindNormalBrowserWindow();
+ if (browser == NULL) {
+ LogErrorMessage("Can't find browser window.");
+ return false;
+ }
+ set_active_browser(browser);
+ return true;
+}
+
bool AutomatedUITestBase::DuplicateTab() {
return RunCommand(IDC_DUPLICATE_TAB);
}
@@ -91,3 +139,18 @@
}
return true;
}
+
+TabProxy* AutomatedUITestBase::GetActiveTab() {
+ BrowserProxy* browser = active_browser();
+ if (browser == NULL) {
+ LogErrorMessage("browser_window_not_found");
+ return false;
+ }
+
+ bool did_timeout;
+ TabProxy* tab =
+ browser->GetActiveTabWithTimeout(action_max_timeout_ms(), &did_timeout);
+ if (did_timeout)
+ return NULL;
+ return tab;
+}

Powered by Google App Engine
This is Rietveld 408576698